Skip to content

Commit f86fd26

Browse files
committed
refactor test and generic utils
1 parent 7d66e0c commit f86fd26

File tree

5 files changed

+10
-6
lines changed

5 files changed

+10
-6
lines changed

backend/src/models/utils/generic_utils.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ def create_diagnostics_error(value):
137137

138138
def form_json(response, _element, identifier, baseurl):
139139
self_url = f"{baseurl}?identifier={identifier}" + (f"&_elements={_element}" if _element else "")
140+
meta = {"versionId": response["version"]} if response and "version" in response else {}
140141
json = {
141142
"resourceType": "Bundle",
142143
"type": "searchset",
@@ -152,7 +153,7 @@ def form_json(response, _element, identifier, baseurl):
152153
# Full Immunization payload to be returned if only the identifier parameter was provided
153154
if identifier and not _element:
154155
resource = response["resource"]
155-
resource["meta"] = {"versionId": response["version"]}
156+
resource["meta"] = meta
156157

157158
elif identifier and _element:
158159
element = {e.strip().lower() for e in _element.split(",") if e.strip()}
@@ -165,7 +166,7 @@ def form_json(response, _element, identifier, baseurl):
165166
# Add 'meta' if specified
166167
if "meta" in element:
167168
resource["id"] = response["id"]
168-
resource["meta"] = {"versionId": response["version"]}
169+
resource["meta"] = meta
169170

170171
json["entry"] = [{
171172
"fullUrl": f"https://api.service.nhs.uk/immunisation-fhir-api/Immunization/{response['id']}",

backend/tests/sample_data/completed_covid19_immunization_event.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
],
5252
"identifier": [
5353
{
54+
"use": "official",
5455
"system": "https://supplierABC/identifiers/vacc",
5556
"value": "ACME-vacc123456"
5657
}

backend/tests/sample_data/completed_covid19_immunization_event_for_read.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
}
5151
],"identifier": [
5252
{
53+
"use": "official",
5354
"system": "https://supplierABC/identifiers/vacc",
5455
"value": "ACME-vacc123456"
5556
}

backend/tests/test_fhir_service.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -320,17 +320,17 @@ def tearDown(self):
320320

321321
def test_get_immunization_by_identifier(self):
322322
"""it should find an Immunization by id"""
323-
imms = "an-id#an-id"
323+
imms_id = "an-id#an-id"
324324
identifier = "test"
325325
element = "id,mEta,DDD"
326326
self.imms_repo.get_immunization_by_identifier.return_value = None
327327

328328
# When
329-
service_resp = self.fhir_service.get_immunization_by_identifier(imms, "COVID19.S", identifier, element)
329+
service_resp = self.fhir_service.get_immunization_by_identifier(imms_id, "COVID19.S", identifier, element)
330330
act_imms = service_resp
331331

332332
# Then
333-
self.imms_repo.get_immunization_by_identifier.assert_called_once_with(imms, "COVID19.S")
333+
self.imms_repo.get_immunization_by_identifier.assert_called_once_with(imms_id, "COVID19.S")
334334

335335
self.assertEqual(act_imms["resourceType"], "Bundle")
336336

@@ -339,7 +339,7 @@ def test_immunization_not_found(self):
339339
imms_id = "none"
340340
identifier = "test"
341341
element = "id"
342-
self.imms_repo.get_immunization_by_identifier.return_value = {}
342+
self.imms_repo.get_immunization_by_identifier.return_value = None
343343

344344
# When
345345
act_imms = self.fhir_service.get_immunization_by_identifier(imms_id, "COVID19.CRUDS", identifier, element)

backend/tests/utils/immunization_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def create_covid_19_immunization_dict(
2727

2828
return immunization_json
2929

30+
3031
def create_covid_19_immunization_dict_no_id(
3132
nhs_number=VALID_NHS_NUMBER, occurrence_date_time="2021-02-07T13:28:17.271+00:00"
3233
):

0 commit comments

Comments
 (0)