kardokh/ctrcd-data-extraction
๐ฅ 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
- Clone the repository
git clone <your-repo-url>
cd ctrcd- Install dependencies
pip install -r requirements.txt- Install Tesseract OCR
- macOS:
brew install tesseract - Ubuntu/Debian:
sudo apt-get install tesseract-ocr - Windows: Download from GitHub
- Install poppler (for pdf2image)
- macOS:
brew install poppler - Ubuntu/Debian:
sudo apt-get install poppler-utils - Windows: Download from poppler releases
- Run the application
python app.pyThe 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:
- Convert HTML to PDF (you can use your browser's "Print to PDF" feature or wkhtmltopdf):
# 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
- 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
- Create a new Space
- Go to HuggingFace Spaces
- Click "Create new Space"
- Choose a name (e.g.,
ctrcd-data-extraction) - Select Gradio as the SDK
- Choose visibility (Public or Private)
- Click "Create Space"
- Clone your Space repository
git clone https://huggingface.co/spaces/<your-username>/<space-name>
cd <space-name>- Copy the application files
cp /path/to/ctrcd/app.py .
cp /path/to/ctrcd/requirements.txt .
cp /path/to/ctrcd/README.md .- Create a packages.txt file (for system dependencies)
echo "tesseract-ocr" > packages.txt
echo "poppler-utils" >> packages.txt- Commit and push
git add app.py requirements.txt README.md packages.txt
git commit -m "Initial commit: CTRCD data extraction POC"
git push- Wait for deployment
- HuggingFace will automatically build and deploy your Space
- This typically takes 2-5 minutes
- You'll see the build logs in your Space's dashboard
- Access your Space
- 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.txtfile 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
- PDF Upload: User uploads a patient health record in PDF format
- Text Extraction:
- Tries direct text extraction first (for digital PDFs)
- Falls back to OCR if needed (for scanned documents)
- Pattern Matching: Uses regex patterns to identify clinical variables
- Entity Extraction: Applies NLP techniques to extract values
- 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
