-
Notifications
You must be signed in to change notification settings - Fork 3
VED-813-Fix NHS-Number-Change #847
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 25 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
3b31be8
log resources
Akol125 1c3eb9c
debugging demographics match
Akol125 3081b06
change debug logs
Akol125 4cb13c9
confirm logs info
Akol125 abd7ca2
add info logs
Akol125 40b6e05
fix lint issues
Akol125 85e86ba
logging INFO issues
Akol125 ffcb6f8
fix git issues
Akol125 b2d312f
fix duplicate logs and missing logs
Akol125 c96c0b3
probe logs
Akol125 53c90da
probe logs
Akol125 e573538
create seperate logger per module
Akol125 2b299c1
spotted log issue
Akol125 3c7bffe
record_processor logs
Akol125 5b72fe6
resolve log issues
Akol125 01cdff5
record processor
Akol125 2697aca
extract patient resource
Akol125 df943c8
reverting some changes
Akol125 2df8adb
fix lint issues
Akol125 a95ae31
fixes
Akol125 aae949a
improve coverage
Akol125 ae64fde
remove PII logs
Akol125 837ba1e
fix lint issues3
Akol125 97d7d0a
remove pii2
Akol125 ef8a796
Merge branch 'master' into VED-000-NHS-Number-Change
Akol125 3335d7a
remove pii logs
Akol125 c4b261a
Merge remote branch into VED-813-NHS-Number-Change
Akol125 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
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 |
|---|---|---|
|
|
@@ -57,6 +57,9 @@ def process_nhs_number(nhs_number: str) -> Dict[str, Any]: | |
| logger.exception("process_nhs_number: failed to fetch demographic details: %s", e) | ||
| return make_status(str(e), nhs_number, "error") | ||
|
|
||
| logger.debug("Fetched PDS details: %s", pds_patient_resource) | ||
|
||
| logger.info("Fetched IEDS resources. IEDS count: %d", len(ieds_resources) if ieds_resources else 0) | ||
|
|
||
| if not ieds_resources: | ||
| logger.info("No IEDS records returned for NHS number: %s", nhs_number) | ||
| return make_status(f"No records returned for ID: {nhs_number}", nhs_number) | ||
|
|
@@ -65,6 +68,7 @@ def process_nhs_number(nhs_number: str) -> Dict[str, Any]: | |
| matching_records = [] | ||
| discarded_count = 0 | ||
| for detail in ieds_resources: | ||
| logger.info("Processing IEDS record: %s", detail) | ||
| if demographics_match(pds_patient_resource, detail): | ||
| matching_records.append(detail) | ||
| else: | ||
|
|
@@ -84,16 +88,21 @@ def process_nhs_number(nhs_number: str) -> Dict[str, Any]: | |
| return response | ||
|
|
||
|
|
||
| # Function to fetch PDS Patient details and IEDS Immunisation records | ||
| # Function to fetch PDS Patient details and IEDS Immunisation records. | ||
| def fetch_pds_and_ieds_resources(nhs_number: str): | ||
| logger.info("fetch_pds_and_ieds_resources: fetching for %s", nhs_number) | ||
| try: | ||
| pds = pds_get_patient_details(nhs_number) | ||
| except Exception as e: | ||
| logger.exception("fetch_pds_and_ieds_resources: failed to fetch PDS details for %s", nhs_number) | ||
| raise RuntimeError("Failed to fetch PDS details") from e | ||
|
|
||
| try: | ||
| ieds = get_items_from_patient_id(nhs_number) | ||
| except Exception as e: | ||
| logger.exception("fetch_pds_and_ieds_resources: failed to fetch IEDS items for %s", nhs_number) | ||
| raise RuntimeError("Failed to fetch IEDS items") from e | ||
|
|
||
| return pds, ieds | ||
|
|
||
|
|
||
|
|
@@ -132,17 +141,20 @@ def normalize_strings(item: Any) -> str | None: | |
| pds_name = normalize_strings(extract_normalized_name_from_patient(pds_details)) | ||
| pds_gender = normalize_strings(pds_details.get("gender")) | ||
| pds_birth = normalize_strings(pds_details.get("birthDate")) | ||
| logger.debug("demographics_match: demographics match for name=%s, gender=%s, birthDate=%s", | ||
| pds_name, pds_gender, pds_birth) | ||
|
|
||
| # Retrieve patient resource from IEDS item | ||
| patient = extract_patient_resource_from_item(ieds_item) | ||
| if not patient: | ||
| logger.debug("demographics_match: no patient resource in IEDS table item") | ||
| logger.info("demographics_match: no patient resource in IEDS table item") | ||
| return False | ||
|
|
||
| # normalize patient fields from IEDS | ||
| ieds_name = normalize_strings(extract_normalized_name_from_patient(patient)) | ||
| ieds_gender = normalize_strings(patient.get("gender")) | ||
| ieds_birth = normalize_strings(patient.get("birthDate")) | ||
| logger.debug("demographics_match: demographics match for %s", patient) | ||
|
|
||
| # All required fields must be present | ||
| if not all([pds_name, pds_gender, pds_birth, ieds_name, ieds_gender, ieds_birth]): | ||
|
|
||
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
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,63 +1,61 @@ | ||
| import unittest | ||
| from unittest.mock import patch | ||
| import common.clients as clients | ||
| from unittest.mock import patch, MagicMock | ||
| import logging | ||
| import importlib | ||
| import common.clients as clients | ||
|
|
||
|
|
||
| class TestClients(unittest.TestCase): | ||
|
|
||
| BUCKET_NAME = "default-bucket" | ||
| AWS_REGION = "eu-west-2" | ||
|
|
||
| def setUp(self): | ||
| self.boto3_client_patch = patch("boto3.client") | ||
| # Patch boto3.client | ||
| self.boto3_client_patch = patch("boto3.client", autospec=True) | ||
| self.mock_boto3_client = self.boto3_client_patch.start() | ||
| self.logging_patch = patch("logging.getLogger") | ||
| self.mock_logging = self.logging_patch.start() | ||
| self.logger_info_patcher = patch("logging.Logger.info") | ||
| self.mock_logger_info = self.logger_info_patcher.start() | ||
| self.getenv_patch = patch("os.getenv") | ||
| self.addCleanup(self.boto3_client_patch.stop) | ||
|
|
||
| # Patch logging.getLogger | ||
| self.logging_patch = patch("logging.getLogger", autospec=True) | ||
| self.mock_getLogger = self.logging_patch.start() | ||
| self.addCleanup(self.logging_patch.stop) | ||
|
|
||
| # Patch os.getenv | ||
| self.getenv_patch = patch("os.getenv", autospec=True) | ||
| self.mock_getenv = self.getenv_patch.start() | ||
| self.addCleanup(self.getenv_patch.stop) | ||
|
|
||
| # Set environment variable mock return values | ||
| self.mock_getenv.side_effect = lambda key, default=None: { | ||
| "CONFIG_BUCKET_NAME": self.BUCKET_NAME, | ||
| "AWS_REGION": self.AWS_REGION, | ||
| }.get(key, default) | ||
|
|
||
| self.mock_boto3_client.return_value = self.mock_boto3_client | ||
| self.mock_boto3_client.return_value.send_message = {} | ||
|
|
||
| def tearDown(self): | ||
| patch.stopall() | ||
| # Simulate logger instance and patch setLevel | ||
| self.mock_logger_instance = MagicMock() | ||
| self.mock_getLogger.return_value = self.mock_logger_instance | ||
|
|
||
| def test_os_environ(self): | ||
| # Test if environment variables are set correctly | ||
| # Reload the module under test to apply patches | ||
| importlib.reload(clients) | ||
|
|
||
| def test_env_variables_loaded(self): | ||
| """Test that environment variables are loaded correctly""" | ||
| self.assertEqual(clients.CONFIG_BUCKET_NAME, self.BUCKET_NAME) | ||
| self.assertEqual(clients.REGION_NAME, self.AWS_REGION) | ||
|
|
||
| def test_boto3_client(self): | ||
| ''' Test boto3 client is created with correct parameters ''' | ||
| importlib.reload(clients) | ||
| def test_boto3_client_created_for_s3(self): | ||
| """Test that S3 boto3 client is created with correct region""" | ||
| self.mock_boto3_client.assert_any_call("s3", region_name=self.AWS_REGION) | ||
|
|
||
| def test_firehose_client(self): | ||
| ''' Test firehose client is created with correct parameters ''' | ||
| importlib.reload(clients) | ||
| def test_boto3_client_created_for_firehose(self): | ||
| """Test that Firehose boto3 client is created with correct region""" | ||
| self.mock_boto3_client.assert_any_call("firehose", region_name=self.AWS_REGION) | ||
|
|
||
| def test_logging_setup(self): | ||
| ''' Test logging is set up correctly ''' | ||
| importlib.reload(clients) | ||
| self.assertTrue(hasattr(clients, 'logger')) | ||
| def test_logger_is_initialized(self): | ||
| """Test that a logger instance is initialized""" | ||
| self.mock_getLogger.assert_called_once_with() | ||
| self.assertTrue(hasattr(clients, "logger")) | ||
|
|
||
| def test_logging_configuration(self): | ||
| ''' Test logging configuration ''' | ||
| importlib.reload(clients) | ||
| clients.logger.setLevel.assert_called_once_with("INFO") | ||
|
|
||
| def test_logging_initialization(self): | ||
| ''' Test logging initialization ''' | ||
| importlib.reload(clients) | ||
| self.mock_logging.assert_called_once_with() | ||
| self.assertTrue(hasattr(clients, 'logger')) | ||
| clients.logger.setLevel.assert_any_call("INFO") | ||
| def test_logger_set_level(self): | ||
| """Test that logger level is set to INFO""" | ||
| self.mock_logger_instance.setLevel.assert_called_once_with(logging.INFO) |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be error. Means we have somehow persisted bad data to our events DB.