diff --git a/packages/gsul/src/dynamoDBclient.ts b/packages/gsul/src/dynamoDBclient.ts index fc030f660..7d78fe291 100644 --- a/packages/gsul/src/dynamoDBclient.ts +++ b/packages/gsul/src/dynamoDBclient.ts @@ -39,7 +39,7 @@ export async function getItemsUpdatesForPrescription( return items.map((singleUpdate) => ({ itemId: String(singleUpdate.LineItemID), latestStatus: String(singleUpdate.Status), - isTerminalState: String(singleUpdate.TerminalStatus), + isTerminalState: String(singleUpdate.TerminalStatus) === "completed", lastUpdateDateTime: String(singleUpdate.LastModified) })) } diff --git a/packages/gsul/src/schema/response.ts b/packages/gsul/src/schema/response.ts index 9138197d6..cd496e762 100644 --- a/packages/gsul/src/schema/response.ts +++ b/packages/gsul/src/schema/response.ts @@ -11,7 +11,7 @@ const itemSchema = { type: "string" }, isTerminalState: { - type: "string" + type: "boolean" }, lastUpdateDateTime: { type: "string" diff --git a/packages/gsul/tests/testBuildResult.test.ts b/packages/gsul/tests/testBuildResult.test.ts index d0ff359c5..0847bef88 100644 --- a/packages/gsul/tests/testBuildResult.test.ts +++ b/packages/gsul/tests/testBuildResult.test.ts @@ -19,7 +19,7 @@ const scenarios: Array = [ { itemId: "item_1", latestStatus: "latest_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1970-01-01T00:00:00Z" } ], @@ -30,7 +30,7 @@ const scenarios: Array = [ { itemId: "item_1", latestStatus: "latest_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1970-01-01T00:00:00Z" } ] @@ -59,13 +59,13 @@ const scenarios: Array = [ { itemId: "item_1", latestStatus: "early_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1970-01-01T00:00:00Z" }, { itemId: "item_1", latestStatus: "latest_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1971-01-01T00:00:00Z" } ], @@ -76,7 +76,7 @@ const scenarios: Array = [ { itemId: "item_1", latestStatus: "latest_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1971-01-01T00:00:00Z" } ] @@ -92,25 +92,25 @@ const scenarios: Array = [ { itemId: "item_1", latestStatus: "item_1_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1970-01-01T00:00:00Z" }, { itemId: "item_1", latestStatus: "latest_item_1_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1972-01-01T00:00:00Z" }, { itemId: "item_2", latestStatus: "item_2_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1971-01-01T00:00:00Z" }, { itemId: "item_2", latestStatus: "early_item_2_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1970-01-01T00:00:00Z" } ], @@ -121,13 +121,13 @@ const scenarios: Array = [ { itemId: "item_1", latestStatus: "latest_item_1_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1972-01-01T00:00:00Z" }, { itemId: "item_2", latestStatus: "item_2_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1971-01-01T00:00:00Z" } ] diff --git a/packages/gsul/tests/testHander.test.ts b/packages/gsul/tests/testHander.test.ts index 5def4371a..114a95308 100644 --- a/packages/gsul/tests/testHander.test.ts +++ b/packages/gsul/tests/testHander.test.ts @@ -29,74 +29,134 @@ describe("test handler", () => { jest.clearAllMocks() }) - it("respond with error when schema version is 2", async () => { - const response = await handler({ - "schemaVersion": 2, - "prescriptions": [{ - prescriptionID: "abc", - odsCode: "123" - }] - }, dummyContext) - expect(response).toMatchObject({ - schemaVersion: 1, - isSuccess: false, - prescriptions: [] - }) - }) - - it("respond with success for empty request", async () => { - const mockReply = { - Count: 0, - Items: [] - } - jest.spyOn(DynamoDBDocumentClient.prototype, "send").mockResolvedValue(mockReply as never) - - const response = await handler( - { - "schemaVersion": 1, - "prescriptions": [] - }, dummyContext) - expect(response).toMatchObject({ - schemaVersion: 1, - isSuccess: true, - prescriptions: [] - }) - }) - - it("respond with success when data passed in", async () => { - const mockReply = { - Count: 1, - Items: [{ - PrescriptionID: "abc", - LineItemID: "item_1", - Status: "latest_status", - TerminalStatus: "terminal", - LastModified: "1970-01-01T00:00:00Z" - }] + const testCases = [ + { + description: "responds with error when schema version is 2", + event: { + schemaVersion: 2, + prescriptions: [ + { + prescriptionID: "abc", + odsCode: "123" + } + ] + }, + mockReply: null, + expectedResponse: { + schemaVersion: 1, + isSuccess: false, + prescriptions: [] + } + }, + { + description: "responds with success for empty request", + event: { + schemaVersion: 1, + prescriptions: [] + }, + mockReply: { + Count: 0, + Items: [] + }, + expectedResponse: { + schemaVersion: 1, + isSuccess: true, + prescriptions: [] + } + }, + { + description: "responds with success when data passed in with a terminal status 'completed'", + event: { + schemaVersion: 1, + prescriptions: [ + { + prescriptionID: "abc", + odsCode: "123" + } + ] + }, + mockReply: { + Count: 1, + Items: [ + { + PrescriptionID: "abc", + LineItemID: "item_1", + Status: "latest_status", + TerminalStatus: "completed", + LastModified: "1970-01-01T00:00:00Z" + } + ] + }, + expectedResponse: { + schemaVersion: 1, + isSuccess: true, + prescriptions: [ + { + prescriptionID: "abc", + onboarded: true, + items: [ + { + itemId: "item_1", + latestStatus: "latest_status", + isTerminalState: true, + lastUpdateDateTime: "1970-01-01T00:00:00Z" + } + ] + } + ] + } + }, + { + description: "responds with success when data passed in with a terminal status 'in-progress'", + event: { + schemaVersion: 1, + prescriptions: [ + { + prescriptionID: "abc", + odsCode: "123" + } + ] + }, + mockReply: { + Count: 1, + Items: [ + { + PrescriptionID: "abc", + LineItemID: "item_1", + Status: "latest_status", + TerminalStatus: "in-progress", + LastModified: "1970-01-01T00:00:00Z" + } + ] + }, + expectedResponse: { + schemaVersion: 1, + isSuccess: true, + prescriptions: [ + { + prescriptionID: "abc", + onboarded: true, + items: [ + { + itemId: "item_1", + latestStatus: "latest_status", + isTerminalState: false, + lastUpdateDateTime: "1970-01-01T00:00:00Z" + } + ] + } + ] + } } - jest.spyOn(DynamoDBDocumentClient.prototype, "send").mockResolvedValue(mockReply as never) + ] - const response = await handler( - { - "schemaVersion": 1, - "prescriptions": [{ - prescriptionID: "abc", - odsCode: "123" - }] - }, dummyContext) - expect(response).toMatchObject({ - schemaVersion: 1, - isSuccess: true, - prescriptions: [{ - prescriptionID: "abc", - onboarded: true, - items: [{ - itemId: "item_1", - latestStatus: "latest_status", - isTerminalState: "terminal", - lastUpdateDateTime: "1970-01-01T00:00:00Z" - }] - }] + testCases.forEach(({description, event, mockReply, expectedResponse}) => { + it(description, async () => { + if (mockReply) { + jest.spyOn(DynamoDBDocumentClient.prototype, "send").mockResolvedValue(mockReply as never) + } + const response = await handler(event, dummyContext) + expect(response).toMatchObject(expectedResponse) }) }) }) diff --git a/packages/gsul/tests/testRunDynamoDBQueries.test.ts b/packages/gsul/tests/testRunDynamoDBQueries.test.ts index 0c92b4374..2371588b0 100644 --- a/packages/gsul/tests/testRunDynamoDBQueries.test.ts +++ b/packages/gsul/tests/testRunDynamoDBQueries.test.ts @@ -21,7 +21,7 @@ describe("testing dynamoDBClient", () => { PrescriptionID: "abc", LineItemID: "item_1", Status: "latest_status", - TerminalStatus: "is_terminal_status", + TerminalStatus: "completed", LastModified: "1970-01-01T00:00:00Z" } ] @@ -37,7 +37,7 @@ describe("testing dynamoDBClient", () => { { itemId: "item_1", latestStatus: "latest_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1970-01-01T00:00:00Z" } ]) @@ -71,7 +71,7 @@ describe("testing pagination in dynamoDBClient", () => { PrescriptionID: "abc", LineItemID: "item_1", Status: "first_status", - TerminalStatus: "is_terminal_status", + TerminalStatus: "completed", LastModified: "1970-01-01T00:00:00Z" } ], @@ -88,7 +88,7 @@ describe("testing pagination in dynamoDBClient", () => { PrescriptionID: "abc", LineItemID: "item_1", Status: "second_status", - TerminalStatus: "is_terminal_status", + TerminalStatus: "completed", LastModified: "1970-01-01T00:00:00Z" } ] @@ -106,13 +106,13 @@ describe("testing pagination in dynamoDBClient", () => { { itemId: "item_1", latestStatus: "first_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1970-01-01T00:00:00Z" }, { itemId: "item_1", latestStatus: "second_status", - isTerminalState: "is_terminal_status", + isTerminalState: true, lastUpdateDateTime: "1970-01-01T00:00:00Z" } ]) diff --git a/packages/specification/examples/request-erd-dispatched.json b/packages/specification/examples/request-erd-dispatched.json index 15b7b2fae..81b69d2d2 100644 --- a/packages/specification/examples/request-erd-dispatched.json +++ b/packages/specification/examples/request-erd-dispatched.json @@ -1,63 +1,62 @@ { - "resourceType": "Bundle", - "type": "transaction", - "entry": [ - { - "fullUrl": "urn:uuid:4d70678c-81e4-4ff4-8c67-17596fd0aa46", - "resource": { - "resourceType": "Task", - "id": "4d70678c-81e4-4ff4-8c67-17596fd0aa46", - "basedOn": [ - { - "identifier": { - "system": "https://fhir.nhs.uk/Id/prescription-order-number", - "value": "07A66F-A83008-1EEEA0" - } - } - ], - "status": "completed", - "businessStatus": { - "coding": [ - { - "system": "https://fhir.nhs.uk/CodeSystem/task-businessStatus-nppt", - "code": "Dispatched" - } - ] - }, - "intent": "order", - "focus": { + "resourceType": "Bundle", + "type": "transaction", + "entry": [ + { + "fullUrl": "urn:uuid:4d70678c-81e4-4ff4-8c67-17596fd0aa46", + "resource": { + "resourceType": "Task", + "id": "4d70678c-81e4-4ff4-8c67-17596fd0aa46", + "basedOn": [ + { "identifier": { - "system": "https://fhir.nhs.uk/Id/prescription-order-item-number", - "value": "6989b7bd-8db6-428c-a593-4022e3044c00" + "system": "https://fhir.nhs.uk/Id/prescription-order-number", + "value": "07A66F-A83008-1EEEA0" } - }, - "for": { - "identifier": { - "system": "https://fhir.nhs.uk/Id/nhs-number", - "value": "9449304130" - } - }, - "lastModified": "2024-01-30T12:01:24Z", - "owner": { - "identifier": { - "system": "https://fhir.nhs.uk/Id/ods-organization-code", - "value": "C9Z1O" - } - }, - "input": [ + } + ], + "status": "completed", + "businessStatus": { + "coding": [ { - "type": { - "text": "Repeat Number" - }, - "valueInteger": 2 + "system": "https://fhir.nhs.uk/CodeSystem/task-businessStatus-nppt", + "code": "Dispatched" } ] }, - "request": { - "method": "POST", - "url": "Task" - } + "intent": "order", + "focus": { + "identifier": { + "system": "https://fhir.nhs.uk/Id/prescription-order-item-number", + "value": "6989b7bd-8db6-428c-a593-4022e3044c00" + } + }, + "for": { + "identifier": { + "system": "https://fhir.nhs.uk/Id/nhs-number", + "value": "9449304130" + } + }, + "lastModified": "2024-01-30T12:01:24Z", + "owner": { + "identifier": { + "system": "https://fhir.nhs.uk/Id/ods-organization-code", + "value": "C9Z1O" + } + }, + "input": [ + { + "type": { + "text": "Repeat Number" + }, + "valueInteger": 2 + } + ] + }, + "request": { + "method": "POST", + "url": "Task" } - ] - } - + } + ] +} diff --git a/packages/specification/schemas/resources/UpdatePrescriptionStatusTask.yaml b/packages/specification/schemas/resources/UpdatePrescriptionStatusTask.yaml index d69c1c33a..479edaeee 100644 --- a/packages/specification/schemas/resources/UpdatePrescriptionStatusTask.yaml +++ b/packages/specification/schemas/resources/UpdatePrescriptionStatusTask.yaml @@ -45,16 +45,16 @@ properties: enum: [https://fhir.nhs.uk/CodeSystem/task-businessStatus-nppt] code: type: string - enum: - - With Pharmacy - - With Pharmacy - Preparing Remainder - - Ready to Collect - - Ready to Collect - Partial - - Collected - - Dispatched - - Not Dispensed - - Ready to Dispatch - - Ready to Dispatch - Partial + enum: + - With Pharmacy + - With Pharmacy - Preparing Remainder + - Ready to Collect + - Ready to Collect - Partial + - Collected + - Dispatched + - Not Dispensed + - Ready to Dispatch + - Ready to Dispatch - Partial intent: type: string description: Order is the allowed value to indicate the update informs an actionable task. @@ -116,7 +116,7 @@ properties: type: object required: [_type, valueInteger] properties: - _type: + _type: type: object required: [text] properties: @@ -126,4 +126,4 @@ properties: valueInteger: type: integer minimum: 1 - maximum: 6 + maximum: 6