Skip to content

Taher9845/MediCheck

Repository files navigation

Drug Interaction Checker

A Django-based web application that analyzes medical reports and prescriptions to detect drug interactions and provide AI-powered diagnosis suggestions.

Features

  • 📄 File Upload Support: Upload medical reports in TXT, PDF, or image formats (PNG, JPG, JPEG)
  • 🔍 OCR Processing: Extract text from images using Tesseract OCR
  • 💊 Drug Interaction Detection: Identify potential drug interactions from a comprehensive database
  • 🩺 AI Diagnosis: Get AI-powered diagnosis suggestions using LangChain and Groq
  • 📊 Multi-specialist Analysis: Cardiologist, Psychologist, and Pulmonologist agents provide specialized insights
  • 🎨 Modern UI: Clean, responsive interface built with Tailwind CSS

Prerequisites

  • Python 3.8+
  • Tesseract OCR (for Windows: install from here)
  • Groq API key (get one from Groq Console)

Installation

  1. Clone the repository

    cd Drug_detect_app/drugchecker
  2. Create a virtual environment

    python -m venv venv
    venv\Scripts\activate  # On Windows
  3. Install dependencies

    pip install -r requirements.txt
  4. Set up environment variables

    • Copy .env.example to .env
    • Add your Groq API key:
      GROQ_API_KEY=your-groq-api-key-here
      
  5. Run migrations

    python manage.py migrate
  6. Start the development server

    python manage.py runserver
  7. Access the application

    • Open your browser and navigate to http://127.0.0.1:8000/

Project Structure

drugchecker/
├── interaction/              # Main Django app
│   ├── templates/           # HTML templates
│   ├── utils/              # Utility modules
│   │   ├── agent.py        # LangChain agents
│   │   ├── file_classifier.py
│   │   └── text_extractor.py
│   ├── views.py            # View functions
│   ├── urls.py             # URL routing
│   ├── tests.py            # Unit tests
│   └── drug_analyzer.py    # Drug interaction analyzer
├── drugchecker/            # Project settings
├── media/                  # Uploaded files
├── db_drug_interactions.csv # Drug interaction database
└── requirements.txt        # Python dependencies

Usage

  1. Upload a Medical File

    • Click "Upload Medical File" on the home page
    • Select a TXT, PDF, or image file containing medical information
  2. Choose Analysis Type

    • If a structured report is detected, choose:
      • Extract Diagnosis only
      • Check Drug Interactions only
      • Do Both
  3. View Results

    • See extracted text from the document
    • View detected drugs and potential interactions
    • Read AI-generated diagnosis suggestions

Testing

Run the test suite:

python manage.py test interaction

Run specific test files:

python manage.py test interaction.tests
python manage.py test interaction.tests_drug_analyzer

Performance & Speed Tips

  • Prefer digital PDFs: The app first extracts text with PyMuPDF. Scanned PDFs/images require OCR and take longer.
  • Image size: Large images slow OCR. Resize to ~1600–1800px width before upload for faster results.
  • Diagnosis mode: Multi-agent diagnosis is heavier than interaction-only. Use only when needed.
  • Windows Tesseract path: On Windows, pytesseract.pytesseract.tesseract_cmd is set to C:\\Program Files\\Tesseract-OCR\\tesseract.exe. Ensure it exists.
  • CSV lookups: Drug interaction CSV is loaded once at startup from db_drug_interactions.csv.

UI & Theming

  • The UI uses Tailwind CSS with a custom design system defined in interaction/templates/interaction/base.html.
  • Theme is controlled with CSS variables under :root and .dark.
  • Theme toggle button persists user choice via localStorage and applies the .dark class to <html>.

Routes

  • / or /upload/ → upload and smart analysis (upload_file)
  • /analyze/ → choose action after structured report (choose_action)
  • /diagnosis/ → run diagnosis on uploaded structured text (diagnosis_view)
  • /check-interactions/ and /drug-interactions/ → manual drug interaction analysis (analyze_drugs)

Configuration Notes

  • Interaction DB CSV columns should include Drug 1, Drug 2, and Interaction.
  • If your CSV uses Interaction Description, it is auto-renamed to Interaction at load time.
  • Media uploads are stored under media/ (served in DEBUG mode via Django static serving).

Troubleshooting

  • Tesseract not found (Windows): Install Tesseract and verify the path: C:\\Program Files\\Tesseract-OCR\\tesseract.exe.
  • Slow analysis: Use smaller images, prefer text PDFs, or run interaction-only first.
  • No interactions found: Ensure drug names match the CSV exactly (case-sensitive in current implementation). Try entering generic names.
  • 500 errors after upload: Check server logs; confirm PDF is not password-protected and images are not corrupted.

Security Notes

  • Never commit your .env file or API keys to version control
  • The current implementation includes a fallback API key for development only
  • In production, always use environment variables for sensitive data
  • This application is for educational purposes only and should not replace professional medical advice

Technologies Used

  • Backend: Django 5.2.4
  • AI/ML: LangChain, Groq (Llama 3)
  • OCR: Tesseract, PyTesseract
  • PDF Processing: PyMuPDF
  • Data Processing: Pandas, NumPy
  • Frontend: Tailwind CSS
  • Image Processing: Pillow

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Run tests to ensure everything works
  5. Submit a pull request

License

This project is for educational purposes only.

Disclaimer

This application is designed for educational and informational purposes only. It should not be used as a substitute for professional medical advice, diagnosis, or treatment. Always consult with qualified healthcare providers for medical decisions.

About

AI-powered Drug Interaction & Diagnosis Assistant built with Django and LangChain. Detects drug conflicts from prescriptions and medical reports using OCR and smart analysis.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors