diff --git a/README.md b/README.md index e0bcbb8..03b4617 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ -= OSC-Variant +# OSC-Variant Anwendung zum Anpassen einer OSC-Datei an einen Standort. -== Funktion +## Funktion Diese Anwendung passt eine OSC-Datei so an, dass (standortbezogene) Formularvarianten für Formularverweise verwendet werden. diff --git a/src/main.rs b/src/main.rs index 62889f9..9655513 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,9 @@ fn main() { let contents = fs::read_to_string(cli.input) .expect("Should have been able to read the file"); - let xml: OnkostarEditor = from_str(contents.as_str()).unwrap(); + let mut xml: OnkostarEditor = from_str(contents.as_str()).unwrap(); + + xml.apply_variant(); let mut buf = String::new(); diff --git a/src/model/data_form.rs b/src/model/data_form.rs index fb29d9e..bba9f33 100644 --- a/src/model/data_form.rs +++ b/src/model/data_form.rs @@ -144,6 +144,22 @@ pub struct DataForm { ansichten: Option } +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()) + } + } + } + }) + } + } +} + #[derive(Serialize, Deserialize, Debug)] pub struct DataCatalogues { #[serde(rename = "DataCatalogue")] diff --git a/src/model/onkostar_editor.rs b/src/model/onkostar_editor.rs index 311100a..3956eb8 100644 --- a/src/model/onkostar_editor.rs +++ b/src/model/onkostar_editor.rs @@ -37,6 +37,17 @@ pub struct OnkostarEditor { editor: Editor } +impl OnkostarEditor { + pub fn apply_variant(&mut self) { + self.editor.data_form.iter_mut().for_each(|data_form| { + data_form.apply_variant(); + }); + self.editor.unterformular.iter_mut().for_each(|data_form| { + data_form.apply_variant(); + }) + } +} + #[derive(Serialize, Deserialize, Debug)] pub struct InfoXML { #[serde(rename = "DatumXML")] diff --git a/src/model/unterformular.rs b/src/model/unterformular.rs index 1c50936..4945671 100644 --- a/src/model/unterformular.rs +++ b/src/model/unterformular.rs @@ -152,6 +152,22 @@ pub struct Unterformular { ansichten: Option } +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()) + } + } + } + }) + } + } +} + #[derive(Serialize, Deserialize, Debug)] pub struct DataCatalogues { #[serde(rename = "DataCatalogue")]