From 99758bbb9da154cf44b4dae8508dbc7c85dd9ab8 Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Mon, 30 Sep 2024 09:32:38 +0000 Subject: [PATCH 1/3] removes nhs number sequence check --- .../src/utils/databaseClient.ts | 4 +- .../src/validation/content.ts | 32 ------------ .../tests/testHandler.test.ts | 4 +- .../testRequestContentValidation.test.ts | 49 ++----------------- 4 files changed, 8 insertions(+), 81 deletions(-) diff --git a/packages/updatePrescriptionStatus/src/utils/databaseClient.ts b/packages/updatePrescriptionStatus/src/utils/databaseClient.ts index ad8a3f028..bf239ca72 100644 --- a/packages/updatePrescriptionStatus/src/utils/databaseClient.ts +++ b/packages/updatePrescriptionStatus/src/utils/databaseClient.ts @@ -99,8 +99,8 @@ export async function getPreviousItem(currentItem: DataItem): Promise unmarshall(item) as DataItem) - .filter((item) => item.TaskID !== currentItem.TaskID) // Can't do NE in the query so filter here + .map((item) => unmarshall(item) as DataItem) + .filter((item) => item.TaskID !== currentItem.TaskID) // Can't do NE in the query so filter here ) } lastEvaluatedKey = result.LastEvaluatedKey diff --git a/packages/updatePrescriptionStatus/src/validation/content.ts b/packages/updatePrescriptionStatus/src/validation/content.ts index e0dd83925..4d3b23158 100644 --- a/packages/updatePrescriptionStatus/src/validation/content.ts +++ b/packages/updatePrescriptionStatus/src/validation/content.ts @@ -93,37 +93,6 @@ export function nhsNumber(task: Task): string | undefined { return validateNhsNumber(nhsNumber) ? undefined : message } -export function nhsNumberRange(task: Task): string | undefined { - type Range = { low: number; high: number; description?: string }; - - const validRanges: Array = [ - {low: 3_113_000_000, high: 3_200_000_000}, - {low: 4_000_000_000, high: 4_999_999_999}, - {low: 6_000_000_000, high: 7_999_999_999}, - {low: 9_000_000_000, high: 9_999_999_999} - ] - - const nhsNumber = Number(task.for!.identifier!.value) - for (const range of validRanges) { - if (range.low <= nhsNumber && nhsNumber <= range.high) { - return undefined - } - } - - const invalidRanges: Array = [ - {low: 101_000_000, high: 3_112_999_999, description: "Scottish"}, - {low: 3_200_000_001, high: 3_999_999_999, description: "Northern Irish"} - ] - - for (const range of invalidRanges) { - if (range.low <= nhsNumber && nhsNumber <= range.high) { - return `NHS number is in the ${range.description} range.` - } - } - - return "NHS number is not in a known, valid range." -} - export function resourceType(task: Task): string | undefined { const message = "Resource's resourceType is not 'Task'." const isTask = task.resourceType === "Task" @@ -215,7 +184,6 @@ export function taskContent(task: Task): Array { businessStatus, lastModified, nhsNumber, - nhsNumberRange, prescriptionID, resourceType, taskStatusAgainstBusinessStatus, diff --git a/packages/updatePrescriptionStatus/tests/testHandler.test.ts b/packages/updatePrescriptionStatus/tests/testHandler.test.ts index 984b916c4..dfd82b7d0 100644 --- a/packages/updatePrescriptionStatus/tests/testHandler.test.ts +++ b/packages/updatePrescriptionStatus/tests/testHandler.test.ts @@ -379,8 +379,8 @@ describe("Integration tests for updatePrescriptionStatus handler", () => { async (command) => { if (command instanceof QueryCommand) { return new Object({Items: [ - itemQueryResult("71a3cf0d-c096-4b72-be0c-b1dd5f94ab0b", "in-progress", "With Pharmacy", "2023-09-11T10:09:12Z"), - itemQueryResult("c523a80a-5346-46b3-81d2-a7420959c26b", "in-progress", "Ready to Dispatch", "2023-09-11T10:10:12Z"), + itemQueryResult("71a3cf0d-c096-4b72-be0c-b1dd5f94ab0b", "in-progress", "With Pharmacy", "2023-09-11T10:09:12Z"), + itemQueryResult("c523a80a-5346-46b3-81d2-a7420959c26b", "in-progress", "Ready to Dispatch", "2023-09-11T10:10:12Z"), itemQueryResult(TASK_VALUES[0].id, TASK_VALUES[0].status, TASK_VALUES[0].businessStatus, TASK_VALUES[0].lastModified) ]}) } diff --git a/packages/updatePrescriptionStatus/tests/validation/testRequestContentValidation.test.ts b/packages/updatePrescriptionStatus/tests/validation/testRequestContentValidation.test.ts index 0ca4b6e87..b07066e77 100644 --- a/packages/updatePrescriptionStatus/tests/validation/testRequestContentValidation.test.ts +++ b/packages/updatePrescriptionStatus/tests/validation/testRequestContentValidation.test.ts @@ -22,7 +22,6 @@ import { ValidationOutcome, validateContent, entryContent, - nhsNumberRange, status } from "../../src/validation/content" @@ -57,14 +56,14 @@ describe("Unit test for validateContent", () => { it("When task is invalid in multiple ways, should return false with issues.", async () => { const task = validTask() - task.for!.identifier!.value = "invalidNhsNumber" task.focus!.identifier!.system = "invalidLineItemIdCodeSystem" + task.lastModified = "invalidDate" const entry: BundleEntry = {fullUrl: FULL_URL_0, resource: task} const expectedOutcome = { valid: false, issues: - "NHS number is invalid. NHS number is not in a known, valid range. Invalid CodeSystem(s) - LineItemID." + "Date format provided for lastModified is invalid. Invalid CodeSystem(s) - LineItemID." } const actual: ValidationOutcome = validateContent(entry) @@ -83,12 +82,11 @@ describe("Unit test for taskContent", () => { it("When task is invalid in multiple ways, should return array with all issues.", async () => { const task = validTask() - task.for!.identifier!.value = "invalidNhsNumber" task.focus!.identifier!.system = "invalidLineItemIdCodeSystem" + task.lastModified = "invalidDate" const expectedOutcome = [ - "NHS number is invalid.", - "NHS number is not in a known, valid range.", + "Date format provided for lastModified is invalid.", "Invalid CodeSystem(s) - LineItemID." ] @@ -223,45 +221,6 @@ describe("Unit tests for validation of NHS number", () => { }) }) -describe("Unit tests for validation of NHS number range", () => { - it.each([ - { - nhsNumbers: ["0101000000", "3112999999"], - expected: "NHS number is in the Scottish range.", - scenarioDescription: - "When NHS number is in the Scottish range, should return expected issue." - }, - { - nhsNumbers: ["3200000001", "3999999999"], - expected: "NHS number is in the Northern Irish range.", - scenarioDescription: - "When NHS number is in the Northern Irish range, should return expected issue." - }, - { - nhsNumbers: [ - "3113000000", - "3200000000", - "4000000000", - "4999999999", - "6000000000", - "7999999999", - "9000000000", - "9999999999" - ], - expected: undefined, - scenarioDescription: "When NHS number is in the NHSE range." - } - ])("$scenarioDescription", async ({nhsNumbers, expected}) => { - for (const _nhsNumber of nhsNumbers) { - const task = {for: {identifier: {value: _nhsNumber}}} - - const actual = nhsNumberRange(task as Task) - - expect(actual).toEqual(expected) - } - }) -}) - describe("Unit tests for validation of status", () => { it.each([ { From eecf3745552256cb6491e2a2e0a72b7c5236ecf2 Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Wed, 2 Oct 2024 13:32:41 +0000 Subject: [PATCH 2/3] removes nhs number range validation from cpsu --- packages/cpsuLambda/src/schema/format_1/validator.ts | 6 ------ packages/cpsuLambda/tests/testHandler.test.ts | 8 +++----- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/packages/cpsuLambda/src/schema/format_1/validator.ts b/packages/cpsuLambda/src/schema/format_1/validator.ts index 62162c6b3..d2be45e5a 100644 --- a/packages/cpsuLambda/src/schema/format_1/validator.ts +++ b/packages/cpsuLambda/src/schema/format_1/validator.ts @@ -16,11 +16,5 @@ export const validator: Validator = (event, logger: Logg return Err(wrap_with_status(202, {})("Message Ignored")) } - const nhsNumber = parseInt(requestBody.nHSCHI) - if (nhsNumber >= 101000000 && nhsNumber < 3113000000) { - logger.warn(`Message with nHSCHI number '${nhsNumber}' Ignored`) - return Err(wrap_with_status(202, {})("Message Ignored")) - } - return Ok(requestBody) } diff --git a/packages/cpsuLambda/tests/testHandler.test.ts b/packages/cpsuLambda/tests/testHandler.test.ts index 191634aae..d7413ff4e 100644 --- a/packages/cpsuLambda/tests/testHandler.test.ts +++ b/packages/cpsuLambda/tests/testHandler.test.ts @@ -125,20 +125,18 @@ describe("format_1 handler", () => { expect(logger_warn).toHaveBeenCalledWith("Message of type 'NOTPrescriptionStatusChanged' Ignored") }) - test("Messages with non NHSEngland number are ignored", async () => { + test("Messages with non NHSEngland number are not ignored", async () => { const body = format_1_request() body.nHSCHI = "1996344668" - const {handler, logger_warn} = mockedWarnHandler() + const {handler} = mockedWarnHandler() const event = { headers: {}, body } const response = await handler(event as format_1.eventType, dummyContext) - expect(response.statusCode).toEqual(202) - expect(JSON.parse(response.body)).toEqual("Message Ignored") - expect(logger_warn).toHaveBeenCalledWith("Message with nHSCHI number '1996344668' Ignored") + expect(response.statusCode).toEqual(200) }) // PSU will validate the NHS number so pass it through and let the PSU provide the error message From 069b556a82a0b5fe41d70563308a8859ebb28b74 Mon Sep 17 00:00:00 2001 From: Jack Spagnoli Date: Wed, 2 Oct 2024 14:45:31 +0000 Subject: [PATCH 3/3] wording change --- packages/cpsuLambda/tests/testHandler.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/cpsuLambda/tests/testHandler.test.ts b/packages/cpsuLambda/tests/testHandler.test.ts index d7413ff4e..6e63d71b7 100644 --- a/packages/cpsuLambda/tests/testHandler.test.ts +++ b/packages/cpsuLambda/tests/testHandler.test.ts @@ -125,7 +125,7 @@ describe("format_1 handler", () => { expect(logger_warn).toHaveBeenCalledWith("Message of type 'NOTPrescriptionStatusChanged' Ignored") }) - test("Messages with non NHSEngland number are not ignored", async () => { + test("Messages with non NHSEngland number are accepted", async () => { const body = format_1_request() body.nHSCHI = "1996344668"