@@ -845,3 +845,98 @@ def test_build_condition_results_cohorts_status_not_matching_iteration_status(se
845845 assert_that (len (result .cohort_results ), is_ (1 ))
846846 assert_that (result .cohort_results [0 ].cohort_code , is_ ("COHORT_X" ))
847847 assert_that (result .cohort_results [0 ].status , is_ (Status .not_eligible ))
848+
849+ @pytest .mark .parametrize (
850+ ("reason_2" , "expected_reasons" ),
851+ [
852+ # Same rule name and priority, different description
853+ (
854+ Reason (
855+ RuleType .suppression ,
856+ eligibility_status .RuleName ("Supress Rule 1" ),
857+ RulePriority ("1" ),
858+ RuleDescription ("Matching" ),
859+ matcher_matched = True ,
860+ ),
861+ [ # Only reason_1 expected
862+ Reason (
863+ RuleType .suppression ,
864+ eligibility_status .RuleName ("Supress Rule 1" ),
865+ RulePriority ("1" ),
866+ RuleDescription ("Not matching" ),
867+ matcher_matched = True ,
868+ )
869+ ],
870+ ),
871+ # Different rule name, same priority
872+ (
873+ Reason (
874+ RuleType .suppression ,
875+ eligibility_status .RuleName ("Supress Rule 2" ),
876+ RulePriority ("1" ),
877+ RuleDescription ("Matching" ),
878+ matcher_matched = True ,
879+ ),
880+ [ # Only reason_1 expected
881+ Reason (
882+ RuleType .suppression ,
883+ eligibility_status .RuleName ("Supress Rule 1" ),
884+ RulePriority ("1" ),
885+ RuleDescription ("Not matching" ),
886+ matcher_matched = True ,
887+ )
888+ ],
889+ ),
890+ # Same rule name, different priority
891+ (
892+ Reason (
893+ RuleType .suppression ,
894+ eligibility_status .RuleName ("Supress Rule 1" ),
895+ RulePriority ("2" ),
896+ RuleDescription ("Matching" ),
897+ matcher_matched = True ,
898+ ),
899+ [ # Both reasons expected
900+ Reason (
901+ RuleType .suppression ,
902+ eligibility_status .RuleName ("Supress Rule 1" ),
903+ RulePriority ("1" ),
904+ RuleDescription ("Not matching" ),
905+ matcher_matched = True ,
906+ ),
907+ Reason (
908+ RuleType .suppression ,
909+ eligibility_status .RuleName ("Supress Rule 1" ),
910+ RulePriority ("2" ),
911+ RuleDescription ("Matching" ),
912+ matcher_matched = True ,
913+ ),
914+ ],
915+ ),
916+ ],
917+ )
918+ def test_build_condition_results_grouping_reasons (self , reason_2 , expected_reasons ):
919+ reason_1 = Reason (
920+ RuleType .suppression ,
921+ eligibility_status .RuleName ("Supress Rule 1" ),
922+ RulePriority ("1" ),
923+ RuleDescription ("Not matching" ),
924+ matcher_matched = True ,
925+ )
926+
927+ cohort_group_results = [
928+ CohortGroupResult (
929+ "COHORT_Y" ,
930+ Status .not_actionable ,
931+ [reason_1 , reason_2 ],
932+ "Cohort Y Description" ,
933+ [],
934+ )
935+ ]
936+
937+ iteration_result = IterationResult (Status .not_actionable , cohort_group_results , [])
938+
939+ result = EligibilityCalculator .build_condition_results (iteration_result , ConditionName ("RSV" ))
940+
941+ assert_that (len (result .cohort_results ), is_ (1 ))
942+ assert_that (result .cohort_results [0 ].reasons , contains_inanyorder (* expected_reasons ))
0 commit comments