Skip to content

Commit

Permalink
Fix: [AEA-4203] - 'repeatNo' not stored in the psu-PrescriptionStatus…
Browse files Browse the repository at this point in the history
…Updates table (#477)

## Summary

🎫 [AEA-4203](https://nhsd-jira.digital.nhs.uk/browse/AEA-4203) CPSU -
'repeatNo' not stored in the psu-PrescriptionStatusUpdates table

- Routine Change

### Details

'repeatNo' not stored in the psu-PrescriptionStatusUpdates table
  • Loading branch information
kris-szlapa authored Jul 11, 2024
1 parent 7e04e7f commit bf6f0f3
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ properties:
description: The eRD Repeat Number, with the prescription tracking status updates for eRD prescriptions. This is optional and only required for eRD type prescriptions.
items:
type: object
required: [_type, valueInteger]
required: [type, valueInteger]
properties:
_type:
type:
type: object
required: [text]
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface DataItem {
PatientNHSNumber: string
PharmacyODSCode: string
PrescriptionID: string
RepeatNo?: number
RequestID: string
Status: string
TaskID: string
Expand Down Expand Up @@ -193,12 +194,15 @@ export function buildDataItems(
const task = requestEntry.resource as Task
logger.info("Building data item for task.", {task: task, id: task.id})

const repeatNo = task.input?.[0]?.valueInteger

const dataItem: DataItem = {
LastModified: task.lastModified!,
LineItemID: task.focus!.identifier!.value!.toUpperCase(),
PatientNHSNumber: task.for!.identifier!.value!,
PharmacyODSCode: task.owner!.identifier!.value!.toUpperCase(),
PrescriptionID: task.basedOn![0].identifier!.value!.toUpperCase(),
...(repeatNo !== undefined && {RepeatNo: repeatNo}),
RequestID: xRequestID,
Status: task.businessStatus!.coding![0].code!,
TaskID: task.id!,
Expand Down
51 changes: 51 additions & 0 deletions packages/updatePrescriptionStatus/tests/testHandler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,57 @@ describe("Integration tests for updatePrescriptionStatus handler", () => {
expect(mockSend).toHaveBeenCalledWith(expect.objectContaining(expectedItems))
})

it("when input field is absent in a single item request, expect DynamoDB item without RepeatNo field", async () => {
const body = generateBody()
const entryResource: any = body.entry?.[0]?.resource
if (entryResource?.input) {
delete entryResource.input
}

const event: APIGatewayProxyEvent = generateMockEvent(body)
const expectedItems = generateExpectedItems()
const transactItem: any = expectedItems.input?.TransactItems?.[0]?.Put?.Item
if (transactItem?.RepeatNo) {
delete transactItem.RepeatNo
}

mockTransact.mockReturnValue(expectedItems)

const response: APIGatewayProxyResult = await handler(event, {})

expect(response.statusCode).toEqual(201)
expect(JSON.parse(response.body)).toEqual(responseSingleItem)

expect((expectedItems.input.TransactItems[0].Put.Item as any).RepeatNo).toEqual(undefined)
expect(mockSend).toHaveBeenCalledTimes(1)
expect(mockSend).toHaveBeenCalledWith(expect.objectContaining(expectedItems))
})

it("when input field is present in a single item request, expect DynamoDB item with RepeatNo field", async () => {
const body = generateBody()
const entryResource: any = body.entry?.[0]?.resource
if (!entryResource.input) {
entryResource.input = [{valueInteger: 1}]
}

const event: APIGatewayProxyEvent = generateMockEvent(body)
const expectedItems = generateExpectedItems()

const transactItem: any = expectedItems.input?.TransactItems?.[0]?.Put?.Item
transactItem.RepeatNo = 1

mockTransact.mockReturnValue(expectedItems)

const response: APIGatewayProxyResult = await handler(event, {})

expect(response.statusCode).toEqual(201)
expect(JSON.parse(response.body)).toEqual(responseSingleItem)

expect((expectedItems.input.TransactItems[0].Put.Item as any).RepeatNo).toEqual(1)
expect(mockSend).toHaveBeenCalledTimes(1)
expect(mockSend).toHaveBeenCalledWith(expect.objectContaining(expectedItems))
})

it("when multiple items in request, expect multiple items sent to DynamoDB in a single call", async () => {
const body = generateBody(2)
const event: APIGatewayProxyEvent = generateMockEvent(body)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,32 @@ describe("buildDataItems", () => {
expect(dataItems[0].PrescriptionID).toEqual(prescriptionID)
expect(dataItems[0].PharmacyODSCode).toEqual(pharmacyODSCode)
})

it("should include RepeatNo in data item when defined", () => {
const task = validTask()
const repeatNo = 1

task.input = [
{
valueInteger: repeatNo,
type: {
coding: [
{
system: "http://example.com/system",
code: "repeat-number"
}
]
}
}
]

const requestEntry: BundleEntry = {
resource: task,
fullUrl: ""
}

const dataItems = buildDataItems([requestEntry], "", "")

expect(dataItems[0].RepeatNo).toEqual(repeatNo)
})
})

0 comments on commit bf6f0f3

Please sign in to comment.