diff --git a/docs/checks.md b/docs/checks.md index 42a4117..87b0b6e 100644 --- a/docs/checks.md +++ b/docs/checks.md @@ -26,3 +26,9 @@ Dies kann bei wechselseitiger Abhängigkeit zwischen zwei (Unter-)Formularen auf In diesem Fall kann ein erneuter/zweiter Import helfen, da das Onkostar in diesem Fall alle Formulare importiert hat und der Formularverweis dann gespeichert werden kann. + +### Problem `2024-0005`: Formular hat Formularverweise ohne Angabe des Formulars in den Formularfeldern + +Formularverweise ohne Angabe des Formulars führen zu Problemen bei der Verwendung und Darstellung des entsprechenden +Formularverweises. +Dieses Problem muss manuell behoben werden. \ No newline at end of file diff --git a/src/checks/mod.rs b/src/checks/mod.rs index ca8edab..9b16415 100644 --- a/src/checks/mod.rs +++ b/src/checks/mod.rs @@ -236,6 +236,15 @@ pub fn print_checks() { ", fixable: false, }, + Problem { + code: "2024-0005", + name: "Formular hat Formularverweise ohne Angabe des Formulars in den Formularfeldern", + description: " Formularverweise ohne Angabe des Formulars führen zu Problemen\n \ + bei der Verwendung und Darstellung des entsprechenden Formularverweises.\n\n \ + Dieses Problem muss manuell behoben werden. + ", + fixable: false, + }, ] .iter() .for_each(|problem| println!("{}\n", problem)) diff --git a/src/model/form.rs b/src/model/form.rs index 9aa4f83..7cce11b 100644 --- a/src/model/form.rs +++ b/src/model/form.rs @@ -412,9 +412,38 @@ impl FolderContent for Form { } } +impl Form { + fn common_check(&self) -> Vec { + let missing_forms = self + .entries + .entry + .iter() + .filter(|entry| entry.type_ == "formReference" && entry.referenced_data_form.is_none()) + .map(|entry| format!("'{}'", entry.get_name())) + .collect::>(); + + let mut result = vec![]; + + if missing_forms.len() > 0 { + result.push(ErrorWithCode { + code: "2024-0005".to_string(), + description: format!( + "Formular '{}' hat Formularverweise ohne Angabe des Formulars in: {}", + self.name, + missing_forms.join(", ") + ), + line: None, + example: None, + }); + } + + result + } +} + impl Checkable for Form { fn check(&self) -> Vec { - if self + let mut result = if self .entries .entry .iter() @@ -422,7 +451,7 @@ impl Checkable for Form { .count() == 0 { - return vec![ErrorWithCode { + vec![ErrorWithCode { code: "2023-0002".to_string(), description: format!( "Formular '{}' hat keine Angabe zum Prozedurdatum", @@ -430,16 +459,21 @@ impl Checkable for Form { ), line: None, example: None, - }]; - } - vec![] + }] + } else { + vec![] + }; + + result.append(&mut self.common_check()); + + result } } impl Checkable for Form { fn check(&self) -> Vec { - if self.hat_unterformulare { - return vec![ErrorWithCode { + let mut result = if self.hat_unterformulare { + vec![ErrorWithCode { code: "2023-0001".to_string(), description: format!( "Unterformular '{}' mit Markierung 'hat Unterformulare'", @@ -447,10 +481,14 @@ impl Checkable for Form { ), line: None, example: None, - }]; - } + }] + } else { + vec![] + }; - vec![] + result.append(&mut self.common_check()); + + result } }