Skip to content

Latest commit

Β 

History

14 Commits

Folders and files

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

Repository files navigation

πŸš€ MediScan AI

AI-Powered Medical Prescription Analysis Platform

MediScan AI is a production-ready medical prescription analysis platform that uses OCR and Generative AI to extract, analyze, and structure information from prescription images.

The platform provides a complete workflow from prescription upload to OCR processing, AI-powered analysis, structured data persistence, usage tracking, history management, and risk-based alerts.

Built with modern backend engineering practices including REST APIs, PostgreSQL, Alembic migrations, Docker, automated testing, GitHub Actions CI, and cloud deployment.

🌐 Live Demo: https://mediscan-2lzy.onrender.com

πŸ”— Backend API: https://mediscan-backend-82ft.onrender.com

❀️ Backend Health: https://mediscan-backend-82ft.onrender.com/health


πŸ“Έ Screenshots

🏠 Dashboard

MediScan Dashboard

πŸ“€ Prescription Upload

Prescription Upload

πŸ€– AI Prescription Analysis

AI Analysis

πŸ“‹ Prescription History

Prescription History

🚨 Alerts

Alerts


✨ Features

  • πŸ“€ Upload prescription images
  • πŸ” OCR-based text extraction
  • πŸ€– AI-powered prescription analysis using Gemini
  • πŸ’Š Structured prescription information extraction
  • πŸ“‹ Prescription history
  • πŸ‘€ User authentication and isolation
  • πŸ“Š Usage tracking and limits
  • 🚨 Risk-based alert generation
  • πŸ“§ Optional email alert support
  • πŸ—„οΈ PostgreSQL database persistence
  • πŸ”„ Alembic database migrations
  • πŸ” JWT-based authentication
  • πŸ›‘οΈ API security and validation
  • 🐳 Dockerized application
  • πŸ§ͺ Automated test suite
  • βš™οΈ GitHub Actions CI
  • ☁️ Render deployment
  • 🌐 Configurable CORS
  • ❀️ Backend health monitoring

πŸ—οΈ Architecture

                         User
                           β”‚
                           β–Ό
                    Streamlit Frontend
                           β”‚
                           β”‚ REST API
                           β–Ό
                    FastAPI Backend
                           β”‚
          β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
          β”‚                β”‚                β”‚
          β–Ό                β–Ό                β–Ό
        OCR             Gemini AI       PostgreSQL
     Processing          Analysis         / Supabase
          β”‚                β”‚                β”‚
          β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
                           β–Ό
                    Alert & Usage System
                           β”‚
                           β–Ό
                     Email Service

πŸ”„ Application Workflow

Prescription Image
        β”‚
        β–Ό
      Upload
        β”‚
        β–Ό
   Authentication
        β”‚
        β–Ό
       OCR
        β”‚
        β–Ό
Extract Prescription Text
        β”‚
        β–Ό
    Gemini AI
        β”‚
        β–Ό
Structured Prescription Data
        β”‚
        β–Ό
   Risk Analysis
        β”‚
        β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β–Ό               β–Ό
   PostgreSQL        Alert System
        β”‚
        β–Ό
 Prescription History

πŸ› οΈ Tech Stack

Layer Technology
Frontend Streamlit
Backend FastAPI
Language Python
Database PostgreSQL
Database Hosting Supabase
ORM SQLAlchemy
Migrations Alembic
Authentication JWT / Python-Jose
Password Hashing Argon2
OCR RapidAPI OCR
AI Google Gemini API
API Communication REST
Validation Pydantic
Testing Pytest
Containerization Docker
Local Orchestration Docker Compose
CI/CD GitHub Actions
Deployment Render

πŸ” Security

MediScan implements several application-level security mechanisms:

  • πŸ” JWT authentication
  • πŸ”’ Password hashing using Argon2
  • πŸ›‘οΈ Protected API routes
  • πŸ‘€ User-level data isolation
  • βœ… Request validation using Pydantic
  • πŸ“ File upload validation
  • πŸ“Š Usage limit enforcement
  • πŸ”‘ Environment-based secret management
  • 🌐 CORS configuration
  • 🚫 No production secrets committed to Git

