RS
RISHI SINGH
Back to All Projects
HEALTHCARE · AI · DATA QUALITYCompleted & Verified45 Vitest Specs Passing

VitalTrace

Personal Health Record Intelligence & Deterministic Data Quality Governance

A full-stack clinical data intelligence platform that ingests unstructured lab report PDFs and scans, normalizes test aliases to canonical LOINC standards with zero hallucination tolerance, executes deterministic physiological validations, and tracks longitudinal biomarkers.

Test Coverage
45/45 Passed
Vitest Unit & Integration
Validation Rule
100% Deterministic
Physiological bounds check
Database Model
3NF + RLS
security_invoker views
LOINC Policy
Zero Guessing
Null fallback on unmapped

01. Problem & Clinical Motivation

Diagnostic laboratory reports represent one of the most critical, yet fragmented, categories of personal health data. Patients accumulate scattered physical PDFs, paper printouts, and photographic scans across different healthcare providers and lab chains.

When engineers attempt to ingest these documents with modern multimodal Large Language Models, two dangerous failure modes emerge:

1. The Unit & Scaling Catastrophe

A fasting blood glucose value of 105 evaluated in mg/dL is pre-diabetic, whereas in mmol/L it indicates severe acute hyperosmolar toxicity. Models frequently drop or confuse units without strict schema gating.

2. Hallucinated Diagnostic Coding

LLMs hallucinate plausible-looking 5-digit LOINC codes (e.g. inventing code 1558-6 for random non-fasting glucose). This permanently corrupts longitudinal health records.

Core Engineering Directive: The LLM is an untrusted optical transducer; deterministic software must serve as the authoritative judge and gatekeeper.

02. End-to-End System Architecture

VitalTrace couples a React 19 frontend with server-side Supabase Edge Functions, enforcing strict separation between data extraction, deterministic clinical validation, and patient review.

VitalTrace Ingestion & Validation Pipeline
[ Lab Report PDF / Scan ]
        │
        ▼
[ Private Supabase Storage Vault ] ───► Encrypted at rest (AES-256)
        │
        ▼
[ Edge Function: extract-report ] ────► Gemini 1.5/2.5 Multimodal Extraction
        │
        ▼
[ Strict Zod Schema Parsing ] ────────► ExtractedReportSchema Validation
        │
        ▼
[ Deterministic Validator Engine ]
  ├── Biological Plausibility Check ──► PLAUSIBILITY_BOUNDS screening
  ├── LOINC Alias Dictionary ─────────► Canonical mapping (null fallback)
  ├── Unit Harmonization ─────────────► mg/dL, mmol/L, x10^3/uL
  └── Duplicate Collision Audit ──────► Same analyte + date in batch
        │
        ▼
[ PostgreSQL Database (3NF) ] ────────► status = 'pending' (RLS Auth Enforced)
        │
        ▼
[ Human Review Workbench ] ───────────► Clinician / Patient Verification Gate
        │
        ▼
[ Longitudinal Trajectories ] ────────► PostgreSQL security_invoker Views

03. Deterministic Validator Engine

Implemented in src/lib/validationRules.ts, the validator operates after Zod parsing and enforces four non-negotiable checks:

  • 01
    Physiological Plausibility Limits:

    Evaluates readings against hard human physiological bounds. For example, Potassium must fall between 1.0 and 10.0 mmol/L; values exceeding these trigger a CRITICAL_PLAUSIBILITY_BREACH.

  • 02
    Zero-Hallucination LOINC Dictionary:

    Maps synonyms (e.g. “Fasting Blood Sugar”, “Glucose Plasma”) to canonical code 1558-6. Any unmapped test retains its raw string name with a null LOINC code.

  • 03
    Unit Harmonization & Audit:

    Flags missing units or incompatible unit representations before numeric trends are plotted.

  • 04
    Duplicate Collision Detection:

    Identifies conflicting readings for the same biomarker within the same specimen draw date.

04. Multi-Tenant Isolation & SQL Security

In healthcare applications, tenant data leakage is intolerable. VitalTrace enforces complete Row-Level Security (RLS) across all tables:

PostgreSQL 15+ Analytical View with security_invoker = true
CREATE OR REPLACE VIEW view_patient_biomarker_trajectories
WITH (security_invoker = true) AS
SELECT 
  obs.profile_id,
  obs.loinc_code,
  obs.canonical_name,
  obs.observation_date,
  obs.value_numeric,
  obs.unit
FROM observations obs
WHERE obs.status = 'confirmed';

By specifying WITH (security_invoker = true), PostgreSQL enforces the querying user's credentials rather than the view owner's permissions, eliminating auth bypass vulnerabilities across analytical queries.

05. Automated Testing & Verification

The repository includes a comprehensive automated test suite executed via Vitest. The suite covers biological boundary checks, dictionary aliases, Zod schema invariants, and the idempotent retry engine:

Vitest Execution Log✓ 45 passed (100%)
✓ tests/validationRules.test.ts (18 specs)
✓ tests/aliasDictionary.test.ts (12 specs)
✓ tests/schema.test.ts (8 specs)
✓ tests/ingestionFunnel.test.ts (7 specs)
Production build command: tsc -b && vite build verified.

06. Current Limitations & Roadmap

  • !Clinical Scope: VitalTrace is an engineering demonstration of data quality architectures and is not a certified diagnostic medical device.
  • ▸Roadmap 1: Direct HL7 FHIR Observation resource export for interoperability with hospital EHR systems.
  • ▸Roadmap 2: Expanded LOINC dictionary coverage to pathology narratives and microbiology culture reports.