Skip to content

Commit 67af227

Browse files
committed
eli-579 removing comments and adding info to docstring, where appropriate
1 parent a1e1e99 commit 67af227

2 files changed

Lines changed: 8 additions & 16 deletions

File tree

src/eligibility_signposting_api/services/processors/derived_values/add_days_handler.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ class AddDaysHandler(DerivedValueHandler):
2727

2828
function_name: str = "ADD_DAYS"
2929

30-
# Mapping of derived attribute names to their source attributes
3130
DERIVED_ATTRIBUTE_SOURCES: ClassVar[dict[str, str]] = {
3231
"NEXT_DOSE_DUE": "LAST_SUCCESSFUL_DATE",
3332
}
@@ -62,7 +61,6 @@ def get_source_attribute(self, target_attribute: str, function_args: str | None
6261
The source attribute name (e.g., 'LAST_SUCCESSFUL_DATE')
6362
"""
6463
if function_args and "," in function_args:
65-
# Extract source from args if present (second argument)
6664
parts = [p.strip() for p in function_args.split(",")]
6765
if len(parts) > 1 and parts[1]:
6866
return parts[1].upper()
@@ -98,6 +96,9 @@ def calculate(self, context: DerivedValueContext) -> str:
9896
def _find_source_date(self, context: DerivedValueContext) -> str | None:
9997
"""Find the source date value from person data.
10098
99+
For PERSON-level attributes, looks for ATTRIBUTE_TYPE == "PERSON".
100+
For TARGET-level attributes, looks for ATTRIBUTE_TYPE == context.attribute_name (e.g., "COVID").
101+
101102
Args:
102103
context: The derived value context
103104
@@ -108,8 +109,6 @@ def _find_source_date(self, context: DerivedValueContext) -> str | None:
108109
if not source_attr:
109110
return None
110111

111-
# For PERSON-level attributes, look for ATTRIBUTE_TYPE == "PERSON"
112-
# For TARGET-level attributes, look for ATTRIBUTE_TYPE == context.attribute_name (e.g., "COVID")
113112
attribute_type_to_match = "PERSON" if context.attribute_level == "PERSON" else context.attribute_name
114113

115114
for attribute in context.person_data:
@@ -132,7 +131,6 @@ def _get_days_to_add(self, context: DerivedValueContext) -> int:
132131
Returns:
133132
Number of days to add
134133
"""
135-
# Priority 1: Token argument (if non-empty)
136134
if context.function_args:
137135
args = context.function_args.split(",")[0].strip()
138136
if args:
@@ -142,11 +140,9 @@ def _get_days_to_add(self, context: DerivedValueContext) -> int:
142140
message = f"Invalid days argument '{args}' for ADD_DAYS function. Expected an integer."
143141
raise ValueError(message) from e
144142

145-
# Priority 2: Vaccine-specific configuration
146143
if context.attribute_name in self.vaccine_type_days:
147144
return self.vaccine_type_days[context.attribute_name]
148145

149-
# Priority 3: Default
150146
return self.default_days
151147

152148
def _add_days_to_date(self, date_str: str, days: int) -> datetime:

src/eligibility_signposting_api/services/processors/token_processor.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,15 @@ def get_token_replacement(token: str, person_data: list[dict], present_attribute
9090
if TokenProcessor.should_replace_with_empty(parsed_token, present_attributes):
9191
return ""
9292

93-
# Check if this is a derived value (has a function like ADD_DAYS)
9493
if parsed_token.function_name:
9594
return TokenProcessor.get_derived_value(parsed_token, person_data, present_attributes, token)
9695

97-
# For non-derived tokens, validate that target attributes are allowed
9896
TokenProcessor.validate_target_attribute(parsed_token, token)
9997

10098
found_attribute, key_to_replace = TokenProcessor.find_matching_attribute(parsed_token, person_data)
10199

102100
if not found_attribute or not key_to_replace:
103101
TokenProcessor.handle_token_not_found(parsed_token, token)
104-
# handle_token_not_found always raises, but the type checker needs help
105102
msg = "Unreachable"
106103
raise RuntimeError(msg) # pragma: no cover
107104

@@ -116,6 +113,11 @@ def get_derived_value(
116113
) -> str:
117114
"""Calculate a derived value using the registered handler.
118115
116+
For TARGET level tokens, validates that the condition is allowed before processing.
117+
If the vaccine type is not in person data, returns an empty string.
118+
For derived values, any target attribute name is allowed (e.g., NEXT_BOOKING_AVAILABLE)
119+
since it's just a placeholder that may be surfaced in the future.
120+
119121
Args:
120122
parsed_token: The parsed token containing function information
121123
person_data: List of person attribute dictionaries
@@ -139,17 +141,12 @@ def get_derived_value(
139141
message = f"Unknown function '{function_name}' in token '{token}'."
140142
raise ValueError(message)
141143

142-
# For TARGET level tokens, validate the condition is allowed
143144
if parsed_token.attribute_level == TARGET_ATTRIBUTE_LEVEL:
144145
is_allowed_condition = parsed_token.attribute_name in ALLOWED_CONDITIONS.__args__
145146

146-
# If condition is not allowed, raise error
147147
if not is_allowed_condition:
148148
TokenProcessor.handle_token_not_found(parsed_token, token)
149149

150-
# If vaccine type is not in person data, return empty string
151-
# For derived values, any target attribute name is allowed (e.g., NEXT_BOOKING_AVAILABLE)
152-
# since it's just a placeholder that may be surfaced in the future
153150
if parsed_token.attribute_name not in present_attributes:
154151
return ""
155152

@@ -175,7 +172,6 @@ def get_derived_value(
175172
context=context,
176173
)
177174
except ValueError as e:
178-
# Re-raise with more context
179175
message = f"Error calculating derived value for token '{token}': {e}"
180176
raise ValueError(message) from e
181177

0 commit comments

Comments
 (0)