πŸ§ͺ Testing

The project includes automated tests covering:

  • Authentication
  • Prescription processing
  • Security
  • User isolation
  • Usage limits
  • Alerts
  • Alert service
  • API client
  • Database bootstrap

Current Test Status

21 passed
0 failed

Regression validation also covers the previously completed application phases.

Run the complete test suite:

pytest -q

πŸ—„οΈ Database & Migrations

MediScan uses PostgreSQL for production persistence.

Database schema changes are managed using Alembic.

Run migrations

python -m alembic upgrade head

Check the current migration

python -m alembic current

The production deployment runs database migrations before starting the backend application.


βš™οΈ Installation

1. Clone the Repository

git clone https://github.com/prijithjohn/Mediscan.git

cd Mediscan

2. Create a Virtual Environment

python -m venv .venv

3. Activate the Virtual Environment

Windows

.venv\Scripts\activate

Linux / macOS

source .venv/bin/activate

4. Install Dependencies

pip install -r requirements.txt

πŸ”‘ Environment Variables

Create a .env file for local development.

DATABASE_URL=postgresql://username:password@host:5432/database

SECRET_KEY=your_secret_key

GEMINI_API_KEY=your_gemini_api_key

RAPIDAPI_KEY=your_rapidapi_key

RAPIDAPI_HOST=pen-to-print-handwriting-ocr.p.rapidapi.com

CORS_ALLOW_ORIGINS=http://localhost:8501

Optional Email Configuration

Email alerts can be enabled by configuring:

SMTP_HOST=
SMTP_PORT=
SMTP_USERNAME=
SMTP_PASSWORD=
ALERT_EMAIL=

⚠️ Never commit real API keys, database passwords, JWT secrets, or SMTP credentials to Git.


🐳 Run with Docker

Build and start the application:

docker compose up --build

The application runs as:

Frontend:
http://localhost:8501

Backend:
http://localhost:8000

Health:
http://localhost:8000/health

Stop the Containers

docker compose down

πŸ§ͺ Run Tests

Run the complete test suite:

pytest -q

Expected result:

21 passed

πŸš€ Deployment

MediScan is deployed using:

  • 🐳 Docker
  • ☁️ Render
  • πŸ—„οΈ PostgreSQL
  • 🟒 Supabase
  • βš™οΈ GitHub Actions
  • πŸ”„ Alembic

Frontend

🌐 https://mediscan-2lzy.onrender.com

Backend

🌐 https://mediscan-backend-82ft.onrender.com

Health Check

❀️ https://mediscan-backend-82ft.onrender.com/health

The backend uses Render's dynamic PORT environment variable and binds to:

0.0.0.0

Database migrations are executed during backend startup.


βš™οΈ CI/CD

GitHub Actions validates the application before deployment.

The CI pipeline performs:

Push to GitHub
      β”‚
      β–Ό
Install Dependencies
      β”‚
      β–Ό
Validate Workflow
      β”‚
      β–Ό
Run Pytest
      β”‚
      β–Ό
Validate Docker Build
      β”‚
      β–Ό
Validate Docker Compose
      β”‚
      β–Ό
      βœ… PASS

πŸ“‚ Project Structure

