Lab Reports Example
A clinician dashboard on the Lab Reports API: upload a lab report PDF, get standardized biomarkers, and read them against the patient's wearable history.
Terra Panel is a clinician-facing dashboard that joins lab results to wearable data. Upload a lab report PDF and the Lab Reports API returns standardized biomarkers with ranges, flags, and provenance, which the app charts against the same patient's sleep, resting heart rate, and training history.
Without credentials it runs in demo mode on bundled synthetic data: four patients, three years of lab history for one of them, and 18 months of wearable data.
terra examples clone lab-reports-web-app my-app
cd my-app && npm install && npm run devWhat it demonstrates
Upload and standardization: PDF to canonical biomarkers with ranges, flags, and provenance
Cross-report trends matched by
biomarker.key, so a marker charts across labs, languages, and formatsJoining labs to wearable data by
reference_id, the only key they shareA timeline plotting lab draws over resting heart rate, HRV, sleep, and training lanes
Pre-draw context: recent exertion and short sleep sit next to each report, since both skew results
Deterministic domain scoring with an explainable breakdown, kept separate from the AI layer
Chronicity assessed against each patient's own baseline
AI insights with schema-validated structured output, cached by input hash
Run it yourself
Start in demo mode
terra examples clone lab-reports-web-app my-app
cd my-app
npm install
npm run devOpen http://localhost:5173. Mutating actions are disabled behind a banner. This is the same read path as live mode, served from a local cache.
Add an ANTHROPIC_API_KEY for the Intelligence Brief, chat, and wearable-signal insights on flagged values. Without it the rest of the app still works.
How the integration works
Lab sessions are immutable once terminal, so the app caches terminal payloads write-through and refetches anything still in flight.
Some standardizations return normal for in-range rows but null for out-of-range ones. withComputedFlags fills that gap on the read path when the value and its applied range are both present, marking what it derived as source: "computed". The cache keeps Terra's payload verbatim.
Explore the code
AGENTS.md maps the integration code worth lifting.
src/server/lib/lab-reports.ts
Session access, cache, computed flags; start here
src/server/lib/terra/
API client, typed responses, error handling
src/server/lib/wearables.ts
Per-user, per-resource, per-day caching
src/server/lib/analysis/
Declarative registry of domains, weights, guideline bands
src/server/lib/ai.ts
Structured-output insights, cached by input hash
scripts/
Sample report generation and wearable seeding
Last updated
Was this helpful?