This project is created for educational purposes only.
It is not a medical diagnostic tool and should not be used for real medical decisions.
The explanations generated by the AI are simplified interpretations of medical report text and may not always be accurate. Always consult a qualified healthcare professional for medical advice, diagnosis, or treatment.
AI for Better Living and Smarter Communities
GenAI APAC / Hackathon Edition β Production RAG & Decision Intelligence Platform
Compared to the initial prototype, this platform has undergone major architectural, security, performance, and user experience refinements:
| Feature Area | Previous Version (v1.0) | Refined Version (v2.0) |
|---|---|---|
| User Interface | Single Streamlit dashboard | Production React 19 + Vite Frontend (frontend/) with split-theme design system, responsive tabs, and dual-mode operation |
| AI Q&A & Streaming | Synchronous blocking responses | Server-Sent Events (SSE) Live Streaming (/api/chat/stream) for real-time token rendering |
| Source Grounding | Large plain-text block quotes | Collapsible RAG Source Evidence: Compact toggle accordion, ~100 character truncated preview, "Show full excerpt" toggle, and Page X badges |
| LLM Model Engine | gemini-1.5-flash |
Upgraded to gemini-2.5-flash & gemini-embedding-001 via direct REST endpoints for lower latency and zero SDK conflicts |
| Backend Service | Streamlit-only backend | FastAPI Production REST API (main.py) with CORS middleware, health endpoints, and static asset serving |
| Cloud Deployment | Local / manual setup | Single-Container Deployment for Google Cloud Run via multi-stage Dockerfile and Cloud Build (cloudbuild.yaml) |
| Security & Compliance | Unscreened logging & paths | 100% CodeQL Hardened: Sanitized path-injection vulnerabilities, zero stack-trace exposure to clients, and dynamic credential masking (_mask_credentials) |
| Privacy & Analytics | Basic aggregate counts | Differential Privacy (Laplace noise) + Linear Regression Trend Forecasting + CDC ESSENCE epidemiological alert detection |
| Repository Structure | Flat root file clutter | Clean Directory Organization: All technical guides, specs, and history moved into a structured docs/ directory |
The Community Health Intelligence Assistant transforms disconnected medical report PDFs into actionable health intelligence at two levels: it helps individual patients understand their lab results through AI-powered plain-language explanations, while simultaneously enabling community health workers, clinics, and public health planners to surface population-level trends β like rising HbA1c rates or regional anemia spikes β from aggregated, anonymized data.
Built on a Retrieval-Augmented Generation (RAG) pipeline with automatic anomaly detection and a structured analytics layer, the platform embodies a decision intelligence platform that predicts outcomes and helps communities make better, data-driven health decisions. Every AI response is grounded in source evidence with full transparency, medical disclaimers, and formal differential privacy guarantees β delivering responsible AI that improves everyday life.
Medical reports contain complex terminology, abbreviations, and numerical values that most patients struggle to interpret. This confusion causes unnecessary anxiety and often leads to unreliable internet searches for answers.
Local health workers (ASHA workers), clinic administrators, and public health departments lack visibility into aggregate health trends across the populations they serve. Lab reports exist as unconnected PDFs on individual phones and clinic desks β no one sees the bigger picture. When 30% of patients in a region show elevated blood sugar markers, no alarm goes off. When anemia rates spike among a particular age group, it goes unnoticed until it becomes a crisis.
This platform bridges both gaps with a single unified system:
- Patients upload their reports and get clear, AI-generated explanations grounded in their actual report data.
- Health workers & planners see anonymized, aggregated trends across all uploaded reports β flagging risks, surfacing patterns, and enabling proactive public health response.
Solution Area: Healthcare access, community wellness, and decision intelligence
| Hackathon Requirement | How We Address It |
|---|---|
| "Analyze information, generate insights" | RAG pipeline extracts, structures, and analyzes lab values from medical report PDFs |
| "Predict outcomes" | Linear regression forecasting projects abnormal rate trends 30-90 days ahead per test and region |
| "Make better decisions" | Community dashboard + NL interface lets health workers query aggregate data for resource allocation |
| "Answer questions in natural language" | Dual-audience conversational interface β patients ask about their reports, health workers ask about population trends |
| "Identify patterns and anomalies" | Automatic anomaly detection flags 100+ lab tests against clinical reference ranges at ingestion time |
| "Generate recommendations" | AI generates specialist referrals (patient) and intervention suggestions like screening camps (community) |
| "Automate workflows" | Multi-agent pipeline (Extraction β QA β Risk β Community) automates the flow from PDF upload to actionable insight |
| "Responsible and explainable AI" | Collapsible source evidence attribution, medical disclaimers, Differential Privacy, CodeQL security compliance |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β COMMUNITY HEALTH INTELLIGENCE ASSISTANT (v2.0) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β ββββββββββββββββββββββββββββ βββββββββββββββββββββββββββ β
β β Vite React 19 Web UI β β Streamlit / CLI Interfaceβ β
β β (Patient & Community UI) β β (Legacy / Dev Tools) β β
β ββββββββββββββ¬ββββββββββββββ ββββββββββββββ¬βββββββββββββ β
β β β β
β ββββββββββββββββ¬βββββββββββββββββ β
β βΌ β
β ββββββββββββββββββββββββββ β
β β FastAPI Backend Serverβ β
β β (main.py) β β
β βββββββββββββ¬βββββββββββββ β
β β β
β βΌ β
β ββββββββββββββββββββββββββ β
β β EXTRACTION AGENT β β
β β PDF β Text + Tables β β
β β β Lab Value Parser β β
β β β Anomaly Detector β β
β βββββββββββββ¬βββββββββββββ β
β β β
β βββββββββββββββββββ΄ββββββββββββββββββ β
β βΌ βΌ β
β ββββββββββββββββββββββ ββββββββββββββββββββββββ β
β β ChromaDB β β SQLite Database β β
β β (RAG Vector Store) β β (Structured Values & β β
β ββββββββββββ¬ββββββββββ β Differential Privacy)β β
β β ββββββββββββ¬ββββββββββββ β
β βΌ βΌ β
β ββββββββββββββββββββββ ββββββββββββββββββββββββ β
β β QA AGENT β β COMMUNITY AGENT β β
β β (SSE Streaming β β (Epidemiology Alert β β
β β & Source Evidence) β β & Trend Forecasts) β β
β ββββββββββββ¬ββββββββββ ββββββββββββ¬ββββββββββββ β
β β β β
β βΌ βΌ β
β ββββββββββββββββββββββ ββββββββββββββββββββββββ β
β β RISK CARD β β POPULATION DASHBOARD β β
β β (Clinical Summary) β β (Trend Forecasting) β β
β ββββββββββββββββββββββ ββββββββββββββββββββββββ β
β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Google Gemini (REST Engine v2.5) β β
β β `gemini-2.5-flash` & `gemini-embedding-001` β β
β βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
| Component | Technology | GCP / Cloud Production Path |
|---|---|---|
| Frontend | React 19, Vite, Lucide Icons, Plotly.js | Cloud Run (Served via FastAPI) / Vercel |
| Backend API | FastAPI, Uvicorn, Pydantic | Google Cloud Run (Serverless Container) |
| PDF Processing | pdfplumber, regex table parsers | Google Cloud Document AI |
| Embeddings | Gemini Embedding 001 (gemini-embedding-001) |
Vertex AI Embeddings |
| Vector Store | ChromaDB (in-memory / local) | Vertex AI Vector Search / AlloyDB |
| Structured Data | SQLite (with Laplace noise Differential Privacy) | Google BigQuery |
| LLM Engine | Google Gemini API (gemini-2.5-flash) |
Vertex AI Gemini 2.5 |
| Analytics & Trend | Linear Regression Forecasting & CDC ESSENCE Aberration | BigQuery ML / Vertex AI AutoML |
| Security | CodeQL Hardened, Input Sanitization, Path Boundary Validation | Cloud Armor / Secret Manager |
medical-report-rag/
βββ main.py # FastAPI Production REST API Server & Static Asset Router
βββ config.py # Centralized Configuration & Lab Reference Ranges
βββ app.py # Interactive CLI Terminal Application (CodeQL Hardened)
βββ streamlit_app.py # Streamlit UI Entry Point (Fallback / Dev Shell)
βββ requirements.txt # Python Package Dependencies
βββ runtime.txt # Python Engine Runtime (3.11.9)
βββ Dockerfile # Multi-stage Container Dockerfile for Cloud Run
βββ cloudbuild.yaml # Google Cloud Build CI/CD Configuration
βββ render.yaml # Render Deployment Configuration
βββ Procfile # Web Process Command Specification
β
βββ frontend/ # Production React 19 + Vite Frontend App
β βββ src/
β β βββ App.jsx # Main React Application (Patient & Community Modes + Collapsible RAG Sources)
β β βββ index.css # Premium Split-Theme Design System & CSS Animations
β β βββ main.jsx # React Application DOM Mount Point
β βββ package.json # Frontend Dependencies & Scripts
β βββ vite.config.js # Vite Build & Proxy Configuration
β βββ vercel.json # Vercel Deployment Configuration
β
βββ agents/ # Multi-Agent Pipeline Modules
β βββ extraction_agent.py # PDF Ingestion, Parsing & Anomaly Orchestration
β βββ qa_agent.py # Patient RAG Q&A Engine with Source Grounding
β βββ risk_agent.py # Clinical Risk Score & Risk Card Generation
β βββ community_agent.py # Aggregate Analytics & Natural Language Community Q&A
β βββ orchestrator.py # Session State & Multi-Agent Flow Manager
β
βββ core/ # Core NLP & Medical Utilities
β βββ pdf_extractor.py # PDF Text & Table Extraction
β βββ chunker.py # Text Chunking for Vector Search
β βββ embeddings.py # Embedding Generation Wrapper
β βββ llm_client.py # Unified Google Gemini REST API Client
β βββ lab_value_parser.py # LLM & Regex Medical Parameter Parser
β βββ anomaly_detector.py # Reference Range Evaluator
β βββ fhir_models.py # HL7 FHIR R4 Data Structures
β βββ fhir_converter.py # Lab Data to FHIR R4 Bundle Serializer
β βββ anonymizer.py # Safe Demographics Anonymizer
β
βββ data_store/ # Data Persistence Layer
β βββ models.py # Data Schemas (Report, LabValue, Alert)
β βββ sqlite_store.py # SQLite Database, Differential Privacy & Forecasting
β βββ vector_store.py # ChromaDB Vector Store Client
β
βββ ui/ # Streamlit Component Modules
β βββ patient_mode.py # Patient Mode Interface Component
β βββ community_mode.py # Community Dashboard Component
β βββ components.py # Shared UI Widgets
β βββ styles.py # Streamlit Custom Styling
β
βββ docs/ # Documentation & Technical Specifications
βββ ARCHITECTURE.md # Technical Architecture & System Specifications
βββ GCP_DEPLOYMENT_GUIDE.md # Step-by-Step Google Cloud Run Deployment Guide
βββ activity_log.md # Engineering Development History & Changelog
βββ project_requirement.md # Original System Requirements Document
βββ prototype_refinement.md # Refinement & Enhancement Technical Specs
βββ requirements_and_memory.md # Architectural Context & Decisions Log
All technical specifications, deployment guides, and architectural decision records are organized inside the docs/ directory:
- π Architecture Guide: Deep dive into multi-agent workflows, data flow diagrams, and schema definitions.
- π Google Cloud Run Deployment Guide: 3-minute deployment instructions for Google Cloud Shell.
- π οΈ Prototype Refinement Specs: Comprehensive breakdown of feature additions and UI upgrades.
- π Activity Log & Engineering History: Record of code commits, bug fixes, and security patches.
- π§ Requirements & Memory Context: Architectural decisions and system requirements.
- Python 3.10+
- Node.js 20+ (for React frontend)
- A Google Gemini API key (Google AI Studio)
# Clone repository
git clone https://github.com/Astroidkiller/medical-report-rag.git
cd medical-report-rag
# Install Python backend dependencies
pip install -r requirements.txt
# Create .env file with your API key
echo "GEMINI_API_KEY=your_gemini_api_key_here" > .envBackend Server:
python -m uvicorn main:app --host 127.0.0.1 --port 8000- API Docs (Swagger):
http://127.0.0.1:8000/docs
Frontend Dev Server:
cd frontend
npm install
npm run dev- React UI Application:
http://localhost:5173/
Streamlit Dashboard:
python -m streamlit run streamlit_app.pyInteractive CLI Application:
python app.pyDeploy the full application to Google Cloud Run using Cloud Shell:
# 1. Set your GCP Project ID
gcloud config set project YOUR_PROJECT_ID
# 2. Clone repository & enter directory
git clone https://github.com/Astroidkiller/medical-report-rag.git
cd medical-report-rag
# 3. Enable GCP Services
gcloud services enable run.googleapis.com cloudbuild.googleapis.com containerregistry.googleapis.com
# 4. Build & Deploy
gcloud builds submit --config=cloudbuild.yamlCloud Run will output your live URL:
https://community-health-assistant-xxxxx-uc.a.run.app
-
Source Evidence Grounding: Every patient answer includes a collapsible accordion with truncated excerpts and
Page Xreferences. -
Differential Privacy (DP): All community dashboard metrics apply Laplace Noise (
$\epsilon = 0.5$ ) to protect population privacy. -
CodeQL Security Hardened: Cleaned path injection vectors (
os.path.normpath+ boundary checks), suppressed stack trace exposures, and masked credentials. - Medical Disclaimers: Prominent disclaimers remind users that explanations are for educational guidance and do not replace professional medical advice.
This project is created for educational and hackathon purposes. Not intended for clinical diagnostic use.