AI Agents & LLMs

CareFlow AI Clinical Assistant

CareFlow is an enterprise-grade, 10-microservice AI clinical copilot platform engineered to reduce physician administrative documentation time by up to 40%. The platform seamlessly orchestrates real-time Arabic speech-to-text intake (Cohere/Whisper), medical vision models (MedGemma 1.5 4B IT and MedSAM 2.0), layout-aware Lab OCR with 98% recall PII anonymization, and a 1024-dim BGE-M3 vector RAG engine in Qdrant to deliver evidence-grounded differential diagnoses and automated SOAP notes.

PythonFastAPILangChainLangGraphLangSmithQdrantBGE-M3MedGemma 1.5 4BMedSAM 2.0Modal GPUPostgreSQLDocker

Problem Statement

Physicians spend up to 40% of their workday typing consultation notes, transcribing patient history, and manually inspecting legacy lab PDFs and radiology scans. In overburdened healthcare systems, this administrative workload causes physician burnout and contributes to a 20% patient misdirection rate at initial clinic entry. Existing clinical software lacks real-time Arabic speech understanding, automated multi-modal diagnostic assistance, and secure edge PII redaction.

Solution

Engineered CareFlow, a 10-microservice clinical copilot platform that automates the patient journey from symptom intake to diagnostic support. Built an Arabic voice ingestion pipeline using fine-tuned ASR models (Cohere/Whisper) connected to a LangGraph clinical interview state machine. Integrated vision-language models (MedGemma 1.5 4B IT) and promptable 2D ROI segmentation (MedSAM 2.0) for radiology interpretation. Implemented a layout-aware OCR engine with 98% recall PII redaction for lab reports, and anchored all diagnostic suggestions in a 1024-dim BGE-M3 vector RAG pipeline querying PubMed and WHO guidelines in Qdrant.

Architecture

CareFlow operates as a decoupled multi-microservice architecture managed by an API Gateway (workflow-orchestrator). Product A handles real-time voice history taking using FastAPI WebSocket streams, LangGraph interview graphs, and PostgreSQL state snapshots. Product B powers clinical decision support through asynchronous services: radiology analysis (MedGemma 1.5), lesion segmentation (MedSAM 2.0), lab report extraction (PaddleOCR/MinerU), PII masking (Qwen2.5-7B on Modal GPU), and dense vector RAG (Qdrant + BGE-M3). The physician interacts with a real-time Next.js 14 Doctor Portal.

Key Features

  • Real-time Arabic speech-to-text intake (ar-EG) for automated voice history taking
  • LangGraph clinical interview state machine with dynamic symptom extraction
  • Vision-Language radiology analysis powered by google/medgemma-1.5-4b-it
  • Interactive 2D medical image ROI segmentation with MedSAM 2.0 (SAM 2.1 Hiera Small)
  • Layout-aware Lab OCR with 96% precision / 98% recall automated PII redaction
  • 1024-dimensional dense BGE-M3 vector search over medical references in Qdrant
  • Automated SOAP note generation and physician-in-the-loop diagnostic approval
  • Serverless GPU deployment on Modal with persistent Hugging Face weight caching

Challenges

  • Low-Latency Streaming Speech Ingestion. Engineered a WebSocket audio streaming pipeline with LangGraph state machine persistence to handle real-time Egyptian Arabic voice chunks without audio frame loss or latency spikes.
  • Multi-Modal Clinical Data Harmonization. Integrated disparate vision model findings (MedGemma 1.5), 2D lesion masks (MedSAM 2.0), lab OCR tables, and PubMed guidelines into a unified, non-conflicting SOAP note payload.
  • Handling heterogeneous lab report layouts without breaking tables. Implemented layout-aware document chunking (MinerU) coupled with regex scrubbing to preserve reference range relationships.
  • Handling asynchronous out-of-order document uploads in the Doctor Portal. Refactored single-string Encounter status states into step-completion bitmasks to prevent UI lockout when lab/radiology reports arrive post-interview.

Results & Metrics

40% reduction in physician documentation time per patient encounter

88% medical vision diagnostic accuracy achieved with MedGemma 1.5 4B IT

92% zero-shot JSON schema parsing rate for radiological report synthesis

0.88 - 0.93 Dice Coefficient & 3.2mm HD95 boundary precision in MedSAM 2.0 segmentation

98% PII redaction recall score guaranteeing HIPAA-compliant data handling

1.2s GPU inference latency for radiology image assessment (bfloat16 on CUDA)

20% improvement in RAG diagnostic retrieval relevance via BGE-M3 dense embeddings

100% platform microservice integration completion rate across 10 microservices

Lessons Learned

  • 💡Layout-aware parsing (e.g. MinerU) is essential for lab reports because standard text chunking fragments lab value reference tables.
  • 💡Serverless GPU weight caching via persistent Docker volumes (hf_cache) or Modal Volumes reduces cold-start latency from 45s down to 1.2s.
  • 💡Decoupling voice intake from lab and radiology analysis into asynchronous microservices enables doctors to process multi-modal patient files seamlessly as they arrive throughout the shift.

