Skip to content

Commit 873516a

Browse files
test for cohort description
1 parent ac6550c commit 873516a

2 files changed

Lines changed: 65 additions & 57 deletions

File tree

tests/fixtures/builders/model/rule.py

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def fix_iteration_date_invariants(iterations: list[rules.Iteration], start_date:
7171
iteration.iteration_date = current
7272
previous = current
7373

74+
7475
# Iteration cohort factories
7576
class Rsv75RollingCohortFactory(IterationCohortFactory):
7677
cohort_label = rules.CohortLabel("rsv_75_rolling")
@@ -79,20 +80,23 @@ class Rsv75RollingCohortFactory(IterationCohortFactory):
7980
negative_description = rules.Description("rsv_age_range negative description")
8081
priority = 1
8182

83+
8284
class Rsv75to79CohortFactory(IterationCohortFactory):
8385
cohort_label = rules.CohortLabel("rsv_75to79_2024")
8486
cohort_group = rules.CohortGroup("rsv_age_range")
8587
positive_description = rules.Description("rsv_age_range positive description")
8688
negative_description = rules.Description("rsv_age_range negative description")
8789
priority = 1
8890

91+
8992
class RsvPretendClinicalCohortFactory(IterationCohortFactory):
9093
cohort_label = rules.CohortLabel("rsv_pretend_clinical_cohort")
9194
cohort_group = rules.CohortGroup("rsv_clinical_cohort")
9295
positive_description = rules.Description("rsv_clinical_cohort positive description")
9396
negative_description = rules.Description("rsv_clinical_cohort negative description")
9497
priority = 1
9598

99+
96100
# Iteration rule factories
97101
class PersonAgeSuppressionRuleFactory(IterationRuleFactory):
98102
type = rules.RuleType.suppression
@@ -125,15 +129,3 @@ class ICBSuppressionRuleFactory(IterationRuleFactory):
125129
attribute_level = rules.RuleAttributeLevel.PERSON
126130
attribute_name = rules.RuleAttributeName("ICB")
127131
comparator = rules.RuleComparator("QE1")
128-
129-
130-
class ICBSuppressionRuleFactory(IterationRuleFactory):
131-
type = rules.RuleType.filter
132-
name = rules.RuleName("Not in QE1")
133-
description = rules.RuleDescription("Not in QE1")
134-
priority = rules.RulePriority(10)
135-
operator = rules.RuleOperator.ne
136-
attribute_level = rules.RuleAttributeLevel.PERSON
137-
attribute_name = rules.RuleAttributeName("ICB")
138-
comparator = rules.RuleComparator("QE1")
139-

tests/unit/services/calculators/test_eligibility_calculator.py

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
)
1919
from eligibility_signposting_api.services.calculators.eligibility_calculator import EligibilityCalculator
2020
from tests.fixtures.builders.model import rule as rule_builder
21-
from tests.fixtures.builders.model.rule import Rsv75RollingCohortFactory, Rsv75to79CohortFactory, \
22-
RsvPretendClinicalCohortFactory
2321
from tests.fixtures.builders.repos.person import person_rows_builder
2422
from tests.fixtures.matchers.eligibility import (
2523
is_cohort_result,
@@ -1024,37 +1022,14 @@ def test_eligibility_results_when_multiple_cohorts(
10241022
)
10251023

10261024

1027-
@pytest.mark.parametrize(
1028-
("person_cohorts", "expected_cohort_results", "test_comment"),
1029-
[
1030-
(
1031-
["rsv_75_rolling"],
1032-
["rsv_age_range"],
1033-
"rsv_75_rolling is actionable, others are not-eligible",
1034-
),
1035-
(
1036-
["rsv_75_rolling", "rsv_75to79_2024"],
1037-
["rsv_age_range"],
1038-
"rsv_75_rolling, rsv_75to79_2024 is actionable, rsv_pretend_clinical_cohort are not-eligible",
1039-
),
1040-
(
1041-
["rsv_75_rolling", "rsv_75to79_2024", "rsv_pretend_clinical_cohort"],
1042-
["rsv_age_range", "rsv_clinical_cohort"],
1043-
"all are actionable",
1044-
),
1045-
],
1046-
)
1047-
def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is_actionable(
1048-
person_cohorts: list[str],
1049-
expected_cohort_results: list[str],
1050-
test_comment: str,
1025+
def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is_not_eligible(
10511026
faker: Faker,
10521027
):
10531028
# Given
10541029
nhs_number = NHSNumber(faker.nhs_number())
10551030
date_of_birth = DateOfBirth(faker.date_of_birth(minimum_age=66, maximum_age=74))
10561031

1057-
person_rows = person_rows_builder(nhs_number, date_of_birth=date_of_birth, cohorts=person_cohorts, postcode="hp")
1032+
person_rows = person_rows_builder(nhs_number, date_of_birth=date_of_birth, cohorts=[])
10581033
campaign_configs = [
10591034
rule_builder.CampaignConfigFactory.build(
10601035
target="RSV",
@@ -1063,7 +1038,7 @@ def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is
10631038
iteration_cohorts=[
10641039
rule_builder.Rsv75RollingCohortFactory.build(),
10651040
rule_builder.Rsv75to79CohortFactory.build(),
1066-
rule_builder.RsvPretendClinicalCohortFactory.build()
1041+
rule_builder.RsvPretendClinicalCohortFactory.build(),
10671042
],
10681043
iteration_rules=[rule_builder.PostcodeSuppressionRuleFactory.build()],
10691044
)
@@ -1083,39 +1058,48 @@ def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is
10831058
has_items(
10841059
is_condition()
10851060
.with_condition_name(ConditionName("RSV"))
1086-
.and_status(Status.actionable)
1061+
.and_status(Status.not_eligible)
10871062
.and_cohort_results(
1088-
contains_exactly(*[is_cohort_result().with_cohort_code(code) for code in expected_cohort_results])
1063+
contains_exactly(
1064+
is_cohort_result()
1065+
.with_cohort_code("rsv_age_range")
1066+
.with_description("rsv_age_range negative description"),
1067+
is_cohort_result()
1068+
.with_cohort_code("rsv_clinical_cohort")
1069+
.with_description("rsv_clinical_cohort negative description"),
1070+
)
10891071
)
10901072
)
10911073
),
1092-
test_comment,
10931074
)
10941075

10951076

10961077
@pytest.mark.parametrize(
1097-
("person_cohorts", "expected_cohort_results", "test_comment"),
1078+
("person_cohorts", "expected_cohort_group_and_description", "test_comment"),
10981079
[
10991080
(
11001081
["rsv_75_rolling"],
1101-
["rsv_age_range"],
1082+
[("rsv_age_range", "rsv_age_range positive description")],
11021083
"rsv_75_rolling is not-actionable, others are not-eligible",
11031084
),
11041085
(
11051086
["rsv_75_rolling", "rsv_75to79_2024"],
1106-
["rsv_age_range"],
1087+
[("rsv_age_range", "rsv_age_range positive description")],
11071088
"rsv_75_rolling, rsv_75to79_2024 is not-actionable, rsv_pretend_clinical_cohort are not-eligible",
11081089
),
11091090
(
11101091
["rsv_75_rolling", "rsv_75to79_2024", "rsv_pretend_clinical_cohort"],
1111-
["rsv_age_range", "rsv_clinical_cohort"],
1092+
[
1093+
("rsv_age_range", "rsv_age_range positive description"),
1094+
("rsv_clinical_cohort", "rsv_clinical_cohort positive description"),
1095+
],
11121096
"all are not-actionable",
11131097
),
11141098
],
11151099
)
11161100
def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is_not_actionable(
11171101
person_cohorts: list[str],
1118-
expected_cohort_results: list[str],
1102+
expected_cohort_group_and_description: list[tuple[str, str]],
11191103
test_comment: str,
11201104
faker: Faker,
11211105
):
@@ -1132,7 +1116,7 @@ def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is
11321116
iteration_cohorts=[
11331117
rule_builder.Rsv75RollingCohortFactory.build(),
11341118
rule_builder.Rsv75to79CohortFactory.build(),
1135-
rule_builder.RsvPretendClinicalCohortFactory.build()
1119+
rule_builder.RsvPretendClinicalCohortFactory.build(),
11361120
],
11371121
iteration_rules=[rule_builder.PostcodeSuppressionRuleFactory.build()],
11381122
)
@@ -1154,22 +1138,53 @@ def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is
11541138
.with_condition_name(ConditionName("RSV"))
11551139
.and_status(Status.not_actionable)
11561140
.and_cohort_results(
1157-
contains_exactly(*[is_cohort_result().with_cohort_code(code) for code in expected_cohort_results])
1158-
)
1141+
contains_exactly(
1142+
*[
1143+
is_cohort_result().with_cohort_code(item[0]).with_description(item[1])
1144+
for item in expected_cohort_group_and_description
1145+
]
1146+
)
1147+
),
11591148
)
11601149
),
11611150
test_comment,
11621151
)
11631152

