Skip to content

Commit db984a8

Browse files
authored
New: [AEA-6063] - Process post-dated prescription updates (#2589)
## Summary - ✨ New Feature ### Details The metadata is now being added to the PSU data item when it is present. This PR will add a new lambda and SQS which will implement the business logic, as described here: [link](https://nhsd-confluence.digital.nhs.uk/x/zUoSPQ)
1 parent e6b3ca9 commit db984a8

45 files changed

Lines changed: 3571 additions & 580 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ jobs:
8686
ENABLE_BACKUP: "True"
8787
ENABLE_NOTIFICATIONS_INTERNAL: true
8888
ENABLE_NOTIFICATIONS_EXTERNAL: false
89+
ENABLE_POST_DATED_NOTIFICATIONS: true
8990
ENABLED_SYSTEMS: "Internal Test System"
9091
BLOCKED_SITE_ODS_CODES: "B3J1Z"
9192
NOTIFY_ROUTING_PLAN_ID: "e57fe5cc-0567-4854-abe2-b7dd9014a50c"
@@ -126,6 +127,7 @@ jobs:
126127
ENABLE_BACKUP: "False"
127128
ENABLE_NOTIFICATIONS_INTERNAL: false
128129
ENABLE_NOTIFICATIONS_EXTERNAL: false
130+
ENABLE_POST_DATED_NOTIFICATIONS: true
129131
ENABLED_SYSTEMS: "Internal Test System"
130132
BLOCKED_SITE_ODS_CODES: "B3J1Z"
131133
NOTIFY_ROUTING_PLAN_ID: "e57fe5cc-0567-4854-abe2-b7dd9014a50c"
@@ -163,6 +165,7 @@ jobs:
163165
ENABLE_BACKUP: "False"
164166
ENABLE_NOTIFICATIONS_INTERNAL: false
165167
ENABLE_NOTIFICATIONS_EXTERNAL: false
168+
ENABLE_POST_DATED_NOTIFICATIONS: true
166169
ENABLED_SYSTEMS: "Internal Test System"
167170
BLOCKED_SITE_ODS_CODES: "B3J1Z"
168171
NOTIFY_ROUTING_PLAN_ID: "e57fe5cc-0567-4854-abe2-b7dd9014a50c"

.github/workflows/pull_request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ jobs:
119119
ENABLE_BACKUP: "False"
120120
ENABLE_NOTIFICATIONS_INTERNAL: true
121121
ENABLE_NOTIFICATIONS_EXTERNAL: false
122+
ENABLE_POST_DATED_NOTIFICATIONS: true
122123
ENABLED_SYSTEMS: "Internal Test System"
123124
BLOCKED_SITE_ODS_CODES: "XXXXX" # Workaround empty string handling
124125
NOTIFY_ROUTING_PLAN_ID: "e57fe5cc-0567-4854-abe2-b7dd9014a50c"

.github/workflows/release.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ jobs:
8484
ENABLE_BACKUP: "True"
8585
ENABLE_NOTIFICATIONS_INTERNAL: false
8686
ENABLE_NOTIFICATIONS_EXTERNAL: false
87+
ENABLE_POST_DATED_NOTIFICATIONS: true
8788
ENABLED_SYSTEMS: "Internal Test System"
8889
BLOCKED_SITE_ODS_CODES: "XXXXX" # Workaround empty string handling
8990
NOTIFY_ROUTING_PLAN_ID: "e57fe5cc-0567-4854-abe2-b7dd9014a50c"
@@ -223,6 +224,7 @@ jobs:
223224
ENABLE_BACKUP: "False"
224225
ENABLE_NOTIFICATIONS_INTERNAL: false
225226
ENABLE_NOTIFICATIONS_EXTERNAL: false
227+
ENABLE_POST_DATED_NOTIFICATIONS: true
226228
ENABLED_SYSTEMS: "Internal Test System, Apotec Ltd - Apotec CRM - Production, CrxPatientApp, nhsPrescriptionApp, Titan PSU Prod"
227229
BLOCKED_SITE_ODS_CODES: "B3J1Z"
228230
NOTIFY_ROUTING_PLAN_ID: "e57fe5cc-0567-4854-abe2-b7dd9014a50c"
@@ -266,6 +268,7 @@ jobs:
266268
ENABLE_BACKUP: "True"
267269
ENABLE_NOTIFICATIONS_INTERNAL: true
268270
ENABLE_NOTIFICATIONS_EXTERNAL: true
271+
ENABLE_POST_DATED_NOTIFICATIONS: true
269272
ENABLED_SYSTEMS: "Internal Test System" # Workaround empty string handling
270273
BLOCKED_SITE_ODS_CODES: "XXXXX" # Workaround empty string handling
271274
NOTIFY_ROUTING_PLAN_ID: "e57fe5cc-0567-4854-abe2-b7dd9014a50c"

.github/workflows/run_release_code_and_api.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ on:
8484
required: false
8585
type: boolean
8686
default: false
87+
ENABLE_POST_DATED_NOTIFICATIONS:
88+
required: false
89+
type: boolean
90+
default: false
8791
ENABLED_SYSTEMS:
8892
required: true
8993
type: string
@@ -215,6 +219,7 @@ jobs:
215219
ENABLE_BACKUP: ${{ inputs.ENABLE_BACKUP }}
216220
ENABLE_NOTIFICATIONS_INTERNAL: ${{ inputs.ENABLE_NOTIFICATIONS_INTERNAL }}
217221
ENABLE_NOTIFICATIONS_EXTERNAL: ${{ inputs.ENABLE_NOTIFICATIONS_EXTERNAL }}
222+
ENABLE_POST_DATED_NOTIFICATIONS: ${{ inputs.ENABLE_POST_DATED_NOTIFICATIONS }}
218223
REQUIRE_APPLICATION_NAME: ${{ inputs.REQUIRE_APPLICATION_NAME }}
219224
ENABLED_SITE_ODS_CODES: ${{ steps.read.outputs.ods_csv }}
220225
ENABLED_SYSTEMS: ${{ inputs.ENABLED_SYSTEMS }}

.pre-commit-config.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ repos:
8686
files: ^packages\/checkPrescriptionStatusUpdates
8787
types_or: [ts, tsx, javascript, jsx, json]
8888
pass_filenames: false
89-
89+
9090
- id: lint-nhsNotifyLambda
9191
name: Lint nhsNotifyLambda
9292
entry: npm
@@ -97,6 +97,16 @@ repos:
9797
types_or: [ts, tsx, javascript, jsx, json]
9898
pass_filenames: false
9999

100+
- id: lint-postDatedLambda
101+
name: List Post-dated handling lambda
102+
entry: npm
103+
args:
104+
["run", "--prefix=packages/postDatedLambda", "lint"]
105+
language: system
106+
files: ^packages\/postDatedLambda
107+
types_or: [ts, tsx, javascript, jsx, json]
108+
pass_filenames: false
109+
100110
- id: lint-commonTesting
101111
name: Lint common/testing
102112
entry: npm

.trivyignore.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ vulnerabilities:
55
- id: CVE-2026-25547
66
statement: isaacs/brace-expansion vulnerability accepted as risk - dependency of aws-sdk/client-dynamodb
77
expired_at: 2026-03-01
8-
9-

.vscode/eps-prescription-status-update-api.code-workspace

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"name": "packages/nhsNotifyLambda",
3333
"path": "../packages/nhsNotifyLambda"
3434
},
35+
{
36+
"name": "packages/postDatedLambda",
37+
"path": "../packages/postDatedLambda"
38+
},
3539
{
3640
"name": "packages/nhsNotifyUpdateCallback",
3741
"path": "../packages/nhsNotifyUpdateCallback"

Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ sam-list-resources: guard-AWS_DEFAULT_PROFILE guard-stack_name
104104
sam-list-outputs: guard-AWS_DEFAULT_PROFILE guard-stack_name
105105
sam list stack-outputs --stack-name $$stack_name
106106

107-
sam-validate:
107+
sam-validate:
108108
sam validate --template-file SAMtemplates/main_template.yaml --region eu-west-2
109109
sam validate --template-file SAMtemplates/apis/main.yaml --region eu-west-2
110110
sam validate --template-file SAMtemplates/apis/api_resources.yaml --region eu-west-2
@@ -168,6 +168,7 @@ lint-node: compile-node
168168
npm run lint --workspace packages/cpsuLambda
169169
npm run lint --workspace packages/checkPrescriptionStatusUpdates
170170
npm run lint --workspace packages/nhsNotifyLambda
171+
npm run lint --workspace packages/postDatedLambda
171172
npm run lint --workspace packages/nhsNotifyUpdateCallback
172173
npm run lint --workspace packages/common/testing
173174
npm run lint --workspace packages/common/middyErrorHandler
@@ -200,6 +201,7 @@ test: compile
200201
npm run test --workspace packages/cpsuLambda
201202
npm run test --workspace packages/checkPrescriptionStatusUpdates
202203
npm run test --workspace packages/nhsNotifyLambda
204+
npm run test --workspace packages/postDatedLambda
203205
npm run test --workspace packages/nhsNotifyUpdateCallback
204206
npm run test --workspace packages/common/middyErrorHandler
205207
npm run test --workspace packages/psuRestoreValidationLambda
@@ -220,6 +222,8 @@ clean:
220222
rm -rf packages/cpsuLambda/lib
221223
rm -rf packages/nhsNotifyLambda/coverage
222224
rm -rf packages/nhsNotifyLambda/lib
225+
rm -rf packages/postDatedLambda/coverage
226+
rm -rf packages/postDatedLambda/lib
223227
rm -rf packages/nhsNotifyUpdateCallback/coverage
224228
rm -rf packages/nhsNotifyUpdateCallback/lib
225229
rm -rf packages/checkPrescriptionStatusUpdates/lib

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# EPS Prescription Status Update API
22

3-
![Build](https://github.com/NHSDigital/eps-prescription-status-update-api/actions/workflows/ci.yml/badge.svg?branch=main)
3+
![Build](https://github.com/NHSDigital/eps-prescription-status-update-api/actions/workflows/ci.yml/badge.svg?branch=main)
44
![Release](https://github.com/NHSDigital/eps-prescription-status-update-api/actions/workflows/release.yml/badge.svg?branch=main)
55

66
## Versions and deployments
77

8-
Version release history can be found ot https://github.com/NHSDigital/eps-prescription-status-update-api/releases.
9-
We use eslint convention for commit messages for commits to main branch. Descriptions for the types of changes in a release can be found in the [contributing guidelines](./CONTRIBUTING.md)
8+
Version release history can be found ot https://github.com/NHSDigital/eps-prescription-status-update-api/releases.
9+
We use eslint convention for commit messages for commits to main branch. Descriptions for the types of changes in a release can be found in the [contributing guidelines](./CONTRIBUTING.md)
1010
Deployment history can be found at https://nhsdigital.github.io/eps-prescription-status-update-api/
1111

1212
## Introduction
@@ -20,6 +20,7 @@ This is the AWS layer that provides an API for EPS Prescription Status Update.
2020
- `packages/capabilityStatement` Returns a static capability statement.
2121
- `packages/cpsuLambda` Handles updating prescription status using a custom format.
2222
- `packages/nhsNotifyLambda` Handles sending prescription notifications to the NHS Notify service.
23+
- `packages/postDatedLambda` Handles business logic for post-dated prescriptions getting notifications \[deprecated\].
2324
- `packages/nhsNotifyUpdateCallback` Handles receiving notification updates from the NHS Notify service.
2425
- `packages/checkPrescriptionStatusUpdates` Validates and retrieves prescription status update data.
2526
- `packages/gsul` Expose data owned by PSU but needed by [PfP](https://github.com/NHSDigital/prescriptionsforpatients)
@@ -56,9 +57,9 @@ The contents of this repository are protected by Crown Copyright (C).
5657

5758
## Development
5859

59-
It is recommended that you use visual studio code and a devcontainer as this will install all necessary components and correct versions of tools and languages.
60-
See https://code.visualstudio.com/docs/devcontainers/containers for details on how to set this up on your host machine.
61-
There is also a workspace file in .vscode that should be opened once you have started the devcontainer. The workspace file can also be opened outside of a devcontainer if you wish.
60+
It is recommended that you use visual studio code and a devcontainer as this will install all necessary components and correct versions of tools and languages.
61+
See https://code.visualstudio.com/docs/devcontainers/containers for details on how to set this up on your host machine.
62+
There is also a workspace file in .vscode that should be opened once you have started the devcontainer. The workspace file can also be opened outside of a devcontainer if you wish.
6263
The project uses [SAM](https://aws.amazon.com/serverless/sam/) to develop and deploy the APIs and associated resources.
6364

6465
All commits must be made using [signed commits](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits).
@@ -239,8 +240,8 @@ Workflows are in the `.github/workflows` folder:
239240

240241
### Github pages
241242

242-
Github pages is used to display deployment information. The source for github pages is in the gh-pages branch.
243-
As part of the ci and release workflows, the release tag (either the short commit SHA or release tag) is appended to \_data/{environment}\_deployments.csv so we have a history of releases and replaced in \_data/{environment}\_latest.csv so we now what the latest released version is.
243+
Github pages is used to display deployment information. The source for github pages is in the gh-pages branch.
244+
As part of the ci and release workflows, the release tag (either the short commit SHA or release tag) is appended to \_data/{environment}\_deployments.csv so we have a history of releases and replaced in \_data/{environment}\_latest.csv so we now what the latest released version is.
244245
There are different makefile targets in this branch. These are
245246

246247
- `run-jekyll` - runs the site locally so changes can be previewed during development

SAMtemplates/functions/main.yaml

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ Parameters:
3333
Type: String
3434
Default: none
3535

36+
PostDatedNotificationsSQSQueueUrl:
37+
Type: String
38+
Default: none
39+
3640
SQSSaltSecret:
3741
Type: AWS::SecretsManager::Secret::Name<String>
3842

@@ -57,6 +61,10 @@ Parameters:
5761
EnableNotificationsInternalParam:
5862
Type: AWS::SSM::Parameter::Name<String>
5963

64+
EnablePostDatedNotifications:
65+
Type: AWS::SSM::Parameter::Name<String>
66+
Default: "false"
67+
6068
RequireApplicationName:
6169
Type: String
6270
Default: false
@@ -121,6 +129,8 @@ Resources:
121129
Variables:
122130
TABLE_NAME: !Ref PrescriptionStatusUpdatesTableName
123131
NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref NHSNotifyPrescriptionsSQSQueueUrl
132+
POST_DATED_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref PostDatedNotificationsSQSQueueUrl
133+
ENABLE_POST_DATED_NOTIFICATIONS: !Ref EnablePostDatedNotifications
124134
SQS_SALT: !Ref SQSSaltSecret
125135
ENABLED_SITE_ODS_CODES_PARAM: !Ref EnabledSiteODSCodesParam
126136
ENABLED_SYSTEMS_PARAM: !Ref EnabledSystemsParam
@@ -165,6 +175,7 @@ Resources:
165175
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionStatusUpdatesKMSKeyPolicyArn
166176
- Fn::ImportValue: !Sub ${StackName}-UseNotificationSQSQueueKMSKeyPolicyArn
167177
- Fn::ImportValue: !Sub ${StackName}-WriteNHSNotifyPrescriptionsSQSQueuePolicyArn
178+
- Fn::ImportValue: !Sub ${StackName}-WritePostDatedNotificationsSQSQueuePolicyArn
168179
- Fn::ImportValue: !Sub ${StackName}-GetSQSSaltSecretPolicy
169180
- Fn::ImportValue: !Sub ${StackName}-GetNotificationsParameterPolicy
170181
LogRetentionInDays: !Ref LogRetentionInDays
@@ -489,6 +500,98 @@ Resources:
489500
- Fn::ImportValue: !Sub ${StackName}-GetPSUSecretPolicy
490501
- Fn::ImportValue: !Sub ${StackName}-UsePSUSecretsKMSKeyPolicyArn
491502

503+
## Post-dated lambda definitions
504+
PostDatedNotifyLambdaScheduleEventRole:
505+
Type: AWS::IAM::Role
506+
Properties:
507+
AssumeRolePolicyDocument:
508+
Version: 2012-10-17
509+
Statement:
510+
- Effect: Allow
511+
Principal:
512+
Service:
513+
- scheduler.amazonaws.com
514+
Action:
515+
- sts:AssumeRole
516+
ManagedPolicyArns:
517+
- !Ref PostDatedNotifyLambdaScheduleEventRolePolicy
518+
519+
PostDatedNotifyLambdaScheduleEventRolePolicy:
520+
Type: AWS::IAM::ManagedPolicy
521+
Properties:
522+
PolicyDocument:
523+
Version: 2012-10-17
524+
Statement:
525+
- Effect: Allow
526+
Action:
527+
- lambda:InvokeFunction
528+
Resource:
529+
- !GetAtt PostDatedNotifyLambda.Arn
530+
531+
PostDatedNotifyLambda:
532+
Type: AWS::Serverless::Function
533+
Properties:
534+
FunctionName: !Sub ${StackName}-postDatedNotifyLambda
535+
Timeout: 900
536+
CodeUri: ../../packages/
537+
Handler: main.handler
538+
Role: !GetAtt PostDatedNotifyLambdaResources.Outputs.LambdaRoleArn
539+
Environment:
540+
Variables:
541+
LOG_LEVEL: !Ref LogLevel
542+
NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref NHSNotifyPrescriptionsSQSQueueUrl
543+
POST_DATED_PRESCRIPTIONS_SQS_QUEUE_URL: !Ref PostDatedNotificationsSQSQueueUrl
544+
TABLE_NAME: !Ref PrescriptionStatusUpdatesTableName
545+
Events:
546+
ScheduleEvent:
547+
Type: ScheduleV2
548+
Properties:
549+
Name: !Sub ${StackName}-PostDatedNotifySchedule
550+
ScheduleExpression: "rate(15 minutes)"
551+
RoleArn: !GetAtt PostDatedNotifyLambdaScheduleEventRole.Arn
552+
Metadata:
553+
BuildMethod: esbuild
554+
guard:
555+
SuppressedRules:
556+
- LAMBDA_DLQ_CHECK
557+
- LAMBDA_INSIDE_VPC
558+
- LAMBDA_CONCURRENCY_CHECK
559+
BuildProperties:
560+
Minify: true
561+
Target: es2020
562+
Sourcemap: true
563+
packages: bundle
564+
# set tsconfig path to whatever you actually have for this lambda package
565+
tsconfig: postDatedLambda/tsconfig.json
566+
EntryPoints:
567+
- postDatedLambda/src/main.ts
568+
569+
PostDatedNotifyLambdaResources:
570+
Type: AWS::Serverless::Application
571+
Properties:
572+
Location: lambda_resources.yaml
573+
Parameters:
574+
StackName: !Ref StackName
575+
LambdaName: !Sub ${StackName}-postDatedNotifyLambda
576+
LambdaArn: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${StackName}-postDatedNotifyLambda
577+
LogRetentionInDays: !Ref LogRetentionInDays
578+
CloudWatchKMSKeyId: !ImportValue account-resources:CloudwatchLogsKmsKeyArn
579+
EnableSplunk: !Ref EnableSplunk
580+
SplunkSubscriptionFilterRole: !ImportValue lambda-resources:SplunkSubscriptionFilterRole
581+
SplunkDeliveryStreamArn: !ImportValue lambda-resources:SplunkDeliveryStream
582+
IncludeAdditionalPolicies: true
583+
AdditionalPolicies: !Join
584+
- ","
585+
- - Fn::ImportValue: !Sub ${StackName}-WriteNHSNotifyPrescriptionsSQSQueuePolicyArn
586+
- Fn::ImportValue: !Sub ${StackName}-ReadNHSNotifyPrescriptionsSQSQueuePolicyArn
587+
- Fn::ImportValue: !Sub ${StackName}-UseNotificationSQSQueueKMSKeyPolicyArn
588+
- Fn::ImportValue: !Sub ${StackName}-WritePostDatedNotificationsSQSQueuePolicyArn
589+
- Fn::ImportValue: !Sub ${StackName}-ReadPostDatedNotificationsSQSQueuePolicyArn
590+
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionStatusUpdatesTableName}:TableWritePolicyArn
591+
- Fn::ImportValue: !Sub ${StackName}:tables:${PrescriptionStatusUpdatesTableName}:TableReadPolicyArn
592+
- Fn::ImportValue: !Sub ${StackName}:tables:UsePrescriptionStatusUpdatesKMSKeyPolicyArn
593+
## End of post-dated lambda bits
594+
492595
NHSNotifyUpdateCallback:
493596
Type: AWS::Serverless::Function
494597
Properties:
@@ -719,3 +822,12 @@ Outputs:
719822
NHSNotifyUpdateCallbackFunctionArn:
720823
Description: The function ARN of the NHSNotifyUpdateCallback lambda
721824
Value: !GetAtt NHSNotifyUpdateCallback.Arn
825+
826+
# Post-dated lambda outputs
827+
PostDatedNotifyLambdaFunctionName:
828+
Description: The function name of the postDatedNotifyLambda
829+
Value: !Ref PostDatedNotifyLambda
830+
831+
PostDatedNotifyLambdaFunctionArn:
832+
Description: The function ARN of the postDatedNotifyLambda
833+
Value: !GetAtt PostDatedNotifyLambda.Arn

0 commit comments

Comments
 (0)