Skip to main content

cima_rs/endpoints/
clinical_descriptions.rs

1use crate::api_client::CimaClient;
2use crate::models::ClinicalDescription;
3use anyhow::{Context, Result};
4
5/// VMP/VMPP search parameters
6#[derive(Debug, Default, Clone)]
7pub struct SearchClinicalDescriptionParams {
8    /// Active ingredient name
9    pub active_ingredient: Option<String>,
10    /// Active ingredient ID
11    pub active_ingredient_id: Option<i32>,
12    /// Dose
13    pub dose: Option<String>,
14    /// Pharmaceutical form name
15    pub pharmaceutical_form: Option<String>,
16    /// ATC code or description
17    pub atc: Option<String>,
18    /// Medication name
19    pub name: Option<String>,
20    /// If included, returns results in hierarchical mode
21    pub tree_mode: bool,
22    /// Page number
23    pub page: Option<u32>,
24}
25
26impl SearchClinicalDescriptionParams {
27    pub fn new() -> Self {
28        Self::default()
29    }
30
31    pub(crate) fn to_query_params(&self) -> Vec<(&str, String)> {
32        let mut params = Vec::new();
33
34        if let Some(ref v) = self.active_ingredient {
35            params.push(("practiv1", v.clone()));
36        }
37        if let Some(v) = self.active_ingredient_id {
38            params.push(("idpractiv1", v.to_string()));
39        }
40        if let Some(ref v) = self.dose {
41            params.push(("dosis", v.clone()));
42        }
43        if let Some(ref v) = self.pharmaceutical_form {
44            params.push(("forma", v.clone()));
45        }
46        if let Some(ref v) = self.atc {
47            params.push(("atc", v.clone()));
48        }
49        if let Some(ref v) = self.name {
50            params.push(("nombre", v.clone()));
51        }
52        if self.tree_mode {
53            params.push(("modoArbol", "true".to_string()));
54        }
55        if let Some(v) = self.page {
56            params.push(("pagina", v.to_string()));
57        }
58
59        params
60    }
61}
62
63impl CimaClient {
64    /// Search clinical descriptions (VMP/VMPP)
65    ///
66    /// Returns a paginated response with clinical descriptions
67    pub async fn search_clinical_descriptions(
68        &self,
69        params: &SearchClinicalDescriptionParams,
70    ) -> Result<crate::models::PaginatedResponse<ClinicalDescription>> {
71        let query_params = params.to_query_params();
72
73        self.get_with_params("vmpp", &query_params)
74            .await
75            .context("Failed to search clinical descriptions")
76    }
77}