File tree Expand file tree Collapse file tree 3 files changed +23
-3
lines changed
Expand file tree Collapse file tree 3 files changed +23
-3
lines changed Original file line number Diff line number Diff line change 1+ import logging
12from uuid import uuid4
23import datetime
34import os
2627from timer import timed
2728from filter import Filter
2829
30+ logging .basicConfig (level = "INFO" )
31+ logger = logging .getLogger ()
2932
3033def 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 :
Original file line number Diff line number Diff line change 11import json
2+ import os
23import uuid
34import datetime
45import unittest
56from copy import deepcopy
67from unittest import skip
7- from unittest .mock import create_autospec
8+ from unittest .mock import create_autospec , patch
89from decimal import Decimal
910
1011from 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
435446class TestUpdateImmunization (unittest .TestCase ):
436447 """Tests for FhirService.update_immunization"""
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments