Skip to content

Latest commit

Β 

History

98 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

⚠️ Disclaimer

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.


πŸ₯ Community Health Intelligence Assistant (v2.0)

AI for Better Living and Smarter Communities
GenAI APAC / Hackathon Edition β€” Production RAG & Decision Intelligence Platform


πŸš€ Key Refinements & Enhancements (v2.0 vs Previous Version)

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

🎯 Judge-Facing Pitch

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.


πŸ“‹ Problem Statement

Individual Level

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.

Community Level

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.

What This Project Solves

This platform bridges both gaps with a single unified system:

  1. Patients upload their reports and get clear, AI-generated explanations grounded in their actual report data.
  2. Health workers & planners see anonymized, aggregated trends across all uploaded reports β€” flagging risks, surfacing patterns, and enabling proactive public health response.

πŸ—οΈ Solution Areas Addressed

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

🧬 System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚              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`        β”‚  β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Technology Stack

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

πŸ“ Organized Project Structure

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

πŸ“– Key Documentation Sitemap (docs/)

All technical specifications, deployment guides, and architectural decision records are organized inside the docs/ directory:


⚑ Quick Start & Running Locally

Prerequisites

  • Python 3.10+
  • Node.js 20+ (for React frontend)
  • A Google Gemini API key (Google AI Studio)

1. Environment Setup

# 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" > .env

2. Running the Full Stack App (FastAPI + React Frontend)

Backend 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/

3. Running Legacy Streamlit UI / CLI Terminal App

Streamlit Dashboard:

python -m streamlit run streamlit_app.py

Interactive CLI Application:

python app.py

☁️ Google Cloud Run One-Click Deployment

Deploy 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.yaml

Cloud Run will output your live URL:
https://community-health-assistant-xxxxx-uc.a.run.app


πŸ›‘οΈ Security & Responsible AI

  • Source Evidence Grounding: Every patient answer includes a collapsible accordion with truncated excerpts and Page X references.
  • 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.

πŸ“„ License

This project is created for educational and hackathon purposes. Not intended for clinical diagnostic use.

About

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages