Skip to content

Commit a6677b1

Browse files
authored
Chore: [AEA-5828] - report ODS code (#2315)
## Summary - 🤖 Operational or Infrastructure Change ### Details Log additionally the ODS code and message status needed for reports
1 parent ef7c1ae commit a6677b1

File tree

4 files changed

+45
-13
lines changed

4 files changed

+45
-13
lines changed

packages/nhsNotifyLambda/src/utils/notify.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ export async function makeRealNotifyRequest(
191191
messageReferences: messages.map(e => ({
192192
nhsNumber: e.recipient.nhsNumber,
193193
messageReference: e.messageReference,
194-
psuRequestId: data.find((el) => el.messageReference === e.messageReference)?.PSUDataItem.RequestID
194+
psuRequestId: data.find((el) => el.messageReference === e.messageReference)?.PSUDataItem.RequestID,
195+
pharmacyODSCode: e.originator.odsCode
195196
})),
196-
deliveryStatus: "requested" // TODO: change splunk report query to messageStatus
197+
deliveryStatus: "requested", // TODO: remove once Splunk report adopts messageStatus
198+
messageStatus: "requested"
197199
})
198200

199201
// Map each input item to a NotifyDataItemMessage, marking success and attaching the notify ID.

packages/updatePrescriptionStatus/src/utils/sqsClient.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,6 @@ export async function pushPrescriptionToNotificationSQS(
114114

115115
// Only allow through sites and systems that are allowedSitesAndSystems
116116
const allowedSitesAndSystemsData = await checkSiteOrSystemIsNotifyEnabled(data)
117-
logger.info(
118-
"Filtered out sites and suppliers that are not enabled, or are explicitly disabled",
119-
{numItemsAllowed: allowedSitesAndSystemsData.length}
120-
)
121117

122118
function norm(str: string) {
123119
return str.toLowerCase().trim()

packages/updatePrescriptionStatus/src/validation/notificationSiteAndSystemFilters.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {PSUDataItemWithPrevious} from "@PrescriptionStatusUpdate_common/commonTypes"
22
import {SSMProvider} from "@aws-lambda-powertools/parameters/ssm"
3+
import {Logger} from "@aws-lambda-powertools/logger"
34

45
const ssm = new SSMProvider()
56

@@ -41,15 +42,18 @@ async function loadConfig(): Promise<{
4142
* - AND are NOT blocked at the site level.
4243
*
4344
* @param data - Array of PSUDataItem to be processed
45+
* @param logger - Optional logger instance
4446
* @returns - the filtered array
4547
*/
4648
export async function checkSiteOrSystemIsNotifyEnabled(
47-
data: Array<PSUDataItemWithPrevious>
49+
data: Array<PSUDataItemWithPrevious>,
50+
logger?: Logger
4851
): Promise<Array<PSUDataItemWithPrevious>> {
4952
// Get the configuration from either the cache or SSM
5053
const {enabledSiteODSCodes, enabledSystems, blockedSiteODSCodes} = await loadConfig()
54+
const unfilteredItemCount = data.length
5155

52-
return data.filter((item) => {
56+
const filteredItems = data.filter((item) => {
5357
const appName = item.current.ApplicationName.trim().toLowerCase()
5458
const odsCode = item.current.PharmacyODSCode.trim().toLowerCase()
5559

@@ -66,4 +70,13 @@ export async function checkSiteOrSystemIsNotifyEnabled(
6670

6771
return true
6872
})
73+
74+
if (logger) {
75+
logger.info(
76+
"Filtered out sites and suppliers that are not enabled, or are explicitly disabled",
77+
{numItemsReceived: unfilteredItemCount, numItemsAllowed: filteredItems.length}
78+
)
79+
}
80+
81+
return filteredItems
6982
}

packages/updatePrescriptionStatus/tests/testSqsClient.test.ts

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,14 @@ describe("Unit tests for getSaltValue", () => {
293293
})
294294
})
295295
describe("Unit tests for checkSiteOrSystemIsNotifyEnabled", () => {
296+
let logger: Logger
297+
let infoSpy: SpiedFunction<(input: LogItemMessage, ...extraInput: LogItemExtraInput) => void>
298+
beforeEach(() => {
299+
// Fresh logger and spies
300+
logger = new Logger({serviceName: "test-service"})
301+
infoSpy = jest.spyOn(logger, "info")
302+
})
303+
296304
it("includes an item with an enabled ODS code", async () => {
297305
const previous = createMockDataItem({
298306
PharmacyODSCode: "FA565",
@@ -303,8 +311,9 @@ describe("Unit tests for checkSiteOrSystemIsNotifyEnabled", () => {
303311
PharmacyODSCode: "FA565",
304312
ApplicationName: "not a real test supplier"
305313
})
306-
const result = await checkSiteOrSystemIsNotifyEnabled([{previous, current}])
314+
const result = await checkSiteOrSystemIsNotifyEnabled([{previous, current}], logger)
307315
expect(result).toStrictEqual([{previous, current}])
316+
expectLogReceivedAndAllowed(infoSpy, 1, 1)
308317
})
309318

310319
it("includes an item with an enabled ApplicationName", async () => {
@@ -317,8 +326,9 @@ describe("Unit tests for checkSiteOrSystemIsNotifyEnabled", () => {
317326
PharmacyODSCode: "ZZZ999",
318327
ApplicationName: "Internal Test System"
319328
})
320-
const result = await checkSiteOrSystemIsNotifyEnabled([{previous, current}])
329+
const result = await checkSiteOrSystemIsNotifyEnabled([{previous, current}], logger)
321330
expect(result).toEqual([{previous, current}])
331+
expectLogReceivedAndAllowed(infoSpy, 1, 1)
322332
})
323333

324334
it("is case insensitive for both ODS code and ApplicationName", async () => {
@@ -339,7 +349,7 @@ describe("Unit tests for checkSiteOrSystemIsNotifyEnabled", () => {
339349
previous: item2,
340350
current: item2
341351
}
342-
])
352+
], logger)
343353
expect(result).toEqual([
344354
{
345355
previous: item1,
@@ -362,8 +372,9 @@ describe("Unit tests for checkSiteOrSystemIsNotifyEnabled", () => {
362372
PharmacyODSCode: "b3j1z",
363373
ApplicationName: "Internal Test System"
364374
})
365-
const result = await checkSiteOrSystemIsNotifyEnabled([{previous, current}])
375+
const result = await checkSiteOrSystemIsNotifyEnabled([{previous, current}], logger)
366376
expect(result).toEqual([])
377+
expectLogReceivedAndAllowed(infoSpy, 1, 0)
367378
})
368379

369380
it("excludes items that are neither enabled nor blocked", async () => {
@@ -376,8 +387,18 @@ describe("Unit tests for checkSiteOrSystemIsNotifyEnabled", () => {
376387
PharmacyODSCode: "NOTINLIST",
377388
ApplicationName: "Some Other System"
378389
})
379-
const result = await checkSiteOrSystemIsNotifyEnabled([{previous, current}])
390+
const result = await checkSiteOrSystemIsNotifyEnabled([{previous, current}], logger)
380391
expect(result).toEqual([])
392+
expectLogReceivedAndAllowed(infoSpy, 1, 0)
381393
})
382394

383395
})
396+
function expectLogReceivedAndAllowed(
397+
infoSpy: SpiedFunction<(input: LogItemMessage, ...extraInput: LogItemExtraInput) => void>,
398+
numItemsReceived: number,
399+
numItemsAllowed: number) {
400+
expect(infoSpy).toHaveBeenCalledWith(
401+
expect.stringContaining("Filtered out sites and suppliers that are not enabled, or are explicitly disabled"),
402+
expect.objectContaining({numItemsReceived, numItemsAllowed})
403+
)
404+
}

0 commit comments

Comments
 (0)