mirror of
https://github.com/pcvolkmer/osc-variant.git
synced 2025-07-01 16:32:54 +00:00
Apply changes from profile to data
This commit is contained in:
31
examples/dnpm-ukw.yml
Normal file
31
examples/dnpm-ukw.yml
Normal file
@ -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}'
|
13
src/main.rs
13
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::<OnkostarEditor>(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();
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -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);
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
@ -26,8 +26,8 @@ use serde::Deserialize;
|
||||
use std::str::FromStr;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Profile {
|
||||
forms: Vec<Form>,
|
||||
pub struct Profile {
|
||||
pub forms: Vec<Form>,
|
||||
}
|
||||
|
||||
impl FromStr for Profile {
|
||||
@ -42,17 +42,17 @@ impl FromStr for Profile {
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct Form {
|
||||
name: String,
|
||||
form_references: Vec<FormReference>,
|
||||
pub struct Form {
|
||||
pub name: String,
|
||||
pub form_references: Vec<FormReference>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct FormReference {
|
||||
name: String,
|
||||
referenced_data_form: Option<String>,
|
||||
anzeige: Option<String>,
|
||||
anzeige_auswahl: Option<String>,
|
||||
pub struct FormReference {
|
||||
pub name: String,
|
||||
pub referenced_data_form: Option<String>,
|
||||
pub anzeige: Option<String>,
|
||||
pub anzeige_auswahl: Option<String>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
Reference in New Issue
Block a user