11641153

1165-
def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is_not_eligible(
1154+
@pytest.mark.parametrize(
1155+
("person_cohorts", "expected_cohort_group_and_description", "test_comment"),
1156+
[
1157+
(
1158+
["rsv_75_rolling"],
1159+
[("rsv_age_range", "rsv_age_range positive description")],
1160+
"rsv_75_rolling is actionable, others are not-eligible",
1161+
),
1162+
(
1163+
["rsv_75_rolling", "rsv_75to79_2024"],
1164+
[("rsv_age_range", "rsv_age_range positive description")],
1165+
"rsv_75_rolling, rsv_75to79_2024 is actionable, rsv_pretend_clinical_cohort are not-eligible",
1166+
),
1167+
(
1168+
["rsv_75_rolling", "rsv_75to79_2024", "rsv_pretend_clinical_cohort"],
1169+
[
1170+
("rsv_age_range", "rsv_age_range positive description"),
1171+
("rsv_clinical_cohort", "rsv_clinical_cohort positive description"),
1172+
],
1173+
"all are actionable",
1174+
),
1175+
],
1176+
)
1177+
def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is_actionable(
1178+
person_cohorts: list[str],
1179+
expected_cohort_group_and_description: list[tuple[str, str]],
1180+
test_comment: str,
11661181
faker: Faker,
11671182
):
11681183
# Given
11691184
nhs_number = NHSNumber(faker.nhs_number())
11701185
date_of_birth = DateOfBirth(faker.date_of_birth(minimum_age=66, maximum_age=74))
11711186

1172-
person_rows = person_rows_builder(nhs_number, date_of_birth=date_of_birth, cohorts=[])
1187+
person_rows = person_rows_builder(nhs_number, date_of_birth=date_of_birth, cohorts=person_cohorts, postcode="hp")
11731188
campaign_configs = [
11741189
rule_builder.CampaignConfigFactory.build(
11751190
target="RSV",
@@ -1178,7 +1193,7 @@ def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is
11781193
iteration_cohorts=[
11791194
rule_builder.Rsv75RollingCohortFactory.build(),
11801195
rule_builder.Rsv75to79CohortFactory.build(),
1181-
rule_builder.RsvPretendClinicalCohortFactory.build()
1196+
rule_builder.RsvPretendClinicalCohortFactory.build(),
11821197
],
11831198
iteration_rules=[rule_builder.PostcodeSuppressionRuleFactory.build()],
11841199
)
@@ -1198,15 +1213,16 @@ def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is
11981213
has_items(
11991214
is_condition()
12001215
.with_condition_name(ConditionName("RSV"))
1201-
.and_status(Status.not_eligible)
1216+
.and_status(Status.actionable)
12021217
.and_cohort_results(
12031218
contains_exactly(
12041219
*[
1205-
is_cohort_result().with_cohort_code(code)
1206-
for code in ["rsv_age_range", "rsv_clinical_cohort"]
1220+
is_cohort_result().with_cohort_code(item[0]).with_description(item[1])
1221+
for item in expected_cohort_group_and_description
12071222
]
12081223
)
12091224
)
12101225
)
12111226
),
1227+
test_comment,
12121228
)

0 commit comments

Comments
 (0)