|
18 | 18 | ) |
19 | 19 | from eligibility_signposting_api.services.calculators.eligibility_calculator import EligibilityCalculator |
20 | 20 | from tests.fixtures.builders.model import rule as rule_builder |
| 21 | +from tests.fixtures.builders.model.rule import Rsv75RollingCohortFactory, Rsv75to79CohortFactory, \ |
| 22 | + RsvPretendClinicalCohortFactory |
21 | 23 | from tests.fixtures.builders.repos.person import person_rows_builder |
22 | 24 | from tests.fixtures.matchers.eligibility import ( |
23 | 25 | is_cohort_result, |
@@ -1020,3 +1022,191 @@ def test_eligibility_results_when_multiple_cohorts( |
1020 | 1022 | ) |
1021 | 1023 | ), |
1022 | 1024 | ) |
| 1025 | + |
| 1026 | + |
| 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, |
| 1051 | + faker: Faker, |
| 1052 | +): |
| 1053 | + # Given |
| 1054 | + nhs_number = NHSNumber(faker.nhs_number()) |
| 1055 | + date_of_birth = DateOfBirth(faker.date_of_birth(minimum_age=66, maximum_age=74)) |
| 1056 | + |
| 1057 | + person_rows = person_rows_builder(nhs_number, date_of_birth=date_of_birth, cohorts=person_cohorts, postcode="hp") |
| 1058 | + campaign_configs = [ |
| 1059 | + rule_builder.CampaignConfigFactory.build( |
| 1060 | + target="RSV", |
| 1061 | + iterations=[ |
| 1062 | + rule_builder.IterationFactory.build( |
| 1063 | + iteration_cohorts=[ |
| 1064 | + rule_builder.Rsv75RollingCohortFactory.build(), |
| 1065 | + rule_builder.Rsv75to79CohortFactory.build(), |
| 1066 | + rule_builder.RsvPretendClinicalCohortFactory.build() |
| 1067 | + ], |
| 1068 | + iteration_rules=[rule_builder.PostcodeSuppressionRuleFactory.build()], |
| 1069 | + ) |
| 1070 | + ], |
| 1071 | + ) |
| 1072 | + ] |
| 1073 | + |
| 1074 | + calculator = EligibilityCalculator(person_rows, campaign_configs) |
| 1075 | + |
| 1076 | + # When |
| 1077 | + actual = calculator.evaluate_eligibility() |
| 1078 | + |
| 1079 | + # Then |
| 1080 | + assert_that( |
| 1081 | + actual, |
| 1082 | + is_eligibility_status().with_conditions( |
| 1083 | + has_items( |
| 1084 | + is_condition() |
| 1085 | + .with_condition_name(ConditionName("RSV")) |
| 1086 | + .and_status(Status.actionable) |
| 1087 | + .and_cohort_results( |
| 1088 | + contains_exactly(*[is_cohort_result().with_cohort_code(code) for code in expected_cohort_results]) |
| 1089 | + ) |
| 1090 | + ) |
| 1091 | + ), |
| 1092 | + test_comment, |
| 1093 | + ) |
| 1094 | + |
| 1095 | + |
| 1096 | +@pytest.mark.parametrize( |
| 1097 | + ("person_cohorts", "expected_cohort_results", "test_comment"), |
| 1098 | + [ |
| 1099 | + ( |
| 1100 | + ["rsv_75_rolling"], |
| 1101 | + ["rsv_age_range"], |
| 1102 | + "rsv_75_rolling is not-actionable, others are not-eligible", |
| 1103 | + ), |
| 1104 | + ( |
| 1105 | + ["rsv_75_rolling", "rsv_75to79_2024"], |
| 1106 | + ["rsv_age_range"], |
| 1107 | + "rsv_75_rolling, rsv_75to79_2024 is not-actionable, rsv_pretend_clinical_cohort are not-eligible", |
| 1108 | + ), |
| 1109 | + ( |
| 1110 | + ["rsv_75_rolling", "rsv_75to79_2024", "rsv_pretend_clinical_cohort"], |
| 1111 | + ["rsv_age_range", "rsv_clinical_cohort"], |
| 1112 | + "all are not-actionable", |
| 1113 | + ), |
| 1114 | + ], |
| 1115 | +) |
| 1116 | +def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is_not_actionable( |
| 1117 | + person_cohorts: list[str], |
| 1118 | + expected_cohort_results: list[str], |
| 1119 | + test_comment: str, |
| 1120 | + faker: Faker, |
| 1121 | +): |
| 1122 | + # Given |
| 1123 | + nhs_number = NHSNumber(faker.nhs_number()) |
| 1124 | + date_of_birth = DateOfBirth(faker.date_of_birth(minimum_age=66, maximum_age=74)) |
| 1125 | + |
| 1126 | + person_rows = person_rows_builder(nhs_number, date_of_birth=date_of_birth, cohorts=person_cohorts, postcode="SW19") |
| 1127 | + campaign_configs = [ |
| 1128 | + rule_builder.CampaignConfigFactory.build( |
| 1129 | + target="RSV", |
| 1130 | + iterations=[ |
| 1131 | + rule_builder.IterationFactory.build( |
| 1132 | + iteration_cohorts=[ |
| 1133 | + rule_builder.Rsv75RollingCohortFactory.build(), |
| 1134 | + rule_builder.Rsv75to79CohortFactory.build(), |
| 1135 | + rule_builder.RsvPretendClinicalCohortFactory.build() |
| 1136 | + ], |
| 1137 | + iteration_rules=[rule_builder.PostcodeSuppressionRuleFactory.build()], |
| 1138 | + ) |
| 1139 | + ], |
| 1140 | + ) |
| 1141 | + ] |
| 1142 | + |
| 1143 | + calculator = EligibilityCalculator(person_rows, campaign_configs) |
| 1144 | + |
| 1145 | + # When |
| 1146 | + actual = calculator.evaluate_eligibility() |
| 1147 | + |
| 1148 | + # Then |
| 1149 | + assert_that( |
| 1150 | + actual, |
| 1151 | + is_eligibility_status().with_conditions( |
| 1152 | + has_items( |
| 1153 | + is_condition() |
| 1154 | + .with_condition_name(ConditionName("RSV")) |
| 1155 | + .and_status(Status.not_actionable) |
| 1156 | + .and_cohort_results( |
| 1157 | + contains_exactly(*[is_cohort_result().with_cohort_code(code) for code in expected_cohort_results]) |
| 1158 | + ) |
| 1159 | + ) |
| 1160 | + ), |
| 1161 | + test_comment, |
| 1162 | + ) |
| 1163 | + |
| 1164 | + |
| 1165 | +def test_grouped_description_for_multiple_clinical_risk_cohort_if_best_status_is_not_eligible( |
| 1166 | + faker: Faker, |
| 1167 | +): |
| 1168 | + # Given |
| 1169 | + nhs_number = NHSNumber(faker.nhs_number()) |
| 1170 | + date_of_birth = DateOfBirth(faker.date_of_birth(minimum_age=66, maximum_age=74)) |
| 1171 | + |
| 1172 | + person_rows = person_rows_builder(nhs_number, date_of_birth=date_of_birth, cohorts=[]) |
| 1173 | + campaign_configs = [ |
| 1174 | + rule_builder.CampaignConfigFactory.build( |
| 1175 | + target="RSV", |
| 1176 | + iterations=[ |
| 1177 | + rule_builder.IterationFactory.build( |
| 1178 | + iteration_cohorts=[ |
| 1179 | + rule_builder.Rsv75RollingCohortFactory.build(), |
| 1180 | + rule_builder.Rsv75to79CohortFactory.build(), |
| 1181 | + rule_builder.RsvPretendClinicalCohortFactory.build() |
| 1182 | + ], |
| 1183 | + iteration_rules=[rule_builder.PostcodeSuppressionRuleFactory.build()], |
| 1184 | + ) |
| 1185 | + ], |
| 1186 | + ) |
| 1187 | + ] |
| 1188 | + |
| 1189 | + calculator = EligibilityCalculator(person_rows, campaign_configs) |
| 1190 | + |
| 1191 | + # When |
| 1192 | + actual = calculator.evaluate_eligibility() |
| 1193 | + |
| 1194 | + # Then |
| 1195 | + assert_that( |
| 1196 | + actual, |
| 1197 | + is_eligibility_status().with_conditions( |
| 1198 | + has_items( |
| 1199 | + is_condition() |
| 1200 | + .with_condition_name(ConditionName("RSV")) |
| 1201 | + .and_status(Status.not_eligible) |
| 1202 | + .and_cohort_results( |
| 1203 | + contains_exactly( |
| 1204 | + *[ |
| 1205 | + is_cohort_result().with_cohort_code(code) |
| 1206 | + for code in ["rsv_age_range", "rsv_clinical_cohort"] |
| 1207 | + ] |
| 1208 | + ) |
| 1209 | + ) |
| 1210 | + ) |
| 1211 | + ), |
| 1212 | + ) |
0 commit comments