Skip to content

Commit

Permalink
Fix: [AEA-4167] - Unable to find lowercase item ids (#424)
Browse files Browse the repository at this point in the history
## Summary

- Routine Change

### Details

Converting potentially case-sensitive keys to uppercase when accepting
and returning status updates.
  • Loading branch information
originalphil authored Jun 25, 2024
1 parent 3f1d2bb commit 9a9255e
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 17 deletions.
23 changes: 14 additions & 9 deletions packages/gsul/src/dynamoDBclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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()
}
}
}
18 changes: 17 additions & 1 deletion packages/gsul/tests/testRunDynamoDBQueries.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down Expand Up @@ -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)
})
})

0 comments on commit 9a9255e

Please sign in to comment.