use crate::connection::MDRSConnection; use crate::models::laboratory::{Laboratories, Laboratory}; use serde::Deserialize; /// API response is a flat list; we wrap it in `Laboratories { items }` for cache compatibility. #[derive(Debug, Deserialize)] struct LabListResponse { results: Option>, } impl MDRSConnection { pub async fn list_laboratories(&self) -> Result { let resp = self.get("v3/laboratories/").await?; if !resp.status().is_success() { anyhow::bail!("List laboratories failed: {}", resp.status()); } // The API may return a paginated object or a direct array let text = resp.text().await?; let items: Vec = if let Ok(list) = serde_json::from_str::>(&text) { list } else if let Ok(paged) = serde_json::from_str::(&text) { paged.results.unwrap_or_default() } else { vec![] }; Ok(Laboratories { items }) } }