Skip to content

ck4957/med-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

med-parser

Parse unstructured medication text into structured entities using a Django API and a React UI.

Project layout

  • Django backend: med_parser/ + med_app/
  • React frontend: med_ui/
  • SQLite DB: db.sqlite3

Backend setup (Django)

  1. Create and activate a virtual environment:

    python3 -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
  2. Install dependencies:

    pip install -r requirement.txt
  3. Download the spaCy medical model (required for medspaCy):

    python -m spacy download en_core_web_sm
  4. (Optional) Set up MedGemma with Google AI:

    To use the MedGemma model, you need a Google API key:

    export GOOGLE_API_KEY="your-api-key-here"

    Get your API key from: https://makersuite.google.com/app/apikey

  5. Run migrations:

    python manage.py migrate
  6. Start the dev server:

    python manage.py runserver

The API is served at http://127.0.0.1:8000/api/.

API endpoints

  • GET /api/ — health check.
  • POST /api/parse_medical_text — extracts entities using medspaCy (local).
  • POST /api/parse_medical_text_gemma — extracts entities using MedGemma (Google AI).

Request body (both endpoints):

{
  "medical_text": "Metformin 500mg twice daily"
}

Response example:

{
  "entities": [
     ["Metformin", "DRUG"],
     ["500mg", "DOSAGE"],
     ["twice daily", "FREQUENCY"]
  ],
  "model": "medspacy"
}

Frontend setup (React)

From the med_ui folder:

  1. Install dependencies:

    npm install
  2. Configure the API URL (optional):

    • Copy .env.example to .env if needed
    • Default API URL is http://127.0.0.1:8000
    • To change it, edit the .env file:
      REACT_APP_API_URL=http://127.0.0.1:8000
      
  3. Run the dev server:

    npm start

The UI runs at http://localhost:3000 and connects to the Django API.

Features

  • Multiple AI Models: Choose between two parsing engines:
    • medspaCy: Fast, local medical NLP processing (no API key needed)
    • MedGemma: Google's advanced medical AI model (requires API key)
  • Medical Text Input: Enter unstructured medical text in a user-friendly interface
  • Entity Extraction: Automatically extracts and categorizes medical entities:
    • Drugs/Medications
    • Dosages
    • Frequencies
    • Durations
    • Conditions
    • Procedures
  • Visual Results: Color-coded entity cards for easy identification
  • API Health Check: Test connection to the backend API
  • Responsive Design: Works on desktop and mobile devices

Notes

  • CORS is enabled for local development in med_parser/settings.py.
  • The Django backend uses medspaCy for medical NLP processing.
  • MedGemma uses Google's Gemini API for advanced medical entity extraction.
  • The frontend is built with React and uses Axios for API calls.
  • All dependencies are listed in requirement.txt (backend) and med_ui/package.json (frontend).

Model Comparison

Feature medspaCy MedGemma
Speed Very Fast Moderate (API call)
Setup Local install only Requires API key
Accuracy Good Excellent
Cost Free Free tier available
Privacy Fully local Cloud-based

Quick Start

  1. Start Backend:

    python manage.py runserver
  2. Start Frontend (in a new terminal):

    cd med_ui
    npm start
  3. Access the app: Open http://localhost:3000 in your browser

  4. Select a model: Choose medspaCy or MedGemma in the UI

  5. Test it: Try parsing "Metformin 500mg twice daily for diabetes"

About

Parsing a unstructured medication text into structured fields

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors