Skip to content

Commit

Permalink
Merge pull request #1467 from pnnl/RT/WX/ruletest_na
Browse files Browse the repository at this point in the history
set rulebase to add not applicable message to empty list after fliter…
  • Loading branch information
weilixu authored Aug 5, 2024
2 parents d3225f8 + 2b6adcb commit eb2fc53
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
13 changes: 11 additions & 2 deletions rct229/rule_engine/rule_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions rct229/rule_engine/rule_list_indexed_base.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit eb2fc53

Please sign in to comment.