Conversation
There was a problem hiding this comment.
Pull request overview
Adds a new reminder-dispatch flow (7-day reminders) and refactors notification sending into dedicated “notify service” + “message builder” components to support both order-status notifications and reminders.
Changes:
- Introduces
reminder-dispatch-lambdawith env-driven reminder scheduling/config parsing and per-reminder dispatch via SQS-backed notify services. - Refactors order status notification logic into
lib/notify/services/*andlib/notify/message-builders/*, and updates existing lambdas to usedispatch(...). - Extends notify event codes to include dispatched reminder variants and updates related types/tests.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| lambdas/src/reminder-dispatch-lambda/init.ts | Wires DB/SQS/notify dependencies for the new reminder dispatch lambda. |
| lambdas/src/reminder-dispatch-lambda/index.ts | EventBridge handler that loads pending reminders and dispatches notifications based on config. |
| lambdas/src/reminder-dispatch-lambda/index.test.ts | Unit tests validating dispatch, skip logic, and error propagation for reminder dispatch. |
| lambdas/src/reminder-dispatch-lambda/config.ts | Parses/validates reminder scheduling configuration from environment variables. |
| lambdas/src/order-status-lambda/init.ts | Switches to the new OrderStatusNotifyService dependency shape. |
| lambdas/src/order-status-lambda/init.test.ts | Updates init wiring tests for the new notify service dependencies. |
| lambdas/src/order-status-lambda/index.ts | Updates notification call site to orderStatusNotifyService.dispatch(...). |
| lambdas/src/order-status-lambda/index.test.ts | Updates handler tests to mock/expect dispatch(...) rather than the old method. |
| lambdas/src/order-result-lambda/init.ts | Switches to the new OrderStatusNotifyService dependency shape. |
| lambdas/src/order-result-lambda/init.test.ts | Updates init wiring tests for the new notify service dependencies. |
| lambdas/src/order-result-lambda/index.ts | Updates notification call site to orderStatusNotifyService.dispatch(...). |
| lambdas/src/order-result-lambda/index.test.ts | Updates handler tests to mock/expect dispatch(...). |
| lambdas/src/lib/types/notify-message.ts | Adds reminder event codes and changes eventCode typing. |
| lambdas/src/lib/notify/services/base-notify-service.ts | New shared base for SQS dispatch + notification audit insertion and logging. |
| lambdas/src/lib/notify/services/order-status-notify-service.ts | New service that chooses message builders based on order status and dispatches notifications. |
| lambdas/src/lib/notify/services/order-status-notify-service.test.ts | Updates tests to match builder-based service behavior. |
| lambdas/src/lib/notify/services/reminder-notify-service.ts | New service that builds and dispatches reminder notifications for dispatched orders. |
| lambdas/src/lib/notify/services/reminder-notify-service.test.ts | Unit tests for reminder notification dispatch behavior and error cases. |
| lambdas/src/lib/notify/message-builders/base-notify-message-builder.ts | Shared builder utilities (recipient lookup, reference number, URL building, date formatting). |
| lambdas/src/lib/notify/message-builders/order-dispatched-message-builder.ts | Builder for dispatched-order notification payload. |
| lambdas/src/lib/notify/message-builders/order-dispatched-message-builder.test.ts | Unit tests for dispatched-order notification builder. |
| lambdas/src/lib/notify/message-builders/order-received-message-builder.ts | Builder for received-order notification payload. |
| lambdas/src/lib/notify/message-builders/order-received-message-builder.test.ts | Unit tests for received-order notification builder. |
| lambdas/src/lib/notify/message-builders/order-result-available-message-builder.ts | Builder for result-available notification payload. |
| lambdas/src/lib/notify/message-builders/order-result-available-message-builder.test.ts | Unit tests for result-available notification builder. |
| lambdas/src/lib/notify/message-builders/dispatched-reminder-message-builder.ts | Builder for dispatched reminders (uses reminderId as message reference). |
| lambdas/src/lib/notify/message-builders/dispatched-reminder-message-builder.test.ts | Unit tests for dispatched reminder message builder. |
| lambdas/src/lib/db/order-status-reminder-db-client.ts | Introduces DB client abstraction for pending reminders (currently stubbed). |
| lambdas/src/lib/db/notification-audit-db-client.ts | Updates audit entry typing for eventCode. |
| lambdas/src/lib/notify/notify-service.ts | Removes legacy notify service implementation in favor of new services. |
| lambdas/src/lib/notify/notify-message-builder.ts | Removes legacy monolithic notify message builder in favor of per-message builders. |
| lambdas/src/lib/notify/notify-message-builder.test.ts | Removes tests for the legacy notify message builder. |
# Conflicts: # lambdas/src/lib/notify/notify-message-builder.test.ts # lambdas/src/lib/notify/notify-message-builder.ts # lambdas/src/lib/notify/notify-service.ts # lambdas/src/lib/notify/services/order-status-notify-service.test.ts # lambdas/src/order-result-lambda/init.ts # lambdas/src/order-status-lambda/init.test.ts # lambdas/src/order-status-lambda/init.ts
…inder scheduling and dispatching
|
lewisbirks
left a comment
There was a problem hiding this comment.
What are your thoughts on splitting the refactor out into its own PR to reduce noise and get that change in quicker?
| export interface NotificationAuditEntryParams { | ||
| messageReference: string; | ||
| eventCode: NotifyEventCode; | ||
| eventCode: string; |
There was a problem hiding this comment.
any particular reason for this?
There was a problem hiding this comment.
It can be changed to "NotifyEventCode | string" but not big difference, the string is because we can have something from config that is not defined in this NotifyEventCode
| ); | ||
|
|
||
| if (nextSchedule) { | ||
| await orderStatusReminderDbClient.scheduleReminder( |
There was a problem hiding this comment.
I worry about this being a lot of individual requests if there are lots of reminders being processed. What are your thoughts on extracting it out to one batch at the end?
| const nextSchedule = schedules.find( | ||
| (s) => | ||
| s.triggerStatus === reminder.triggerStatus && | ||
| s.reminderNumber === reminder.reminderNumber + 1, | ||
| ); | ||
|
|
||
| if (nextSchedule) { | ||
| await orderStatusReminderDbClient.scheduleReminder( | ||
| reminder.orderUid, | ||
| reminder.triggerStatus, | ||
| nextSchedule.reminderNumber, | ||
| reminder.triggeredAt, | ||
| ); | ||
| commons.logInfo(name, "Next reminder scheduled", { | ||
| ...logContext, | ||
| reminderNumber: nextSchedule.reminderNumber, | ||
| }); | ||
| } |
There was a problem hiding this comment.
This essentially covers https://nhsd-jira.digital.nhs.uk/browse/HOTE-1135 right?
There was a problem hiding this comment.
ahh yes, I must have lost track of what I was supposed to do and I accidentally did it
| const outcomes: ReminderOutcome[] = []; | ||
| for (const reminder of reminders) { | ||
| outcomes.push( | ||
| await processReminder(reminder, { |
There was a problem hiding this comment.
would we want to await here or await outside of the array? using something like Promise.allSettled



Description
https://nhsd-jira.digital.nhs.uk/browse/HOTE-1024
Context
Type of changes
Checklist
Sensitive Information Declaration
To ensure the utmost confidentiality and protect your and others privacy, we kindly ask you to NOT including PII (Personal Identifiable Information) / PID (Personal Identifiable Data) or any other sensitive data in this PR (Pull Request) and the codebase changes. We will remove any PR that do contain any sensitive information. We really appreciate your cooperation in this matter.