Skip to content

[HOTE-1024] feat: Generate Reminder: 7 days#346

Open
cptiv2020 wants to merge 6 commits intomainfrom
feature/hote-1024/reminders-seven-days
Open

[HOTE-1024] feat: Generate Reminder: 7 days#346
cptiv2020 wants to merge 6 commits intomainfrom
feature/hote-1024/reminders-seven-days

Conversation

@cptiv2020
Copy link
Copy Markdown
Contributor

@cptiv2020 cptiv2020 commented Apr 13, 2026

Description

https://nhsd-jira.digital.nhs.uk/browse/HOTE-1024

Context

Type of changes

  • Refactoring (non-breaking change)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would change existing functionality)
  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • I am familiar with the contributing guidelines
  • I have followed the code style of the project
  • I have added tests to cover my changes
  • I have updated the documentation accordingly
  • This PR is a result of pair or mob programming

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.

  • I confirm that neither PII/PID nor sensitive data are included in this PR and the codebase changes.

Copilot AI review requested due to automatic review settings April 13, 2026 13:36
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 13, 2026

Lambdas Coverage Report

Lines Statements Branches Functions
Coverage: 98%
98.56% (1644/1668) 93.24% (428/459) 97.1% (268/276)

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 13, 2026

UI Coverage Report

Lines Statements Branches Functions
Coverage: 96%
96.16% (5669/5895) 88.22% (682/773) 88.06% (214/243)

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-lambda with env-driven reminder scheduling/config parsing and per-reminder dispatch via SQS-backed notify services.
  • Refactors order status notification logic into lib/notify/services/* and lib/notify/message-builders/*, and updates existing lambdas to use dispatch(...).
  • 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
Copilot AI review requested due to automatic review settings April 14, 2026 10:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 32 out of 32 changed files in this pull request and generated 7 comments.

Copilot AI review requested due to automatic review settings April 14, 2026 12:23
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 36 out of 36 changed files in this pull request and generated 4 comments.

@cptiv2020 cptiv2020 marked this pull request as ready for review April 14, 2026 13:35
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

@lewisbirks lewisbirks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any particular reason for this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Comment on lines +94 to +111
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,
});
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This essentially covers https://nhsd-jira.digital.nhs.uk/browse/HOTE-1135 right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would we want to await here or await outside of the array? using something like Promise.allSettled

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants