Skip to content

Commit 496446f

Browse files
authored
VED-464 Vaccine Product Code (#717)
* pre-validation snomed check for vaccineCode * python = ">=3.11" * poetry env use 3.11 * revert: python = "~3.11" * python = ">=3.11,<4.0" * python = ">=3.11,<4.0" * init: move 'install poetry' * move 'install poetry' II * retooled after VED-699
1 parent 9c3d637 commit 496446f

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

backend/poetry.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/src/models/fhir_immunization_pre_validators.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def validate(self):
9494
self.pre_validate_value_codeable_concept,
9595
self.pre_validate_extension_length,
9696
self.pre_validate_vaccination_procedure_code,
97+
self.pre_validate_vaccine_code,
9798
]
9899

99100
for method in validation_methods:
@@ -903,3 +904,21 @@ def pre_validate_location_identifier_system(self, values: dict) -> dict:
903904
PreValidation.for_string(field_value, "location.identifier.system")
904905
except KeyError:
905906
pass
907+
908+
def pre_validate_vaccine_code(self, values: dict) -> dict:
909+
"""
910+
Pre-validate that, if vaccineCode.coding[?(@.system=='http://snomed.info/sct')].code
911+
(legacy CSV field : VACCINE_PRODUCT_CODE) exists, then it is a valid snomed code
912+
913+
NOTE: vaccineCode is a mandatory FHIR field. A value of None will be rejected by the
914+
FHIR model before pre-validators are run.
915+
"""
916+
url = "http://snomed.info/sct"
917+
field_location = f"vaccineCode.coding[?(@.system=='{url}')].code"
918+
try:
919+
field_value = [x for x in values["vaccineCode"]["coding"] if x.get("system") == url][0]["code"]
920+
PreValidation.for_string(field_value, field_location)
921+
PreValidation.for_snomed_code(field_value, field_location)
922+
except (KeyError, IndexError):
923+
pass
924+

backend/src/models/utils/generic_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def is_valid_simple_snomed(simple_snomed: str) -> bool:
7575
return (
7676
simple_snomed is not None
7777
and simple_snomed.isdigit()
78+
and simple_snomed[0] != '0'
7879
and min_snomed_length <= len(simple_snomed) <= max_snomed_length
7980
and validate(simple_snomed)
8081
and (simple_snomed[-3:-1] in ("00", "10"))

backend/tests/test_immunization_pre_validator.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,7 @@ def test_pre_validate_extension_snomed_code(self):
749749
"""Test test_pre_validate_extension_url accepts valid values and rejects invalid values for extension[0].url"""
750750
# Test case: missing "extension"
751751
invalid_json_data = deepcopy(self.json_data)
752-
test_values = ["12345abc", "12345", "1234567890123456789", "12345671", "1324681000000111"]
752+
test_values = ["12345abc", "12345", "1234567890123456789", "12345671", "1324681000000111", "0101291008"]
753753
for values in test_values:
754754
invalid_json_data["extension"][0]["valueCodeableConcept"]["coding"][0]["code"] = values
755755

@@ -1201,6 +1201,20 @@ def test_pre_validate_location_identifier_system(self):
12011201
valid_strings_to_test=["https://fhir.hl7.org.uk/Id/140565"],
12021202
)
12031203

1204+
def test_pre_validate_vaccine_code(self):
1205+
"""Test pre_validate_vaccine_code accepts valid values and rejects invalid values for vaccineCode.coding[0].code"""
1206+
invalid_json_data = deepcopy(self.json_data)
1207+
test_values = ["12345abc", "12345", "1234567890123456789", "12345671", "1324681000000111", "0101291008"]
1208+
for values in test_values:
1209+
invalid_json_data["vaccineCode"]["coding"][0]["code"] = values
1210+
1211+
with self.assertRaises(Exception) as error:
1212+
self.validator.validate(invalid_json_data)
1213+
1214+
full_error_message = str(error.exception)
1215+
actual_error_messages = full_error_message.replace("Validation errors: ", "").split("; ")
1216+
self.assertIn("vaccineCode.coding[?(@.system=='http://snomed.info/sct')].code is not a valid snomed code", actual_error_messages)
1217+
12041218

12051219
class TestImmunizationModelPreValidationRulesForReduceValidation(unittest.TestCase):
12061220
"""Test immunization pre validation rules on the FHIR model using the status="reduce validation" data"""

0 commit comments

Comments
 (0)