66import json
77from typing import Optional
88
9+
910def process_record (event_record : AwsLambdaSqsEventRecord ):
1011 record = AwsLambdaSqsEventRecord (event_record ) if isinstance (event_record , dict ) else event_record
1112 logger .info ("Processing record: %s" , record )
@@ -14,7 +15,37 @@ def process_record(event_record: AwsLambdaSqsEventRecord):
1415
1516 exists = check_records_exist (id )
1617
17- return f"hello world { record } "
18+ if exists :
19+ # get patient details from PDS
20+ patient_details = get_pds_patient_details (id )
21+
22+ patient_details_id = patient_details .get ("id" )
23+
24+ # if patient NHS != id, update patient index of vax events to new number
25+ if patient_details_id != id :
26+ return update_patient_index (id , patient_details_id )
27+ else :
28+ return {"status" : "success" , "message" : "No update required" }
29+ else :
30+ return {"status" : "error" , "message" : f"No records found for ID: { id } " }
31+
32+
33+ def check_records_exist (id : str ) -> bool :
34+ # TODO: Implement logic to check if records exist in the database
35+ logger .info (f"TODO Check if records exist for { id } " )
36+ return False
37+
38+
39+ def get_pds_patient_details (id : str ) -> dict :
40+ # TODO: Implement logic to retrieve patient details from PDS
41+ logger .info (f"TODO Get patient details for { id } " )
42+ return {"id" : id , "name" : "Mr Man" }
43+
44+
45+ def update_patient_index (old_id : str , new_id : str ):
46+ # TODO: Implement logic to update patient index in Redis or other data store
47+ logger .info (f"TODO Update patient index from { old_id } to { new_id } " )
48+ return {"status" : "success" , "message" : f"Updated patient idx from { old_id } to { new_id } " , "TODO" : "Implement logic" }
1849
1950
2051def get_id (event_body ) -> Optional [str ]:
@@ -26,34 +57,8 @@ def get_id(event_body) -> Optional[str]:
2657 else :
2758 data = event_body
2859 # Navigate through the nested structure
29- entries = data .get ("entry" , [])
30- if not entries :
31- logger .warning ("No entries found in bundle" )
32- return None
33-
34- # Get the first entry's resource
35- first_entry = entries [0 ]
36- resource = first_entry .get ("resource" , {})
37- parameters = resource .get ("parameter" , [])
38-
39- # Find the "additional-context" parameter
40- for param in parameters :
41- if param .get ("name" ) == "additional-context" :
42- parts = param .get ("part" , [])
43-
44- # Find the "subject" part within additional-context
45- for part in parts :
46- if part .get ("name" ) == "subject" :
47- value_ref = part .get ("valueReference" , {})
48- identifier = value_ref .get ("identifier" , {})
49- subject_id = identifier .get ("value" )
50-
51- if subject_id :
52- logger .info ("Found subject identifier: %s" , subject_id )
53- return subject_id
54-
55- logger .warning ("Subject identifier not found in notification event" )
56- return None
60+ subject = data .get ("subject" )
61+ return subject
5762
5863 except (json .JSONDecodeError , KeyError , AttributeError ) as e :
5964 logger .error ("Error extracting subject identifier: %s" , e )
0 commit comments