cima_rs/endpoints/
clinical_descriptions.rs1use crate::api_client::CimaClient;
2use crate::models::ClinicalDescription;
3use anyhow::{Context, Result};
4
5#[derive(Debug, Default, Clone)]
7pub struct SearchClinicalDescriptionParams {
8 pub active_ingredient: Option<String>,
10 pub active_ingredient_id: Option<i32>,
12 pub dose: Option<String>,
14 pub pharmaceutical_form: Option<String>,
16 pub atc: Option<String>,
18 pub name: Option<String>,
20 pub tree_mode: bool,
22 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 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}