generated from NHSDigital/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrule.py
More file actions
67 lines (46 loc) · 2.29 KB
/
rule.py
File metadata and controls
67 lines (46 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from datetime import UTC, date, datetime, timedelta
from random import randint
from polyfactory import Use
from polyfactory.factories.pydantic_factory import ModelFactory
from eligibility_signposting_api.model import rules
def past_date(days_behind: int = 365) -> date:
return datetime.now(tz=UTC).date() - timedelta(days=randint(1, days_behind))
def future_date(days_ahead: int = 365) -> date:
return datetime.now(tz=UTC).date() + timedelta(days=randint(1, days_ahead))
class IterationCohortFactory(ModelFactory[rules.IterationCohort]): ...
class IterationRuleFactory(ModelFactory[rules.IterationRule]): ...
class IterationFactory(ModelFactory[rules.Iteration]):
iteration_cohorts = Use(IterationCohortFactory.batch, size=2)
iteration_rules = Use(IterationRuleFactory.batch, size=2)
iteration_date = Use(past_date)
class CampaignConfigFactory(ModelFactory[rules.CampaignConfig]):
iterations = Use(IterationFactory.batch, size=2)
start_date = Use(past_date)
end_date = Use(future_date)
class PersonAgeSuppressionRuleFactory(IterationRuleFactory):
type = rules.RuleType.suppression
name = rules.RuleName("Exclude too young less than 75")
description = rules.RuleDescription("Exclude too young less than 75")
priority = rules.RulePriority(10)
operator = rules.RuleOperator.year_gt
attribute_level = rules.RuleAttributeLevel.PERSON
attribute_name = rules.RuleAttributeName("DATE_OF_BIRTH")
comparator = rules.RuleComparator("-75")
class PostcodeSuppressionRuleFactory(IterationRuleFactory):
type = rules.RuleType.suppression
name = rules.RuleName("In SW19")
description = rules.RuleDescription("In SW19")
priority = rules.RulePriority(10)
operator = rules.RuleOperator.starts_with
attribute_level = rules.RuleAttributeLevel.PERSON
attribute_name = rules.RuleAttributeName("POSTCODE")
comparator = rules.RuleComparator("SW19")
class ICBSuppressionRuleFactory(IterationRuleFactory):
type = rules.RuleType.filter
name = rules.RuleName("Not in QE1")
description = rules.RuleDescription("Not in QE1")
priority = rules.RulePriority(10)
operator = rules.RuleOperator.ne
attribute_level = rules.RuleAttributeLevel.PERSON
attribute_name = rules.RuleAttributeName("ICB")
comparator = rules.RuleComparator("QE1")