AWS Builder Center
How to Send Patient Report-Ready Notifications with DynamoDB and AWS Lambda

How to Send Patient Report-Ready Notifications with DynamoDB and AWS Lambda

Send patient report-ready notifications after publication. Use DynamoDB and AWS Lambda to track delivery, handle retries, and keep report details inside the patient portal.

A clinic employee uploads a report at 9:00 a.m. The file reaches storage immediately, but validation and staff approval take another eight minutes. If the notification fires on upload, the patient can receive a message about a report they cannot open yet.
Send the notification when the approved report becomes available in the portal. That gives the patient a clear action and gives the engineering team a well-defined event to track.

1. Create the notification when the report becomes ready

Suppose a report moves from  AWAITING_APPROVAL  to  READY  after staff approval and publication. The application writes two records in one DynamoDB transaction:
  1. Update the report to  READY , conditional on the expected version and current status.
  1. Insert a  PENDING  notification job for that report version and recipient, conditional on the job key being new.
A job key such as  REPORT#r_209#VERSION#v3#RECIPIENT#p_815#CHANNEL#EMAIL  makes the notification intent traceable. If an approval request is retried, the application can look up the existing report and job to determine whether the first attempt succeeded.
Writing both changes together closes a failure gap. If the application crashes just after the transaction commits, the report and its pending notification job still exist.

2. Give the notification worker a small, explicit job

Use DynamoDB Streams to invoke a Lambda worker for new notification jobs. Keep the job identifier, report version, recipient reference, and channel in the job. Resolve the contact details from the current recipient record when processing it.
The worker can follow this sequence:
  1. Claim the job with a conditional update and a short processing lease.
  1. Check that the report version is still available and the recipient can still access it.
  1. Check the recipient’s current notification preferences and verified contact details.
  1. Send the approved generic message and record the provider response.
An example message is: “A new document is available in your patient portal. Sign in to view it.”
Keep the report title, clinical details, and presigned download credentials out of the message. If the message includes a link, point it to the normal portal sign-in page. The portal checks current access before showing the report.

3. Distinguish provider acceptance from delivery

A messaging provider may accept a request before it knows whether the message reached the recipient. Use status labels that reflect the evidence available.
Job state
What the application observed
 PENDING 
The notification job was saved
 PROCESSING 
A worker has claimed the job
 ACCEPTED 
The provider accepted the send request
 DELIVERED 
The provider reported delivery, if supported
 SUPPRESSED 
The worker skipped sending because a current eligibility check failed
 FAILED 
The job needs retry or investigation
A worker can time out after the provider accepts a message and before DynamoDB records that acceptance. If the provider supports idempotency keys, use the same job identifier on retry. Otherwise, an ambiguous send can produce a duplicate. Where the provider supports lookup or reconciliation, use it before retrying an uncertain outcome.
Add a scheduled reconciliation check for old  PENDING  jobs and expired processing leases. Treat it as a recovery path for saved jobs that never reached a final state.

4. Test what happens when the workflow breaks

Scenario
Expected result
A report is uploaded but approval is still pending
No notification job is created
Staff approval is submitted twice
One notification job exists for the same report version, recipient, and channel
Access is revoked before the worker checks eligibility
The worker suppresses the notification
The worker stops after claiming a job
The job can be recovered after the lease expires
The provider accepts a send just before the worker times out
The retry reuses the same provider key where supported
A patient opens an old notification after access changes
The portal applies its current authorization rules
Monitor pending-job age, failed sends, and suppressed notifications. Keep message contents and contact details out of routine operational logs.
When troubleshooting, trace the report version to the saved notification job and then to the provider response. Those three records tell staff where the workflow stopped without requiring anyone to inspect the report itself.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article