Skip to content

Commit 9fd3890

Browse files
committed
VED-746: test for search by identifier2
1 parent 2ef7c5a commit 9fd3890

File tree

1 file changed

+90
-1
lines changed

1 file changed

+90
-1
lines changed

e2e/test_search_immunization.py

Lines changed: 90 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class TestSearchImmunization(ImmunizationBaseTest):
1414
# in the result set and assert the one that we don't expect is not present.
1515
# This is to make these tests stateless otherwise; we need to clean up the db after each test
1616

17-
# create one or more immunization resources and return the created resource ids
1817
def store_records(self, *resources):
1918
ids = []
2019
for res in resources:
@@ -138,6 +137,27 @@ def test_search_backwards_compatible(self):
138137
self.assertEqual(response_imm["search"], {"mode": "match"})
139138
self.assertEqual(response_imm["resource"], expected_imms_resource)
140139

140+
def test_search_ignore_deleted(self):
141+
# Given patient has three vaccines and the last one is deleted
142+
mmr1 = generate_imms_resource(valid_nhs_number1, VaccineTypes.mmr)
143+
mmr2 = generate_imms_resource(valid_nhs_number1, VaccineTypes.mmr)
144+
mmr1_id, mmr2_id = self.store_records(mmr1, mmr2)
145+
146+
to_delete_mmr = generate_imms_resource(valid_nhs_number1, VaccineTypes.mmr)
147+
deleted_mmr = self.default_imms_api.create_a_deleted_immunization_resource(to_delete_mmr)
148+
149+
# When
150+
response = self.default_imms_api.search_immunizations(valid_nhs_number1, VaccineTypes.mmr)
151+
152+
# Then
153+
self.assertEqual(response.status_code, 200, response.text)
154+
body = response.json()
155+
156+
resource_ids = [entity["resource"]["id"] for entity in body["entry"]]
157+
self.assertTrue(mmr1_id in resource_ids)
158+
self.assertTrue(mmr2_id in resource_ids)
159+
self.assertTrue(deleted_mmr["id"] not in resource_ids)
160+
141161
def test_search_immunization_parameter_smoke_tests(self):
142162
time_1 = "2024-01-30T13:28:17.271+00:00"
143163
time_2 = "2024-02-01T13:28:17.271+00:00"
@@ -318,3 +338,72 @@ class SearchTestParams(NamedTuple):
318338
assert len(created_and_returned_ids) == len(search.expected_indexes)
319339
for expected_index in search.expected_indexes:
320340
assert created_resource_ids[expected_index] in result_ids
341+
342+
def test_search_immunization_accepts_include_and_provides_patient(self):
343+
"""it should accept the _include parameter of "Immunization:patient" and return the patient."""
344+
345+
# Arrange
346+
imms_obj = generate_imms_resource(valid_nhs_number1, VaccineTypes.mmr)
347+
imms_obj_id = self.store_records(imms_obj)
348+
349+
response = self.default_imms_api.search_immunizations_full(
350+
"POST",
351+
f"patient.identifier={valid_patient_identifier1}&-immunization.target={VaccineTypes.mmr}"
352+
+ "&_include=Immunization:patient",
353+
body=None,
354+
)
355+
356+
assert response.ok
357+
result = response.json()
358+
entries = result["entry"]
359+
360+
entry_ids = [result["resource"]["id"] for result in result["entry"]]
361+
assert imms_obj_id in entry_ids
362+
363+
patient_entry = next(entry for entry in entries if entry["resource"]["resourceType"] == "Patient")
364+
assert patient_entry["search"]["mode"] == "include"
365+
366+
assert patient_entry["resource"]["identifier"][0]["system"] == "https://fhir.nhs.uk/Id/nhs-number"
367+
assert patient_entry["resource"]["identifier"][0]["value"] == valid_nhs_number1
368+
369+
response_without_include = self.default_imms_api.search_immunizations_full(
370+
"POST",
371+
f"patient.identifier={valid_patient_identifier1}&-immunization.target={VaccineTypes.mmr}",
372+
body=None
373+
)
374+
375+
assert response_without_include.ok
376+
result_without_include = response_without_include.json()
377+
378+
# Matches Immunisation History API in that it doesn't matter if you don't pass "_include".
379+
380+
# Ignore link, patient full url and immunisation patient reference as these will always differ.
381+
result["link"] = []
382+
result_without_include["link"] = []
383+
384+
for entry in result["entry"]:
385+
if entry["resource"]["resourceType"] == "Immunization":
386+
entry["resource"]["patient"]["reference"] = "MOCK VALUE"
387+
elif entry["resource"]["resourceType"] == "Patient":
388+
entry["fullUrl"] = "MOCK VALUE"
389+
390+
for entry in result_without_include["entry"]:
391+
if entry["resource"]["resourceType"] == "Immunization":
392+
entry["resource"]["patient"]["reference"] = "MOCK VALUE"
393+
elif entry["resource"]["resourceType"] == "Patient":
394+
entry["fullUrl"] = "MOCK VALUE"
395+
396+
self.assertEqual(result, result_without_include)
397+
398+
def test_search_reject_tbc(self):
399+
# Given patient has a vaccine with no NHS number
400+
imms = generate_imms_resource("TBC", VaccineTypes.mmr)
401+
del imms["contained"][1]["identifier"][0]["value"]
402+
self.store_records(imms)
403+
404+
# When
405+
response = self.default_imms_api.search_immunizations("TBC", f"{VaccineTypes.mmr}",
406+
expected_status_code=400)
407+
408+
# Then
409+
self.assert_operation_outcome(response, 400)

0 commit comments

Comments
 (0)