Skip to content

Commit

Permalink
Revert "Fix: [AEA-4027] - Invalid NHS Numbers accepted in PSU (#165)"
Browse files Browse the repository at this point in the history
This reverts commit 363fedc.
  • Loading branch information
anthony-nhs committed Apr 30, 2024
1 parent e64b841 commit 9e6b181
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
6 changes: 3 additions & 3 deletions packages/updatePrescriptionStatus/src/utils/nhsNumber.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Adapted from: https://github.com/tbrd/nhs-numbers

export function validateNhsNumber(nhsNumber: string): boolean {
if (!nhsNumber || nhsNumber.length !== 10 || !/^\d+$/.test(nhsNumber)) {
if (nhsNumber === undefined || nhsNumber === null || Number.isNaN(Number(nhsNumber))) {
return false
}

Expand All @@ -13,9 +13,9 @@ export function validateNhsNumber(nhsNumber: string): boolean {
calculatedCheckDigit = 0
}

const providedCheckDigit = parseInt(chars[9])
const providedCheckDigit = chars[9]

return calculatedCheckDigit === providedCheckDigit
return calculatedCheckDigit === Number(providedCheckDigit)
}

export function calculateCheckDigit(numberString: string): number {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ describe("validateNhsNumber", () => {
expect(validateNhsNumber("123456789")).toBe(false)
expect(validateNhsNumber("12345678901")).toBe(false)
expect(validateNhsNumber("123456789012")).toBe(false)
expect(validateNhsNumber("96878500351")).toBe(false)
expect(validateNhsNumber("1239687850035")).toBe(false)
expect(validateNhsNumber("1239687850035123")).toBe(false)
expect(validateNhsNumber("9687850035123123123123")).toBe(false)
expect(validateNhsNumber("1239687850035123123123123")).toBe(false)
})
})
})

0 comments on commit 9e6b181

Please sign in to comment.