@@ -2,6 +2,10 @@ import {PSUDataItemWithPrevious} from "@psu-common/commonTypes"
22import { initiatedSSMProvider } from "@psu-common/utilities"
33import { 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+
59function 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
1418async 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