-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PRMP-571 - Lloyd George Ingestion - PDS Matching Updates Issues (#390)
* [PRMP-571] Add unicode utils method to check string starts_with and end_withs * [PRMP-571] Add helper to assert test not raising expection * [PRMP-571] Add test cases to reflect changes in PDS name match requirement * [PRMP-571] Adding unit tests, replace try except catch block with `expect_not_to_raise` * [PRMP-571] Amend implementation according to new requirements * [PRMP-571] Add mock patients to test bulk upload with new requirements * fix mistake in mock data (patient number not updated) * [PRMP-571] Update name comparison logic at frontend * edit mock patient to allow test with frontend * fix mock patient 103 missing gp ods code * set conftest.py to be exclude from coverage * [PRMP-571] Add logic to select the most recent name for patient * improve test coverage
- Loading branch information
1 parent
4c02b28
commit a735804
Showing
18 changed files
with
2,636 additions
and
107 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { PatientDetails } from '../../types/generic/patientDetails'; | ||
import { buildPatientDetails } from './testBuilders'; | ||
import { | ||
DOCUMENT_TYPE, | ||
DOCUMENT_UPLOAD_STATE as documentUploadStates, | ||
UploadDocument, | ||
} from '../../types/pages/UploadDocumentsPage/types'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
|
||
type PdsNameMatchingTestCase = { | ||
patientDetails: PatientDetails; | ||
patientNameInFileName: string; | ||
shouldAcceptName: boolean; | ||
}; | ||
|
||
type TestCaseJsonFormat = { | ||
pds_name: { | ||
family: string; | ||
given: string[]; | ||
}; | ||
accept: string[]; | ||
reject: string[]; | ||
}; | ||
|
||
export const TEST_CASES_FOR_TWO_WORDS_FAMILY_NAME = { | ||
pds_name: { family: 'Smith Anderson', given: ['Jane', 'Bob'] }, | ||
accept: ['Jane Bob Smith Anderson', 'Jane Smith Anderson', 'Jane B Smith Anderson'], | ||
reject: ['Bob Smith Anderson', 'Jane Smith', 'Jane Anderson', 'Jane Anderson Smith'], | ||
}; | ||
|
||
export const TEST_CASES_FOR_FAMILY_NAME_WITH_HYPHEN = { | ||
pds_name: { family: 'Smith-Anderson', given: ['Jane'] }, | ||
accept: ['Jane Smith-Anderson'], | ||
reject: ['Jane Smith Anderson', 'Jane Smith', 'Jane Anderson'], | ||
}; | ||
|
||
export const TEST_CASES_FOR_TWO_WORDS_GIVEN_NAME = { | ||
pds_name: { family: 'Smith', given: ['Jane Bob'] }, | ||
accept: ['Jane Bob Smith'], | ||
reject: ['Jane Smith', 'Jane B Smith', 'Jane-Bob Smith', 'Bob Smith'], | ||
}; | ||
|
||
export const TEST_CASES_FOR_TWO_WORDS_FAMILY_NAME_AND_GIVEN_NAME = { | ||
pds_name: { family: 'Smith Anderson', given: ['Jane Bob'] }, | ||
accept: ['Jane Bob Smith Anderson'], | ||
reject: [ | ||
'Jane Smith Anderson', | ||
'Bob Smith Anderson', | ||
'Jane B Smith Anderson', | ||
'Jane Bob Smith', | ||
'Jane Bob Anderson', | ||
], | ||
}; | ||
|
||
export function loadTestCases(testCaseJson: TestCaseJsonFormat): Array<PdsNameMatchingTestCase> { | ||
const patientDetails = buildPatientDetails({ | ||
givenName: testCaseJson['pds_name']['given'], | ||
familyName: testCaseJson['pds_name']['family'], | ||
}); | ||
|
||
const testCasesForAccept = testCaseJson['accept'].map((patientNameInFileName) => ({ | ||
patientDetails, | ||
patientNameInFileName, | ||
shouldAcceptName: true, | ||
})); | ||
|
||
const testCasesForReject = testCaseJson['reject'].map((patientNameInFileName) => ({ | ||
patientDetails, | ||
patientNameInFileName, | ||
shouldAcceptName: false, | ||
})); | ||
|
||
return [...testCasesForAccept, ...testCasesForReject]; | ||
} | ||
|
||
export function buildLGUploadDocsFromFilenames(filenames: string[]): UploadDocument[] { | ||
const fileObjects = filenames.map( | ||
(filename) => | ||
new File(['test'], filename, { | ||
type: 'application/pdf', | ||
}), | ||
); | ||
|
||
return fileObjects.map((file) => ({ | ||
file, | ||
state: documentUploadStates.SELECTED, | ||
progress: 0, | ||
id: uuidv4(), | ||
docType: DOCUMENT_TYPE.LLOYD_GEORGE, | ||
attempts: 0, | ||
})); | ||
} |
This file contains 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 |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { patientNameMatchesPds, uploadDocumentValidation } from './uploadDocumentValidation'; | ||
import { buildPatientDetails } from '../test/testBuilders'; | ||
import { | ||
buildLGUploadDocsFromFilenames, | ||
loadTestCases, | ||
TEST_CASES_FOR_FAMILY_NAME_WITH_HYPHEN, | ||
TEST_CASES_FOR_TWO_WORDS_FAMILY_NAME, | ||
TEST_CASES_FOR_TWO_WORDS_FAMILY_NAME_AND_GIVEN_NAME, | ||
TEST_CASES_FOR_TWO_WORDS_GIVEN_NAME, | ||
} from '../test/testDataForPdsNameValidation'; | ||
import { UploadFilesErrors } from '../../types/pages/UploadDocumentsPage/types'; | ||
|
||
describe('uploadDocumentValidation', () => { | ||
describe('name validation', () => { | ||
it('can handle a patient name with multiple words and special chars', () => { | ||
const testPatient = buildPatientDetails({ | ||
givenName: ['Jane François', 'Bob'], // NFC | ||
familyName: "O'Brian-Jones Anderson", | ||
nhsNumber: '9000000009', | ||
birthDate: '2011-09-19', | ||
}); | ||
const patientNameInFile = "Jane François Bob O'Brian-Jones Anderson"; // NFD; | ||
const testFileName = `1of1_Lloyd_George_Record_[${patientNameInFile}]_[9000000009]_[19-09-2011].pdf`; | ||
const testUploadDocuments = buildLGUploadDocsFromFilenames([testFileName]); | ||
|
||
const expected: UploadFilesErrors[] = []; | ||
const actual = uploadDocumentValidation(testUploadDocuments, testPatient); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('patientNameMatchesPds', () => { | ||
it('returns true when the name in pds match patientNameInFileName', () => { | ||
const patientDetails = buildPatientDetails({ givenName: ['Jane'], familyName: 'Smith' }); | ||
const patientNameInFileName = 'Jane Smith'; | ||
const expected: boolean = true; | ||
|
||
const actual: boolean = patientNameMatchesPds(patientNameInFileName, patientDetails); | ||
expect(actual).toBe(expected); | ||
}); | ||
|
||
it('returns false when first name not match', () => { | ||
const patientDetails = buildPatientDetails({ givenName: ['Jane'], familyName: 'Smith' }); | ||
const patientNameInFileName = 'Bob Smith'; | ||
const expected: boolean = false; | ||
|
||
const actual: boolean = patientNameMatchesPds(patientNameInFileName, patientDetails); | ||
expect(actual).toBe(expected); | ||
}); | ||
|
||
it('returns false when last name not match', () => { | ||
const patientDetails = buildPatientDetails({ givenName: ['Jane'], familyName: 'Smith' }); | ||
const patientNameInFileName = 'Jane Anderson'; | ||
const expected: boolean = false; | ||
|
||
const actual: boolean = patientNameMatchesPds(patientNameInFileName, patientDetails); | ||
expect(actual).toBe(expected); | ||
}); | ||
|
||
it('should be case insensitive when comparing names', () => { | ||
const patientDetails = buildPatientDetails({ givenName: ['jane'], familyName: 'SMITH' }); | ||
const patientNameInFileName = 'Jane Smith'; | ||
const expected: boolean = true; | ||
|
||
const actual: boolean = patientNameMatchesPds(patientNameInFileName, patientDetails); | ||
expect(actual).toBe(expected); | ||
}); | ||
|
||
it('should be able to compare names with accent chars', () => { | ||
const patientDetails = buildPatientDetails( | ||
{ givenName: ['Jàne'], familyName: 'Smïth' }, // NFD | ||
); | ||
const patientNameInFileName = 'Jàne Smïth'; // NFC | ||
const expected: boolean = true; | ||
|
||
const actual: boolean = patientNameMatchesPds(patientNameInFileName, patientDetails); | ||
expect(actual).toBe(expected); | ||
}); | ||
|
||
describe('Names with multiple words joined together', () => { | ||
it.each(loadTestCases(TEST_CASES_FOR_TWO_WORDS_FAMILY_NAME))( | ||
'from pds: ["Jane", "Bob"] Smith Anderson, filename: $patientNameInFileName, $shouldAcceptName', | ||
({ patientDetails, patientNameInFileName, shouldAcceptName }) => { | ||
const actual: boolean = patientNameMatchesPds( | ||
patientNameInFileName, | ||
patientDetails, | ||
); | ||
const expected: boolean = shouldAcceptName; | ||
|
||
expect(actual).toBe(expected); | ||
}, | ||
); | ||
|
||
it.each(loadTestCases(TEST_CASES_FOR_FAMILY_NAME_WITH_HYPHEN))( | ||
'from pds: ["Jane"] Smith-Anderson, filename: $patientNameInFileName, $shouldAcceptName', | ||
({ patientDetails, patientNameInFileName, shouldAcceptName }) => { | ||
const actual: boolean = patientNameMatchesPds( | ||
patientNameInFileName, | ||
patientDetails, | ||
); | ||
const expected: boolean = shouldAcceptName; | ||
|
||
expect(actual).toBe(expected); | ||
}, | ||
); | ||
|
||
it.each(loadTestCases(TEST_CASES_FOR_TWO_WORDS_GIVEN_NAME))( | ||
'from pds: ["Jane Bob"] Smith, filename: $patientNameInFileName, $shouldAcceptName', | ||
({ patientDetails, patientNameInFileName, shouldAcceptName }) => { | ||
const actual: boolean = patientNameMatchesPds( | ||
patientNameInFileName, | ||
patientDetails, | ||
); | ||
const expected: boolean = shouldAcceptName; | ||
|
||
expect(actual).toBe(expected); | ||
}, | ||
); | ||
|
||
it.each(loadTestCases(TEST_CASES_FOR_TWO_WORDS_FAMILY_NAME_AND_GIVEN_NAME))( | ||
'from pds: ["Jane Bob"] Smith Anderson, filename: $patientNameInFileName, $shouldAcceptName', | ||
({ patientDetails, patientNameInFileName, shouldAcceptName }) => { | ||
const actual: boolean = patientNameMatchesPds( | ||
patientNameInFileName, | ||
patientDetails, | ||
); | ||
const expected: boolean = shouldAcceptName; | ||
|
||
expect(actual).toBe(expected); | ||
}, | ||
); | ||
}); | ||
}); |
This file contains 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 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.