|
1 | 1 | ''' |
2 | 2 | record Processor |
3 | 3 | ''' |
4 | | -from common.aws_lambda_sqs_event_record import AwsLambdaSqsEventRecord |
5 | 4 | from common.clients import logger |
6 | | -from pds_details import get_pds_patient_details |
7 | 5 | import json |
8 | 6 | from typing import Optional |
9 | | -from to_do_code import check_records_exist, update_patient_index |
| 7 | +from nhs_number_processor import process_nhs_number |
10 | 8 |
|
11 | 9 |
|
12 | | -def process_record(event_record: AwsLambdaSqsEventRecord): |
13 | | - record = AwsLambdaSqsEventRecord(event_record) if isinstance(event_record, dict) else event_record |
14 | | - logger.info("Processing record: %s", record) |
| 10 | +def process_record(event_record): |
15 | 11 |
|
16 | | - id = get_id(event_record.body) |
17 | | - |
18 | | - if id: |
19 | | - # TODO This code is a placeholder for checking if records exist in the database - defaulting to True for now |
20 | | - exists = check_records_exist(id) |
21 | | - |
22 | | - if exists: |
23 | | - # get patient details from PDS |
24 | | - patient_details = get_pds_patient_details(id) |
25 | | - if not patient_details: |
26 | | - return {"status": "error", "message": f"No records returned for ID: {id}"} |
27 | | - |
28 | | - patient_details_id = patient_details.get("id") |
29 | | - |
30 | | - # if patient NHS != id, update patient index of vax events to new number |
31 | | - if patient_details_id != id: |
32 | | - return update_patient_index(id, patient_details_id) |
33 | | - else: |
34 | | - return {"status": "success", "message": "No update required"} |
35 | | - else: |
36 | | - return {"status": "error", "message": f"No records found for ID: {id}"} |
| 12 | + logger.info("Processing record: %s", event_record) |
| 13 | + body = event_record.get('body', {}) |
| 14 | + nhs_number = get_id(body) |
| 15 | + if nhs_number: |
| 16 | + return process_nhs_number(nhs_number) |
37 | 17 | else: |
38 | | - return {"status": "error", "message": "No ID found in event record"} |
| 18 | + return {"status": "error", "message": "No NHS number found in event record"} |
39 | 19 |
|
40 | 20 |
|
41 | 21 | def get_id(event_body) -> Optional[str]: |
|
0 commit comments