Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set rulebase to add not applicable message to empty list after fliter… #1467

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading