Skip to content

nabinkim0318/Medigator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ₯ BBB Medical Report API

CI/CD Python 3.12 Next.js FastAPI Docker

AI-powered medical report generation and analysis system with RAG (Retrieval-Augmented Generation) capabilities.

πŸš€ Quick Start

Option 1: Docker (Recommended)

# Clone and setup
git clone <repository-url>
cd BBB

# Start with unified Docker (single frontend)
make docker-build
make docker-up
# Access: API: http://localhost:8082, Frontend: http://localhost:5173

# OR start with separate frontends (recommended for production)
make docker-build
make docker-up-separate
# Access: API: http://localhost:8082, Patient: http://localhost:3000, Doctor: http://localhost:3001

Option 2: Local Development

# Setup (one-time)
make setup

# Run unified development server
make dev
# Access: API: http://localhost:8082, Frontend: http://localhost:5173

# OR run separate frontend services
make api &          # Backend API (port 8082)
make ui-patient &   # Patient Frontend (port 3000)
make ui-doctor &    # Doctor Frontend (port 3001)

πŸ“‹ Prerequisites

For Docker (Recommended)

  • Docker & Docker Compose
  • Git

For Local Development

  • Python 3.12+
  • Node.js 18+
  • Git

πŸ› οΈ Development

Available Commands

# Setup
make setup          # One-time setup
make dev            # Run API + UI together
make api            # Run API only
make ui-patient     # Patient Frontend (port 3000)
make ui-doctor      # Doctor Frontend (port 3001)

# Docker
make docker-build   # Build Docker images
make docker-up      # Start unified Docker services
make docker-up-separate # Start separate Docker services
make docker-down    # Stop unified Docker services
make docker-down-separate # Stop separate Docker services
make docker-logs    # View logs
make docker-shell   # Open container shell

# Quality
make test           # Run tests (excludes trio)
make lint           # Lint code
make fmt            # Format code
# make type         # Type checking (disabled)
make precommit      # Run all checks

# Utilities
make pdf            # Generate sample PDF
make clean          # Clean caches
make distclean      # Remove all dependencies

πŸ—οΈ Architecture

BBB/
β”œβ”€β”€ api/                    # FastAPI Backend (Port 8082)
β”‚   β”œβ”€β”€ core/              # Core functionality
β”‚   β”œβ”€β”€ routers/           # API endpoints
β”‚   β”œβ”€β”€ services/          # Business logic
β”‚   β”œβ”€β”€ middleware/        # Request/response processing
β”‚   └── tests/             # Backend tests
β”œβ”€β”€ src/                    # Next.js Frontend
β”‚   β”œβ”€β”€ app/               # App router pages
β”‚   β”‚   β”œβ”€β”€ page.tsx       # Unified interface (Port 5173)
β”‚   β”‚   β”œβ”€β”€ patient/       # Patient interface (Port 3000)
β”‚   β”‚   └── doctor/        # Doctor interface (Port 3001)
β”‚   β”œβ”€β”€ components/        # React components
β”‚   └── lib/               # Utilities
β”œβ”€β”€ docker/                 # Docker configurations
β”‚   β”œβ”€β”€ Dockerfile         # Backend API
β”‚   β”œβ”€β”€ Dockerfile.patient # Patient frontend
β”‚   β”œβ”€β”€ Dockerfile.doctor  # Doctor frontend
β”‚   └── docker-compose*.yml # Service orchestration
β”œβ”€β”€ data/                   # Sample data
β”œβ”€β”€ docs/                   # Documentation
└── scripts/               # Utility scripts

πŸ”§ Features

Core Functionality

  • Medical Report Generation: AI-powered report creation
  • Symptom Analysis: Intelligent symptom interpretation
  • Code Generation: Automatic ICD-10/CPT coding
  • Evidence Retrieval: RAG-based evidence search
  • PDF Export: Professional report formatting

