Skip to content

Commit 801e127

Browse files
committed
implement the ID checking in parallel, with env flag to toggle between id and name checkign
1 parent 8025904 commit 801e127

6 files changed

Lines changed: 59 additions & 8 deletions

File tree

SAMtemplates/functions/main.yaml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ Parameters:
4646
EnabledSystemsParam:
4747
Type: AWS::SSM::Parameter::Name<String>
4848

49+
EnabledSupplierProductIDsParam:
50+
Type: AWS::SSM::Parameter::Name<String>
51+
4952
BlockedSiteODSCodesParam:
5053
Type: AWS::SSM::Parameter::Name<String>
5154

@@ -132,8 +135,13 @@ Resources:
132135
POST_DATED_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref PostDatedNotificationsSQSQueueUrl
133136
ENABLE_POST_DATED_NOTIFICATIONS: !Ref EnablePostDatedNotifications
134137
SQS_SALT: !Ref SQSSaltSecret
135-
ENABLED_SITE_ODS_CODES_PARAM: !Ref EnabledSiteODSCodesParam
138+
# Remove this once we've confirmed that product ID based filtering is working as expected and we
139+
# no longer need the ability to switch back to the old filtering method
140+
USE_PRODUCT_ID_FOR_NOTIFICATIONS_FILTERING: false
136141
ENABLED_SYSTEMS_PARAM: !Ref EnabledSystemsParam
142+
#
143+
ENABLED_PRODUCT_IDS_PARAM: !Ref EnabledSupplierProductIDsParam
144+
ENABLED_SITE_ODS_CODES_PARAM: !Ref EnabledSiteODSCodesParam
137145
BLOCKED_SITE_ODS_CODES_PARAM: !Ref BlockedSiteODSCodesParam
138146
ENABLE_NOTIFICATIONS_PARAM: !Ref EnableNotificationsInternalParam
139147
LOG_LEVEL: !Ref LogLevel

SAMtemplates/main_template.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ Resources:
254254
SQSSaltSecret: !GetAtt Secrets.Outputs.SQSSaltSecret
255255
EnabledSiteODSCodesParam: !GetAtt Parameters.Outputs.EnabledSiteODSCodesParameterName
256256
EnabledSystemsParam: !GetAtt Parameters.Outputs.EnabledSystemsParameterName
257+
EnabledSupplierProductIDsParam: !GetAtt Parameters.Outputs.EnabledSupplierProductIDsParameterName
257258
BlockedSiteODSCodesParam: !GetAtt Parameters.Outputs.BlockedSiteODSCodesParameterName
258259
NotifyRoutingPlanIDParam: !GetAtt Parameters.Outputs.NotifyRoutingPlanIDParameterName
259260
NotifyAPIBaseURLParam: !GetAtt Parameters.Outputs.NotifyAPIBaseURLParameterName

SAMtemplates/parameters/main.yaml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ Parameters:
2828
Type: String
2929
Default: " "
3030

31+
EnabledSupplierProductIDsValue:
32+
Type: String
33+
Default: " "
34+
3135
BlockedSiteODSCodesValue:
3236
Type: String
3337
Default: " "
@@ -39,7 +43,7 @@ Parameters:
3943
NotifyAPIBaseURLValue:
4044
Type: String
4145
Default: " "
42-
46+
4347
TestPresciptionsParamValue1:
4448
Type: String
4549

@@ -69,6 +73,14 @@ Resources:
6973
Type: String
7074
Value: !Ref EnabledSystemsValue
7175

76+
EnabledSupplierProductIDsParameter:
77+
Type: AWS::SSM::Parameter
78+
Properties:
79+
Name: !Sub ${StackName}-PSUNotifyEnabledSupplierProductIDs
80+
Description: "List of supplier product IDs for which notifications are enabled"
81+
Type: String
82+
Value: !Ref EnabledSupplierProductIDsValue
83+
7284
BlockedSiteODSCodesParameter:
7385
Type: AWS::SSM::Parameter
7486
Properties:
@@ -155,6 +167,7 @@ Resources:
155167
Resource:
156168
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-PSUNotifyEnabledSiteODSCodes
157169
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-PSUNotifyEnabledSystems
170+
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-PSUNotifyEnabledSupplierProductIDs
158171
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-PSUNotifyBlockedSiteODSCodes
159172
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-PSUNotifyRoutingPlanID
160173
- !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/${StackName}-PSUNotifyApiBaseUrl
@@ -179,6 +192,12 @@ Outputs:
179192
Export:
180193
Name: !Sub ${StackName}-PSUNotifyEnabledSystemsParam
181194

195+
EnabledSupplierProductIDsParameterName:
196+
Description: "Name of the SSM parameter holding enabled supplier product IDs"
197+
Value: !Ref EnabledSupplierProductIDsParameter
198+
Export:
199+
Name: !Sub ${StackName}-PSUNotifyEnabledSupplierProductIDsParam
200+
182201
BlockedSiteODSCodesParameterName:
183202
Description: "Name of the SSM parameter holding blocked site ODS codes"
184203
Value: !Ref BlockedSiteODSCodesParameter

packages/nhsNotifyLambda/tests/testHelpers.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ export function constructPSUDataItem(overrides: Partial<PSUDataItem> = {}): PSUD
5353
TaskID: "mnopqr-ghijkl-abcdef",
5454
TerminalStatus: "ready to collect",
5555
ApplicationName: "Jim's Pills",
56+
ApplicationID: "550e8400-e29b-41d4-a716-446655440000",
5657
ExpiryTime: 123,
5758
...overrides
5859
}

packages/postDatedLambda/tests/testBusinessLogic.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ function createPSURecord(overrides: Partial<PSUDataItem> = {}): PSUDataItem {
3939
TaskID: "task-123",
4040
TerminalStatus: "terminal",
4141
ApplicationName: "post-dated-tests",
42+
ApplicationID: "550e8400-e29b-41d4-a716-446655440000",
4243
ExpiryTime: 0,
4344
PostDatedLastModifiedSetAt: "2026-01-01T00:00:00.000Z"
4445
}

packages/updatePrescriptionStatus/src/validation/notificationSiteAndSystemFilters.ts

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ import {PSUDataItemWithPrevious} from "@psu-common/commonTypes"
22
import {initiatedSSMProvider} from "@psu-common/utilities"
33
import {Logger} from "@aws-lambda-powertools/logger"
44

5+
const USE_PRODUCT_ID_FOR_NOTIFICATIONS_FILTERING =
6+
(process.env.USE_PRODUCT_ID_FOR_NOTIFICATIONS_FILTERING || "false")
7+
.toLowerCase() === "true"
8+
59
function str2set(value: string | undefined): Set<string> {
610
const raw = value ?? ""
711
return new Set(raw
@@ -13,22 +17,26 @@ function str2set(value: string | undefined): Set<string> {
1317

1418
async function loadConfig(): Promise<{
1519
enabledSiteODSCodes: Set<string>,
20+
enabledSystemAppNames: Set<string>,
1621
enabledSystemAppIds: Set<string>,
1722
blockedSiteODSCodes: Set<string>
1823
}> {
1924
const paramNames = {
2025
[process.env.ENABLED_SITE_ODS_CODES_PARAM!]: {maxAge: 5},
2126
[process.env.ENABLED_SYSTEMS_PARAM!]: {maxAge: 5},
27+
[process.env.ENABLED_PRODUCT_IDS_PARAM!]: {maxAge: 5},
2228
[process.env.BLOCKED_SITE_ODS_CODES_PARAM!]: {maxAge: 5}
2329
}
2430
const all = await initiatedSSMProvider.getParametersByName(paramNames)
2531

2632
const enabledSiteODSCodes = str2set(all[process.env.ENABLED_SITE_ODS_CODES_PARAM!] as string)
27-
const enabledSystemAppIds = str2set(all[process.env.ENABLED_SYSTEMS_PARAM!] as string)
33+
const enabledSystemAppNames = str2set(all[process.env.ENABLED_SYSTEMS_PARAM!] as string)
34+
const enabledSystemAppIds = str2set(all[process.env.ENABLED_PRODUCT_IDS_PARAM!] as string)
2835
const blockedSiteODSCodes = str2set(all[process.env.BLOCKED_SITE_ODS_CODES_PARAM!] as string)
2936

3037
return {
3138
enabledSiteODSCodes,
39+
enabledSystemAppNames,
3240
enabledSystemAppIds,
3341
blockedSiteODSCodes
3442
}
@@ -48,17 +56,30 @@ export async function checkSiteOrSystemIsNotifyEnabled(
4856
logger?: Logger
4957
): Promise<Array<PSUDataItemWithPrevious>> {
5058
// Get the configuration from either the cache or SSM
51-
const {enabledSiteODSCodes, enabledSystemAppIds, blockedSiteODSCodes} = await loadConfig()
59+
const {enabledSiteODSCodes, enabledSystemAppNames, enabledSystemAppIds, blockedSiteODSCodes} = await loadConfig()
5260
const unfilteredItemCount = data.length
5361

5462
const filteredItems = data.filter((item) => {
5563
const appId = item.current.ApplicationID.trim().toLowerCase()
64+
const appName = item.current.ApplicationName.trim().toLowerCase()
5665
const odsCode = item.current.PharmacyODSCode.trim().toLowerCase()
5766

58-
// Is this item either ODS enabled, or supplier enabled?
59-
const isEnabledSystem = enabledSiteODSCodes.has(odsCode) || enabledSystemAppIds.has(appId)
60-
if (!isEnabledSystem) {
61-
return false
67+
logger?.info(
68+
"Product ID, application name, and ODS code",
69+
{productId: appId, applicationName: appName, odsCode, enabledSystemAppIds}
70+
)
71+
72+
// Is this item supplier enabled?
73+
if (USE_PRODUCT_ID_FOR_NOTIFICATIONS_FILTERING) {
74+
const isEnabledProduct = enabledSiteODSCodes.has(odsCode) || enabledSystemAppIds.has(appId)
75+
if (!isEnabledProduct) {
76+
return false
77+
}
78+
} else {
79+
const isEnabledSystem = enabledSiteODSCodes.has(odsCode) || enabledSystemAppNames.has(appId)
80+
if (!isEnabledSystem) {
81+
return false
82+
}
6283
}
6384

6485
// Cannot have a blocked ODS code

0 commit comments

Comments
 (0)