Skip to content

Commit

Permalink
Prmdr 520 accept apostrophes in patient names for bulk upload (#165)
Browse files Browse the repository at this point in the history
* Add apostrophe to LG validation regex
* Update unit tests
  • Loading branch information
thisusernameisnowtaken authored Nov 27, 2023
1 parent 667fc7c commit 5dcd7aa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lambdas/handlers/back_channel_logout_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"},
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

import pytest
from botocore.exceptions import ClientError
from handlers.back_channel_logout_handler import lambda_handler
Expand Down
23 changes: 23 additions & 0 deletions lambdas/tests/unit/utils/test_lloyd_george_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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 = [
Expand Down
4 changes: 2 additions & 2 deletions lambdas/utils/lloyd_george_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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<page_no>[1-9][0-9]*)"
total_page_number = r"(?P<total_page_no>[1-9][0-9]*)"
patient_name = r"(?P<patient_name>[A-Za-z À-ÿ\-]+)"
patient_name = r"(?P<patient_name>[A-Za-z À-ÿ\-']+)"
nhs_number = r"(?P<nhs_number>\d{10})"
date_of_birth = r"(?P<date_of_birth>\d\d-\d\d-\d\d\d\d)"

Expand Down

0 comments on commit 5dcd7aa

Please sign in to comment.