Skip to content

Commit 6bcd216

Browse files
committed
pass in the name and fetch the parameter values from ssm in the code
1 parent b1574b1 commit 6bcd216

3 files changed

Lines changed: 49 additions & 27 deletions

File tree

.github/workflows/pull_request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
get_issue_number:
2020
runs-on: ubuntu-22.04
21-
needs: quality_checks
21+
# needs: quality_checks
2222
outputs:
2323
issue_number: ${{steps.get_issue_number.outputs.result}}
2424

SAMtemplates/functions/main.yaml

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ Parameters:
3434
Default: none
3535

3636
EnabledSiteODSCodesParam:
37-
Type: AWS::SSM::Parameter::Value<List<String>>
37+
Type: String
3838

3939
EnabledSystemsParam:
40-
Type: AWS::SSM::Parameter::Value<List<String>>
40+
Type: String
4141

4242
BlockedSiteODSCodesParam:
43-
Type: AWS::SSM::Parameter::Value<List<String>>
43+
Type: String
4444

4545
LogLevel:
4646
Type: String
@@ -92,18 +92,9 @@ Resources:
9292
TABLE_NAME: !Ref PrescriptionStatusUpdatesTableName
9393
NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref NHSNotifyPrescriptionsSQSQueueUrl
9494
SQS_SALT: !Sub "{{resolve:secretsmanager:${SQSSaltSecret}:SecretString:salt}}"
95-
ENABLED_SITE_ODS_CODES:
96-
Fn::Join:
97-
- ","
98-
- !Ref EnabledSiteODSCodesParam
99-
ENABLED_SYSTEMS:
100-
Fn::Join:
101-
- ","
102-
- !Ref EnabledSystemsParam
103-
BLOCKED_SITE_ODS_CODES:
104-
Fn::Join:
105-
- ","
106-
- !Ref BlockedSiteODSCodesParam
95+
ENABLED_SITE_ODS_CODES: !Ref EnabledSiteODSCodesParam
96+
ENABLED_SYSTEMS: !Ref EnabledSystemsParam
97+
BLOCKED_SITE_ODS_CODES: !Ref BlockedSiteODSCodesParam
10798
LOG_LEVEL: !Ref LogLevel
10899
ENVIRONMENT: !Ref Environment
109100
TEST_PRESCRIPTIONS_1: "None"

packages/updatePrescriptionStatus/src/validation/notificationSiteAndSystemFilters.ts

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,42 @@
11
import {PSUDataItem} from "@PrescriptionStatusUpdate_common/commonTypes"
2+
import AWS from "aws-sdk"
23

3-
function getEnvList(name: string): Set<string> {
4-
const raw = process.env[name] ?? ""
5-
return new Set(raw
6-
.split(",")
7-
.map((s) => s.trim().toLowerCase())
8-
.filter(Boolean) // Remove empty entries
4+
const ssm = new AWS.SSM()
5+
6+
/**
7+
* Fetches the comma-delimited StringList from SSM, normalizes & returns a Set<string>.
8+
*/
9+
async function fetchListFromSSM(paramNameEnvVar: string): Promise<Set<string>> {
10+
const paramName = process.env[paramNameEnvVar]
11+
if (!paramName) {
12+
throw new Error(`Missing required env-var ${paramNameEnvVar}`)
13+
}
14+
const resp = await ssm
15+
.getParameter({Name: paramName, WithDecryption: false})
16+
.promise()
17+
18+
const raw = resp.Parameter?.Value ?? ""
19+
return new Set(
20+
raw
21+
.split(",")
22+
.map((s) => s.trim().toLowerCase())
23+
.filter(Boolean)
924
)
1025
}
1126

12-
const enabledSiteODSCodes = getEnvList("ENABLED_SITE_ODS_CODES")
13-
const enabledSystems = getEnvList("ENABLED_SYSTEMS")
14-
const blockedSiteODSCodes = getEnvList("BLOCKED_SITE_ODS_CODES")
27+
const listsReady: Promise<{
28+
enabledSiteODSCodes: Set<string>;
29+
enabledSystems: Set<string>;
30+
blockedSiteODSCodes: Set<string>;
31+
}> = (async () => {
32+
const [enabledSiteODSCodes, enabledSystems, blockedSiteODSCodes] =
33+
await Promise.all([
34+
fetchListFromSSM("ENABLED_SITE_ODS_CODES"),
35+
fetchListFromSSM("ENABLED_SYSTEMS"),
36+
fetchListFromSSM("BLOCKED_SITE_ODS_CODES")
37+
])
38+
return {enabledSiteODSCodes, enabledSystems, blockedSiteODSCodes}
39+
})()
1540

1641
/**
1742
* Given an array of PSUDataItem, only returns those which:
@@ -21,9 +46,15 @@ const blockedSiteODSCodes = getEnvList("BLOCKED_SITE_ODS_CODES")
2146
* @param data - Array of PSUDataItem to be processed
2247
* @returns - the filtered array
2348
*/
24-
export function checkSiteOrSystemIsNotifyEnabled(
49+
export async function checkSiteOrSystemIsNotifyEnabled(
2550
data: Array<PSUDataItem>
26-
): Array<PSUDataItem> {
51+
): Promise<Array<PSUDataItem>> {
52+
const {
53+
enabledSiteODSCodes,
54+
enabledSystems,
55+
blockedSiteODSCodes
56+
} = await listsReady
57+
2758
return data.filter((item) => {
2859
const appName = item.ApplicationName.toLowerCase()
2960
const odsCode = item.PharmacyODSCode.toLowerCase()

0 commit comments

Comments
 (0)