From 49439c841949df4bf879974767fefd2353a12a6f Mon Sep 17 00:00:00 2001 From: NogaNHS Date: Fri, 24 Jan 2025 16:45:35 +0000 Subject: [PATCH] [PRMP-1367] reverting changes --- .../unit/utils/test_lloyd_george_validator.py | 124 ++++++++++++++++-- 1 file changed, 114 insertions(+), 10 deletions(-) diff --git a/lambdas/tests/unit/utils/test_lloyd_george_validator.py b/lambdas/tests/unit/utils/test_lloyd_george_validator.py index 206e18a18..21c7e7c7c 100644 --- a/lambdas/tests/unit/utils/test_lloyd_george_validator.py +++ b/lambdas/tests/unit/utils/test_lloyd_george_validator.py @@ -53,7 +53,7 @@ validate_lg_files, validate_patient_date_of_birth, validate_patient_name_strict, - validate_patient_name_lenient + validate_patient_name_lenient, validate_patient_name_using_full_name_history ) @@ -260,6 +260,9 @@ def test_validate_nhs_id_with_pds_service(mock_pds_patient): with expect_not_to_raise(LGInvalidFilesException): validate_filename_with_patient_details_lenient(lg_file_list, mock_pds_patient) + with expect_not_to_raise(LGInvalidFilesException): + validate_filename_with_patient_details_strict(lg_file_list, mock_pds_patient) + def test_mismatch_nhs_id(mocker): lg_file_list = [ @@ -271,13 +274,20 @@ def test_mismatch_nhs_id(mocker): mocker.patch( "utils.lloyd_george_validator.check_for_number_of_files_match_expected" ) - mocker.patch("utils.lloyd_george_validator.validate_file_name") with pytest.raises(LGInvalidFilesException): validate_lg_file_names(lg_file_list, "9000000009") +def test_mismatch_name_with_pds_service_strict(mock_pds_patient): + lg_file_list = [ + "1of2_Lloyd_George_Record_[Jake Plain Smith]_[9000000009]_[22-10-2010].pdf", + "2of2_Lloyd_George_Record_[Jake Plain Smith]_[9000000009]_[22-10-2010].pdf", + ] -def test_mismatch_name_with_pds_service(mock_pds_patient): + with pytest.raises(LGInvalidFilesException): + validate_filename_with_patient_details_strict(lg_file_list, mock_pds_patient) + +def test_mismatch_name_with_pds_service_lenient(mock_pds_patient): lg_file_list = [ "1of2_Lloyd_George_Record_[Jake Plain Moody]_[9000000009]_[22-10-2010].pdf", "2of2_Lloyd_George_Record_[Jake Plain Moody]_[9000000009]_[22-10-2010].pdf", @@ -287,7 +297,7 @@ def test_mismatch_name_with_pds_service(mock_pds_patient): validate_filename_with_patient_details_lenient(lg_file_list, mock_pds_patient) -def test_validate_name_with_correct_name(mocker, mock_pds_patient): +def test_validate_name_with_correct_name_lenient(mocker, mock_pds_patient): lg_file_patient_name = "Jane Smith" mock_validate_name = mocker.patch( "utils.lloyd_george_validator.validate_patient_name_lenient" @@ -305,8 +315,41 @@ def test_validate_name_with_correct_name(mocker, mock_pds_patient): assert actual_is_name_validation_based_on_historic_name is False assert actual_score == ValidationScore.FULL_MATCH +def test_validate_name_with_correct_name_strict(mocker, mock_pds_patient): + lg_file_patient_name = "Jane Smith" + mock_validate_name = mocker.patch( + "utils.lloyd_george_validator.validate_patient_name_strict" + ) + with expect_not_to_raise(LGInvalidFilesException): + validate_patient_name_using_full_name_history( + lg_file_patient_name, mock_pds_patient + ) + assert mock_validate_name.call_count == 1 + + +def test_validate_name_with_file_missing_middle_name(mocker): + lg_file_patient_name = "Jane Smith" + patient = Patient.model_validate(PDS_PATIENT_WITH_MIDDLE_NAME) + mock_validate_name = mocker.patch("utils.lloyd_george_validator.validate_patient_name_strict") + with expect_not_to_raise(LGInvalidFilesException): + validate_patient_name_using_full_name_history(lg_file_patient_name, patient) -def test_validate_name_with_additional_middle_name_in_file_mismatching_pds(mocker): + assert mock_validate_name.call_count == 1 + + +def test_validate_name_with_additional_middle_name_in_file_mismatching_pds_strict(mocker): + lg_file_patient_name = "Jane David Smith" + mock_validate_name = mocker.patch( + "utils.lloyd_george_validator.validate_patient_name_strict" + ) + patient = Patient.model_validate(PDS_PATIENT_WITH_MIDDLE_NAME) + with expect_not_to_raise(LGInvalidFilesException): + actual_is_name_validation_based_on_historic_name = validate_patient_name_using_full_name_history(lg_file_patient_name, patient) + assert mock_validate_name.call_count == 1 + assert actual_is_name_validation_based_on_historic_name is False + + +def test_validate_name_with_additional_middle_name_in_file_mismatching_pds_lenient(mocker): lg_file_patient_name = "Jane David Smith" mock_validate_name = mocker.patch( "utils.lloyd_george_validator.validate_patient_name_lenient" @@ -326,6 +369,21 @@ def test_validate_name_with_additional_middle_name_in_file_mismatching_pds(mocke assert actual_score == ValidationScore.FULL_MATCH +def test_validate_name_with_additional_middle_name_in_file_but_none_in_pds_strict( + mock_pds_patient, mocker +): + lg_file_patient_name = "Jane David Smith" + mock_validate_name = mocker.patch( + "utils.lloyd_george_validator.validate_patient_name_strict" + ) + + actual_is_name_validation_based_on_historic_name = ( + validate_patient_name_using_full_name_history(lg_file_patient_name, mock_pds_patient) + ) + + assert mock_validate_name.call_count == 1 + assert actual_is_name_validation_based_on_historic_name is False + def test_validate_name_with_additional_middle_name_in_file_but_none_in_pds( mock_pds_patient, mocker ): @@ -335,7 +393,8 @@ def test_validate_name_with_additional_middle_name_in_file_but_none_in_pds( ) mock_validate_name.return_value = ValidationResult( score=ValidationScore.FULL_MATCH, - name_match=["Jane", "Smith"], + given_name_match=["Jane"], + family_name_match="Smith", ) actual_score, actual_is_name_validation_based_on_historic_name, result_message = ( calculate_validation_score(lg_file_patient_name, mock_pds_patient) @@ -346,7 +405,16 @@ def test_validate_name_with_additional_middle_name_in_file_but_none_in_pds( assert actual_score == ValidationScore.FULL_MATCH -def test_validate_name_with_wrong_first_name(mocker, mock_pds_patient): +def test_validate_name_with_wrong_first_name_strict(mocker, mock_pds_patient): + lg_file_patient_name = "John Smith" + mock_validate_name = mocker.patch("utils.lloyd_george_validator.validate_patient_name_strict") + mock_validate_name.return_value = False + with pytest.raises(LGInvalidFilesException): + validate_patient_name_using_full_name_history(lg_file_patient_name, mock_pds_patient) + assert mock_validate_name.call_count == 3 + + +def test_validate_name_with_wrong_first_name_lenient(mock_pds_patient): lg_file_patient_name = "John Smith" actual_response = validate_patient_name_lenient( @@ -360,7 +428,16 @@ def test_validate_name_with_wrong_first_name(mocker, mock_pds_patient): ) -def test_validate_name_with_wrong_family_name(mocker, mock_pds_patient): +def test_validate_name_with_wrong_family_name_strict(mocker, mock_pds_patient): + lg_file_patient_name = "John Johnson" + mock_validate_name = mocker.patch("utils.lloyd_george_validator.validate_patient_name_strict") + mock_validate_name.return_value = False + with pytest.raises(LGInvalidFilesException): + validate_patient_name_using_full_name_history(lg_file_patient_name, mock_pds_patient) + assert mock_validate_name.call_count == 3 + + +def test_validate_name_with_wrong_family_name_lenient(mock_pds_patient): lg_file_patient_name = "Jane Johnson" actual_response = validate_patient_name_lenient( lg_file_patient_name, @@ -373,7 +450,19 @@ def test_validate_name_with_wrong_family_name(mocker, mock_pds_patient): ) -def test_validate_name_with_historical_name(mocker, mock_pds_patient): +def test_validate_name_with_historical_name_strict(mocker, mock_pds_patient): + lg_file_patient_name = "Jim Stevens" + mock_validate_name = mocker.patch( + "utils.lloyd_george_validator.validate_patient_name_strict" + ) + mock_validate_name.side_effect = [False, True] + with expect_not_to_raise(LGInvalidFilesException): + actual_is_name_validation_based_on_historic_name = (validate_patient_name_using_full_name_history(lg_file_patient_name, mock_pds_patient)) + + assert mock_validate_name.call_count == 2 + assert actual_is_name_validation_based_on_historic_name is True + +def test_validate_name_with_historical_name_lenient(mocker, mock_pds_patient): lg_file_patient_name = "Jim Stevens" mock_validate_name = mocker.patch( "utils.lloyd_george_validator.validate_patient_name_lenient" @@ -394,7 +483,22 @@ def test_validate_name_with_historical_name(mocker, mock_pds_patient): assert actual_is_validate_on_historic is True -def test_validate_name_without_given_name(mocker, mock_pds_patient): +def test_validate_name_without_given_name_strict(mocker, mock_pds_patient): + lg_file_patient_name = "Jane Smith" + mock_pds_patient.name[0].given = [""] + mock_validate_name = mocker.patch( + "utils.lloyd_george_validator.validate_patient_name_strict" + ) + + with expect_not_to_raise(LGInvalidFilesException): + actual_is_validate_on_historic = (validate_patient_name_using_full_name_history(lg_file_patient_name, mock_pds_patient)) + + assert actual_is_validate_on_historic is False + assert mock_validate_name.call_count == 1 + + + +def test_validate_name_without_given_name_lenient(mocker, mock_pds_patient): lg_file_patient_name = "Jane Smith" mock_pds_patient.name[0].given = [""] mock_validate_name = mocker.patch(