Skip to content

Commit 01ac156

Browse files
committed
dose sequence addressed comments and added unit tests
1 parent 848439a commit 01ac156

File tree

4 files changed

+46
-22
lines changed

4 files changed

+46
-22
lines changed

delta_backend/src/ConversionLayout.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
21
# This file holds the schema/base layout that maps FHIR fields to flat JSON fields
32
# Each entry tells the converter how to extract and transform a specific value
4-
from utils import is_integer_like
5-
63
EXTENSION_URL_VACCINATION_PRODEDURE = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure"
74
EXTENSION_URL_SCT_DESC_DISPLAY = "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-CodingSCTDescDisplay"
85

@@ -99,13 +96,13 @@ def _extract_route_of_vaccination_term(immunization) -> str:
9996
# - requirements: If element doseNumberPositiveInt exists and is < 10 then populate as received, else null
10097
# - path : protocolApplied.doseNumber[x]
10198
def _extract_dose_sequence(immunization) -> str:
102-
protocol_applied = immunization.get("protocolApplied")
103-
dose_number_positive_int = protocol_applied.get("doseNumberPositiveInt", "")
104-
105-
return dose_number_positive_int if is_integer_like(dose_number_positive_int) else ""
106-
99+
protocol_applied = immunization.get("protocolApplied", [])
107100

108-
101+
if protocol_applied:
102+
dose = protocol_applied[0].get("doseNumberPositiveInt", None)
103+
return str(dose) if dose else ""
104+
return ""
105+
109106
ConvertLayout = {
110107
"id": "7d78e9a6-d859-45d3-bb05-df9c405acbdb",
111108
"schemaName": "JSON Base",
@@ -279,7 +276,7 @@ def _extract_dose_sequence(immunization) -> str:
279276
"fieldNameFlat": "DOSE_SEQUENCE",
280277
"expression": {
281278
"expressionName": "Not Empty",
282-
"expressionType": "DOSESEQUENCE",
279+
"expressionType": "NORMAL",
283280
"expressionRule": _extract_dose_sequence
284281
}
285282
},

delta_backend/src/utils.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
from stdnum.verhoeff import validate
3-
from decimal import Decimal
43

54
def is_valid_simple_snomed(simple_snomed: str) -> bool:
65
"""
@@ -19,12 +18,3 @@ def is_valid_simple_snomed(simple_snomed: str) -> bool:
1918
)
2019
except:
2120
return False
22-
23-
def is_integer_like(val):
24-
if isinstance(val, Decimal):
25-
return val == int(val)
26-
try:
27-
int(val)
28-
return True
29-
except (ValueError, TypeError):
30-
return False
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import copy
2+
import json
3+
import unittest
4+
from tests.utils_for_converter_tests import ValuesForTests
5+
from Converter import Converter
6+
7+
8+
class TestDoseSequenceToFlatJson(unittest.TestCase):
9+
10+
def setUp(self):
11+
self.request_json_data = copy.deepcopy(ValuesForTests.json_data)
12+
13+
def _run_test(self, expected_result):
14+
"""Helper function to run the test"""
15+
self.converter = Converter(json.dumps(self.request_json_data))
16+
flat_json = self.converter.runConversion(self.request_json_data, False, True)
17+
self.assertEqual(flat_json["DOSE_SEQUENCE"], expected_result)
18+
19+
def test_dose_sequence_present_int(self):
20+
self.request_json_data["protocolApplied"] = [
21+
{
22+
"doseNumberPositiveInt": 2
23+
}
24+
]
25+
self._run_test(expected_result="2")
26+
27+
def test_dose_sequence_missing(self):
28+
self.request_json_data["protocolApplied"] = [{}]
29+
self._run_test(expected_result="")
30+
31+
def test_dose_sequence_protocol_applied_empty(self):
32+
self.request_json_data["protocolApplied"] = []
33+
self._run_test(expected_result="")
34+
35+
def test_dose_sequence_protocol_applied_absent(self):
36+
self.request_json_data.pop("protocolApplied", None)
37+
self._run_test(expected_result="")

delta_backend/tests/utils_for_converter_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def get_expected_imms(expected_action_flag):
196196
"PRIMARY_SOURCE": True,
197197
"VACCINATION_PROCEDURE_CODE": "13246814444444",
198198
"VACCINATION_PROCEDURE_TERM": "Test Value string 123456 COVID19 vaccination",
199-
"DOSE_SEQUENCE": Decimal('1'),
199+
"DOSE_SEQUENCE": "1",
200200
"VACCINE_PRODUCT_CODE": "39114911000001105",
201201
"VACCINE_PRODUCT_TERM": "COVID-19 Vaccine Vaxzevria (ChAdOx1 S [recombinant]) not less than 2.5x100,000,000 infectious units/0.5ml dose suspension for injection multidose vials (AstraZeneca UK Ltd) (product)",
202202
"VACCINE_MANUFACTURER": "AstraZeneca Ltd",
@@ -272,7 +272,7 @@ def get_expected_imms(expected_action_flag):
272272
"PRIMARY_SOURCE": True,
273273
"VACCINATION_PROCEDURE_CODE": "13246814444444",
274274
"VACCINATION_PROCEDURE_TERM": "Test Value string 123456 COVID19 vaccination",
275-
"DOSE_SEQUENCE": 1,
275+
"DOSE_SEQUENCE": "1",
276276
"VACCINE_PRODUCT_CODE": "39114911000001105",
277277
"VACCINE_PRODUCT_TERM": "COVID-19 Vaccine Vaxzevria (ChAdOx1 S [recombinant]) not less than 2.5x100,000,000 infectious units/0.5ml dose suspension for injection multidose vials (AstraZeneca UK Ltd) (product)",
278278
"VACCINE_MANUFACTURER": "AstraZeneca Ltd",

0 commit comments

Comments
 (0)