Skip to content

Commit 9f9ddf1

Browse files
committed
smells
1 parent 9e5fe5b commit 9f9ddf1

File tree

7 files changed

+74
-85
lines changed

7 files changed

+74
-85
lines changed

lambdas/shared/src/common/models/fhir_immunization.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ def validate(self, immunization_json_data: dict) -> Immunization:
6060
if self.add_post_validators and not reduce_validation:
6161
self.run_post_validators(immunization_json_data, vaccine_type)
6262

63-
def run_postalCode_validator(self, values: dict) -> None:
63+
def run_postal_code_validator(self, values: dict) -> None:
6464
"""Run pre validation on the FHIR Immunization Resource JSON data"""
6565
if error := PreValidators.pre_validate_patient_address_postal_code(self, values):
6666
raise ValueError(error)
67-
else:
68-
pass

lambdas/shared/src/common/models/fhir_immunization_pre_validators.py

Lines changed: 58 additions & 58 deletions
Large diffs are not rendered by default.

lambdas/shared/src/common/models/obtain_field_value.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
class ObtainFieldValue:
1414
"""Functions for obtaining a field value from the FHIR immunization resource json data"""
1515

16-
def __init__(self) -> None:
17-
pass
18-
1916
@staticmethod
2017
def target_disease(imms: dict):
2118
return imms["protocolApplied"][0]["targetDisease"]

lambdas/shared/src/common/models/utils/generic_utils.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import datetime
55
import json
66
import urllib.parse
7-
from typing import Any, Dict, Literal, Optional, Union
7+
from typing import Any, Dict, Literal, Optional
88

99
from fhir.resources.R4B.bundle import (
1010
Bundle as FhirBundle,
@@ -37,7 +37,7 @@ def get_contained_practitioner(imms: dict):
3737

3838
def get_generic_extension_value(
3939
json_data: dict, url: str, system: str, field_type: Literal["code", "display"]
40-
) -> Union[str, None]:
40+
) -> str | None:
4141
"""Get the value of an extension field, given its url, field_type, and system"""
4242
value_codeable_concept = [x for x in json_data["extension"] if x.get("url") == url][0]["valueCodeableConcept"]
4343
value_codeable_concept_coding = value_codeable_concept["coding"]
@@ -67,7 +67,7 @@ def is_actor_referencing_contained_resource(element, contained_resource_id):
6767
return False
6868

6969

70-
def check_for_unknown_elements(resource, resource_type) -> Union[None, list]:
70+
def check_for_unknown_elements(resource, resource_type) -> list | None:
7171
"""
7272
Checks each key in the resource to see if it is allowed. If any disallowed keys are found,
7373
returns a list containing an error message for each disallowed element
@@ -256,7 +256,7 @@ def obtain_current_name_period(period: dict, occurrence_date: datetime) -> bool:
256256
return True
257257

258258

259-
def get_current_name_instance(names: list, occurrence_date: datetime) -> dict:
259+
def get_current_name_instance(names: list, occurrence_date: datetime) -> dict | tuple:
260260
"""Selects the correct "current" name instance based on the 'period' and 'use' criteria."""
261261

262262
# DUE TO RUNNING PRE_VALIDATE_PATIENT_NAME AND PRE_VALIDATE_PRACTITIONER NAME BEFORE THE RESPECTIVE CHECKS
@@ -278,9 +278,10 @@ def get_current_name_instance(names: list, occurrence_date: datetime) -> dict:
278278
for index, name in valid_name_instances:
279279
try:
280280
# Check for 'period' and occurrence date
281-
if isinstance(name, dict):
282-
if "period" not in name or obtain_current_name_period(name.get("period", {}), occurrence_date):
283-
current_names.append((index, name))
281+
if isinstance(name, dict) and (
282+
"period" not in name or obtain_current_name_period(name.get("period", {}), occurrence_date)
283+
):
284+
current_names.append((index, name))
284285
except (KeyError, ValueError):
285286
continue
286287

lambdas/shared/src/common/models/utils/pre_validator_utils.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from datetime import date, datetime
22
from decimal import Decimal
3-
from typing import Optional, Union
3+
from typing import Optional
44

55
from .generic_utils import is_valid_simple_snomed, nhs_number_mod11_check
66

@@ -33,16 +33,13 @@ def for_string(
3333
if len(field_value) == 0:
3434
raise ValueError(f"{field_location} must be a non-empty string")
3535

36-
if max_length:
37-
if len(field_value) > max_length:
36+
if max_length and len(field_value) > max_length:
3837
raise ValueError(f"{field_location} must be {max_length} or fewer characters")
3938

40-
if predefined_values:
41-
if field_value not in predefined_values:
39+
if predefined_values and field_value not in predefined_values:
4240
raise ValueError(f"{field_location} must be one of the following: " + str(", ".join(predefined_values)))
4341

44-
if not spaces_allowed:
45-
if " " in field_value:
42+
if not spaces_allowed and " " in field_value:
4643
raise ValueError(f"{field_location} must not contain spaces")
4744

4845
@staticmethod
@@ -192,12 +189,11 @@ def for_positive_integer(field_value: int, field_location: str, max_value: int =
192189
if field_value <= 0:
193190
raise ValueError(f"{field_location} must be a positive integer")
194191

195-
if max_value:
196-
if field_value > max_value:
192+
if max_value and field_value > max_value:
197193
raise ValueError(f"{field_location} must be an integer in the range 1 to {max_value}")
198194

199195
@staticmethod
200-
def for_integer_or_decimal(field_value: Union[int, Decimal], field_location: str):
196+
def for_integer_or_decimal(field_value: int | Decimal, field_location: str):
201197
"""
202198
Apply pre-validation to a decimal field to ensure that it is an integer or decimal,
203199
which does not exceed the maximum allowed number of decimal places (if applicable)

lambdas/shared/src/common/models/validation_sets.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ class ValidationSets:
1717
The validator will then automatically pick up the correct validation set.
1818
"""
1919

20-
def __init__(self) -> None:
21-
pass
22-
2320
vaccine_type_agnostic = {
2421
"patient_identifier_value": MandationRules.required,
2522
"patient_name_given": MandationRules.mandatory,

lambdas/shared/tests/test_common/test_immunization_pre_validator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ def test_pre_validate_patient_address_postal_code(self):
593593
}
594594
]
595595
}
596-
result = self.validator.run_postalCode_validator(values)
596+
result = self.validator.run_postal_code_validator(values)
597597
self.assertIsNone(result)
598598

599599
def test_pre_validate_occurrence_date_time(self):

0 commit comments

Comments
 (0)