Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/common/commonTypes/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface PSUDataItem {
TaskID: string
TerminalStatus: string
ApplicationName: string
ApplicationID: string
Comment thread
wildjames marked this conversation as resolved.
ExpiryTime: number
// (Optional, legacy batch-processors only) Indicates that {@link LastModified} is postdated;
// contains the ISO 8601 timestamp when the postdated update was set.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ security:
x-nhsd-apim:
temporary: false
monitoring: true
productidcheck: true
access:
- title: Application Restricted
grants:
Expand All @@ -459,6 +460,9 @@ x-nhsd-apim:
- name: show-all-suppliers
required: false
header: show-all-suppliers
- name: id
required: false
header: nhsd-application-id
ratelimiting:
proxy:
limit: 20000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ const lambdaHandler = async (event: APIGatewayProxyEvent): Promise<APIGatewayPro

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

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

const dataItems = buildDataItems(requestEntries, xRequestID, applicationName)
const dataItems = buildDataItems(requestEntries, xRequestID, applicationName, applicationId)

// If the dataItems contain any invalid ODS codes, then return an error
const invalidODSCodes = dataItems
Expand Down Expand Up @@ -358,7 +359,8 @@ export function handleTransactionCancelledException(
export function buildDataItems(
requestEntries: Array<BundleEntry>,
xRequestID: string,
applicationName: string
applicationName: string,
applicationId: string
): Array<PSUDataItem> {
const dataItems: Array<PSUDataItem> = []

Expand All @@ -381,6 +383,7 @@ export function buildDataItems(
TaskID: task.id!,
TerminalStatus: task.status,
ApplicationName: applicationName,
ApplicationID: applicationId,
ExpiryTime: (Math.floor(Date.now() / 1000) + TTL_DELTA)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function str2set(value: string | undefined): Set<string> {

async function loadConfig(): Promise<{
enabledSiteODSCodes: Set<string>,
enabledSystems: Set<string>,
enabledSystemAppIds: Set<string>,
blockedSiteODSCodes: Set<string>
}> {
const paramNames = {
Expand All @@ -24,12 +24,12 @@ async function loadConfig(): Promise<{
const all = await initiatedSSMProvider.getParametersByName(paramNames)

const enabledSiteODSCodes = str2set(all[process.env.ENABLED_SITE_ODS_CODES_PARAM!] as string)
const enabledSystems = str2set(all[process.env.ENABLED_SYSTEMS_PARAM!] as string)
const enabledSystemAppIds = str2set(all[process.env.ENABLED_SYSTEMS_PARAM!] as string)
const blockedSiteODSCodes = str2set(all[process.env.BLOCKED_SITE_ODS_CODES_PARAM!] as string)
Comment thread
wildjames marked this conversation as resolved.

return {
enabledSiteODSCodes,
enabledSystems,
enabledSystemAppIds,
blockedSiteODSCodes
}
}
Expand All @@ -48,15 +48,15 @@ export async function checkSiteOrSystemIsNotifyEnabled(
logger?: Logger
): Promise<Array<PSUDataItemWithPrevious>> {
// Get the configuration from either the cache or SSM
const {enabledSiteODSCodes, enabledSystems, blockedSiteODSCodes} = await loadConfig()
const {enabledSiteODSCodes, enabledSystemAppIds, blockedSiteODSCodes} = await loadConfig()
const unfilteredItemCount = data.length

const filteredItems = data.filter((item) => {
const appName = item.current.ApplicationName.trim().toLowerCase()
const appId = item.current.ApplicationID.trim().toLowerCase()
const odsCode = item.current.PharmacyODSCode.trim().toLowerCase()

// Is this item either ODS enabled, or supplier enabled?
const isEnabledSystem = enabledSiteODSCodes.has(odsCode) || enabledSystems.has(appName)
const isEnabledSystem = enabledSiteODSCodes.has(odsCode) || enabledSystemAppIds.has(appId)
if (!isEnabledSystem) {
Comment thread
wildjames marked this conversation as resolved.
Outdated
return false
}
Expand Down
11 changes: 11 additions & 0 deletions packages/updatePrescriptionStatus/tests/testDatabaseClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ describe("Unit test persistDataItems", () => {
TaskID: "TaskID_1",
TerminalStatus: "TerminalStatus_1",
ApplicationName: "name",
ApplicationID: "id",
ExpiryTime: 10
},
{
Expand All @@ -48,6 +49,7 @@ describe("Unit test persistDataItems", () => {
TaskID: "TaskID_1",
TerminalStatus: "TerminalStatus_2",
ApplicationName: "name",
ApplicationID: "id",
ExpiryTime: 10
}
]
Expand Down Expand Up @@ -87,6 +89,7 @@ describe("Unit test persistDataItems", () => {
TaskID: "TaskID_1",
TerminalStatus: "TerminalStatus_1",
ApplicationName: "name",
ApplicationID: "id",
ExpiryTime: 10
},
{
Expand All @@ -100,6 +103,7 @@ describe("Unit test persistDataItems", () => {
TaskID: "TaskID_1",
TerminalStatus: "TerminalStatus_2",
ApplicationName: "name",
ApplicationID: "id",
ExpiryTime: 10
}
]
Expand All @@ -123,6 +127,7 @@ describe("Unit test persistDataItems", () => {
TaskID: "TaskID_1",
TerminalStatus: "TerminalStatus_1",
ApplicationName: "name",
ApplicationID: "id",
ExpiryTime: 10
}
const dataItems = Array(150).fill(dataItem)
Expand All @@ -148,6 +153,7 @@ describe("Unit test persistDataItems", () => {
TaskID: "TaskID_1",
TerminalStatus: "TerminalStatus_1",
ApplicationName: "name",
ApplicationID: "id",
ExpiryTime: 10
},
{
Expand All @@ -161,6 +167,7 @@ describe("Unit test persistDataItems", () => {
TaskID: "TaskID_1",
TerminalStatus: "TerminalStatus_2",
ApplicationName: "name",
ApplicationID: "id",
ExpiryTime: 10
}
]
Expand Down Expand Up @@ -194,6 +201,7 @@ describe("Unit test getPreviousItem", () => {
TaskID: "previous-task-id",
TerminalStatus: "ready to collect",
ApplicationName: "Jim's Pills",
ApplicationID: "id",
ExpiryTime: 123
}
const previousItem = {
Expand All @@ -207,6 +215,7 @@ describe("Unit test getPreviousItem", () => {
TaskID: "previous-task-id",
TerminalStatus: "ready to collect",
ApplicationName: "Jim's Pills",
ApplicationID: "id",
ExpiryTime: 123
}
const currentItem = {
Expand All @@ -220,6 +229,7 @@ describe("Unit test getPreviousItem", () => {
TaskID: "current-task-id",
TerminalStatus: "ready to collect",
ApplicationName: "Jim's Pills",
ApplicationID: "id",
ExpiryTime: 123
}

Expand Down Expand Up @@ -334,6 +344,7 @@ describe("Unit test rollbackDataItems", () => {
TaskID: "TaskID_1",
TerminalStatus: "TerminalStatus_1",
ApplicationName: "name",
ApplicationID: "id",
ExpiryTime: 10,
...overrides
})
Expand Down
7 changes: 5 additions & 2 deletions packages/updatePrescriptionStatus/tests/testSqsClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,8 @@ describe("Unit tests for checkSiteOrSystemIsNotifyEnabled", () => {
})
const item2 = createMockDataItem({
PharmacyODSCode: "zzz999",
ApplicationName: "internal test SYSTEM"
ApplicationName: "internal test SYSTEM",
ApplicationID: "internal test SYSTEM"
})
Comment thread
wildjames marked this conversation as resolved.
const result = await checkSiteOrSystemIsNotifyEnabled([
{
Expand Down Expand Up @@ -530,11 +531,13 @@ describe("Unit tests for checkSiteOrSystemIsNotifyEnabled", () => {
const previous = createMockDataItem({
PharmacyODSCode: "NOTINLIST",
ApplicationName: "Some Other System",
ApplicationID: "Some Other System",
Status: "previous"
})
const current = createMockDataItem({
PharmacyODSCode: "NOTINLIST",
ApplicationName: "Some Other System"
ApplicationName: "Some Other System",
ApplicationID: "Some Other System"
})
const result = await checkSiteOrSystemIsNotifyEnabled([{previous, current}], logger)
expect(result).toEqual([])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ describe("buildDataItems", () => {
fullUrl: ""
}

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

expect(dataItems[0].LineItemID).toEqual(lineItemID)
expect(dataItems[0].PrescriptionID).toEqual(prescriptionID)
Expand Down Expand Up @@ -269,7 +269,7 @@ describe("buildDataItems", () => {
fullUrl: ""
}

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

expect(dataItems[0].RepeatNo).toEqual(repeatNo)
})
Expand All @@ -283,7 +283,7 @@ describe("buildDataItems", () => {
fullUrl: ""
}

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

expect(dataItems[0].ExpiryTime).toBeGreaterThan(expectedExpiryTime)
})
Expand All @@ -300,7 +300,7 @@ describe("buildDataItems", () => {
fullUrl: ""
}

const dataItems = buildDataItems([requestEntry], "", "")
const dataItems = buildDataItems([requestEntry], "", "", "")
const first: any = dataItems[0]
expect(first.PostDatedLastModifiedSetAt).toEqual(lastUpdated)
})
Expand Down
1 change: 1 addition & 0 deletions packages/updatePrescriptionStatus/tests/utils/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ export function createMockDataItem(overrides: Partial<PSUDataItem>): PSUDataItem
TaskID: "mnopqr-ghijkl-abcdef",
TerminalStatus: "ready to collect",
ApplicationName: "Internal Test System",
ApplicationID: "Internal Test System",
ExpiryTime: 123,
...overrides
}
Expand Down
Loading