Skip to content

Commit 1dcfa69

Browse files
authored
VED-890 Vaccination Procedure Term (#954)
* pre_validate_vaccination_procedure_display * S5332 * unit test
1 parent af00d98 commit 1dcfa69

File tree

2 files changed

+34
-9
lines changed

2 files changed

+34
-9
lines changed

backend/src/models/fhir_immunization_pre_validators.py

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ def validate(self):
9696
self.pre_validate_value_codeable_concept,
9797
self.pre_validate_extension_length,
9898
self.pre_validate_vaccination_procedure_code,
99+
self.pre_validate_vaccination_procedure_display,
99100
self.pre_validate_vaccine_code,
100101
]
101102

@@ -590,7 +591,7 @@ def pre_validate_vaccination_procedure_code(self, values: dict) -> dict:
590591
(legacy CSV field name: VACCINATION_PROCEDURE_CODE) exists, then it is a non-empty string
591592
"""
592593
url = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-" + "VaccinationProcedure"
593-
system = "http://snomed.info/sct"
594+
system = Urls.snomed
594595
field_type = "code"
595596
field_location = generate_field_location_for_extension(url, system, field_type)
596597
try:
@@ -600,14 +601,30 @@ def pre_validate_vaccination_procedure_code(self, values: dict) -> dict:
600601
except (KeyError, IndexError):
601602
pass
602603

604+
def pre_validate_vaccination_procedure_display(self, values: dict) -> dict:
605+
"""
606+
Pre-validate that, if extension[?(@.url=='https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-
607+
VaccinationProcedure')].valueCodeableConcept.coding[?(@.system=='http://snomed.info/sct')].display
608+
(legacy CSV field name: VACCINATION_PROCEDURE_TERM) exists, then it is a non-empty string
609+
"""
610+
url = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-" + "VaccinationProcedure"
611+
system = Urls.snomed
612+
field_type = "display"
613+
field_location = generate_field_location_for_extension(url, system, field_type)
614+
try:
615+
field_value = get_generic_extension_value(values, url, system, field_type)
616+
PreValidation.for_string(field_value, field_location)
617+
except (KeyError, IndexError):
618+
pass
619+
603620
def pre_validate_vaccination_situation_code(self, values: dict) -> dict:
604621
"""
605622
Pre-validate that, if extension[?(@.url=='https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-
606623
VaccinationSituation')].valueCodeableConcept.coding[?(@.system=='http://snomed.info/sct')].code
607624
(legacy CSV field name: VACCINATION_SITUATION_CODE) exists, then it is a non-empty string
608625
"""
609626
url = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationSituation"
610-
system = "http://snomed.info/sct"
627+
system = Urls.snomed
611628
field_type = "code"
612629
field_location = generate_field_location_for_extension(url, system, field_type)
613630
try:
@@ -623,7 +640,7 @@ def pre_validate_vaccination_situation_display(self, values: dict) -> dict:
623640
(legacy CSV field name: VACCINATION_SITUATION_TERM) exists, then it is a non-empty string
624641
"""
625642
url = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationSituation"
626-
system = "http://snomed.info/sct"
643+
system = Urls.snomed
627644
field_type = "display"
628645
field_location = generate_field_location_for_extension(url, system, field_type)
629646
try:
@@ -702,7 +719,7 @@ def pre_validate_disease_type_coding_codes(self, values: dict) -> dict:
702719
Pre-validate that, if protocolApplied[0].targetDisease[{i}].coding[?(@.system=='http://snomed.info/sct')].code
703720
exists, then it is a non-empty string
704721
"""
705-
url = "http://snomed.info/sct"
722+
url = Urls.snomed
706723
try:
707724
for i in range(len(values["protocolApplied"][0]["targetDisease"])):
708725
field_location = f"protocolApplied[0].targetDisease[{i}].coding[?(@.system=='{url}')].code"
@@ -761,7 +778,7 @@ def pre_validate_site_coding_code(self, values: dict) -> dict:
761778
Pre-validate that, if site.coding[?(@.system=='http://snomed.info/sct')].code
762779
(legacy CSV field name: SITE_OF_VACCINATION_CODE) exists, then it is a non-empty string
763780
"""
764-
url = "http://snomed.info/sct"
781+
url = Urls.snomed
765782
field_location = f"site.coding[?(@.system=='{url}')].code"
766783
try:
767784
site_coding_code = [x for x in values["site"]["coding"] if x.get("system") == url][0]["code"]
@@ -774,7 +791,7 @@ def pre_validate_site_coding_display(self, values: dict) -> dict:
774791
Pre-validate that, if site.coding[?(@.system=='http://snomed.info/sct')].display
775792
(legacy CSV field name: SITE_OF_VACCINATION_TERM) exists, then it is a non-empty string
776793
"""
777-
url = "http://snomed.info/sct"
794+
url = Urls.snomed
778795
field_location = f"site.coding[?(@.system=='{url}')].display"
779796
try:
780797
field_value = [x for x in values["site"]["coding"] if x.get("system") == url][0]["display"]
@@ -795,7 +812,7 @@ def pre_validate_route_coding_code(self, values: dict) -> dict:
795812
Pre-validate that, if route.coding[?(@.system=='http://snomed.info/sct')].code
796813
(legacy CSV field name: ROUTE_OF_VACCINATION_CODE) exists, then it is a non-empty string
797814
"""
798-
url = "http://snomed.info/sct"
815+
url = Urls.snomed
799816
field_location = f"route.coding[?(@.system=='{url}')].code"
800817
try:
801818
field_value = [x for x in values["route"]["coding"] if x.get("system") == url][0]["code"]
@@ -808,7 +825,7 @@ def pre_validate_route_coding_display(self, values: dict) -> dict:
808825
Pre-validate that, if route.coding[?(@.system=='http://snomed.info/sct')].display
809826
(legacy CSV field name: ROUTE_OF_VACCINATION_TERM) exists, then it is a non-empty string
810827
"""
811-
url = "http://snomed.info/sct"
828+
url = Urls.snomed
812829
field_location = f"route.coding[?(@.system=='{url}')].display"
813830
try:
814831
field_value = [x for x in values["route"]["coding"] if x.get("system") == url][0]["display"]
@@ -951,7 +968,7 @@ def pre_validate_vaccine_code(self, values: dict) -> dict:
951968
NOTE: vaccineCode is a mandatory FHIR field. A value of None will be rejected by the
952969
FHIR model before pre-validators are run.
953970
"""
954-
url = "http://snomed.info/sct"
971+
url = Urls.snomed
955972
field_location = f"vaccineCode.coding[?(@.system=='{url}')].code"
956973
try:
957974
field_value = [x for x in values["vaccineCode"]["coding"] if x.get("system") == url][0]["code"]

backend/tests/test_immunization_pre_validator.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,14 @@ def test_pre_validate_vaccine_code(self):
14041404
actual_error_messages,
14051405
)
14061406

1407+
def test_pre_validate_vaccination_procedure_display(self):
1408+
"""Test test_pre_validate_vaccination_procedure_display accepts valid values and rejects invalid values"""
1409+
ValidatorModelTests.test_string_value(
1410+
self,
1411+
field_location="extension[?(@.url=='https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure')].valueCodeableConcept.coding[?(@.system=='http://snomed.info/sct')].display",
1412+
valid_strings_to_test=["DUMMY"],
1413+
)
1414+
14071415

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

0 commit comments

Comments
 (0)