Skip to content

Commit b54e956

Browse files
authored
VED-427: Add switch to disable PDS check & disable in int. (#627)
1 parent aa9e0c9 commit b54e956

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

backend/src/fhir_service.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import logging
12
from uuid import uuid4
23
import datetime
34
import os
@@ -26,6 +27,8 @@
2627
from timer import timed
2728
from filter import Filter
2829

30+
logging.basicConfig(level="INFO")
31+
logger = logging.getLogger()
2932

3033
def get_service_url(
3134
service_env: str = os.getenv("IMMUNIZATION_ENV"),
@@ -349,13 +352,18 @@ def _validate_patient(self, imms: dict) -> dict:
349352
If the NHS number exists, get the patient details from PDS and return the patient details.
350353
"""
351354
try:
352-
nhs_number = [x for x in imms["contained"] if x["resourceType"] == "Patient"][0]["identifier"][0]["value"]
355+
contained_patient = get_contained_patient(imms)
356+
nhs_number = contained_patient["identifier"][0]["value"]
353357
except (KeyError, IndexError):
354-
nhs_number = None
358+
return {}
355359

356360
if not nhs_number:
357361
return {}
358362

363+
if os.getenv("PDS_CHECK_ENABLED") == "false":
364+
logger.warning("Skipping PDS check")
365+
return contained_patient
366+
359367
patient = self.pds_service.get_patient_details(nhs_number)
360368
# To check whether the Superseded NHS number present in PDS
361369
if patient:

backend/tests/test_fhir_service.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import json
2+
import os
23
import uuid
34
import datetime
45
import unittest
56
from copy import deepcopy
67
from unittest import skip
7-
from unittest.mock import create_autospec
8+
from unittest.mock import create_autospec, patch
89
from decimal import Decimal
910

1011
from fhir.resources.R4B.bundle import Bundle as FhirBundle, BundleEntry
@@ -431,6 +432,16 @@ def test_patient_error(self):
431432
self.assertEqual(e.exception.patient_identifier, invalid_nhs_number)
432433
self.imms_repo.create_immunization.assert_not_called()
433434

435+
@patch.dict(os.environ, {"PDS_CHECK_ENABLED": "false"}, False)
436+
def test_pds_check_skipped(self):
437+
bad_patient_imms = create_covid_19_immunization_dict_no_id("a-bad-patient-id")
438+
self.imms_repo.create_immunization.return_value = bad_patient_imms
439+
440+
self.fhir_service.create_immunization(bad_patient_imms, "COVID19:create", "Test")
441+
442+
self.imms_repo.create_immunization.assert_called()
443+
self.fhir_service.pds_service.get_patient_details.assert_not_called()
444+
434445

435446
class TestUpdateImmunization(unittest.TestCase):
436447
"""Tests for FhirService.update_immunization"""

terraform/endpoints.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ locals {
2727
"IMMUNIZATION_BASE_PATH" = strcontains(local.environment, "pr-") ? "immunisation-fhir-api-${local.environment}" : "immunisation-fhir-api"
2828
# except for prod and ref, any other env uses PDS int environment
2929
"PDS_ENV" = local.environment == "prod" ? "prod" : local.environment == "ref" ? "ref" : "int",
30+
"PDS_CHECK_ENABLED" = tostring(local.environment != "int")
3031
"SPLUNK_FIREHOSE_NAME" = module.splunk.firehose_stream_name
3132
"SQS_QUEUE_URL" = "https://sqs.eu-west-2.amazonaws.com/${local.immunisation_account_id}/${local.short_prefix}-ack-metadata-queue.fifo"
3233
"REDIS_HOST" = data.aws_elasticache_cluster.existing_redis.cache_nodes[0].address

0 commit comments

Comments
 (0)