@@ -756,6 +756,116 @@ def test_eligibility_status_replaces_tokens_with_attribute_data(faker: Faker):
756756 assert audit_condition .actions [0 ].action_url_label == "Your GP practice code is ."
757757
758758
759+ def test_regardless_of_final_status_audit_all_types_of_cohort_status_rules (faker : Faker ):
760+ # Given
761+ nhs_number = NHSNumber (faker .nhs_number ())
762+ date_of_birth = DateOfBirth (faker .date_of_birth (minimum_age = 85 , maximum_age = 85 ))
763+
764+ person_rows = person_rows_builder (
765+ nhs_number ,
766+ date_of_birth = date_of_birth ,
767+ cohorts = [
768+ "rsv_eli_376_cohort_1" ,
769+ "rsv_eli_376_cohort_2" ,
770+ "rsv_eli_376_cohort_3" ,
771+ "rsv_eli_376_cohort_4" ,
772+ "rsv_eli_376_cohort_5" ,
773+ ],
774+ icb = "ABC" ,
775+ )
776+
777+ available_action = AvailableAction (
778+ ActionType = "ButtonAuthLink" ,
779+ ExternalRoutingCode = "BookNBS" ,
780+ ActionDescription = "## Get vaccinated at your GP surgery in [[PERSON.ICB]]." ,
781+ UrlLink = HttpUrl ("https://www.nhs.uk/book-rsv" ),
782+ UrlLabel = "Your GP practice code is [[PERSON.GP_PRACTICE]]." ,
783+ )
784+
785+ campaign_configs = [
786+ rule_builder .CampaignConfigFactory .build (
787+ target = "RSV" ,
788+ iterations = [
789+ rule_builder .IterationFactory .build (
790+ default_comms_routing = "TOKEN_TEST" ,
791+ default_not_actionable_routing = "TOKEN_TEST" ,
792+ default_not_eligible_routing = "TOKEN_TEST" ,
793+ iteration_cohorts = [
794+ rule_builder .IterationCohortFactory .build (
795+ cohort_label = "rsv_eli_376_cohort_1" , cohort_group = "rsv_eli_376_cohort_group" , priority = 0
796+ ),
797+ rule_builder .IterationCohortFactory .build (
798+ cohort_label = "rsv_eli_376_cohort_2" , cohort_group = "rsv_eli_376_cohort_group" , priority = 1
799+ ),
800+ rule_builder .IterationCohortFactory .build (
801+ cohort_label = "rsv_eli_376_cohort_3" , cohort_group = "rsv_eli_376_cohort_group" , priority = 2
802+ ),
803+ rule_builder .IterationCohortFactory .build (
804+ cohort_label = "rsv_eli_376_cohort_4" ,
805+ cohort_group = "rsv_eli_376_cohort_group_other" ,
806+ priority = 3 ,
807+ ),
808+ rule_builder .IterationCohortFactory .build (
809+ cohort_label = "rsv_eli_376_cohort_5" ,
810+ cohort_group = "rsv_eli_376_cohort_group_another" ,
811+ priority = 4 ,
812+ ),
813+ ],
814+ iteration_rules = [
815+ rule_builder .PersonAgeSuppressionRuleFactory .build (
816+ type = RuleType .filter ,
817+ name = RuleName ("NotEligible Reason 1" ),
818+ description = RuleDescription ("NotEligible Description 1" ),
819+ priority = RulePriority ("100" ),
820+ operator = RuleOperator .year_lte ,
821+ attribute_level = RuleAttributeLevel .PERSON ,
822+ attribute_name = RuleAttributeName ("DATE_OF_BIRTH" ),
823+ comparator = RuleComparator ("-80" ),
824+ cohort_label = CohortLabel ("rsv_eli_376_cohort_1" ),
825+ ),
826+ rule_builder .ICBRedirectRuleFactory .build (
827+ operator = RuleOperator .ne , comparator = RuleComparator ("ABC" )
828+ ),
829+ rule_builder .PersonAgeSuppressionRuleFactory .build (
830+ type = RuleType .suppression ,
831+ name = RuleName ("NotActionable Reason 1" ),
832+ description = RuleDescription ("NotActionable Description 1" ),
833+ priority = RulePriority ("110" ),
834+ operator = RuleOperator .year_lte ,
835+ attribute_level = RuleAttributeLevel .PERSON ,
836+ attribute_name = RuleAttributeName ("DATE_OF_BIRTH" ),
837+ comparator = RuleComparator ("-80" ),
838+ cohort_label = CohortLabel ("rsv_eli_376_cohort_5" ),
839+ ),
840+ ],
841+ actions_mapper = rule_builder .ActionsMapperFactory .build (root = {"TOKEN_TEST" : available_action }),
842+ )
843+ ],
844+ )
845+ ]
846+
847+ calculator = EligibilityCalculator (person_rows , campaign_configs )
848+
849+ # When
850+ actual = calculator .get_eligibility_status ("Y" , ["ALL" ], "ALL" )
851+
852+ # Then
853+ assert_that (
854+ actual ,
855+ is_eligibility_status ().with_conditions (
856+ has_item (is_condition ().with_condition_name (ConditionName ("RSV" )).and_status (Status .actionable ))
857+ ),
858+ )
859+
860+ assert len (g .audit_log .response .condition [0 ].filter_rules ) == 1
861+ assert g .audit_log .response .condition [0 ].filter_rules [0 ].rule_name == "NotEligible Reason 1"
862+ assert g .audit_log .response .condition [0 ].filter_rules [0 ].rule_priority == "100"
863+ assert len (g .audit_log .response .condition [0 ].suitability_rules ) == 1
864+ assert g .audit_log .response .condition [0 ].suitability_rules [0 ].rule_name == "NotActionable Reason 1"
865+ assert g .audit_log .response .condition [0 ].suitability_rules [0 ].rule_message == "NotActionable Description 1"
866+ assert g .audit_log .response .condition [0 ].suitability_rules [0 ].rule_priority == "110"
867+
868+
759869def test_eligibility_status_with_invalid_tokens_raises_attribute_error (faker : Faker ):
760870 # Given
761871 nhs_number = NHSNumber (faker .nhs_number ())
0 commit comments