22
33from _operator import attrgetter
44from collections import defaultdict
5- from collections .abc import Collection , Iterable , Iterator , Mapping
65from dataclasses import dataclass , field
76from itertools import groupby
8- from typing import Any
7+ from typing import TYPE_CHECKING
98
109from wireup import service
1110
4342from eligibility_signposting_api .services .processors .campaign_evaluator import CampaignEvaluator
4443from eligibility_signposting_api .services .processors .person_data_reader import PersonDataReader
4544
46- Row = Collection [Mapping [str , Any ]]
45+ if TYPE_CHECKING :
46+ from collections .abc import Collection , Iterable , Iterator
47+
48+ from eligibility_signposting_api .model .person import Person
4749
4850
4951@service
5052class EligibilityCalculatorFactory :
5153 @staticmethod
52- def get (person_data : Row , campaign_configs : Collection [CampaignConfig ]) -> EligibilityCalculator :
53- return EligibilityCalculator (person_data = person_data , campaign_configs = campaign_configs )
54+ def get (person : Person , campaign_configs : Collection [CampaignConfig ]) -> EligibilityCalculator :
55+ return EligibilityCalculator (person = person , campaign_configs = campaign_configs )
5456
5557
5658@dataclass
5759class EligibilityCalculator :
58- person_data : Row
60+ person : Person
5961 campaign_configs : Collection [CampaignConfig ]
6062
6163 campaign_evaluator : CampaignEvaluator = field (default_factory = CampaignEvaluator )
@@ -238,7 +240,7 @@ def handle_action_rules(
238240 for _ , rule_group in groupby (sorted_rules_by_priority , key = priority_getter ):
239241 rule_group_list = list (rule_group )
240242 matcher_matched_list = [
241- RuleCalculator (person_data = self .person_data , rule = rule ).evaluate_exclusion ()[1 ].matcher_matched
243+ RuleCalculator (person = self .person , rule = rule ).evaluate_exclusion ()[1 ].matcher_matched
242244 for rule in rule_group_list
243245 ]
244246
@@ -258,7 +260,7 @@ def get_cohort_results(self, active_iteration: Iteration) -> dict[str, CohortGro
258260 filter_rules , suppression_rules = self .get_rules_by_type (active_iteration )
259261 for cohort in sorted (active_iteration .iteration_cohorts , key = attrgetter ("priority" )):
260262 # Base Eligibility - check
261- person_cohorts = self .person_data_reader .get_person_cohorts (self .person_data )
263+ person_cohorts = self .person_data_reader .get_person_cohorts (self .person )
262264 if cohort .cohort_label in person_cohorts or cohort .is_magic_cohort :
263265 # Eligibility - check
264266 if self .is_eligible_by_filter_rules (cohort , cohort_results , filter_rules ):
@@ -329,7 +331,7 @@ def is_eligible_by_filter_rules(
329331 if status .is_exclusion :
330332 if cohort .cohort_label is not None :
331333 cohort_results [cohort .cohort_label ] = CohortGroupResult (
332- ( cohort .cohort_group ) ,
334+ cohort .cohort_group ,
333335 Status .not_eligible ,
334336 [],
335337 cohort .negative_description ,
@@ -383,7 +385,7 @@ def evaluate_rules_priority_group(
383385
384386 for rule in rules_group :
385387 is_rule_stop = rule .rule_stop or is_rule_stop
386- rule_calculator = RuleCalculator (person_data = self .person_data , rule = rule )
388+ rule_calculator = RuleCalculator (person = self .person , rule = rule )
387389 status , reason = rule_calculator .evaluate_exclusion ()
388390 if status .is_exclusion :
389391 best_status = eligibility_status .Status .best (status , best_status )
0 commit comments