spchetan1987/hospitalqueuemanager
๐ฅ AI Hospital Queue Management System (ML-Powered)
An intelligent hospital queue management system that uses Machine Learning to prioritize patients based on age and critical symptoms.
๐ฏ Features
- ML-Based Prioritization: Uses a Random Forest Classifier trained on 5000 samples
- Real-time Queue Management: Automatically sorts patients by priority
- Confidence Scores: Shows prediction confidence for transparency
- Interactive UI: Built with Gradio for easy use
- Feature Engineering: Extracts meaningful features from age and symptoms
๐ง ML Model Details
Model Performance
- Training Accuracy: 92.37%
- Test Accuracy: 91.10%
- Algorithm: Random Forest Classifier (100 trees)
- Training Samples: 5000 synthetic patient records
Features Used
- Age: Patient's age
- Has Critical Symptom: Binary indicator for life-threatening symptoms
- Has Medium Symptom: Binary indicator for moderate symptoms
- Is Elderly: Age > 65
- Is Child: Age < 12
- Is Infant: Age < 5
- Age Normalized: Age scaled to 0-1 range
- Symptom Word Count: Complexity of symptom description
Priority Levels
- Priority 1 (HIGH): Critical symptoms requiring immediate attention
- Examples: chest pain, shortness of breath, severe bleeding, unconscious, heart attack, stroke
- Priority 2 (MEDIUM): Moderate symptoms or vulnerable age groups
- Examples: high fever, fracture, vomiting, elderly patients, infants
- Priority 3 (LOW): Minor symptoms that can wait
- Examples: cold, cough, minor headache, rash, routine check-up
๐ฆ Installation
Prerequisites
- Python 3.7 or higher
- pip package manager
Steps
- Clone or download this repository
- Install dependencies:
pip install -r requirements.txt- Train the ML model (if not already trained):
python train_model.pyThis will:
- Generate 5000 synthetic training samples
- Train a Random Forest model
- Save the model to
queue_priority_model.pkl - Save configuration to
model_config.json - Create
training_data.csvwith the training dataset
- Run the application:
python app.pyThe Gradio interface will launch in your default browser (usually at http://127.0.0.1:7860)
๐ Usage
Adding Patients to Queue
- Enter the patient's Name
- Enter the patient's Age (0-120)
- Enter Symptoms (e.g., "chest pain", "high fever", "minor headache")
- Click "Add to Queue"
The ML model will:
- Extract features from the input
- Predict the priority level (1, 2, or 3)
- Show confidence scores for transparency
- Add the patient to the queue sorted by priority
Example Inputs
High Priority Patient:
- Name: John Doe
- Age: 55
- Symptoms: chest pain and shortness of breath
Medium Priority Patient:
- Name: Mary Smith
- Age: 72
- Symptoms: high fever and dizziness
Low Priority Patient:
- Name: Tom Brown
- Age: 25
- Symptoms: minor headache and cough
Clearing the Queue
Click the "Clear Queue" button to reset the patient queue.
๐ Model Training Details
Data Generation
The training data is synthetically generated with realistic distributions:
- 25% High Priority cases
- 25% Medium Priority cases
- 50% Low Priority cases
Special rules applied:
- Elderly patients (>65) with non-critical symptoms โ Medium priority
- Infants (<5) with any symptoms โ At least Medium priority
- Critical symptoms โ Always High priority regardless of age
Feature Importance
Based on the trained model:
- Has Critical Symptom: 53.96% importance
- Has Medium Symptom: 34.94% importance
- Age: 3.24% importance
- Symptom Word Count: 3.23% importance
- Other features: < 3% each
๐ง Project Structure
hospital-queue-management/
โโโ app.py # Main Gradio application
โโโ train_model.py # ML model training script
โโโ requirements.txt # Python dependencies
โโโ queue_priority_model.pkl # Trained ML model (generated)
โโโ model_config.json # Model configuration (generated)
โโโ training_data.csv # Training dataset (generated)
โโโ README.md # This file๐ ๏ธ Technical Stack
- Frontend: Gradio 5.49.1
- ML Framework: scikit-learn
- Data Processing: pandas, numpy
- Model Persistence: joblib
๐ Future Enhancements
- Add more features (vital signs, medical history)
- Implement real-time model retraining
- Add patient wait time estimation
- Include doctor availability in prioritization
- Export queue data to CSV/Excel
- Multi-language support
- Integration with hospital management systems
๐ค Contributing
Feel free to fork this project and submit pull requests for improvements!
๐ License
This project is open source and available for educational purposes.
๐ Acknowledgments
Built with Gradio and deployed on Hugging Face Spaces
Note: This is a demonstration system. For production use in real hospitals, please consult with medical professionals and ensure compliance with healthcare regulations (HIPAA, etc.).
