-
Notifications
You must be signed in to change notification settings - Fork 4
VED-755: Handling NHS Number confusions #816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 24 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
f7c5872
VED-755: refactor handler
motola 2f9d5e4
VED-755: refactor handler2
motola bc9f4bc
VED-755: Refactor existing id_sync codebase
motola 13610c5
VED-755: refactoring record_processor
motola bac82fe
resolve lint
motola 516ac9a
resolve lint2
motola cd02066
add logic for demographics match and integrate with nhs number proces…
motola b36d8ed
add unit test for demographics test
motola 001fda1
refactor all functions
motola 973c8a2
VED-755: Adding demographics logic
motola 7df9358
resolve failing test
motola 0644072
VED-755: Resolve lint issues
motola 4bb330a
VED-755: remove duplication
motola af29a78
VED-755: remove duplication2
motola 876485f
VED-755: improve coverage
motola f637a93
VED-755: refactor process_nhs_number
motola 31858cc
VED-755: added pagination, remove ieds_check_exist, modify test
motola 2ffffb7
refactor pagination
motola 9da9a17
VED-755: update records whose vaccination match
motola d1cd6a7
Merge branch 'master' into VED-755-Handling-NHS-Confusions
motola 9c446b5
refactoring record processor.py
motola a0381b7
Merge remote branch into VED-755-Handling-NHS-Confusions
motola 1ae026a
reduce cognitive complexity and use utils and constants
motola 8523b24
fix lint errors
motola 1941dba
VED-765: review based on changes
motola c930608
VED-755: code review changes
motola 5dd0764
VED-755: code review
motola e1461b4
Merge branch 'master' into VED-755-Handling-NHS-Confusions
motola File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,50 @@ | ||
| from common.clients import logger | ||
| from common.clients import STREAM_NAME | ||
| """ | ||
| - Parses the incoming AWS event into `AwsLambdaEvent` and iterate its `records`. | ||
| - Delegate each record to `process_record` and collect `nhs_number` from each result. | ||
| - If any record has status == "error" raise `IdSyncException` with aggregated nhs_numbers. | ||
| - Any unexpected error is wrapped into `IdSyncException(message="Error processing id_sync event")`. | ||
| """ | ||
|
|
||
| from typing import Any, Dict | ||
| from common.clients import logger, STREAM_NAME | ||
| from common.log_decorator import logging_decorator | ||
| from common.aws_lambda_event import AwsLambdaEvent | ||
| from exceptions.id_sync_exception import IdSyncException | ||
| from record_processor import process_record | ||
| ''' | ||
| Lambda function handler for processing SQS events.Lambda for ID Sync. Fired by SQS | ||
| ''' | ||
|
|
||
|
|
||
| @logging_decorator(prefix="id_sync", stream_name=STREAM_NAME) | ||
| def handler(event_data, _): | ||
|
|
||
| def handler(event_data: Dict[str, Any], _context) -> Dict[str, Any]: | ||
| try: | ||
| logger.info("id_sync handler invoked") | ||
| event = AwsLambdaEvent(event_data) | ||
|
dlzhry2nhs marked this conversation as resolved.
|
||
| record_count = len(event.records) | ||
| if record_count > 0: | ||
| logger.info("id_sync processing event with %d records", record_count) | ||
| error_count = 0 | ||
| nhs_numbers = [] | ||
| for record in event.records: | ||
| record_result = process_record(record) | ||
| nhs_numbers.append(record_result["nhs_number"]) | ||
| if record_result["status"] == "error": | ||
| error_count += 1 | ||
| if error_count > 0: | ||
| raise IdSyncException(message=f"Processed {record_count} records with {error_count} errors", | ||
| nhs_numbers=nhs_numbers) | ||
|
|
||
| else: | ||
| response = {"status": "success", | ||
| "message": f"Successfully processed {record_count} records", | ||
| "nhs_numbers": nhs_numbers} | ||
| else: | ||
| response = {"status": "success", "message": "No records found in event"} | ||
| records = event.records | ||
|
|
||
| if not records: | ||
| return {"status": "success", "message": "No records found in event"} | ||
|
|
||
| logger.info("id_sync processing event with %d records", len(records)) | ||
|
|
||
| results = [process_record(record) for record in records] | ||
|
Akol125 marked this conversation as resolved.
|
||
| nhs_numbers = [result["nhs_number"] for result in results] | ||
| error_count = sum(1 for result in results if result.get("status") == "error") | ||
|
|
||
| if error_count: | ||
| raise IdSyncException(message=f"Processed {len(records)} records with {error_count} errors", | ||
| nhs_numbers=nhs_numbers) | ||
|
|
||
| response = { | ||
| "status": "success", | ||
| "message": f"Successfully processed {len(records)} records", | ||
| "nhs_numbers": nhs_numbers | ||
| } | ||
|
|
||
| logger.info("id_sync handler completed: %s", response) | ||
| return response | ||
|
|
||
| except IdSyncException as e: | ||
| logger.exception(f"id_sync error: {e.message}") | ||
| raise e | ||
| except Exception as e: | ||
| raise | ||
| except Exception: | ||
| msg = "Error processing id_sync event" | ||
| logger.exception(msg) | ||
| raise IdSyncException(message=msg, exception=e) | ||
| raise IdSyncException(message=msg) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.