commit 193b01dc92f2734ac7d99515628dd08ce6e4ea11 Author: Paul-Christian Volkmer Date: Thu Jun 1 19:31:36 2023 +0200 Initial import diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d070336 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +.idea/* +/target + +*.iml diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..fc4ca3b --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,154 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "anstyle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41ed9a86bf92ae6580e0a31281f65a1b1d867c0cc68d5346e2ae128dddfa6a7d" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "clap" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93aae7a4192245f70fe75dd9157fc7b4a5bf53e88d30bd4396f7d8f9284d5acc" +dependencies = [ + "clap_builder", + "clap_derive", + "once_cell", +] + +[[package]] +name = "clap_builder" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f423e341edefb78c9caba2d9c7f7687d0e72e89df3ce3394554754393ac3990" +dependencies = [ + "anstyle", + "bitflags", + "clap_lex", +] + +[[package]] +name = "clap_derive" +version = "4.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "191d9573962933b4027f932c600cd252ce27a8ad5979418fe78e43c07996f27b" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2da6da31387c7e4ef160ffab6d5e7f00c42626fe39aea70a7b0f1773f7dd6c1b" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "memchr" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" + +[[package]] +name = "once_cell" +version = "1.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9670a07f94779e00908f3e686eab508878ebb390ba6e604d3a284c00e8d0487b" + +[[package]] +name = "osc-variant" +version = "0.1.0" +dependencies = [ + "clap", + "quick-xml", + "serde", + "xml-rs", +] + +[[package]] +name = "proc-macro2" +version = "1.0.59" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aeca18b86b413c660b781aa319e4e2648a3e6f9eadc9b47e9038e6fe9f3451b" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-xml" +version = "0.28.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ce5e73202a820a31f8a0ee32ada5e21029c81fd9e3ebf668a40832e4219d9d1" +dependencies = [ + "memchr", + "serde", +] + +[[package]] +name = "quote" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b9ab9c7eadfd8df19006f1cf1a4aed13540ed5cbc047010ece5826e10825488" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "serde" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2113ab51b87a539ae008b5c6c02dc020ffa39afd2d83cffcb3f4eb2722cebec2" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.163" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c805777e3930c8883389c602315a24224bcc738b63905ef87cd1420353ea93e" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "syn" +version = "2.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32d41677bcbe24c20c52e7c70b0d8db04134c5d1066bf98662e2871ad200ea3e" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "unicode-ident" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b15811caf2415fb889178633e7724bad2509101cde276048e013b9def5e51fa0" + +[[package]] +name = "xml-rs" +version = "0.8.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d8f380ae16a37b30e6a2cf67040608071384b1450c189e61bea3ff57cde922d" diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..b8d9373 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "osc-variant" +version = "0.1.0" +edition = "2021" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +clap = { version = "4.3", features = ["std", "help", "usage", "derive", "error-context" ], default-features = false } +serde = { version = "1.0", features = ["derive"] } +quick-xml = { version = "0.28", features = ["escape-html", "serialize"], default-features=false } +xml-rs = "0.8" diff --git a/LICENSE.txt b/LICENSE.txt new file mode 100644 index 0000000..78e32ed --- /dev/null +++ b/LICENSE.txt @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Comprehensive Cancer Center Mainfranken + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e0bcbb8 --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ += OSC-Variant + +Anwendung zum Anpassen einer OSC-Datei an einen Standort. + +== Funktion + +Diese Anwendung passt eine OSC-Datei so an, dass (standortbezogene) Formularvarianten für Formularverweise +verwendet werden. + +Hierzu wird die Datei deserialisiert, die entsprechenden Formularfelder ermittelt und die Formularvariante +sowie die Anzeige anhand eines Profils angepasst. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..62889f9 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,91 @@ +/* + * MIT License + * + * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +use std::fs; +use std::fs::OpenOptions; +use std::io::Write; +use std::ops::Add; + +use clap::Parser; +use quick_xml::de::from_str; +use quick_xml::se::Serializer; +use serde::Serialize; + +use crate::model::onkostar_editor::OnkostarEditor; + +mod model; + +#[derive(Parser)] +#[command(author, version, about, long_about = None)] +#[command(propagate_version = true, arg_required_else_help(true))] +struct Cli { + #[arg( + long = "input", + help = "Eingabedatei" + )] + input: String, + #[arg( + long = "output", + help = "Ausgabedatei (Optional)" + )] + output: Option +} + +fn main() { + let cli = Cli::parse(); + + 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 buf = String::new(); + + let mut serializier = Serializer::new(&mut buf); + serializier.indent(' ', 2); + + xml.serialize(serializier).expect("Generated XML"); + + let output = "\n".to_string() + .add(buf + // Replace ' and " as used in original file + .replace("'", "'") + .replace(""", "\"") + .as_str()); + + match cli.output { + Some(filename) => { + let mut file = OpenOptions::new() + .read(false) + .write(true) + .create(true) + .truncate(true) + .open(filename).unwrap(); + file.write_all(output.as_bytes()).expect("Should have written output file"); + }, + None => { + println!("{}", output) + } + } +} diff --git a/src/model/data_catalogue.rs b/src/model/data_catalogue.rs new file mode 100644 index 0000000..eca90be --- /dev/null +++ b/src/model/data_catalogue.rs @@ -0,0 +1,136 @@ +/* + * MIT License + * + * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +use serde::{Deserialize, Serialize}; + +use crate::model::onkostar_editor::Ordner; + +#[derive(Serialize, Deserialize, Debug)] +pub struct DataCatalogue { + #[serde(rename = "Name")] + name: String, + #[serde(rename = "NameExport")] + name_export: String, + #[serde(rename = "Category")] + category: String, + #[serde(rename = "Description")] + description: String, + #[serde(rename = "Note")] + note: String, + #[serde(rename = "Readonly")] + readonly: bool, + #[serde(rename = "BestOf")] + best_of: bool, + #[serde(rename = "SID")] + sid: String, + #[serde(rename = "GUID")] + guid: String, + #[serde(rename = "Revision")] + revision: u16, + #[serde(rename = "Entries")] + entries: Entries, + #[serde(rename = "Ordner")] + ordner: Ordner +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Entries { + #[serde(rename = "Entry")] + entry: Vec +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Entry { + #[serde(rename = "PropertyCatalogue")] + #[serde(skip_serializing_if="Option::is_none")] + property_catalogue: Option, + #[serde(rename = "Name")] + name: String, + #[serde(rename = "NameExport")] + name_export: String, + #[serde(rename = "Description")] + description: String, + #[serde(rename = "Type")] + entry_type: String, + #[serde(rename = "SubTable")] + sub_table: String, + #[serde(rename = "ScaleUnit")] + scale_unit: String, + #[serde(rename = "MaxLength")] + max_length: u32, + #[serde(rename = "DefaultValue")] + default_value: String, + #[serde(rename = "Active")] + active: bool, + #[serde(rename = "Readonly")] + read_only: bool, + #[serde(rename = "Filterable")] + filterable: bool, + #[serde(rename = "RangeFrom")] + #[serde(skip_serializing_if="Option::is_none")] + range_from: Option, + #[serde(rename = "RangeUntil")] + #[serde(skip_serializing_if="Option::is_none")] + range_until: Option, + #[serde(rename = "MultipleChoice")] + multiple_choice: bool, + #[serde(rename = "Position")] + position: String, + #[serde(rename = "Note")] + note: String, + #[serde(rename = "DateEstimatedAllowed")] + date_estimated_allowed: bool, + #[serde(rename = "DateUnknownAllowed")] + date_unknown_allowed: bool, + #[serde(rename = "oeChoiceOptions")] + oe_choice_options: String, + #[serde(rename = "Fachabteilungsbezug")] + fachabteilungsbezug: bool, + #[serde(rename = "Use")] + #[serde(skip_serializing_if="Option::is_none")] + use_: Option, + #[serde(rename = "FesteNachkommastellen")] + #[serde(skip_serializing_if="Option::is_none")] + feste_nachkommastellen: Option, + #[serde(rename = "SID")] + sid: String, + #[serde(rename = "GUID")] + guid: String, + #[serde(rename = "Revision")] + revision: u16, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Use { + #[serde(rename = "ProgramModule", default)] + program_module: Vec +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct ProgramModule { + #[serde(rename="@program")] + program: String, + #[serde(rename="@name")] + name: String +} \ No newline at end of file diff --git a/src/model/data_form.rs b/src/model/data_form.rs new file mode 100644 index 0000000..fb29d9e --- /dev/null +++ b/src/model/data_form.rs @@ -0,0 +1,343 @@ +/* + * MIT License + * + * Copyright (c) 2023 Comprehensive Cancer Center Mainfranken + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +use serde::{Deserialize, Serialize}; + +use crate::model::{Ansichten, Entries, Filter, MenuCategory, PlausibilityRules, Script}; +use crate::model::onkostar_editor::Ordner; + +#[derive(Serialize, Deserialize, Debug)] +pub struct DataForm { + #[serde(rename = "DataCatalogues")] + data_catalogues: DataCatalogues, + #[serde(rename = "Category")] + category: String, + #[serde(rename = "Name")] + name: String, + #[serde(rename = "Version")] + version: String, + #[serde(rename = "MenuEntry")] + menu_entry: String, + #[serde(rename = "Title")] + title: String, + #[serde(rename = "Description")] + description: String, + #[serde(rename = "Note")] + note: String, + #[serde(rename = "Readonly")] + readonly: bool, + #[serde(rename = "Active")] + active: bool, + #[serde(rename = "TudokPosition")] + tudok_position: String, + #[serde(rename = "Aktenbereich")] + aktenbereich: String, + #[serde(rename = "BefragungRelevant")] + befragung_relevant: bool, + #[serde(rename = "Hotkey")] + #[serde(skip_serializing_if="Option::is_none")] + hotkey: Option, + #[serde(rename = "Summary")] + summary: String, + #[serde(rename = "BigSummary")] + big_summary: String, + #[serde(rename = "KalenderSchnipsel")] + kalender_schnipsel: String, + #[serde(rename = "EmailTemplate")] + #[serde(skip_serializing_if="Option::is_none")] + mail_template: Option, + #[serde(rename = "ErkrankungText")] + erkrankung_text: String, + #[serde(rename = "ErkrankungTextLong")] + erkrankung_text_long: String, + #[serde(rename = "ErkrankungProzedurText")] + erkrankung_prozedur_text: String, + #[serde(rename = "ErkrankungSummary")] + erkrankung_summary: String, + #[serde(rename = "ErkrankungBigSummary")] + erkrankung_big_summary: String, + #[serde(rename = "Kontext")] + kontext: String, + #[serde(rename = "TudokReadonly")] + tudok_readonly: bool, + #[serde(rename = "VitalstatusRelevant")] + vitalstatus_relevant: bool, + #[serde(rename = "AutoNummerierung")] + auto_nummerierung: bool, + #[serde(rename = "Zwischenspeichern")] + zwischenspeichern: bool, + #[serde(rename = "Zurueckblaettern")] + zurueckblaettern: bool, + #[serde(rename = "Datenbankexport")] + datenbankexport: bool, + #[serde(rename = "DatenschutzRelevant")] + datenschutz_relevant: bool, + #[serde(rename = "KonferenzRelevant")] + konferenz_relevant: bool, + #[serde(rename = "hatUnterformulare")] + hat_unterformulare: bool, + #[serde(rename = "ScriptBeimSchliessen")] + #[serde(skip_serializing_if="Option::is_none")] + script_beim_schliessen: Option