An AI-powered system for OCR + structured extraction of medical document metadata with receptionist review before approval.
- Frontend (Vercel):
https://medical-document-processing-ai-agen.vercel.app - Backend API (Render):
https://medical-document-processing-ai-agent.onrender.com - Backend health:
https://medical-document-processing-ai-agent.onrender.com/health
- Upload PDF/DOCX document.
- OCR extracts text and layout metadata.
- AI prioritizes extraction of 7 core filing fields (and captures additional fields when available).
- Review queue shows confidence and extracted values.
- Receptionist corrects/approves/rejects.
These are the primary fields used for filing and review. The system also extracts additional metadata/clinical fields when present in the document.
patient_namereport_datesubjectsource_contactstore_in(Investigations|Correspondence)assigned_doctorcategory
- Frontend: Next.js 16 + TypeScript + Tailwind
- Backend: NestJS + TypeScript
- OCR: Azure Document Intelligence
- AI: Gemini + Claude fallback
- Data: Supabase Postgres + Storage
- Hosting: Vercel (frontend), Render (backend)
- Node.js 20+
- npm
git clone <repository-url>
cd Medical-Document-Processing-AI-Agent
# backend
cd backend
npm install
# frontend
cd ../frontend
npm install- Backend env:
backend/.env - Frontend env:
frontend/.env.local
Minimum frontend env:
NEXT_PUBLIC_API_URL=http://localhost:3000
NEXT_PUBLIC_SUPABASE_URL=https://<your-project>.supabase.coStart apps:
# terminal 1
cd backend
npm run start:dev
# terminal 2
cd frontend
npm run dev -- -p 3002- Backend expects
CORS_ORIGINS(comma-separated allowlist). - For Vercel + local testing:
CORS_ORIGINS=https://*.vercel.app,http://localhost:3002- Full deployment runbook:
docs/deployment/EC2_VERCEL_DEPLOYMENT.md
GET /healthGET /metrics(Prometheus-compatible backend metrics)POST /documents/processGET /documents/queue/reviewGET /documents/:idPOST /documents/:id/updatePOST /documents/:id/approvePOST /documents/:id/reject
- Backend now exposes Prometheus-style metrics at
/metrics. - HTTP request metrics include method, normalized route, status code, and latency.
- Document pipeline metrics include stage durations (
upload,create,ocr,ai,save,status,total) and fallback counts. - Optional env flags:
METRICS_ENABLED=true,REQUEST_LOGGING_ENABLED=true - Optional protection: set
METRICS_AUTH_TOKENand pass headerx-metrics-token: <token>when scraping/metrics.
- Keep OCR, extraction, and document workflows in separate modules/services.
- Keep controller methods thin; business logic belongs in services.
- Use typed interfaces for DTOs and extracted payloads.
- Add small helper methods for normalization/validation rather than duplicating logic.
- Use structured stage logging for processing timing (
upload,ocr,ai,save,status). - Avoid logging secrets or raw credentials.
- Log CORS allowlist and blocked origins in production for faster incident diagnosis.
- Validate required review fields before approval.
- Validate lookup-backed fields against available lookup values.
- Keep date parsing strict (
YYYY-MM-DDwith calendar validation).
- Centralize constants and regex patterns used across extraction logic.
- Keep environment configuration in
.env.examplewith placeholders only. - Prefer small composable functions over long controller logic.
- Use
npm ciin CI/deployment for reproducible installs. - Keep health checks (
/health) and smoke tests in release checklist. - Run database migrations before production cutover.
- Never commit
.envor credentials. - Keep Supabase service key backend-only.
- See
SECURITY.mdand run:
./scripts/verify_security.sh- Upload -> OCR -> AI extraction -> review queue is live.
- PDF highlight support works for selectable and scanned documents.
- Render + Vercel production deployment is active.





