From eceafe18be25af7486821d4417d54bc100cca7bb Mon Sep 17 00:00:00 2001 From: Paul-Christian Volkmer Date: Sat, 3 Jun 2023 17:50:27 +0200 Subject: [PATCH] Apply changes from profile to data --- examples/dnpm-ukw.yml | 31 ++++++++++++++++++++++++++ src/main.rs | 13 ++++++++++- src/model/data_form.rs | 42 +++++++++++++++++++++++++----------- src/model/onkostar_editor.rs | 7 +++--- src/model/unterformular.rs | 42 +++++++++++++++++++++++++----------- src/profile.rs | 20 ++++++++--------- 6 files changed, 115 insertions(+), 40 deletions(-) create mode 100644 examples/dnpm-ukw.yml diff --git a/examples/dnpm-ukw.yml b/examples/dnpm-ukw.yml new file mode 100644 index 0000000..3bd59e2 --- /dev/null +++ b/examples/dnpm-ukw.yml @@ -0,0 +1,31 @@ +forms: + - name: 'DNPM Klinik/Anamnese' + form_references: + - name: MTB + referenced_data_form: 'OS.Tumorkonferenz.VarianteUKW' + anzeige_auswahl: 'MTB vom {Datum}' + - name: 'DNPM Therapieplan' + form_references: + - name: referstemtb + referenced_data_form: 'OS.Tumorkonferenz.VarianteUKW' + anzeige_auswahl: 'MTB vom {Datum}' + - name: 'DNPM Therapieplan' + form_references: + - name: reftkhumangenber + referenced_data_form: 'OS.Tumorkonferenz.VarianteUKW' + anzeige_auswahl: 'MTB vom {Datum}' + - name: 'DNPM Therapieplan' + form_references: + - name: reftkreevaluation + referenced_data_form: 'OS.Tumorkonferenz.VarianteUKW' + anzeige_auswahl: 'MTB vom {Datum}' + - name: 'DNPM UF Einzelempfehlung' + form_references: + - name: mtb + referenced_data_form: 'OS.Tumorkonferenz.VarianteUKW' + anzeige_auswahl: 'MTB vom {Datum}' + - name: 'DNPM UF Rebiopsie' + form_references: + - name: reftumorkonferenz + referenced_data_form: 'OS.Tumorkonferenz.VarianteUKW' + anzeige_auswahl: 'MTB vom {Datum}' \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index a4cec95..f988942 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,7 @@ use std::fs; use std::fs::OpenOptions; use std::io::Write; use std::ops::Add; +use std::str::FromStr; use clap::{Parser, Subcommand}; use quick_xml::de::from_str; @@ -33,6 +34,7 @@ use quick_xml::se::Serializer; use serde::Serialize; use crate::model::onkostar_editor::OnkostarEditor; +use crate::profile::Profile; mod model; mod profile; @@ -85,7 +87,16 @@ fn main() { fs::read_to_string(inputfile).expect("Should have been able to read the file"); if let Ok(mut data) = from_str::(contents.as_str()) { - data.apply_variant(); + if let Some(profile) = profile { + let profile = + fs::read_to_string(profile).expect("Should have been able to read profile"); + if let Ok(profile) = Profile::from_str(profile.as_str()) { + data.apply_profile(&profile); + } else { + eprintln!("Kann Profildatei nicht lesen!"); + return; + } + } let mut buf = String::new(); diff --git a/src/model/data_form.rs b/src/model/data_form.rs index 5328722..96d18d5 100644 --- a/src/model/data_form.rs +++ b/src/model/data_form.rs @@ -26,6 +26,7 @@ use serde::{Deserialize, Serialize}; use crate::model::Ordner; use crate::model::{Ansichten, Entries, Filter, MenuCategory, PlausibilityRules, Script}; +use crate::profile::Profile; #[derive(Serialize, Deserialize, Debug)] #[serde(deny_unknown_fields)] @@ -146,19 +147,34 @@ pub struct DataForm { } impl DataForm { - pub fn apply_variant(&mut self) { - if self.name.starts_with("DNPM") { - self.entries.entry.iter_mut().for_each(|mut entry| { - if entry.type_ == "formReference" { - if let Some(referenced_data_form) = &entry.referenced_data_form { - if referenced_data_form == "OS.Tumorkonferenz" { - entry.referenced_data_form = - Some("OS.Tumorkonferenz.VarianteUKW".to_string()) - } - } - } - }) - } + pub fn apply_profile(&mut self, profile: &Profile) { + profile.forms.iter().for_each(|profile_form| { + if self.name == profile_form.name { + self.entries.entry.iter_mut().for_each(|entry| { + profile_form + .form_references + .iter() + .for_each(|form_reference| { + if entry.type_ == "formReference" && entry.name == form_reference.name { + if let Some(profile_referenced_data_form) = + &form_reference.referenced_data_form + { + entry.referenced_data_form = + Some(profile_referenced_data_form.clone()) + } + if let Some(profile_anzeige) = &form_reference.anzeige { + entry.anzeige = profile_anzeige.clone() + } + if let Some(profile_anzeige_auswahl) = + &form_reference.anzeige_auswahl + { + entry.anzeige_auswahl = Some(profile_anzeige_auswahl.clone()) + } + } + }); + }) + } + }); } pub fn to_listed_string(&self) -> String { diff --git a/src/model/onkostar_editor.rs b/src/model/onkostar_editor.rs index 3e7f613..7087aaf 100644 --- a/src/model/onkostar_editor.rs +++ b/src/model/onkostar_editor.rs @@ -29,6 +29,7 @@ use crate::model::data_catalogue::DataCatalogue; use crate::model::data_form::DataForm; use crate::model::property_catalogue::PropertyCatalogue; use crate::model::unterformular::Unterformular; +use crate::profile::Profile; #[derive(Serialize, Deserialize, Debug)] #[serde(deny_unknown_fields)] @@ -40,12 +41,12 @@ pub struct OnkostarEditor { } impl OnkostarEditor { - pub fn apply_variant(&mut self) { + pub fn apply_profile(&mut self, profile: &Profile) { self.editor.data_form.iter_mut().for_each(|data_form| { - data_form.apply_variant(); + data_form.apply_profile(profile); }); self.editor.unterformular.iter_mut().for_each(|data_form| { - data_form.apply_variant(); + data_form.apply_profile(profile); }) } diff --git a/src/model/unterformular.rs b/src/model/unterformular.rs index cf6bad9..72ac737 100644 --- a/src/model/unterformular.rs +++ b/src/model/unterformular.rs @@ -27,6 +27,7 @@ use serde::{Deserialize, Serialize}; use crate::model::Ordner; use crate::model::{Ansichten, Entries, Filter, MenuCategory, PlausibilityRules, Script}; +use crate::profile::Profile; #[derive(Serialize, Deserialize, Debug)] #[serde(deny_unknown_fields)] @@ -155,19 +156,34 @@ pub struct Unterformular { } impl Unterformular { - pub fn apply_variant(&mut self) { - if self.name.starts_with("DNPM") { - self.entries.entry.iter_mut().for_each(|mut entry| { - if entry.type_ == "formReference" { - if let Some(referenced_data_form) = &entry.referenced_data_form { - if referenced_data_form == "OS.Tumorkonferenz" { - entry.referenced_data_form = - Some("OS.Tumorkonferenz.VarianteUKW".to_string()) - } - } - } - }) - } + pub fn apply_profile(&mut self, profile: &Profile) { + profile.forms.iter().for_each(|profile_form| { + if self.name == profile_form.name { + self.entries.entry.iter_mut().for_each(|entry| { + profile_form + .form_references + .iter() + .for_each(|form_reference| { + if entry.type_ == "formReference" && entry.name == form_reference.name { + if let Some(profile_referenced_data_form) = + &form_reference.referenced_data_form + { + entry.referenced_data_form = + Some(profile_referenced_data_form.clone()) + } + if let Some(profile_anzeige) = &form_reference.anzeige { + entry.anzeige = profile_anzeige.clone() + } + if let Some(profile_anzeige_auswahl) = + &form_reference.anzeige_auswahl + { + entry.anzeige_auswahl = Some(profile_anzeige_auswahl.clone()) + } + } + }); + }) + } + }); } pub fn to_listed_string(&self) -> String { diff --git a/src/profile.rs b/src/profile.rs index 193cfc9..b754500 100644 --- a/src/profile.rs +++ b/src/profile.rs @@ -26,8 +26,8 @@ use serde::Deserialize; use std::str::FromStr; #[derive(Deserialize)] -struct Profile { - forms: Vec
, +pub struct Profile { + pub forms: Vec, } impl FromStr for Profile { @@ -42,17 +42,17 @@ impl FromStr for Profile { } #[derive(Deserialize)] -struct Form { - name: String, - form_references: Vec, +pub struct Form { + pub name: String, + pub form_references: Vec, } #[derive(Deserialize)] -struct FormReference { - name: String, - referenced_data_form: Option, - anzeige: Option, - anzeige_auswahl: Option, +pub struct FormReference { + pub name: String, + pub referenced_data_form: Option, + pub anzeige: Option, + pub anzeige_auswahl: Option, } #[cfg(test)]