diff --git a/packages/gsul/src/dynamoDBclient.ts b/packages/gsul/src/dynamoDBclient.ts index 23ca1122e..fc030f660 100644 --- a/packages/gsul/src/dynamoDBclient.ts +++ b/packages/gsul/src/dynamoDBclient.ts @@ -33,15 +33,8 @@ export async function getItemsUpdatesForPrescription( return rows } - const items = await getAllData({ - TableName: tableName, - IndexName: "PharmacyODSCodePrescriptionIDIndex", - KeyConditionExpression: "PrescriptionID = :inputPrescriptionID AND PharmacyODSCode = :inputPharmacyODSCode", - ExpressionAttributeValues: { - ":inputPharmacyODSCode": odsCode, - ":inputPrescriptionID": prescriptionID - } - }) + const queryCommandInput = createQueryCommandInput(odsCode, prescriptionID) + const items = await getAllData(queryCommandInput) return items.map((singleUpdate) => ({ itemId: String(singleUpdate.LineItemID), @@ -50,3 +43,15 @@ export async function getItemsUpdatesForPrescription( lastUpdateDateTime: String(singleUpdate.LastModified) })) } + +export function createQueryCommandInput(odsCode: string, prescriptionID: string): QueryCommandInput { + return { + TableName: tableName, + IndexName: "PharmacyODSCodePrescriptionIDIndex", + KeyConditionExpression: "PrescriptionID = :inputPrescriptionID AND PharmacyODSCode = :inputPharmacyODSCode", + ExpressionAttributeValues: { + ":inputPharmacyODSCode": odsCode.toUpperCase(), + ":inputPrescriptionID": prescriptionID.toUpperCase() + } + } +} diff --git a/packages/gsul/tests/testRunDynamoDBQueries.test.ts b/packages/gsul/tests/testRunDynamoDBQueries.test.ts index 2cd04979d..0c92b4374 100644 --- a/packages/gsul/tests/testRunDynamoDBQueries.test.ts +++ b/packages/gsul/tests/testRunDynamoDBQueries.test.ts @@ -1,5 +1,5 @@ import {DynamoDBDocumentClient} from "@aws-sdk/lib-dynamodb" -import {getItemsUpdatesForPrescription} from "../src/dynamoDBclient" +import {createQueryCommandInput, getItemsUpdatesForPrescription} from "../src/dynamoDBclient" import {Logger} from "@aws-lambda-powertools/logger" import { expect, @@ -42,6 +42,22 @@ describe("testing dynamoDBClient", () => { } ]) }) + + it("should create query command input with keys in upper case", async () => { + const queryCommandInput = createQueryCommandInput("odsCode", "prescriptionID") + + const expected = { + TableName: undefined, + IndexName: "PharmacyODSCodePrescriptionIDIndex", + KeyConditionExpression: "PrescriptionID = :inputPrescriptionID AND PharmacyODSCode = :inputPharmacyODSCode", + ExpressionAttributeValues: { + ":inputPharmacyODSCode": "ODSCODE", + ":inputPrescriptionID": "PRESCRIPTIONID" + } + } + + expect(queryCommandInput).toEqual(expected) + }) }) describe("testing pagination in dynamoDBClient", () => { diff --git a/packages/updatePrescriptionStatus/src/updatePrescriptionStatus.ts b/packages/updatePrescriptionStatus/src/updatePrescriptionStatus.ts index 7dcd11f52..e6fdd4f94 100644 --- a/packages/updatePrescriptionStatus/src/updatePrescriptionStatus.ts +++ b/packages/updatePrescriptionStatus/src/updatePrescriptionStatus.ts @@ -195,10 +195,10 @@ export function buildDataItems( const dataItem: DataItem = { LastModified: task.lastModified!, - LineItemID: task.focus!.identifier!.value!, + LineItemID: task.focus!.identifier!.value!.toUpperCase(), PatientNHSNumber: task.for!.identifier!.value!, - PharmacyODSCode: task.owner!.identifier!.value!, - PrescriptionID: task.basedOn![0].identifier!.value!, + PharmacyODSCode: task.owner!.identifier!.value!.toUpperCase(), + PrescriptionID: task.basedOn![0].identifier!.value!.toUpperCase(), RequestID: xRequestID, Status: task.businessStatus!.coding![0].code!, TaskID: task.id!, diff --git a/packages/updatePrescriptionStatus/tests/testUpdatePrescriptionStatus.test.ts b/packages/updatePrescriptionStatus/tests/testUpdatePrescriptionStatus.test.ts index c81bf4d7b..4df2e66d4 100644 --- a/packages/updatePrescriptionStatus/tests/testUpdatePrescriptionStatus.test.ts +++ b/packages/updatePrescriptionStatus/tests/testUpdatePrescriptionStatus.test.ts @@ -7,17 +7,22 @@ import { } from "@jest/globals" import {BundleEntry} from "fhir/r4" +import {v4} from "uuid" import {badRequest, conflictDuplicate} from "../src/utils/responses" -import {DEFAULT_DATE, X_REQUEST_ID, mockInternalDependency} from "./utils/testUtils" +import { + DEFAULT_DATE, + X_REQUEST_ID, + mockInternalDependency, + validTask +} from "./utils/testUtils" import {APIGatewayProxyEvent} from "aws-lambda" import * as content from "../src/validation/content" import {TransactionCanceledException} from "@aws-sdk/client-dynamodb" const mockValidateEntry = mockInternalDependency("../src/validation/content", content, "validateEntry") -const {castEventBody, getXRequestID, validateEntries, handleTransactionCancelledException} = await import( - "../src/updatePrescriptionStatus" -) +const {castEventBody, getXRequestID, validateEntries, handleTransactionCancelledException, buildDataItems} = + await import("../src/updatePrescriptionStatus") describe("Unit test getXRequestID", () => { beforeAll(() => { @@ -201,3 +206,26 @@ describe("handleTransactionCancelledException", () => { expect(validResponseEntry.response?.status).not.toEqual("200 OK") }) }) + +describe("buildDataItems", () => { + it("should uppercase LineItemId, PharmacyODSCode and PrescriptionID", () => { + const task = validTask() + const lineItemID = v4().toUpperCase() + const pharmacyODSCode = "X26" + const prescriptionID = "4F00A8-A83008-2EB4D" + + task.focus!.identifier!.value! = lineItemID.toLowerCase() + task.owner!.identifier!.value! = pharmacyODSCode.toLowerCase() + task.basedOn![0].identifier!.value! = prescriptionID.toLowerCase() + const requestEntry: BundleEntry = { + resource: task, + fullUrl: "" + } + + const dataItems = buildDataItems([requestEntry], "", "") + + expect(dataItems[0].LineItemID).toEqual(lineItemID) + expect(dataItems[0].PrescriptionID).toEqual(prescriptionID) + expect(dataItems[0].PharmacyODSCode).toEqual(pharmacyODSCode) + }) +})