Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
21 changes: 10 additions & 11 deletions src/eligibility_signposting_api/audit/audit_context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import logging
from datetime import UTC, datetime
from operator import attrgetter
from uuid import UUID

from flask import Request, g
Expand Down Expand Up @@ -73,29 +72,29 @@ def append_audit_condition(
best_cohort_results = best_results[2]

if best_cohort_results:
for value in sorted(best_cohort_results.values(), key=attrgetter("cohort_code")):
cohort_status_name = value.status.name if value.status else None
for cohort_label, result in sorted(best_cohort_results.items(), key=lambda item: item[1].cohort_code):
cohort_status_name = result.status.name if result.status else None
audit_eligibility_cohorts.append(
AuditEligibilityCohorts(cohort_code=value.cohort_code, cohort_status=cohort_status_name)
AuditEligibilityCohorts(cohort_code=cohort_label, cohort_status=cohort_status_name)
)

audit_eligibility_cohort_groups.append(
AuditEligibilityCohortGroups(
cohort_code=value.cohort_code, cohort_status=cohort_status_name, cohort_text=value.description
cohort_code=result.cohort_code, cohort_status=cohort_status_name, cohort_text=result.description
)
)

if value.audit_rules and best_candidate:
if result.audit_rules and best_candidate:
if best_candidate.status and best_candidate.status.name == Status.not_eligible.name:
audit_filter_rule = AuditFilterRule(
rule_priority=value.audit_rules[0].rule_priority,
rule_name=value.audit_rules[0].rule_name,
rule_priority=result.audit_rules[0].rule_priority,
rule_name=result.audit_rules[0].rule_name,
)
if best_candidate.status and best_candidate.status.name == Status.not_actionable.name:
audit_suitability_rule = AuditSuitabilityRule(
rule_priority=value.audit_rules[0].rule_priority,
rule_name=value.audit_rules[0].rule_name,
rule_message=value.audit_rules[0].rule_description,
rule_priority=result.audit_rules[0].rule_priority,
rule_name=result.audit_rules[0].rule_name,
rule_message=result.audit_rules[0].rule_description,
)

if best_candidate and best_candidate.status and best_candidate.status.name == Status.actionable.name:
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ def persisted_person_all_cohorts(person_table: Any, faker: Faker) -> Generator[e
nhs_number,
date_of_birth=date_of_birth,
postcode="hp1",
cohorts=["cohort1", "cohort2", "cohort3"],
cohorts=["cohort_label1", "cohort_label2", "cohort_label3"],
icb="QE1",
)
):
Expand Down Expand Up @@ -501,7 +501,7 @@ def multiple_campaign_configs(s3_client: BaseClient, rules_bucket: BucketName) -
iteration_rules=target_rules_map.get(targets[i]),
iteration_cohorts=[
rule.IterationCohortFactory.build(
cohort_label="cohort1",
cohort_label=f"cohort_label{i + 1}",
cohort_group=f"cohort_group{i + 1}",
positive_description=f"positive_desc_{i + 1}",
negative_description=f"negative_desc_{i + 1}",
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/lambda/test_app_running_as_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def test_given_nhs_number_in_path_matches_with_nhs_number_in_headers_and_check_i
"conditionName": campaign_config.target,
"status": "not_actionable",
"statusText": "not_actionable",
"eligibilityCohorts": [{"cohortCode": "cohort_group1", "cohortStatus": "not_actionable"}],
"eligibilityCohorts": [{"cohortCode": "cohort1", "cohortStatus": "not_actionable"}],
"eligibilityCohortGroups": [
{
"cohortCode": "cohort_group1",
Expand Down Expand Up @@ -320,7 +320,7 @@ def test_given_person_has_unique_status_for_different_conditions_with_audit( #
"conditionName": rsv_campaign.target,
"status": "not_eligible",
"statusText": "not_eligible",
"eligibilityCohorts": [{"cohortCode": "cohort_group1", "cohortStatus": "not_eligible"}],
"eligibilityCohorts": [{"cohortCode": "cohort_label1", "cohortStatus": "not_eligible"}],
"eligibilityCohortGroups": [
{
"cohortCode": "cohort_group1",
Expand All @@ -341,7 +341,7 @@ def test_given_person_has_unique_status_for_different_conditions_with_audit( #
"conditionName": covid_campaign.target,
"status": "not_actionable",
"statusText": "not_actionable",
"eligibilityCohorts": [{"cohortCode": "cohort_group2", "cohortStatus": "not_actionable"}],
"eligibilityCohorts": [{"cohortCode": "cohort_label2", "cohortStatus": "not_actionable"}],
"eligibilityCohortGroups": [
{
"cohortCode": "cohort_group2",
Expand All @@ -366,7 +366,7 @@ def test_given_person_has_unique_status_for_different_conditions_with_audit( #
"conditionName": flu_campaign.target,
"status": "actionable",
"statusText": "actionable",
"eligibilityCohorts": [{"cohortCode": "cohort_group3", "cohortStatus": "actionable"}],
"eligibilityCohorts": [{"cohortCode": "cohort_label3", "cohortStatus": "actionable"}],
"eligibilityCohortGroups": [
{
"cohortCode": "cohort_group3",
Expand Down
Loading