From 5dcd7aa862c9becff215690b96b06d2c01562ee8 Mon Sep 17 00:00:00 2001 From: Richard Smith <43441481+thisusernameisnowtaken@users.noreply.github.com> Date: Mon, 27 Nov 2023 12:39:19 +0000 Subject: [PATCH] Prmdr 520 accept apostrophes in patient names for bulk upload (#165) * Add apostrophe to LG validation regex * Update unit tests --- .../handlers/back_channel_logout_handler.py | 9 +++++--- .../test_back_channel_logout_handler.py | 1 - .../unit/utils/test_lloyd_george_validator.py | 23 +++++++++++++++++++ lambdas/utils/lloyd_george_validator.py | 4 ++-- 4 files changed, 31 insertions(+), 6 deletions(-) diff --git a/lambdas/handlers/back_channel_logout_handler.py b/lambdas/handlers/back_channel_logout_handler.py index 55996f62e..ea81cac35 100644 --- a/lambdas/handlers/back_channel_logout_handler.py +++ b/lambdas/handlers/back_channel_logout_handler.py @@ -72,7 +72,7 @@ def logout_handler(token): def remove_session_from_dynamo_db(sid): dynamodb_name = os.environ["AUTH_DYNAMODB_NAME"] dynamodb_service = DynamoDBService() - + filter_sid = Attr("sid").eq(sid) db_response = dynamodb_service.scan_table( dynamodb_name, filter_expression=filter_sid @@ -83,7 +83,10 @@ def remove_session_from_dynamo_db(sid): ndr_session_id = items[0]["NDRSessionId"] dynamodb_service.delete_item( - key={"NDRSessionId": ndr_session_id }, table_name=dynamodb_name + key={"NDRSessionId": ndr_session_id}, table_name=dynamodb_name ) - logger.info(f"Session removed for sid: {sid} and NDRSessionId {ndr_session_id }", {"Result": "Successful logout"}) + logger.info( + f"Session removed for sid: {sid} and NDRSessionId {ndr_session_id }", + {"Result": "Successful logout"}, + ) diff --git a/lambdas/tests/unit/handlers/test_back_channel_logout_handler.py b/lambdas/tests/unit/handlers/test_back_channel_logout_handler.py index 444996701..be1e43da7 100644 --- a/lambdas/tests/unit/handlers/test_back_channel_logout_handler.py +++ b/lambdas/tests/unit/handlers/test_back_channel_logout_handler.py @@ -1,4 +1,3 @@ - import pytest from botocore.exceptions import ClientError from handlers.back_channel_logout_handler import lambda_handler diff --git a/lambdas/tests/unit/utils/test_lloyd_george_validator.py b/lambdas/tests/unit/utils/test_lloyd_george_validator.py index c965cd687..85a0ef3d9 100644 --- a/lambdas/tests/unit/utils/test_lloyd_george_validator.py +++ b/lambdas/tests/unit/utils/test_lloyd_george_validator.py @@ -51,6 +51,16 @@ def test_valid_file_name_special_characters(): assert False, "One or more of the files do not match naming convention" +def test_valid_file_name_with_apostrophe(): + try: + file_name = ( + "1of1_Lloyd_George_Record_[Joé Blöggê's-Glüë]_[1111111111]_[25-12-2019].pdf" + ) + validate_file_name(file_name) + except LGInvalidFilesException: + assert False, "One or more of the files do not match naming convention" + + def test_files_with_duplication(): with pytest.raises(LGInvalidFilesException): lg_file_list = [ @@ -105,6 +115,19 @@ def test_files_list_with_invalid_name(): assert str(e.value) == "One or more of the files do not match naming convention" +def test_file_name_with_apostrophe_as_name(): + """ + This is an edge case which currently passes. + As part of prmdr-520 it was decided that it was acceptable to have an apostrophe accepted as a name + This is because patient names will only ever come from PDS + """ + try: + file_name = "1of1_Lloyd_George_Record_[']_[1111111111]_[25-12-2019].pdf" + validate_file_name(file_name) + except LGInvalidFilesException: + assert False, "One or more of the files do not match naming convention" + + def test_files_without_missing_files(): try: lg_file_list = [ diff --git a/lambdas/utils/lloyd_george_validator.py b/lambdas/utils/lloyd_george_validator.py index 8099dad0c..d0462349c 100644 --- a/lambdas/utils/lloyd_george_validator.py +++ b/lambdas/utils/lloyd_george_validator.py @@ -28,7 +28,7 @@ def validate_lg_file_type(file_type: str): def validate_file_name(name: str): - lg_regex = r"[0-9]+of[0-9]+_Lloyd_George_Record_\[[A-Za-z À-ÿ\-]+]_\[[0-9]{10}]_\[\d\d-\d\d-\d\d\d\d].pdf" + lg_regex = r"[0-9]+of[0-9]+_Lloyd_George_Record_\[[A-Za-z À-ÿ\-']+]_\[[0-9]{10}]_\[\d\d-\d\d-\d\d\d\d].pdf" if not re.fullmatch(lg_regex, name): raise LGInvalidFilesException( "One or more of the files do not match naming convention" @@ -85,7 +85,7 @@ def validate_lg_file_names(file_name_list: list[str], nhs_number: Optional[str] def extract_info_from_filename(filename: str) -> dict: page_number = r"(?P[1-9][0-9]*)" total_page_number = r"(?P[1-9][0-9]*)" - patient_name = r"(?P[A-Za-z À-ÿ\-]+)" + patient_name = r"(?P[A-Za-z À-ÿ\-']+)" nhs_number = r"(?P\d{10})" date_of_birth = r"(?P\d\d-\d\d-\d\d\d\d)"