CoolFace
Apppublic

kardokh/ctrcd-data-extraction

sourceHugging Faceupdated 10mo agoView on Hugging Face
0likes
App README

๐Ÿฅ CTRCD Data Extraction - Proof of Concept

Automated extraction of clinical variables from patient health records using OCR and NLP

This demonstration showcases how Optical Character Recognition (OCR) technology and intelligent parsing can automatically extract Cancer Therapy-Related Cardiac Dysfunction (CTRCD) risk stratification variables from PDF health records.

๐Ÿ“‹ Overview

This proof of concept is part of a research proposal for automating clinical data extraction at Mater Private Hospital's Perl EHR system. The system demonstrates:

  • โ€”OCR-based text extraction from PDF documents
  • โ€”Pattern matching for clinical variables
  • โ€”NLP-based entity extraction for medical data
  • โ€”Structured output in tabular format

Variables Extracted

The system can identify and extract:

  • โ€”Patient demographics (Age, Gender, BMI)
  • โ€”Cancer diagnosis and staging
  • โ€”Chemotherapy regimens (Anthracyclines, Trastuzumab)
  • โ€”Cardiac function parameters (LVEF, GLS)
  • โ€”Cardiac biomarkers (Troponin, NT-proBNP)
  • โ€”Cardiovascular comorbidities (Hypertension, Diabetes, Prior MI)
  • โ€”Risk factors (Smoking status)

๐Ÿš€ Quick Start

Local Development

  1. 1.Clone the repository
bash
git clone <your-repo-url>
cd ctrcd
  1. 1.Install dependencies
bash
pip install -r requirements.txt
  1. 1.Install Tesseract OCR
  2. 2.macOS: brew install tesseract
  3. 3.Ubuntu/Debian: sudo apt-get install tesseract-ocr
  4. 4.Windows: Download from GitHub
  1. 1.Install poppler (for pdf2image)
  2. 2.macOS: brew install poppler
  3. 3.Ubuntu/Debian: sudo apt-get install poppler-utils
  4. 4.Windows: Download from poppler releases
  1. 1.Run the application
bash
python app.py

The app will launch at http://localhost:7860

Testing with Sample Data

A sample patient health record is provided in sample_patient_record.html. To test:

  1. 1.Convert HTML to PDF (you can use your browser's "Print to PDF" feature or wkhtmltopdf):
bash
   # Using wkhtmltopdf (if installed)
   wkhtmltopdf sample_patient_record.html sample_patient_record.pdf

Or simply open sample_patient_record.html in your browser and use File โ†’ Print โ†’ Save as PDF

  1. 1.Upload the PDF to the web interface and click "Extract Clinical Data"

๐Ÿค— Deploying to HuggingFace Spaces

Prerequisites

  • โ€”A HuggingFace account (sign up here)
  • โ€”Git installed on your system

Deployment Steps

  1. 1.Create a new Space
  2. 2.Go to HuggingFace Spaces
  3. 3.Click "Create new Space"
  4. 4.Choose a name (e.g., ctrcd-data-extraction)
  5. 5.Select Gradio as the SDK
  6. 6.Choose visibility (Public or Private)
  7. 7.Click "Create Space"
  1. 1.Clone your Space repository
bash
   git clone https://huggingface.co/spaces/<your-username>/<space-name>
   cd <space-name>
  1. 1.Copy the application files
bash
   cp /path/to/ctrcd/app.py .
   cp /path/to/ctrcd/requirements.txt .
   cp /path/to/ctrcd/README.md .
  1. 1.Create a packages.txt file (for system dependencies)
bash
   echo "tesseract-ocr" > packages.txt
   echo "poppler-utils" >> packages.txt
  1. 1.Commit and push
bash
   git add app.py requirements.txt README.md packages.txt
   git commit -m "Initial commit: CTRCD data extraction POC"
   git push
  1. 1.Wait for deployment
  2. 2.HuggingFace will automatically build and deploy your Space
  3. 3.This typically takes 2-5 minutes
  4. 4.You'll see the build logs in your Space's dashboard
  1. 1.Access your Space
  2. 2.Your app will be available at: https://huggingface.co/spaces/<your-username>/<space-name>

HuggingFace Space Configuration

Your Space should contain these files:

<space-name>/
โ”œโ”€โ”€ app.py              # Main Gradio application
โ”œโ”€โ”€ requirements.txt    # Python dependencies
โ”œโ”€โ”€ packages.txt        # System dependencies (tesseract-ocr, poppler-utils)
โ””โ”€โ”€ README.md          # This file (will appear on your Space page)

Important Notes for HuggingFace Deployment

  • โ€”System Dependencies: The packages.txt file is crucial for installing Tesseract and Poppler
  • โ€”Memory Limits: Free HuggingFace Spaces have 16GB RAM limit. For larger PDFs, consider upgrading
  • โ€”Processing Time: First run may be slower as dependencies are loaded
  • โ€”Privacy: Set your Space to Private if you'll be testing with sensitive data

๐Ÿ“Š How It Works

  1. 1.PDF Upload: User uploads a patient health record in PDF format
  2. 2.Text Extraction:
  3. 3.Tries direct text extraction first (for digital PDFs)
  4. 4.Falls back to OCR if needed (for scanned documents)
  5. 5.Pattern Matching: Uses regex patterns to identify clinical variables
  6. 6.Entity Extraction: Applies NLP techniques to extract values
  7. 7.Output Generation: Returns structured data in a table with confidence scores

๐Ÿ”’ Security & Compliance

Important: This is a demonstration using synthetic data. For production deployment with real patient data:

  • โ€”Ensure GDPR compliance and Irish Data Protection Act 2018 adherence
  • โ€”Implement on-premises processing (no cloud services)
  • โ€”Add proper authentication and access controls
  • โ€”Enable audit logging
  • โ€”Apply data pseudonymization/anonymization
  • โ€”Conduct Data Protection Impact Assessment (DPIA)
  • โ€”Obtain necessary ethical approvals

๐Ÿ“– Related Documents

This proof of concept supports the research proposal:

  • โ€”Title: "Using OCR Technology and API Integration for CTRCD Risk Stratification Research"
  • โ€”Authors: Kardokh Kaka Bra, Dina Neiroukh
  • โ€”Submitted to: Prof. Osama Soliman
  • โ€”Institution: Mater Private Hospital

๐Ÿ› ๏ธ Technology Stack

  • โ€”Frontend: Gradio (Python web framework)
  • โ€”OCR: Tesseract OCR engine
  • โ€”PDF Processing: PyPDF2, pdf2image
  • โ€”Data Processing: pandas
  • โ€”Pattern Matching: Regular expressions (re module)

๐Ÿ“ License

This project is for research and demonstration purposes. Please ensure appropriate permissions and compliance for any production use with real patient data.

๐Ÿ‘ฅ Contact

  • โ€”Kardokh Kaka Bra
  • โ€”Dina Neiroukh
  • โ€”Supervisor: Prof. Osama Soliman

Date: December 11, 2025