Skip to content

Commit 4ee30f0

Browse files
committed
Removed PDS call from search and used Patient resource from last immunisation Contained resource in the final response
1 parent 72ac2e5 commit 4ee30f0

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

backend/src/fhir_service.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from models.field_names import FieldNames
2020
from models.errors import InvalidPatientId, CustomValidationError, UnhandledResponseError
2121
from models.fhir_immunization import ImmunizationValidator
22-
from models.utils.generic_utils import nhs_number_mod11_check, get_occurrence_datetime, create_diagnostics, form_json
22+
from models.utils.generic_utils import nhs_number_mod11_check, get_occurrence_datetime, create_diagnostics, form_json, get_contained_patient
2323
from models.constants import Constants
2424
from models.errors import MandatoryError
2525
from pds_service import PdsService
@@ -316,25 +316,22 @@ def search_immunizations(
316316
if self.is_valid_date_from(r, date_from) and self.is_valid_date_to(r, date_to)
317317
]
318318

319-
# Check whether the Superseded NHS number present in PDS
320-
if pds_patient := self.pds_service.get_patient_details(nhs_number):
321-
if pds_patient["identifier"][0]["value"] != nhs_number:
322-
return create_diagnostics()
323-
324319
# Create the patient URN for the fullUrl field.
325320
# NOTE: This UUID is assigned when a SEARCH request is received and used only for referencing the patient
326321
# resource from immunisation resources within the bundle. The fullUrl value we are using is a urn (hence the
327322
# FHIR key name of "fullUrl" is somewhat misleading) which cannot be used to locate any externally stored
328323
# patient resource. This is as agreed with VDS team for backwards compatibility with Immunisation History API.
329324
patient_full_url = f"urn:uuid:{str(uuid4())}"
330-
331-
# Filter and amend the immunization resources for the SEARCH response
332-
resources_filtered_for_search = [Filter.search(imms, patient_full_url, pds_patient) for imms in resources]
325+
326+
imms_patient_record = get_contained_patient(resources[-1]) if resources else None
327+
328+
# Filter and amend the immunization resources for the SEARCH response
329+
resources_filtered_for_search = [Filter.search(imms, patient_full_url, []) for imms in resources]
333330

334331
# Add bundle entries for each of the immunization resources
335332
entries = [
336333
BundleEntry(
337-
resource=Immunization.parse_obj(handle_s_flag(imms, pds_patient)),
334+
resource=Immunization.parse_obj(imms),
338335
search=BundleEntrySearch(mode="match"),
339336
fullUrl=f"https://api.service.nhs.uk/immunisation-fhir-api/Immunization/{imms['id']}",
340337
)
@@ -345,7 +342,7 @@ def search_immunizations(
345342
if len(resources) > 0:
346343
entries.append(
347344
BundleEntry(
348-
resource=self.process_patient_for_bundle(pds_patient),
345+
resource=self.process_patient_for_bundle(imms_patient_record),
349346
search=BundleEntrySearch(mode="include"),
350347
fullUrl=patient_full_url,
351348
)

backend/src/filter.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""Functions for filtering a FHIR Immunization Resource"""
22

3-
from models.utils.generic_utils import is_actor_referencing_contained_resource, get_contained_practitioner
3+
from models.utils.generic_utils import is_actor_referencing_contained_resource, get_contained_practitioner, get_contained_patient
44
from constants import Urls
55

66

@@ -104,8 +104,9 @@ def read(imms: dict) -> dict:
104104
def search(imms: dict, patient_full_url: str, bundle_patient: dict = None) -> dict:
105105
"""Apply filtering for an individual FHIR Immunization Resource as part of SEARCH request"""
106106
imms = remove_reference_to_contained_practitioner(imms)
107+
imms_patient_data = get_contained_patient(imms)
107108
imms.pop("contained")
108-
imms["patient"] = create_reference_to_patient_resource(patient_full_url, bundle_patient)
109+
imms["patient"] = create_reference_to_patient_resource(patient_full_url, imms_patient_data)
109110
imms = add_use_to_identifier(imms)
110111
return imms
111112

0 commit comments

Comments
 (0)