Skip to content

Commit 9b55d4e

Browse files
committed
test insert
1 parent 90634e6 commit 9b55d4e

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

lambdas/id_sync/src/ieds_db_operations.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from common.aws_dynamodb import get_dynamodb_table
44
from common.clients import logger
55
from exceptions.id_sync_exception import IdSyncException
6+
import json
67

78
ieds_table = None
89

@@ -65,3 +66,22 @@ def ieds_update_patient_id(old_id: str, new_id: str) -> dict:
6566
exception=e
6667
)
6768
raise e
69+
70+
71+
def test_ieds_insert_patient(patient_id: str) -> dict: # NOSONAR
72+
"""Test function for inserting patient ID."""
73+
logger.info("insert to db...")
74+
# write the patient id to table
75+
result = get_ieds_table().put_item(Item={
76+
"PK": f"Patient#{patient_id}",
77+
"PatientPK": f"Patient#{patient_id}",
78+
"PatientSK": f"Patient#{patient_id}",
79+
"Resource": '{"resourceType": "Immunization", "contained": [{"resourceType": "Practitioner", "id": "Pract1", "name": [{"family": "iucds", "given": ["Russell"]}]}, {"resourceType": "Patient", "id": "Pat1", "identifier": [{"system": "https://fhir.nhs.uk/Id/nhs-number", "value": "9726629101"}], "name": [{"family": "VAREY", "given": ["DIANA"]}], "gender": "unknown", "birthDate": "2021-10-24", "address": [{"postalCode": "DN15 8EZ"}]}], "extension": [{"url": "https://fhir.hl7.org.uk/StructureDefinition/Extension-UKCore-VaccinationProcedure", "valueCodeableConcept": {"coding": [{"system": "http://snomed.info/sct", "code": "1303503001", "display": "Administration of vaccine product containing only Human orthopneumovirus antigen (procedure)"}]}}], "identifier": [{"system": "https://www.ieds.england.nhs.uk/", "value": "a7e06f66-339f-4b81-b2f6-016b88bfc422"}], "status": "completed", "vaccineCode": {"coding": [{"system": "http://snomed.info/sct", "code": "42605811000001100", "display": "Abrysvo vaccine powder and solvent for solution for injection 0.5ml vials (Pfizer Ltd) (product)"}]}, "patient": {"reference": "#Pat1"}, "occurrenceDateTime": "2025-05-27T14:53:26.271+00:00", "recorded": "2025-07-10T11:25:56.000+00:00", "primarySource": true, "manufacturer": {"display": "Pfizer"}, "location": {"identifier": {"value": "X8E5B", "system": "https://fhir.nhs.uk/Id/ods-organization-code"}}, "lotNumber": "RSVAPITEST", "expirationDate": "2025-06-01", "site": {"coding": [{"system": "http://snomed.info/sct", "code": "368208006", "display": "Left upper arm structure (body structure)"}]}, "route": {"coding": [{"system": "http://snomed.info/sct", "code": "78421000", "display": "Intramuscular route (qualifier value)"}]}, "doseQuantity": {"value": 0.5, "unit": "milliliter", "system": "http://unitsofmeasure.org", "code": "ml"}, "performer": [{"actor": {"reference": "#Pract1"}}, {"actor": {"type": "Organization", "display": "UNIVERSITY HOSPITAL OF WALES", "identifier": {"system": "https://fhir.nhs.uk/Id/ods-organization-code", "value": "B0C4P"}}}], "reasonCode": [{"coding": [{"code": "443684005", "display": "Disease outbreak (event)", "system": "http://snomed.info/sct"}]}], "protocolApplied": [{"targetDisease": [{"coding": [{"system": "http://snomed.info/sct", "code": "55735004", "display": "Disease caused by severe acute respiratory syndrome coronavirus 2 (disorder)"}]}], "doseNumberPositiveInt": 11}], "id": "088414ed-7d3d-40a5-9968-b3d2b9a266b2"}',
80+
"IdentifierPK": "https://www.ieds.england.nhs.uk/#a7e06f66-339f-4b81-b2f6-016b88bfc422",
81+
"Operation": "CREATE",
82+
"Version": "1",
83+
"SupplierSystem": "RAVS",
84+
})
85+
86+
logger.info(f"Test result: {result}")
87+
return result

lambdas/id_sync/src/record_processor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from common.clients import logger
55
from typing import Optional
66
from pds_details import pds_get_patient_id
7-
from ieds_db_operations import ieds_check_exist, ieds_update_patient_id
7+
from ieds_db_operations import ieds_check_exist, ieds_update_patient_id, test_ieds_insert_patient
88
import json
99
import ast
1010

@@ -47,6 +47,7 @@ def process_nhs_number(nhs_number: str) -> Optional[str]:
4747
# if patient NHS != id, update patient index of vax events to new number
4848
if patient_details_id != nhs_number and patient_details_id:
4949
logger.info(f"process_nhs_number. Update patient ID from {nhs_number} to {patient_details_id}")
50+
test_ieds_insert_patient(patient_details_id) # NOSONAR
5051
if ieds_check_exist(patient_details_id):
5152
response = ieds_update_patient_id(patient_details_id, nhs_number)
5253
else:

lambdas/id_sync/tests/test_record_processor.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ def setUp(self):
2323
self.ieds_update_patient_id_patcher = patch('record_processor.ieds_update_patient_id')
2424
self.mock_ieds_update_patient_id = self.ieds_update_patient_id_patcher.start()
2525

26+
# mock out test_ieds_insert_patient
27+
self.ieds_test_insert_patcher = patch('record_processor.test_ieds_insert_patient') # TODO TEST code
28+
self.mock_ieds_test_insert = self.ieds_test_insert_patcher.start()
29+
2630
def tearDown(self):
2731
patch.stopall()
2832

terraform/id_sync_lambda.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ resource "aws_lambda_function" "id_sync_lambda" {
297297
variables = {
298298
REDIS_HOST = data.aws_elasticache_cluster.existing_redis.cache_nodes[0].address
299299
REDIS_PORT = data.aws_elasticache_cluster.existing_redis.cache_nodes[0].port
300-
IEDS_TABLE_NAME = "imms-int-imms-events" # TODO test only aws_dynamodb_table.events-dynamodb-table.name
300+
# IEDS_TABLE_NAME = "imms-int-imms-events" # TODO test only aws_dynamodb_table.events-dynamodb-table.name
301+
IEDS_TABLE_NAME = aws_dynamodb_table.events-dynamodb-table.name
301302
PDS_ENV = var.pds_environment
302303
SPLUNK_FIREHOSE_NAME = module.splunk.firehose_stream_name
303304
}

0 commit comments

Comments
 (0)