Mediscan/
β”‚
β”œβ”€β”€ backend/
β”‚   └── app/
β”‚       β”œβ”€β”€ api/
β”‚       β”‚   β”œβ”€β”€ routes/
β”‚       β”‚   β”‚   β”œβ”€β”€ auth.py
β”‚       β”‚   β”‚   β”œβ”€β”€ prescriptions.py
β”‚       β”‚   β”‚   β”œβ”€β”€ usage.py
β”‚       β”‚   β”‚   β”œβ”€β”€ alerts.py
β”‚       β”‚   β”‚   └── pipeline.py
β”‚       β”‚   β”‚
β”‚       β”‚   β”œβ”€β”€ deps.py
β”‚       β”‚   └──
β”‚       β”‚
β”‚       β”œβ”€β”€ core/
β”‚       β”‚   β”œβ”€β”€ config.py
β”‚       β”‚   └── security.py
β”‚       β”‚
β”‚       β”œβ”€β”€ db/
β”‚       β”‚   β”œβ”€β”€ models/
β”‚       β”‚   β”œβ”€β”€ base.py
β”‚       β”‚   └── session.py
β”‚       β”‚
β”‚       β”œβ”€β”€ schemas/
β”‚       β”‚
β”‚       β”œβ”€β”€ services/
β”‚       β”‚   β”œβ”€β”€ ocr_service.py
β”‚       β”‚   β”œβ”€β”€ gemini_service.py
β”‚       β”‚   β”œβ”€β”€ prescription_service.py
β”‚       β”‚   β”œβ”€β”€ usage_service.py
β”‚       β”‚   β”œβ”€β”€ alert_service.py
β”‚       β”‚   └── email_service.py
β”‚       β”‚
β”‚       └── main.py
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ app.py
β”‚   └── api_client.py
β”‚
β”œβ”€β”€ alembic/
β”‚   β”œβ”€β”€ versions/
β”‚   β”œβ”€β”€ env.py
β”‚   └── script.py.mako
β”‚
β”œβ”€β”€ scripts/
β”‚   β”œβ”€β”€ container_e2e.py
β”‚   └── create_e2e_data.py
β”‚
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_auth.py
β”‚   β”œβ”€β”€ test_prescription.py
β”‚   β”œβ”€β”€ test_security.py
β”‚   β”œβ”€β”€ test_usage.py
β”‚   β”œβ”€β”€ test_alerts.py
β”‚   β”œβ”€β”€ test_alert_service.py
β”‚   β”œβ”€β”€ test_api_client.py
β”‚   └── test_db_bootstrap.py
β”‚
β”œβ”€β”€ .github/
β”‚   └── workflows/
β”‚       └── ci.yml
β”‚
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ docker-compose.yml
β”œβ”€β”€ docker-entrypoint.sh
β”œβ”€β”€ alembic.ini
β”œβ”€β”€ requirements.txt
└── README.md

πŸ’‘ Engineering Skills Demonstrated

  • ⚑ FastAPI Backend Development
  • πŸ”Œ REST API Design
  • πŸ–₯️ Streamlit Application Development
  • 🐍 Python Backend Engineering
  • πŸ—„οΈ PostgreSQL
  • πŸ”— SQLAlchemy ORM
  • πŸ”„ Alembic Database Migrations
  • πŸ” JWT Authentication
  • πŸ›‘οΈ API Security
  • πŸ” OCR API Integration
  • πŸ€– Google Gemini API Integration
  • 🧠 AI Application Development
  • 🐳 Docker & Docker Compose
  • βš™οΈ GitHub Actions CI
  • ☁️ Cloud Deployment
  • 🟒 Supabase
  • πŸ§ͺ Automated Testing
  • πŸ”¬ End-to-End Validation
  • πŸ”§ Environment Configuration
  • πŸ› Production Debugging

πŸ‘¨β€πŸ’» Author

Prijith John


⭐ Support

If you found MediScan useful, consider giving the project a ⭐ Star on GitHub.

It helps support the project and makes it easier for others to discover.


⚠️ Disclaimer

MediScan AI is an experimental software project intended for educational and demonstration purposes.

The system uses OCR and Generative AI to analyze prescription images and may produce inaccurate, incomplete, or incorrect information.

MediScan AI should not be used as a substitute for professional medical advice, diagnosis, or treatment. Always consult a qualified healthcare professional before making medical decisions.

About

Full-stack AI application for prescription OCR and intelligent medical document analysis.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages