cima_rs/endpoints/
presentations.rs1use crate::api_client::CimaClient;
2use crate::models::{Presentation, PresentationSummary};
3use anyhow::{Context, Result};
4
5#[derive(Debug, Default, Clone)]
7pub struct SearchPresentationsParams {
8 pub national_code: Option<String>,
10 pub registration_number: Option<String>,
12 pub vmp: Option<String>,
14 pub vmpp: Option<String>,
16 pub active_ingredient_id: Option<i32>,
18 pub commercialized: Option<u8>,
20 pub narcotic: Option<u8>,
22 pub psychotropic: Option<u8>,
24 pub narcotic_or_psychotropic: Option<u8>,
26 pub page: Option<u32>,
28}
29
30impl SearchPresentationsParams {
31 pub fn new() -> Self {
32 Self::default()
33 }
34
35 pub(crate) fn to_query_params(&self) -> Vec<(&str, String)> {
36 let mut params = Vec::new();
37
38 if let Some(ref v) = self.national_code {
39 params.push(("cn", v.clone()));
40 }
41 if let Some(ref v) = self.registration_number {
42 params.push(("nregistro", v.clone()));
43 }
44 if let Some(ref v) = self.vmp {
45 params.push(("vmp", v.clone()));
46 }
47 if let Some(ref v) = self.vmpp {
48 params.push(("vmpp", v.clone()));
49 }
50 if let Some(v) = self.active_ingredient_id {
51 params.push(("idpractiv1", v.to_string()));
52 }
53 if let Some(v) = self.commercialized {
54 params.push(("comerc", v.to_string()));
55 }
56 if let Some(v) = self.narcotic {
57 params.push(("estupefaciente", v.to_string()));
58 }
59 if let Some(v) = self.psychotropic {
60 params.push(("psicotropo", v.to_string()));
61 }
62 if let Some(v) = self.narcotic_or_psychotropic {
63 params.push(("estuopsico", v.to_string()));
64 }
65 if let Some(v) = self.page {
66 params.push(("pagina", v.to_string()));
67 }
68
69 params
70 }
71}
72
73impl CimaClient {
74 pub async fn get_presentation(&self, national_code: &str) -> Result<Presentation> {
76 let endpoint = format!("presentacion/{}", national_code);
77 self.get(&endpoint)
78 .await
79 .context("Failed to get presentation")
80 }
81
82 pub async fn search_presentations(
86 &self,
87 params: &SearchPresentationsParams,
88 ) -> Result<crate::models::PaginatedResponse<PresentationSummary>> {
89 let query_params = params.to_query_params();
90
91 self.get_with_params("presentaciones", &query_params)
92 .await
93 .context("Failed to search presentations")
94 }
95}