@@ -14,6 +14,9 @@ import {
1414
1515import { checkSiteOrSystemIsNotifyEnabled } from "../validation/notificationSiteAndSystemFilters"
1616
17+ // eslint-disable-next-line max-len
18+ const ENABLE_POST_DATED_NOTIFICATIONS = ( process . env . ENABLE_POST_DATED_NOTIFICATIONS || "false" ) . toLowerCase ( ) === "true"
19+
1720const sqsUrl : string | undefined = process . env . NHS_NOTIFY_PRESCRIPTIONS_SQS_QUEUE_URL
1821const postDatedSqsUrl : string | undefined = process . env . POST_DATED_PRESCRIPTIONS_SQS_QUEUE_URL
1922
@@ -255,20 +258,27 @@ export async function pushPrescriptionToNotificationSQS(
255258 } )
256259 . map ( ( { current} ) => current )
257260
258- // Build two arrays, one of all post dated, and one of all non-post-dated
259- const postDatedItems = changedStatus . filter ( item => item . PostDatedLastModifiedSetAt )
260- const nonPostDatedItems = changedStatus . filter ( item => ! item . PostDatedLastModifiedSetAt )
261+ let sqsPromises : Promise < Array < string > >
262+ if ( ENABLE_POST_DATED_NOTIFICATIONS ) {
263+ logger . info ( "Post-dated notifications are enabled, separating post-dated and non-post-dated items" )
264+ // Build two arrays, one of all post dated, and one of all non-post-dated
265+ const postDatedItems = changedStatus . filter ( item => item . PostDatedLastModifiedSetAt )
266+ const nonPostDatedItems = changedStatus . filter ( item => ! item . PostDatedLastModifiedSetAt )
261267
262- const postDatedMessageIds = sendItemsToSQS ( postDatedItems , postDatedSqsUrl , requestId , logger )
263- const nonPostDatedMessageIds = sendItemsToSQS ( nonPostDatedItems , sqsUrl , requestId , logger )
268+ const postDatedMessageIds = sendItemsToSQS ( postDatedItems , postDatedSqsUrl , requestId , logger )
269+ const nonPostDatedMessageIds = sendItemsToSQS ( nonPostDatedItems , sqsUrl , requestId , logger )
270+ sqsPromises = Promise . all ( [ postDatedMessageIds , nonPostDatedMessageIds ] ) . then ( results => results . flat ( ) )
271+ } else {
272+ logger . info ( "Post-dated notifications are disabled, sending all items to the standard notifications queue" )
273+ sqsPromises = sendItemsToSQS ( changedStatus , sqsUrl , requestId , logger )
274+ }
264275
265276 logger . info (
266277 "The following patients will have prescription update app notifications requested" ,
267278 { nhsNumbers : changedStatus . map ( e => e . PatientNHSNumber ) }
268279 )
269280
270- return Promise . all ( [ postDatedMessageIds , nonPostDatedMessageIds ] )
271- . then ( results => results . flat ( ) )
281+ return sqsPromises
272282}
273283
274284/**
0 commit comments