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 diff --git a/rct229/rule_engine/rule_list_indexed_base.py b/rct229/rule_engine/rule_list_indexed_base.py index a1c4818359..371769634c 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,9 +141,15 @@ 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]: - list_context.__setitem__( - ruleset_model, find_all(self.list_path, context[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, tmp_context_list) else: list_context.__setitem__(ruleset_model, None)