From 4ef1fd47deb70b5198de7fca4945d6e5cf7ee637 Mon Sep 17 00:00:00 2001 From: Patrick Skowronek Date: Tue, 29 Oct 2024 14:38:13 +0100 Subject: [PATCH] fixed optional json --- src/fhir.rs | 8 +++++++- src/main.rs | 23 +++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/fhir.rs b/src/fhir.rs index 66005e2..632c207 100644 --- a/src/fhir.rs +++ b/src/fhir.rs @@ -24,14 +24,20 @@ pub struct Entry { #[serde(rename_all = "camelCase")] pub struct Resource { pub meta: Meta, + #[serde(skip_serializing_if = "Option::is_none")] pub birth_date: Option, pub resource_type: String, + #[serde(skip_serializing_if = "Option::is_none")] pub gender: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub name: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub deceased_date_time: Option, + #[serde(skip_serializing_if = "Option::is_none")] pub deceased: Option, pub id: String, - pub identifier: Vec, + pub identifier: Option>, + #[serde(skip_serializing_if = "Option::is_none")] pub extension: Option>, } diff --git a/src/main.rs b/src/main.rs index 2811d5b..a3510de 100644 --- a/src/main.rs +++ b/src/main.rs @@ -69,13 +69,14 @@ async fn main() -> anyhow::Result<()> { for project in projects { println!("Adding project information to patients of {}", project.name); for id_type in ["L", "G"] { - let token = match ma_token_request(&mainzel_client, &session_id, &project, &id_type).await { - Ok(url) => url, - Err(_e) => { - eprintln!("Project {} not configured in mainzelliste", project.name); - continue; - } - }; + let token = + match ma_token_request(&mainzel_client, &session_id, &project, &id_type).await { + Ok(url) => url, + Err(_e) => { + eprintln!("Project {} not configured in mainzelliste", project.name); + continue; + } + }; let Ok(patients) = get_patient(&mainzel_client, token).await else { println!("Did not found any patients from project {}", project.name); continue; @@ -101,11 +102,9 @@ async fn main() -> anyhow::Result<()> { if !extension.contains(&project_extension) { extension.push(project_extension); } - } else { - fhir_patient.extension = Some(vec![project_extension]); + post_patient_to_fhir_server(&fhir_client, fhir_patient).await; + println!("Added project to Patient {}", patient); } - post_patient_to_fhir_server(&fhir_client, fhir_patient).await; - println!("Added project to Patient {}", patient); } Err(e) => { eprintln!("Did not find patient with pseudonym {}\n{:#}", &patient, e); @@ -142,7 +141,7 @@ async fn ma_token_request( client: &Client, session_id: &str, project: &Project, - id_type: &str + id_type: &str, ) -> anyhow::Result { let mrdataids = mainzelliste::SearchId { id_string: "*".to_owned(),