
How to Build a FHIR API for a Patient Portal with AWS HealthLake
Build a patient portal endpoint for structured lab results using AWS HealthLake and FHIR. Map signed-in users to patient records, handle corrected results, and test access with synthetic data.
A patient opens a portal to find their latest lab result. They can download a PDF, but they have to open several reports to see whether the result changed over time. A structured results page can show the test name, value, unit, and date directly, while keeping the original PDF available for reference.
This example uses AWS HealthLake as a FHIR data store and AWS Lambda behind a patient portal endpoint. The portal exposes one narrow workflow: show the signed-in patient their released lab results.
1. Start with a small FHIR dataset
Use synthetic records for the first build. Create two
Patient records and a few Observation records for each. Include a final numeric result, a preliminary result, and a corrected result. Add a DiagnosticReport if you want to test grouping multiple observations under a single panel.Observation holds an individual result. DiagnosticReport can provide context for a panel and reference the observations it contains. The portal can start with individual results and add panel grouping once the source system’s references are consistent.2. Resolve the patient on the server
Expose a portal route such as
GET /me/lab-results . The backend verifies the signed-in identity and looks up its current mapping to the clinic and FHIR patient ID. Resolve that mapping before calling HealthLake. A FHIR patient ID supplied in a query parameter cannot establish access.For a datastore configured for IAM authorization, the backend can sign its HealthLake request with Signature Version 4. Its execution role should have only the permissions needed for the intended read workflow.
An illustrative FHIR search looks like this:
GET {datastore-base}/Observation?patient=Patient%2Fdemo-101&category=laboratoryAccept: application/fhir+jsonThe portal backend should check that returned resources still belong to the authorized patient and meet the clinic’s release policy. Keep upstream pagination under backend control. If you expose a portal cursor, bind it to the signed-in user and the authorized search rather than accepting a free-form upstream URL from the browser.
3. Return the fields the portal can safely render
Convert the FHIR search bundle into a small application response:
{ "results": [ { "id": "obs-demo-7", "label": "Synthetic lab result", "value": 4.2, "unit": "mmol/L", "effectiveDate": "2026-11-09", "status": "final" } ]}This example maps a numeric
valueQuantity . Add explicit handling for text results, missing values, and observations with multiple components before supporting them in the same view. Keep units attached to values. Group results into a trend only when the test codes and units are compatible.Decide how the source system represents corrections. It may update an existing resource or issue a replacement with a different identifier. The portal needs a rule for choosing what to display in both cases. Apply the clinic’s release policy to preliminary, corrected, amended, and invalidated results rather than assuming the FHIR status alone determines visibility.
4. Test the cases that affect patients
Test | Expected outcome |
|---|---|
Patient A tries to request Patient B’s ID | The endpoint uses the authorized server-side mapping and exposes no Patient B data |
Preliminary result exists | The portal applies the clinic’s release policy |
A result is corrected | The current released result appears according to the source’s correction rules |
HealthLake times out | The portal shows a temporary error and preserves the distinction from an empty result set |
No released results exist | The portal shows a normal empty state |
Log request IDs, operation outcomes, and timing. Keep raw FHIR bundles and result values out of routine logs. The first release is ready to evaluate when the portal can consistently show the right patient their current released results, including when the source sends a correction.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article