Skip to content

Commit 8025904

Browse files
committed
Filter by application ID. Also enable product ID checking to see if it behaves how I think it does
1 parent 77b4d75 commit 8025904

8 files changed

Lines changed: 37 additions & 14 deletions

File tree

packages/common/commonTypes/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface PSUDataItem {
1010
TaskID: string
1111
TerminalStatus: string
1212
ApplicationName: string
13+
ApplicationID: string
1314
ExpiryTime: number
1415
// (Optional, legacy batch-processors only) Indicates that {@link LastModified} is postdated;
1516
// contains the ISO 8601 timestamp when the postdated update was set.

packages/specification/eps-prescription-status-update-api.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ security:
439439
x-nhsd-apim:
440440
temporary: false
441441
monitoring: true
442+
productidcheck: true
442443
access:
443444
- title: Application Restricted
444445
grants:
@@ -459,6 +460,9 @@ x-nhsd-apim:
459460
- name: show-all-suppliers
460461
required: false
461462
header: show-all-suppliers
463+
- name: id
464+
required: false
465+
header: nhsd-application-id
462466
ratelimiting:
463467
proxy:
464468
limit: 20000

packages/updatePrescriptionStatus/src/updatePrescriptionStatus.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPro
106106

107107
const xRequestID = getXRequestID(event, responseEntries)
108108
const applicationName = event.headers["attribute-name"] ?? "unknown"
109+
const applicationId = event.headers["nhsd-application-id"] ?? "unknown"
109110

110111
if (!xRequestID) {
111112
return response(400, responseEntries)
@@ -131,7 +132,7 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPro
131132
return response(400, responseEntries)
132133
}
133134

134-
const dataItems = buildDataItems(requestEntries, xRequestID, applicationName)
135+
const dataItems = buildDataItems(requestEntries, xRequestID, applicationName, applicationId)
135136

136137
// If the dataItems contain any invalid ODS codes, then return an error
137138
const invalidODSCodes = dataItems
@@ -358,7 +359,8 @@ export function handleTransactionCancelledException(
358359
export function buildDataItems(
359360
requestEntries: Array<BundleEntry>,
360361
xRequestID: string,
361-
applicationName: string
362+
applicationName: string,
363+
applicationId: string
362364
): Array<PSUDataItem> {
363365
const dataItems: Array<PSUDataItem> = []
364366

@@ -381,6 +383,7 @@ export function buildDataItems(
381383
TaskID: task.id!,
382384
TerminalStatus: task.status,
383385
ApplicationName: applicationName,
386+
ApplicationID: applicationId,
384387
ExpiryTime: (Math.floor(Date.now() / 1000) + TTL_DELTA)
385388
}
386389

packages/updatePrescriptionStatus/src/validation/notificationSiteAndSystemFilters.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ function str2set(value: string | undefined): Set<string> {
1313

1414
async function loadConfig(): Promise<{
1515
enabledSiteODSCodes: Set<string>,
16-
enabledSystems: Set<string>,
16+
enabledSystemAppIds: Set<string>,
1717
blockedSiteODSCodes: Set<string>
1818
}> {
1919
const paramNames = {
@@ -24,12 +24,12 @@ async function loadConfig(): Promise<{
2424
const all = await initiatedSSMProvider.getParametersByName(paramNames)
2525

2626
const enabledSiteODSCodes = str2set(all[process.env.ENABLED_SITE_ODS_CODES_PARAM!] as string)
27-
const enabledSystems = str2set(all[process.env.ENABLED_SYSTEMS_PARAM!] as string)
27+
const enabledSystemAppIds = str2set(all[process.env.ENABLED_SYSTEMS_PARAM!] as string)
2828
const blockedSiteODSCodes = str2set(all[process.env.BLOCKED_SITE_ODS_CODES_PARAM!] as string)
2929

3030
return {
3131
enabledSiteODSCodes,
32-
enabledSystems,
32+
enabledSystemAppIds,
3333
blockedSiteODSCodes
3434
}
3535
}
@@ -48,15 +48,15 @@ export async function checkSiteOrSystemIsNotifyEnabled(
4848
logger?: Logger
4949
): Promise<Array<PSUDataItemWithPrevious>> {
5050
// Get the configuration from either the cache or SSM
51-
const {enabledSiteODSCodes, enabledSystems, blockedSiteODSCodes} = await loadConfig()
51+
const {enabledSiteODSCodes, enabledSystemAppIds, blockedSiteODSCodes} = await loadConfig()
5252
const unfilteredItemCount = data.length
5353

5454
const filteredItems = data.filter((item) => {
55-
const appName = item.current.ApplicationName.trim().toLowerCase()
55+
const appId = item.current.ApplicationID.trim().toLowerCase()
5656
const odsCode = item.current.PharmacyODSCode.trim().toLowerCase()
5757

5858
// Is this item either ODS enabled, or supplier enabled?
59-
const isEnabledSystem = enabledSiteODSCodes.has(odsCode) || enabledSystems.has(appName)
59+
const isEnabledSystem = enabledSiteODSCodes.has(odsCode) || enabledSystemAppIds.has(appId)
6060
if (!isEnabledSystem) {
6161
return false
6262
}

packages/updatePrescriptionStatus/tests/testDatabaseClient.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe("Unit test persistDataItems", () => {
3535
TaskID: "TaskID_1",
3636
TerminalStatus: "TerminalStatus_1",
3737
ApplicationName: "name",
38+
ApplicationID: "id",
3839
ExpiryTime: 10
3940
},
4041
{
@@ -48,6 +49,7 @@ describe("Unit test persistDataItems", () => {
4849
TaskID: "TaskID_1",
4950
TerminalStatus: "TerminalStatus_2",
5051
ApplicationName: "name",
52+
ApplicationID: "id",
5153
ExpiryTime: 10
5254
}
5355
]
@@ -87,6 +89,7 @@ describe("Unit test persistDataItems", () => {
8789
TaskID: "TaskID_1",
8890
TerminalStatus: "TerminalStatus_1",
8991
ApplicationName: "name",
92+
ApplicationID: "id",
9093
ExpiryTime: 10
9194
},
9295
{
@@ -100,6 +103,7 @@ describe("Unit test persistDataItems", () => {
100103
TaskID: "TaskID_1",
101104
TerminalStatus: "TerminalStatus_2",
102105
ApplicationName: "name",
106+
ApplicationID: "id",
103107
ExpiryTime: 10
104108
}
105109
]
@@ -123,6 +127,7 @@ describe("Unit test persistDataItems", () => {
123127
TaskID: "TaskID_1",
124128
TerminalStatus: "TerminalStatus_1",
125129
ApplicationName: "name",
130+
ApplicationID: "id",
126131
ExpiryTime: 10
127132
}
128133
const dataItems = Array(150).fill(dataItem)
@@ -148,6 +153,7 @@ describe("Unit test persistDataItems", () => {
148153
TaskID: "TaskID_1",
149154
TerminalStatus: "TerminalStatus_1",
150155
ApplicationName: "name",
156+
ApplicationID: "id",
151157
ExpiryTime: 10
152158
},
153159
{
@@ -161,6 +167,7 @@ describe("Unit test persistDataItems", () => {
161167
TaskID: "TaskID_1",
162168
TerminalStatus: "TerminalStatus_2",
163169
ApplicationName: "name",
170+
ApplicationID: "id",
164171
ExpiryTime: 10
165172
}
166173
]
@@ -194,6 +201,7 @@ describe("Unit test getPreviousItem", () => {
194201
TaskID: "previous-task-id",
195202
TerminalStatus: "ready to collect",
196203
ApplicationName: "Jim's Pills",
204+
ApplicationID: "id",
197205
ExpiryTime: 123
198206
}
199207
const previousItem = {
@@ -207,6 +215,7 @@ describe("Unit test getPreviousItem", () => {
207215
TaskID: "previous-task-id",
208216
TerminalStatus: "ready to collect",
209217
ApplicationName: "Jim's Pills",
218+
ApplicationID: "id",
210219
ExpiryTime: 123
211220
}
212221
const currentItem = {
@@ -220,6 +229,7 @@ describe("Unit test getPreviousItem", () => {
220229
TaskID: "current-task-id",
221230
TerminalStatus: "ready to collect",
222231
ApplicationName: "Jim's Pills",
232+
ApplicationID: "id",
223233
ExpiryTime: 123
224234
}
225235

@@ -334,6 +344,7 @@ describe("Unit test rollbackDataItems", () => {
334344
TaskID: "TaskID_1",
335345
TerminalStatus: "TerminalStatus_1",
336346
ApplicationName: "name",
347+
ApplicationID: "id",
337348
ExpiryTime: 10,
338349
...overrides
339350
})

packages/updatePrescriptionStatus/tests/testSqsClient.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,8 @@ describe("Unit tests for checkSiteOrSystemIsNotifyEnabled", () => {
487487
})
488488
const item2 = createMockDataItem({
489489
PharmacyODSCode: "zzz999",
490-
ApplicationName: "internal test SYSTEM"
490+
ApplicationName: "internal test SYSTEM",
491+
ApplicationID: "internal test SYSTEM"
491492
})
492493
const result = await checkSiteOrSystemIsNotifyEnabled([
493494
{
@@ -530,11 +531,13 @@ describe("Unit tests for checkSiteOrSystemIsNotifyEnabled", () => {
530531
const previous = createMockDataItem({
531532
PharmacyODSCode: "NOTINLIST",
532533
ApplicationName: "Some Other System",
534+
ApplicationID: "Some Other System",
533535
Status: "previous"
534536
})
535537
const current = createMockDataItem({
536538
PharmacyODSCode: "NOTINLIST",
537-
ApplicationName: "Some Other System"
539+
ApplicationName: "Some Other System",
540+
ApplicationID: "Some Other System"
538541
})
539542
const result = await checkSiteOrSystemIsNotifyEnabled([{previous, current}], logger)
540543
expect(result).toEqual([])

packages/updatePrescriptionStatus/tests/testUpdatePrescriptionStatus.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ describe("buildDataItems", () => {
239239
fullUrl: ""
240240
}
241241

242-
const dataItems = buildDataItems([requestEntry], "", "")
242+
const dataItems = buildDataItems([requestEntry], "", "", "")
243243

244244
expect(dataItems[0].LineItemID).toEqual(lineItemID)
245245
expect(dataItems[0].PrescriptionID).toEqual(prescriptionID)
@@ -269,7 +269,7 @@ describe("buildDataItems", () => {
269269
fullUrl: ""
270270
}
271271

272-
const dataItems = buildDataItems([requestEntry], "", "")
272+
const dataItems = buildDataItems([requestEntry], "", "", "")
273273

274274
expect(dataItems[0].RepeatNo).toEqual(repeatNo)
275275
})
@@ -283,7 +283,7 @@ describe("buildDataItems", () => {
283283
fullUrl: ""
284284
}
285285

286-
const dataItems = buildDataItems([requestEntry], "", "")
286+
const dataItems = buildDataItems([requestEntry], "", "", "")
287287

288288
expect(dataItems[0].ExpiryTime).toBeGreaterThan(expectedExpiryTime)
289289
})
@@ -300,7 +300,7 @@ describe("buildDataItems", () => {
300300
fullUrl: ""
301301
}
302302

303-
const dataItems = buildDataItems([requestEntry], "", "")
303+
const dataItems = buildDataItems([requestEntry], "", "", "")
304304
const first: any = dataItems[0]
305305
expect(first.PostDatedLastModifiedSetAt).toEqual(lastUpdated)
306306
})

packages/updatePrescriptionStatus/tests/utils/testUtils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ export function createMockDataItem(overrides: Partial<PSUDataItem>): PSUDataItem
209209
TaskID: "mnopqr-ghijkl-abcdef",
210210
TerminalStatus: "ready to collect",
211211
ApplicationName: "Internal Test System",
212+
ApplicationID: "Internal Test System",
212213
ExpiryTime: 123,
213214
...overrides
214215
}

0 commit comments

Comments
 (0)