Skip to content

Repository files navigation

🏥 Medical Report Analyzer — OCR + LLM Pipeline

An AI-powered system that extracts, structures, and analyzes medical reports (prescriptions, lab results, discharge summaries) using OCR for text extraction and LLM for intelligent interpretation.


🎯 Problem Statement

Medical documents are often scanned images or poorly formatted PDFs. Manually reading and extracting information is time-consuming and error-prone. This system automates:

  • Text extraction from scanned medical documents using Tesseract OCR
  • Intelligent structuring of extracted text into organized medical fields
  • Anomaly detection in lab results (flagging out-of-range values)
  • Summary generation from discharge summaries and clinical notes
  • Medicine extraction from prescriptions with dosage parsing

🏗️ Architecture

Input (Image/PDF) → Preprocessing → OCR (Tesseract) → Text Cleaning
    → LLM Analysis (OpenAI/Llama) → Structured JSON Output
    → Anomaly Detection → Summary + Recommendations

📊 Features

Feature Description Module
OCR Extraction Extract text from scanned reports, prescriptions, X-ray reports ocr_engine.py
Text Preprocessing Deskew, denoise, binarize, enhance contrast image_preprocessor.py
Lab Report Parser Extract test names, values, units, reference ranges lab_parser.py
Prescription Parser Extract medicine names, dosages, frequency, duration prescription_parser.py
Anomaly Detection Flag abnormal lab values with severity levels anomaly_detector.py
Report Summarizer Generate concise summaries using LLM summarizer.py
REST API FastAPI endpoints for all features api/app.py

📁 Project Structure

medical-report-analyzer/
├── src/
│   ├── ocr_engine.py              # Tesseract OCR wrapper
│   ├── image_preprocessor.py      # Image enhancement pipeline
│   ├── lab_parser.py              # Lab report field extraction
│   ├── prescription_parser.py     # Medicine & dosage parser
│   ├── anomaly_detector.py        # Out-of-range value detection
│   ├── summarizer.py              # LLM-powered report summarization
│   └── pipeline.py                # End-to-end orchestration
├── utils/
│   ├── text_cleaner.py            # Post-OCR text cleaning
│   └── medical_constants.py       # Reference ranges, drug databases
├── api/
│   └── app.py                     # FastAPI REST API
├── tests/
│   └── test_pipeline.py           # Unit and integration tests
├── data/
│   └── samples/                   # Sample reports for testing
├── requirements.txt
└── README.md

🚀 Quick Start

git clone https://github.com/niharikabanothu/medical-report-analyzer.git
cd medical-report-analyzer
pip install -r requirements.txt

# Run the full pipeline on a sample report
python src/pipeline.py

# Start API server
uvicorn api.app:app --reload

# Test with a sample image
curl -X POST http://localhost:8000/analyze \
  -F "file=@data/samples/sample_lab_report.png" \
  -F "report_type=lab_report"

🔌 API Endpoints

Method Endpoint Description
POST /ocr Extract raw text from image/PDF
POST /analyze Full analysis pipeline
POST /lab-report Parse and analyze lab results
POST /prescription Extract medicines and dosages
GET /health Health check

Example Response — Lab Report Analysis

{
  "patient_name": "Niharika B.",
  "date": "2026-03-15",
  "lab_results": [
    {
      "test": "Hemoglobin",
      "value": 11.2,
      "unit": "g/dL",
      "reference_range": "12.0-15.5",
      "status": "LOW",
      "severity": "mild"
    },
    {
      "test": "Blood Glucose (Fasting)",
      "value": 95,
      "unit": "mg/dL",
      "reference_range": "70-100",
      "status": "NORMAL",
      "severity": null
    }
  ],
  "anomalies_found": 1,
  "summary": "1 abnormal value detected. Hemoglobin is slightly below normal range."
}

🛠️ Tech Stack

  • Python 3.10+
  • Tesseract OCR — text extraction from images
  • OpenCV / Pillow — image preprocessing
  • OpenAI API / Ollama (Llama-3) — LLM-powered analysis
  • LangChain — LLM orchestration
  • FastAPI — REST API
  • regex — medical pattern matching

👤 Author

Niharika Banothu M.Tech AI @ NIT Bhopal LinkedIn · GitHub

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages