Inspiration

What it does

How we built it

Challenges we ran into

Accomplishments that we're proud of

What we learned

What's next for LabLens AI

Inspiration

Lab reports are one of the most common yet confusing medical documents patients receive. In Vietnam and across Southeast Asia, reports often come as scanned PDFs with mixed Vietnamese-English terminology, SI units, and complex multi-tier reference ranges. Patients struggle to understand what their results mean, which values need attention, and what to do next.

We built LabLens AI to bridge this gap — turning complex lab reports into clear, actionable health insights powered by Qwen.

What it does

LabLens AI is an AI-powered lab report analyzer. Patients upload a PDF lab report and receive an instant analysis that:

  • Extracts every test value from the report (all tests from a full panel)
  • Flags abnormals deterministically using code-based validation (not LLM hallucination)
  • Explains findings in plain language, grouped by body system (Heart, Kidney, Liver, Blood, etc.)
  • Recommends next steps: "No action needed", "Monitor at next checkup", or "Discuss with doctor"
  • Auto-detects language and responds in Vietnamese, English, or other languages

Key Design Principle: "Code Decides, LLM Explains"

Abnormal flags are computed deterministically by TypeScript code, not by the LLM. This ensures consistency, auditability, and eliminates hallucination risk in clinical decisions. The LLM's role is strictly to explain pre-validated results.

How we built it

4-Stage Pipeline

  1. PDF Ingestion — pdfjs-dist extracts text; scanned pages (detected by sparse text threshold) are rendered to PNG and sent to Qwen3-VL-Plus for Vision OCR
  2. Qwen Extraction — Qwen Turbo extracts structured JSON (test names, values, units, reference ranges) from the combined text
  3. Deterministic Validation — A custom TypeScript reference range parser handles simple ranges, less-than/greater-than thresholds, multi-tier ranges (Vitamin D: Deficiency/Insufficiency/Sufficiency), and qualitative results. Panic values table flags critical results. Sensitive markers (cancer, hepatitis) are capped at severity 2 with guardrail notes.
  4. Qwen Analysis — Qwen Turbo generates patient-friendly explanations grouped by body system, in the detected language

Streaming Response

Results are streamed via NDJSON — extraction results appear immediately while analysis continues in the background. Users see their test values and flags within seconds, with explanations filling in progressively.

Tech Stack

  • Frontend: Next.js 16, React, Tailwind v4
  • AI Models: Qwen Turbo (extraction + analysis), Qwen3-VL-Plus (Vision OCR)
  • PDF Processing: pdfjs-dist + @napi-rs/canvas (server-side page rendering)
  • Validation: TypeScript + Zod schemas (comprehensive test suite)
  • API: DashScope OpenAI-compatible endpoint (Singapore region)

Challenges we ran into

  • Scanned PDFs: The sample report had 7 out of 14 pages as scanned images. pdfjs-dist extracted only 3-9 characters per page. We had to build a vision OCR fallback that renders pages to PNG and uses Qwen3-VL-Plus for recognition.
  • Multi-tier reference ranges: Vietnamese lab reports use complex ranges like "Deficiency: < 20 / Insufficiency: 20-29 / Sufficiency: 30-100". We built a custom TypeScript parser that handles all formats deterministically.
  • Token limits: Large reports hit the 16K token extraction limit, producing truncated JSON. We implemented JSON repair that closes brackets and recovers partial data.
  • Model selection: qwen3-max produced the best extraction quality but depleted free quota quickly. qwen-turbo was fast but couldn't parse reference ranges. Solution: use qwen-turbo for extraction with a simple prompt, then parse ranges locally in TypeScript.

Accomplishments that we're proud of

  • 100% accuracy on all known abnormals in the sample report, plus bonus findings the reference answer missed
  • "Code Decides, LLM Explains" architecture that prevents clinical hallucination
  • Multilingual support — auto-detects Vietnamese and responds accordingly
  • Clinical safety features — panic values, sensitive marker guardrails, confidence scoring
  • Comprehensive test suite covering validation, normalization, and panic value detection

What we learned

  • Qwen3-VL-Plus is remarkably accurate at OCR for lab report tables — consistently better than Tesseract.js for numeric data
  • Deterministic validation (code-based) is essential for healthcare AI — LLMs should explain, not decide
  • Streaming responses dramatically improve perceived performance even when total time is similar
  • Vietnamese lab reports use SI units consistently, which simplifies cross-lab normalization

What's next for LabLens AI

  • Performance optimization — reduce processing time from ~120s to under 30s with chunked extraction
  • Trend analysis — upload multiple reports over time to track biomarker trends
  • Integration with Elfie — API-first design ready for embedding into Elfie's health platform
  • Mobile PWA — responsive design for on-the-go report checking
  • Additional languages — Arabic, French, and other languages used in Elfie's 30+ country footprint

Built With

Share this project:

Updates

Submission history