From 6f75698aa8d144fa74c991324e1fff9df6d052b5 Mon Sep 17 00:00:00 2001 From: Emily Cheng Date: Tue, 19 Nov 2024 15:58:04 -0800 Subject: [PATCH] Make temporal error mesage more verbose (explicitly say the second condition) --- nacc_form_validator/errors.py | 4 ++-- nacc_form_validator/nacc_validator.py | 2 +- tests/test_nacc_validator_datastore.py | 10 +++++++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/nacc_form_validator/errors.py b/nacc_form_validator/errors.py index be65f50..c9f9d95 100644 --- a/nacc_form_validator/errors.py +++ b/nacc_form_validator/errors.py @@ -89,7 +89,7 @@ def __set_custom_error_codes(self): 0x1009: "{1} for if {2} else {3} - compatibility rule no: {0}", 0x2000: - "{1} in current visit for {2} in previous visit - temporal rule no: {0}", + "{1} in current visit for if {2} in previous visit then {3} in current visit - temporal rule no: {0}", 0x2001: "primary key variable {0} not set in current visit data", 0x2002: @@ -121,7 +121,7 @@ def __set_custom_error_codes(self): 0x3003: "Error in comparing {0} to age at {1} ({2}): {3}", 0x3004: - "{1} in previous visit for {2} in current visit - temporal rule no: {0}", + "{1} in previous visit for if {2} in current visit then {3} in previous visit - temporal rule no: {0}", } self.messages.update(custom_errors) diff --git a/nacc_form_validator/nacc_validator.py b/nacc_form_validator/nacc_validator.py index fc275f1..8cdebca 100755 --- a/nacc_form_validator/nacc_validator.py +++ b/nacc_form_validator/nacc_validator.py @@ -764,7 +764,7 @@ def _validate_temporalrules(self, temporalrules: List[Mapping], field: str, if not valid and errors: for error in errors.items(): self._error(field, error_def, rule_no, str(error), - prev_conds) + prev_conds, curr_conds) def _validate_logic(self, logic: Dict[str, Any], field: str, value: object): diff --git a/tests/test_nacc_validator_datastore.py b/tests/test_nacc_validator_datastore.py index cc43a48..3662433 100644 --- a/tests/test_nacc_validator_datastore.py +++ b/tests/test_nacc_validator_datastore.py @@ -126,7 +126,7 @@ def test_temporal_check(schema): assert not nv.validate({'patient_id': 'PatientID1', 'visit_num': 4, 'taxes': 8}) assert nv.errors == {'taxes': [ - "('taxes', ['unallowed value 8']) in current visit for {'taxes': {'allowed': [0]}} in previous visit - temporal rule no: 0"]} + "('taxes', ['unallowed value 8']) in current visit for if {'taxes': {'allowed': [0]}} in previous visit then {'taxes': {'forbidden': [8]}} in current visit - temporal rule no: 0"]} def test_temporal_check_swap_order(schema): """ Test temporal check when the order of evaluation is swapped """ @@ -139,7 +139,7 @@ def test_temporal_check_swap_order(schema): nv.reset_record_cache() assert not nv.validate({'patient_id': 'PatientID1', 'visit_num': 2, 'taxes': 1}) assert nv.errors == {'taxes': [ - "('taxes', ['unallowed value 8']) in previous visit for {'taxes': {'allowed': [0]}} in current visit - temporal rule no: 0"]} + "('taxes', ['unallowed value 8']) in previous visit for if {'taxes': {'allowed': [0]}} in current visit then {'taxes': {'forbidden': [8]}} in previous visit - temporal rule no: 0"]} def test_temporal_check_no_prev_visit(schema): """ Temporal test check when there are no previous visits (e.g. before visit 0) """ @@ -304,7 +304,11 @@ def test_temporal_check_with_nested_compare_with_previous_record(): assert nv.validate({'patient_id': 'PatientID1', 'visit_num': 4, 'birthyr': 1950}) assert not nv.validate({'patient_id': 'PatientID1', 'visit_num': 4, 'birthyr': 1951}) - assert nv.errors == {'birthyr': ['(\'birthyr\', ["input value doesn\'t satisfy the condition birthyr == birthyr (previous record)"]) in current visit for {\'birthyr\': {\'forbidden\': [-1]}} in previous visit - temporal rule no: 0']} + assert nv.errors == {'birthyr': [ + '(\'birthyr\', ["input value doesn\'t satisfy the condition birthyr == birthyr (previous record)"]) in current visit for ' + + 'if {\'birthyr\': {\'forbidden\': [-1]}} in previous visit ' + + 'then {\'birthyr\': {\'compare_with\': {\'comparator\': \'==\', \'base\': \'birthyr\', \'previous_record\': True}}} in current visit ' + + '- temporal rule no: 0']} def test_check_with_rxnorm(): """ Test checking drugID is a valid RXCUI """