Live multi-storefront scraping, OCR prescription extraction, lab report biomarker analysis, and medication adherence tracking for India.
MedScan is a comprehensive healthcare platform built for the Indian pharmaceutical ecosystem. It provides real-time price comparison across top Indian online storefronts, prescription parsing via intelligent OCR, automated lab report biomarker evaluation, Jan Aushadhi generic alternative suggestions, scheduled medication reminders, and a cross-platform web and mobile client experience.
- Key Features
- Architecture Overview
- Directory Structure
- Tech Stack
- Prerequisites
- Environment Configuration
- Local Development Setup
- API Reference
- Deployment Guide (Azure & CI/CD)
- Legal & Medical Disclaimer
- 12+ Live Storefront Scrapers: Simultaneously searches leading Indian online pharmacies:
- HTTPX Async Pipelines: PharmEasy, Netmeds, TrueMeds, MedPlus.
- Headless Chromium (Playwright): Tata 1mg, Apollo Pharmacy.
- No Fabricated Data: Performs live extraction for normalized queries, returning direct product links, total pricing, unit prices (per tablet/capsule), and availability.
- Resilient Concurrency: Fault-tolerant execution with per-pharmacy error handling and graceful
502 Bad Gatewayreporting when all storefronts fail.
- Multi-Format Processing: Supports image (
.jpg,.png) and document (.pdf) uploads. - Hybrid OCR Engine:
- Images: Preprocessed with OpenCV + Tesseract OCR / RapidOCR.
- PDFs: Text extraction via PyMuPDF (
fitz) /pdfplumberwith automatic fallback to first-page rasterization & OCR. - Cloud Fallback: Azure Document Intelligence (
prebuilt-read) when enabled.
- Rule-Based & LLM Extraction: Extracts medicine names, dosages, frequencies, and durations with validation against an internal catalog.
- Biomarker Parsing: Automatically scans lab reports for parameters such as Hemoglobin, Blood Sugar (HbA1c / Fasting), Cholesterol levels, Thyroid profiles (TSH/T3/T4), Liver Function (ALT/AST), and Kidney Function (Creatinine/Urea).
- Reference Interval Comparison: Evaluates values against clinical baseline intervals locally without relying on external LLM APIs.
- Cost Savings Discovery: Matches branded drugs with low-cost generic alternatives under the Pradhan Mantri Bhartiya Janaushadhi Pariyanjana (PMBJP) scheme.
- Scheduled Notifications: Background job scheduling via
APSchedulerfor dosage alerts. - Adherence Dashboard: Log daily medication doses, calculate adherence percentages, and track health streaks.
- Contextual FAQ Assistant: Instant support at
/api/chatbotcovering medicine search, dosage queries, prescription processing, lab report analysis, and app features.
- Web Client: Responsive React SPA built with Vite & Tailwind CSS.
- Mobile App: Cross-platform Flutter app (
iOS&Android) featuring native auth, offline state caching, and mobile UI integration.
flowchart TD
subgraph Clients["Client Layer"]
ReactSPA["Web SPA (React + Vite + Tailwind)"]
FlutterApp["Mobile App (Flutter / iOS & Android)"]
end
subgraph API["Backend API (Flask / Python 3.11)"]
AuthModule["Auth & JWT / Supabase"]
ScraperEngine["Scraper Orchestrator"]
OcrPipeline["OCR & Doc Intelligence Engine"]
LabAnalyzer["Lab Report & Biomarker Service"]
ReminderScheduler["APScheduler & Notifications"]
end
subgraph DataScrapers["External Pharmacy Scrapers"]
HttpxScrapers["HTTPX Async (PharmEasy, Netmeds, TrueMeds, MedPlus)"]
PlaywrightScrapers["Playwright Chromium (Tata 1mg, Apollo Pharmacy)"]
end
subgraph Storage["Data & Cloud Services"]
Database[("PostgreSQL / SQLite Database")]
AzureDI["Azure Document Intelligence (Optional)"]
SupabaseAuth["Supabase Auth Service"]
end
ReactSPA -->|REST API / JWT| API
FlutterApp -->|REST API / JWT| API
ScraperEngine --> HttpxScrapers
ScraperEngine --> PlaywrightScrapers
OcrPipeline --> AzureDI
AuthModule --> SupabaseAuth
API --> Database
MediScan/
βββ .github/
β βββ workflows/
β βββ deploy-backend.yml # CI/CD: Azure App Service deployment
β βββ deploy-frontend.yml # CI/CD: Azure Static Web Apps deployment
βββ backend/
β βββ app/
β β βββ models/ # SQLAlchemy DB models (User, Medicine, Prescription, Reminder, etc.)
β β βββ routes/ # Flask Blueprints (Auth, Medicine, Prescription, Reminders, Reports, etc.)
β β βββ scheduler/ # APScheduler background tasks
β β βββ services/ # Scraper, OCR, NLP, Biomarker & LLM services
β β βββ utils/ # Catalog seeding, logger, rate-limiting, SQLite patch
β β βββ config.py # Flask Base, Development & Production configs
β β βββ __init__.py # Application factory & middleware initialization
β βββ migrations/ # Alembic database migration scripts
β βββ Dockerfile # Playwright-enabled backend container
β βββ requirements.txt # Python dependencies
β βββ run.py # Development server entry point
βββ frontend/
β βββ src/
β β βββ components/ # Reusable UI components & navigation
β β βββ pages/ # React pages (Dashboard, Compare, Scan, Reminders, Lab Reports, etc.)
β β βββ services/ # Axios API client & endpoints
β β βββ store/ # Application state management
β βββ Dockerfile # Nginx production frontend container
β βββ package.json # React dependencies and scripts
β βββ vite.config.js # Vite build setup & dev proxy
βββ mobile/
β βββ lib/
β β βββ core/ # Mobile API client, theme & constants
β β βββ features/ # Flutter features (Auth, Search, Compare, Prescription, Reminders)
β β βββ providers/ # Riverpod / Provider state providers
β β βββ main.dart # Flutter application entry point
β βββ pubspec.yaml # Flutter packages & assets declaration
β βββ README.md # Dedicated mobile guide
βββ docs/
β βββ API_KEYS.md # Environment secrets reference
β βββ SUPABASE_AUTH.md # Supabase integration setup
β βββ azure-deployment.md # Full Azure Cloud deployment manual
βββ scripts/ # Utility maintenance scripts
βββ docker-compose.yml # Multi-container orchestration (Backend + Frontend)
βββ .env.example # Global environment variables template
βββ README.md # Main project documentation
| Component | Framework / Library | Description |
|---|---|---|
| Backend Framework | Flask (Python 3.11) | Application factory, RESTful Blueprints, CORS middleware |
| Database & ORM | PostgreSQL / SQLite + SQLAlchemy | Alembic migrations, database models & relationship mapping |
| Scraping Engine | Playwright & HTTPX | Async browser rendering, stealth headers, API interception |
| OCR & Vision | OpenCV, Tesseract, PyMuPDF, Azure DI | Document preprocessing, PDF rasterization & OCR extraction |
| Auth & Security | Flask-JWT-Extended & Supabase Auth | Secure bearer authentication, token refresh & client API key guard |
| Scheduling | APScheduler | Background job execution for reminders & adherence alerts |
| Web Frontend | React 18, Vite, Tailwind CSS | Modern responsive single page interface |
| Mobile Frontend | Flutter / Dart | Native cross-platform app for iOS and Android |
| Container & Cloud | Docker, Azure App Service, SWA | Containerized backend & static web frontend hosting |
Before running MedScan locally, ensure you have the following installed on your machine:
- Python: Version
3.11+ - Node.js: Version
20+andnpm - Flutter SDK (Optional, for mobile app):
3.x+ - Tesseract OCR: Installed on system
PATH(or specified viaTESSERACT_CMDenvironment variable). - Chromium for Playwright: Installed via Python module.
Create a .env file in the project root (or inside backend/ and frontend/) using .env.example:
# Flask & Database
FLASK_ENV=development
SECRET_KEY=dev-secret-key-change-in-production
DATABASE_URL=sqlite:///medscan.db
# JWT Configuration
JWT_SECRET_KEY=jwt-secret-key-change-in-production
JWT_ACCESS_MINUTES=15
JWT_REFRESH_DAYS=7
# OCR Settings
TESSERACT_CMD=C:\Program Files\Tesseract-OCR\tesseract.exe # Windows path if applicable
AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT=
AZURE_DOCUMENT_INTELLIGENCE_KEY=
MEDSCAN_AZURE_OCR=0
# Scraper Settings
SCRAPER_CONCURRENCY=6
SCRAPER_TIMEOUT_SECS=120
SCRAPER_PROXY_URL=
# Supabase Auth (Optional)
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_ANON_KEY=your-supabase-anon-key
SUPABASE_JWT_SECRET=your-supabase-jwt-secret
# Frontend Configuration (frontend/.env)
VITE_API_URL=http://127.0.0.1:5000# Navigate to backend directory
cd backend
# Create and activate a virtual environment
python -m venv venv
# On Windows: venv\Scripts\activate
# On macOS/Linux: source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Install Playwright Chromium browser binary
python -m playwright install chromium
# Run the Flask development server (runs on http://127.0.0.1:5000)
python run.py# Navigate to frontend directory
cd frontend
# Install Node dependencies
npm install
# Start Vite development server (runs on http://localhost:5173 with proxy to /api)
npm run dev# Navigate to mobile directory
cd mobile
# Get Flutter dependencies
flutter pub get
# Run on connected device or emulator
flutter runTo bring up the entire environment (Flask backend with Playwright + React frontend via Nginx) using Docker Compose:
docker compose up --buildAccess the application:
- Frontend SPA:
http://localhost:5173 - Backend API:
http://localhost:5000 - Health Check:
http://localhost:5000/api/health
| Endpoint | Method | Description | Auth Required |
|---|---|---|---|
/health or /api/health |
GET |
Health check & system capability diagnosis (OCR, scrapers) | β |
/api/auth/signup |
POST |
Register a new user account | β |
/api/auth/login |
POST |
User login & JWT issue | β |
/api/search-medicine |
GET |
Live multi-pharmacy price comparison search | β / π |
/api/compare |
POST |
Compare multiple medicine pricing results | β / π |
/api/upload-prescription |
POST |
Upload prescription image/PDF for OCR text extraction | π |
/api/upload-lab-report |
POST |
Upload lab report document for biomarker parsing | π |
/api/reminders |
GET / POST |
Fetch or create scheduled medication reminders | π |
/api/adherence |
GET / POST |
Log medication intake & view adherence statistics | π |
/api/chatbot |
POST |
Send query to rule-based healthcare assistant | β / π |
/api/dashboard |
GET |
Retrieve user dashboard stats, summary, and reminders | π |
/api/nearby-pharmacies |
GET |
Find local pharmacies by GPS / geolocation coordinates | π |
MedScan is optimized for Microsoft Azure:
| Component | Azure Service |
|---|---|
| Backend API | Azure App Service (Linux Docker container) |
| Frontend SPA | Azure Static Web Apps |
| Database | Azure Database for PostgreSQL (Flexible Server) |
| Container Registry | Azure Container Registry (ACR) |
# 1. Build and push backend image to ACR
cd backend
az acr build --registry acrmedscan --image medscan-api:latest --file Dockerfile .
# 2. Deploy frontend to Azure Static Web Apps
cd ../frontend
npm run build
swa deploy ./dist --env productionDetailed deployment configurations, capacity planning, and cost estimation guides are available in docs/azure-deployment.md.
Disclaimer: MedScan is an informational tool designed for price comparison and document management. It does not provide medical advice, diagnosis, or treatment recommendations. Always consult a qualified healthcare professional regarding prescription medications or medical conditions.
Scraping third-party online pharmacy storefronts must comply with local laws and terms of service. Ensure legal and regulatory compliance prior to production deployment.