Delivered remotely for a business based in Boston, United States. Names withheld by agreement.
Project Overview
Diagnostic reports arrive in wildly inconsistent formats—from crisp electronic hematology exports to faxed pathology scans with handwritten margin notes and shifting reference ranges across different testing laboratories. Physicians reviewing ten years of historical PDFs during a brief appointment struggle to spot subtle downward hemoglobin trends or compare lipid panels reported in incompatible units, while patients reading raw medical jargon online often misinterpret benign flags.
Built for diagnostic and care-navigation workflows in Boston, we engineered an AI medical report analyzer powered by Python, FastAPI, React, Celery, and PostgreSQL. The platform transforms multi-format lab and imaging reports into verified, unit-normalized biomarker timelines paired with plain-language clinical summaries where every statement clicks straight back to its highlighted line on the original PDF.
Diagnostic Interpretation Gaps
Analyzing real-world diagnostic packets from regional reference laboratories and hospital portals exposed four technical hurdles:
- Inconsistent analyte naming and units: The same biomarker appeared under dozens of abbreviations across clinics, mixing
mg/dL,mmol/L, andµmol/Lwith varying laboratory-specific reference intervals. - Multi-column table alignment errors: Standard text scrapers scrambled multi-page comprehensive metabolic panels, pairing yesterday's reference range with today's numeric result.
- Unverifiable AI prose: Naive generative wrappers frequently fabricated normal ranges or paraphrased findings inaccurately when faced with borderline results or OCR noise.
- Siloed PDF attachments: Static document viewers forced clinicians and patients to open five separate files sequentially rather than viewing a unified longitudinal curve.
Architectural Strategy
We separated deterministic numeric extraction from probabilistic narrative synthesis. First, Python layout-aware OCR pipelines and geometric table parsers reconstruct structured lab rows anchored to exact page numbers and (x, y) coordinates. Next, a clinical normalization engine resolves analyte synonyms and converts units deterministically without involving any language model.
Only after structured records pass schema and range validation do constrained LLM APIs generate clinician-facing bullet digests or patient-friendly explanations—and every generated sentence must cite structured extraction IDs checked programmatically before display in React.
Core Capabilities
- Multi-Format Diagnostic Ingestion: Parses native clinical PDFs, scanned lab printouts, and mobile captures of blood panels, urinalysis, and imaging impressions.
- Canonical Biomarker & Unit Normalization: Maps variant test names to standardized clinical codes and converts units cleanly so multi-year charts compare apples to apples.
- Longitudinal Trend & Delta Highlighting: Graphs biomarkers over time alongside lab-specific reference bands, surfacing clinically meaningful shifts across encounters.
- Citation-Anchored Split-Pane Viewer: Displays structured tables and AI summaries alongside the original PDF canvas in React, auto-scrolling and highlighting source boxes on click.
- Dual-Audience Summarization: Produces concise technical digests for physicians and jargon-translated, non-alarmist preparation notes for patients awaiting follow-up visits.
Technical Architecture
Clients upload diagnostic files to encrypted object storage via FastAPI pre-signed URLs. FastAPI records document state in PostgreSQL and enqueues an asynchronous Celery pipeline. Workers rasterize pages, execute layout OCR, normalize biomarkers, run de-identified LLM summarization over BAA-compliant endpoints, verify citation integrity, and push live readiness events to the React viewer.
Flow: Encrypted PDF Upload (FastAPI) → Celery Compute Queue → Layout OCR & Table Parser → Deterministic Unit & LOINC Normalizer → De-Identified LLM Summary & Verifier → PostgreSQL Biomarker Store → React Cited Viewer
Isolating OCR and LLM verification inside staged Celery tasks allows granular retries on transient API blips without re-running expensive image rasterization.
Technology Stack
| Category | Technology detail |
|---|---|
| API & Validation Tier | Python FastAPI serving pre-signed upload endpoints, FHIR-aligned schemas, and summary APIs |
| Document & OCR Pipeline | Layout-aware OCR and table reconstruction extracting lab rows, flags, and bounding boxes |
| Clinical Normalization | Deterministic Python engine mapping analyte aliases and converting SI/US reference units |
| AI Synthesis Layer | Constrained LLM APIs generating structured, citation-grounded plain-language explanations |
| Relational Data Store | PostgreSQL storing normalized biomarker series, report provenance, and audit events |
| Async Processing | Celery task workers orchestrating page rasterization, OCR, normalization, and validation |
| Diagnostic Viewer UI | React and TypeScript split-screen PDF canvas paired with longitudinal biomarker trend charts |
| Encrypted File Vault | KMS-encrypted object storage retaining original diagnostic PDFs and de-identified text views |
| Guardrail Verifier | Post-generation schema and numeric verification checks matching LLM claims to extracted rows |
Engineering Trade-offs & Solutions
| Engineering Challenge | Solution & Trade-off |
|---|---|
| Letting an LLM parse numbers from raw PDF text invites silent transcription errors | Restricted numeric extraction strictly to geometric OCR + rule-based table parsers and ran numeric parity checks against LLM summaries; increases parser ruleset maintenance while protecting clinical accuracy. |
| Sending full patient headers to external LLM endpoints creates HIPAA exposure | Applied automated PHI redaction (names, DOB, MRN, addresses) prior to LLM API calls inside BAA-covered tenants, trading slight preprocessing latency for strict privacy minimization. |
| Overlapping OCR text in skewed faxed reports drops confidence on borderline digits | Built confidence-threshold gating that flags low-certainty cells visually in React and omits uncertain metrics from automated summaries rather than guessing values. |
| Comparing historical labs with shifting reference intervals misleads trend plots | Stored each test's original reference range alongside converted values in PostgreSQL rather than applying one global threshold, preserving historical clinical context. |
PHI Protection & Clinical Guardrails
Handling US diagnostic records requires strict HIPAA-aligned safeguards across storage, inference, and display. Source PDFs reside in KMS-encrypted object buckets served exclusively via short-lived authenticated endpoints, while PostgreSQL encrypts sensitive patient identifiers and logs every report upload, review, and API export in append-only audit tables.
Equally critical are clinical safety guardrails inside the synthesis layer. System prompts and post-processing validators enforce non-diagnostic framing—explaining terminology and highlighting documented out-of-range flags without issuing autonomous treatment recommendations or inventing urgency scores not present in the source report. Whenever an analyte value fails numeric cross-checking against the parsed PostgreSQL table, the pipeline blocks automated summary output and surfaces the raw verified table row for human review.
Pipeline Latency & Batch Scalability
Diagnostic volume fluctuates heavily between individual patient uploads and clinic-wide historical chart backfills. To preserve fast turnaround for live portal users, Celery routes interactive single-report uploads onto high-priority compute queues while pacing multi-hundred-document archive migrations on dedicated background workers.
Page-level SHA-256 fingerprinting avoids redundant OCR passes on duplicated cover sheets or repeated cumulative lab printouts, while normalized biomarker rows are indexed by (patient_id, canonical_code, collected_at) in PostgreSQL so React longitudinal trend dashboards render instantaneously across years of accumulated panels.
Operational Outcomes
Combining deterministic clinical normalization with verifiable AI summarization reshaped how care teams and patients interact with diagnostic paperwork:
- Trusted report verification: Clinicians and patients validate every summarized insight in one click against highlighted source coordinates rather than trusting opaque text blocks.
- Unified multi-lab timelines: Automated alias resolution and unit conversion merge fragmented PDF attachments into coherent longitudinal biomarker views.
- Clearer patient preparation: Jargon-translated explanations backed by verified numbers help patients formulate focused questions ahead of specialist consultations.
- Safe, auditable AI execution: Strict PHI scrubbing, confidence gating, and deterministic parity checks keep generative components bounded within clinical compliance standards.