Case Study Overview

Case Study: Engineering CareFlow - The Intelligent Clinical Copilot

CareFlow is a state-of-the-art healthcare AI ecosystem designed to streamline the complete clinical journey. Built across 10 decoupled microservices, CareFlow bridges patient intake, voice history collection, multi-modal lab/radiology analysis, and evidence-based decision support into a unified physician dashboard.


System Architecture & Service Mesh

The CareFlow platform is architected around two core operational products managed by an API Gateway (workflow-orchestrator):

CareFlow 10-Microservice System Architecture & Service Mesh
                    ┌───────────────────────────────────────────┐
                    │         Next.js 14 Doctor Portal          │
                    └─────────────────────┬─────────────────────┘
                                          │ (REST / WebSocket)
                                          ▼
                    ┌───────────────────────────────────────────┐
                    │   Workflow Orchestrator (API Gateway)     │
                    └─────────────────────┬─────────────────────┘
                                          │
                 ┌────────────────────────┴────────────────────────┐
                 ▼                                                 ▼
  ┌──────────────────────────────┐                  ┌──────────────────────────────┐
  │   PRODUCT A: VOICE INTAKE    │                  │   PRODUCT B: AI ASSISTANT    │
  ├──────────────────────────────┤                  ├──────────────────────────────┤
  │ • history-service            │                  │ • decision-support-service   │
  │   (LangGraph State Machine)  │                  │   (SOAP & Differential Dx)   │
  │ • asr (Cohere / Whisper)     │                  │ • radiology-service          │
  │ • PostgreSQL (Encounters)    │                  │   (MedGemma 1.5 4B VLM)      │
  └──────────────────────────────┘                  │ • medsam-2-segmentation      │
                                                    │   (SAM 2.1 Hiera Small)      │
                                                    │ • lab-service (PaddleOCR)    │
                                                    │ • masking-ocr (Qwen2.5 7B)   │
                                                    │ • data-ingestion (BGE-M3)    │
                                                    │ • Qdrant Vector DB           │
                                                    └──────────────────────────────┘

Performance Benchmarks & Key Numbers

Component / SubsystemBenchmark / MetricAchieved ResultImpact / Significance
Clinic Entry TriagePatient Misdirection RateReduced from 20%Directs patients to correct specialty (Internal, Neuro, Oncology)
Radiology VLMMedGemma 1.5 4B Accuracy88.0% AccuracyHigh-fidelity zero-shot report generation
Radiology VLMZero-Shot JSON Parse Rate92.0% RateGuarantees structured schema output for findings/impressions
Radiology VLMGPU Inference Latency1.2 SecondsEvaluated on CUDA (bfloat16) vs 14.0s CPU fallback
ROI SegmentationMedSAM 2.0 Dice Score0.88 - 0.93Precise 2D lesion boundary contour extraction
PII RedactionMasking Precision & Recall96% Prec. / 98% Rec.Scrubs names, IDs, and dates while preserving lab tables
Vector RAGDense Embedding Size1024-dim BGE-M3Dense semantic vector embeddings for high-precision clinical retrieval
Voice ProcessingArabic ASR Response~4.5 SecondsServerless GPU transcription on Modal cloud

Core Technical Breakthroughs

1. Stateful LangGraph Medical Interview Agent

Engineered an interactive voice interview graph that dynamically adjusts question sequences based on real-time symptom extraction, guiding patient intake while persisting turn-by-turn state snapshots to PostgreSQL.

2. Multi-Modal Vision & ROI Segmentation Pipeline

Combined MedGemma 1.5 4B IT for zero-shot radiological report generation with MedSAM 2.0 (SAM 2.1 Hiera Small) for interactive 2D lesion region-of-interest boundary contouring.

3. Layout-Preserving Lab OCR & PII Redaction

Deployed MinerU coupled with Qwen2.5-7B-Instruct on Modal serverless GPUs to anonymize patient PII with 98% recall while maintaining exact 2D table coordinates for downstream clinical parsing.

Technologies

PythonFastAPILangChainLangGraphLangSmithQdrantBGE-M3MedGemma 1.5 4BMedSAM 2.0Modal GPUPostgreSQLDocker

Gallery

CareFlow AI Clinical Assistant gallery image 2
CareFlow AI Clinical Assistant gallery image 3
CareFlow AI Clinical Assistant gallery image 4
CareFlow AI Clinical Assistant gallery image 5
CareFlow AI Clinical Assistant gallery image 6

Related Projects

AI Agents & LLMs

EnergiQ AI EV Assistant

A voice-enabled AI agent integrated within the EnergiQ EV platform, enabling database function calling, a RAG system, and low-latency audio streaming.