Skip to content

Commit 15bdfa6

Browse files
committed
expression rule per field
1 parent 69d8e24 commit 15bdfa6

File tree

8 files changed

+179
-685
lines changed

8 files changed

+179
-685
lines changed

backend/src/models/fhir_immunization_pre_validators.py

Lines changed: 9 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +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,
10099
self.pre_validate_vaccine_code,
101-
self.pre_validate_vaccine_display,
102100
]
103101

104102
for method in validation_methods:
@@ -592,7 +590,7 @@ def pre_validate_vaccination_procedure_code(self, values: dict) -> dict:
592590
(legacy CSV field name: VACCINATION_PROCEDURE_CODE) exists, then it is a non-empty string
593591
"""
594592
url = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-" + "VaccinationProcedure"
595-
system = Urls.snomed
593+
system = "http://snomed.info/sct"
596594
field_type = "code"
597595
field_location = generate_field_location_for_extension(url, system, field_type)
598596
try:
@@ -602,30 +600,14 @@ def pre_validate_vaccination_procedure_code(self, values: dict) -> dict:
602600
except (KeyError, IndexError):
603601
pass
604602

605-
def pre_validate_vaccination_procedure_display(self, values: dict) -> dict:
606-
"""
607-
Pre-validate that, if extension[?(@.url=='https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-
608-
VaccinationProcedure')].valueCodeableConcept.coding[?(@.system=='http://snomed.info/sct')].display
609-
(legacy CSV field name: VACCINATION_PROCEDURE_TERM) exists, then it is a non-empty string
610-
"""
611-
url = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-" + "VaccinationProcedure"
612-
system = Urls.snomed
613-
field_type = "display"
614-
field_location = generate_field_location_for_extension(url, system, field_type)
615-
try:
616-
field_value = get_generic_extension_value(values, url, system, field_type)
617-
PreValidation.for_string(field_value, field_location)
618-
except (KeyError, IndexError):
619-
pass
620-
621603
def pre_validate_vaccination_situation_code(self, values: dict) -> dict:
622604
"""
623605
Pre-validate that, if extension[?(@.url=='https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-
624606
VaccinationSituation')].valueCodeableConcept.coding[?(@.system=='http://snomed.info/sct')].code
625607
(legacy CSV field name: VACCINATION_SITUATION_CODE) exists, then it is a non-empty string
626608
"""
627609
url = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationSituation"
628-
system = Urls.snomed
610+
system = "http://snomed.info/sct"
629611
field_type = "code"
630612
field_location = generate_field_location_for_extension(url, system, field_type)
631613
try:
@@ -641,7 +623,7 @@ def pre_validate_vaccination_situation_display(self, values: dict) -> dict:
641623
(legacy CSV field name: VACCINATION_SITUATION_TERM) exists, then it is a non-empty string
642624
"""
643625
url = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationSituation"
644-
system = Urls.snomed
626+
system = "http://snomed.info/sct"
645627
field_type = "display"
646628
field_location = generate_field_location_for_extension(url, system, field_type)
647629
try:
@@ -720,7 +702,7 @@ def pre_validate_disease_type_coding_codes(self, values: dict) -> dict:
720702
Pre-validate that, if protocolApplied[0].targetDisease[{i}].coding[?(@.system=='http://snomed.info/sct')].code
721703
exists, then it is a non-empty string
722704
"""
723-
url = Urls.snomed
705+
url = "http://snomed.info/sct"
724706
try:
725707
for i in range(len(values["protocolApplied"][0]["targetDisease"])):
726708
field_location = f"protocolApplied[0].targetDisease[{i}].coding[?(@.system=='{url}')].code"
@@ -779,7 +761,7 @@ def pre_validate_site_coding_code(self, values: dict) -> dict:
779761
Pre-validate that, if site.coding[?(@.system=='http://snomed.info/sct')].code
780762
(legacy CSV field name: SITE_OF_VACCINATION_CODE) exists, then it is a non-empty string
781763
"""
782-
url = Urls.snomed
764+
url = "http://snomed.info/sct"
783765
field_location = f"site.coding[?(@.system=='{url}')].code"
784766
try:
785767
site_coding_code = [x for x in values["site"]["coding"] if x.get("system") == url][0]["code"]
@@ -792,7 +774,7 @@ def pre_validate_site_coding_display(self, values: dict) -> dict:
792774
Pre-validate that, if site.coding[?(@.system=='http://snomed.info/sct')].display
793775
(legacy CSV field name: SITE_OF_VACCINATION_TERM) exists, then it is a non-empty string
794776
"""
795-
url = Urls.snomed
777+
url = "http://snomed.info/sct"
796778
field_location = f"site.coding[?(@.system=='{url}')].display"
797779
try:
798780
field_value = [x for x in values["site"]["coding"] if x.get("system") == url][0]["display"]
@@ -813,7 +795,7 @@ def pre_validate_route_coding_code(self, values: dict) -> dict:
813795
Pre-validate that, if route.coding[?(@.system=='http://snomed.info/sct')].code
814796
(legacy CSV field name: ROUTE_OF_VACCINATION_CODE) exists, then it is a non-empty string
815797
"""
816-
url = Urls.snomed
798+
url = "http://snomed.info/sct"
817799
field_location = f"route.coding[?(@.system=='{url}')].code"
818800
try:
819801
field_value = [x for x in values["route"]["coding"] if x.get("system") == url][0]["code"]
@@ -826,7 +808,7 @@ def pre_validate_route_coding_display(self, values: dict) -> dict:
826808
Pre-validate that, if route.coding[?(@.system=='http://snomed.info/sct')].display
827809
(legacy CSV field name: ROUTE_OF_VACCINATION_TERM) exists, then it is a non-empty string
828810
"""
829-
url = Urls.snomed
811+
url = "http://snomed.info/sct"
830812
field_location = f"route.coding[?(@.system=='{url}')].display"
831813
try:
832814
field_value = [x for x in values["route"]["coding"] if x.get("system") == url][0]["display"]
@@ -969,24 +951,11 @@ def pre_validate_vaccine_code(self, values: dict) -> dict:
969951
NOTE: vaccineCode is a mandatory FHIR field. A value of None will be rejected by the
970952
FHIR model before pre-validators are run.
971953
"""
972-
url = Urls.snomed
954+
url = "http://snomed.info/sct"
973955
field_location = f"vaccineCode.coding[?(@.system=='{url}')].code"
974956
try:
975957
field_value = [x for x in values["vaccineCode"]["coding"] if x.get("system") == url][0]["code"]
976958
PreValidation.for_string(field_value, field_location)
977959
PreValidation.for_snomed_code(field_value, field_location)
978960
except (KeyError, IndexError):
979961
pass
980-
981-
def pre_validate_vaccine_display(self, values: dict) -> dict:
982-
"""
983-
Pre-validate that, if vaccineCode.coding[?(@.system=='http://snomed.info/sct')].display
984-
(legacy CSV field : VACCINE_PRODUCT_TERM) exists, then it is a non-empty string
985-
"""
986-
url = Urls.snomed
987-
field_location = f"vaccineCode.coding[?(@.system=='{url}')].display"
988-
try:
989-
field_value = [x for x in values["vaccineCode"]["coding"] if x.get("system") == url][0]["display"]
990-
PreValidation.for_string(field_value, field_location)
991-
except (KeyError, IndexError):
992-
pass
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Constants:
2+
NHS_NUMBER_LENGTH = 10
3+
PERSON_NAME_ELEMENT_MAX_LENGTH = 35
4+
GENDERS = ["male", "female", "other", "unknown"]

0 commit comments

Comments
 (0)