From 42f6166052d06c588d544dce6d6202dc173db895 Mon Sep 17 00:00:00 2001 From: Weili Xu Date: Thu, 1 Aug 2024 19:13:09 -0700 Subject: [PATCH 1/3] set rulebase to add not applicable message to empty list after flitering. --- rct229/rule_engine/rule_base.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/rct229/rule_engine/rule_base.py b/rct229/rule_engine/rule_base.py index d5ee3558b2..ebf7398c4d 100644 --- a/rct229/rule_engine/rule_base.py +++ b/rct229/rule_engine/rule_base.py @@ -172,8 +172,17 @@ def evaluate(self, rmds, data={}): # Evaluate the actual rule check result = self.rule_check(context, calc_vals, data) if isinstance(result, list): - # The result is a list of outcomes - outcome["result"] = result + if len(result) == 0: + # empty list: + outcome["result"] = RCTOutcomeLabel.NOT_APPLICABLE + not_applicable_msg = self.get_not_applicable_msg( + context, data + ) + if not_applicable_msg: + outcome["message"] = not_applicable_msg + # The result is a list of outcomes + else: + outcome["result"] = result # using is False to include the None case. elif self.is_primary_rule is False: # secondary rule applicability check true-> undetermined, false -> not_applicable From c931bf0df1cf895b4523e5407ffff1387c4627b3 Mon Sep 17 00:00:00 2001 From: Weili Xu Date: Thu, 1 Aug 2024 21:59:39 -0700 Subject: [PATCH 2/3] add undetermined assertion handler to handle empty context list issue. --- rct229/rule_engine/rule_list_indexed_base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rct229/rule_engine/rule_list_indexed_base.py b/rct229/rule_engine/rule_list_indexed_base.py index a1c4818359..9058dc5f6f 100644 --- a/rct229/rule_engine/rule_list_indexed_base.py +++ b/rct229/rule_engine/rule_list_indexed_base.py @@ -1,5 +1,6 @@ from rct229.rule_engine.rule_list_base import RuleDefinitionListBase from rct229.rule_engine.ruleset_model_factory import get_rmd_instance +from rct229.utils.assertions import assert_ from rct229.utils.json_utils import slash_prefix_guarantee from rct229.utils.jsonpath_utils import find_all from rct229.utils.match_lists import match_lists @@ -140,8 +141,13 @@ def create_context_list(self, context, data): list_context = get_rmd_instance() for ruleset_model in list_context.get_ruleset_model_types(): if self.rmds_used[ruleset_model]: + tmp_context_list = find_all(self.list_path, context[ruleset_model]) + # handles a case when there is no element available to the target list path. + # This is set to an internal error handling since list_path is defined as part of rule logic. + assert_(tmp_context_list, f"List path {self.list_path} in rule {self.id} is either incorrect or has no data.") + list_context.__setitem__( - ruleset_model, find_all(self.list_path, context[ruleset_model]) + ruleset_model, tmp_context_list ) else: list_context.__setitem__(ruleset_model, None) From 2b6adcb4791f04bc4f4436a88f76cf6bba9778d6 Mon Sep 17 00:00:00 2001 From: Weili Xu Date: Sun, 4 Aug 2024 19:50:32 -0700 Subject: [PATCH 3/3] add assertion to make sure the list path pointing to valid data. --- rct229/rule_engine/rule_list_indexed_base.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/rct229/rule_engine/rule_list_indexed_base.py b/rct229/rule_engine/rule_list_indexed_base.py index 9058dc5f6f..371769634c 100644 --- a/rct229/rule_engine/rule_list_indexed_base.py +++ b/rct229/rule_engine/rule_list_indexed_base.py @@ -144,11 +144,12 @@ def create_context_list(self, context, data): tmp_context_list = find_all(self.list_path, context[ruleset_model]) # handles a case when there is no element available to the target list path. # This is set to an internal error handling since list_path is defined as part of rule logic. - assert_(tmp_context_list, f"List path {self.list_path} in rule {self.id} is either incorrect or has no data.") - - list_context.__setitem__( - ruleset_model, tmp_context_list + assert_( + tmp_context_list, + f"List path {self.list_path} in rule {self.id} is either incorrect or has no data.", ) + + list_context.__setitem__(ruleset_model, tmp_context_list) else: list_context.__setitem__(ruleset_model, None)