Technical Features

  • FastAPI Backend: High-performance Python API
  • Next.js Frontend: Modern TypeScript UI with App Router
  • RAG Integration: FAISS + Sentence Transformers with query expansion
  • HIPAA Compliance: PHI masking and security
  • Comprehensive Logging: Structured logging with PHI protection
  • Error Handling: Global exception management
  • Health Checks: Application monitoring
  • Docker Support: Multi-stage builds for production
  • CI/CD Pipeline: GitHub Actions with automated testing

πŸ”’ Security

  • PHI Masking: Automatic PII/PHI redaction
  • Write Guards: Demo mode protection
  • CORS Configuration: Secure cross-origin requests
  • Input Validation: Comprehensive data validation
  • Security Logging: Audit trail for sensitive operations

πŸ“Š API Endpoints

Core Endpoints

  • POST /api/v1/summary - Generate medical summary
  • POST /api/v1/evidence - Retrieve evidence
  • POST /api/v1/codes - Generate medical codes
  • POST /api/v1/reports - Create medical reports
  • GET /api/v1/rag/status - RAG system status

Health & Monitoring

  • GET /health - Health check
  • GET /api/v1/llm/health - LLM service status
  • GET /api/v1/rag/health - RAG service status

πŸ§ͺ Testing

# Run all tests (excludes trio tests)
make test

# Run specific test categories
pytest api/tests/test_summary.py
pytest api/tests/test_rag.py
pytest api/tests/test_llm_cache.py

# Run hardening tests
make test-hardening

# Run LLM tests with mock data
make test-llm

πŸš€ Deployment

Docker Deployment

# Build production image
docker build -t bbb-medical:latest .

# Run production container
docker run -p 8082:8082 \
  -e OPENAI_API_KEY=your_key \
  -e DEMO_ACCESS_CODE=your_code \
  bbb-medical:latest

Environment Variables

OPENAI_API_KEY=your_openai_key
DEMO_ACCESS_CODE=your_demo_code
DEMO_MODE=true
HIPAA_MODE=false
enable_rag=true
LLM_TEMPERATURE=0.1
LLM_TOP_P=0.9
LLM_SEED=42

πŸ“ˆ Performance

  • Response Time: < 2s for most operations
  • Concurrent Users: Supports multiple simultaneous requests
  • Memory Usage: Optimized for production workloads
  • Database: SQLite for development, PostgreSQL for production

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests and linting
  5. Submit a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

For questions or issues:

  1. Check the documentation
  2. Review existing issues
  3. Create a new issue with detailed information

πŸ”§ Recent Updates

Latest Improvements

  • Separate Frontend Ports: Patient (3000) and Doctor (3001) interfaces
  • Vercel Deployment: Separate Vercel projects for Patient and Doctor frontends
  • LLM Hardening: JSON schema validation, rule engine, normalization
  • RAG Quality: Query expansion, MMR diversity, metadata extraction
  • Docker Support: Multi-stage builds, production optimization
  • CI/CD Pipeline: GitHub Actions with automated testing
  • Test Coverage: Comprehensive test suite with mock data
  • Security: Enhanced PHI masking, CORS configuration

Fixed Issues

  • βœ… Trio test failures in CI/CD
  • βœ… Docker frontend build path issues
  • βœ… Python version consistency (3.12)
  • βœ… Type checking and linting errors
  • βœ… RAG performance optimization
  • βœ… Docker Compose command compatibility
  • βœ… PostCSS configuration for Tailwind CSS
  • βœ… Hardcoded file paths in code generation
  • βœ… Test type checking issues

πŸ“Š Project Stats

  • Language: Python 3.12, TypeScript
  • Framework: FastAPI, Next.js 15.5.4
  • Database: SQLite (dev), PostgreSQL (prod)
  • AI/ML: OpenAI GPT-4, Sentence Transformers, FAISS
  • Deployment: Docker, Vercel, GitHub Actions
  • Security: HIPAA compliant, PHI masking

🎯 Roadmap

  • Enhanced RAG capabilities
  • Multi-language support
  • Advanced analytics
  • Mobile application
  • Integration with EHR systems