Skip to content

Latest commit

Β 

History

History
426 lines (357 loc) Β· 10.1 KB

File metadata and controls

426 lines (357 loc) Β· 10.1 KB

πŸ€– Role-Based Chatbot System

Overview

The SmartCare Hospital Chatbot now features role-based intelligence that provides different features and responses based on whether the user is a Patient or Management/Admin.

Two Distinct Modes

πŸ‘€ Patient Mode

For: Patients and visitors Focus: Personal assistance, appointments, health information

πŸ‘¨β€πŸ’Ό Management Mode

For: Hospital administrators and staff Focus: Analytics, operations, queue management, reports


Patient Mode Features

1. πŸ“… Book Appointments

  • Browse departments
  • View available doctors
  • Check doctor ratings and experience
  • Select appointment slots

Example:

Patient: "Book an appointment"
Bot: Shows departments β†’ Select doctor β†’ Choose time

2. πŸ” Check Appointment Status

  • Track appointment by phone number
  • View appointment details
  • See current status (confirmed, waiting, completed)

Example:

Patient: "Check my status"
Bot: "Please provide your phone number"
Patient: "9876543210"
Bot: Shows all appointments with status

3. ⏰ Estimated Appointment Time

NEW FEATURE - Get precise timing information:

  • Scheduled appointment time
  • Current queue position
  • Estimated actual time
  • Expected wait duration

Example:

Patient: "What's my estimated time?"
Bot: 
"⏰ Your Appointment Estimate:
πŸ“… Date: March 15, 2024
πŸ• Scheduled: 10:00 AM
πŸ“Š Queue Position: #3
⏱️ Estimated Time: 10:30 AM
βŒ› Expected Wait: ~30 minutes"

4. πŸ“‹ Precautions & Preparation

NEW FEATURE - Department-specific guidance:

  • What to bring
  • How to prepare
  • Fasting requirements
  • Clothing recommendations
  • Timing advice

Example:

Patient: "Precautions for cardiology"
Bot:
"πŸ“‹ Precautions for Cardiology:
🩺 Bring previous ECG/Echo reports
πŸ’Š List of current medications
🚫 Avoid caffeine 2 hours before
πŸ‘• Wear comfortable, loose clothing
πŸ“‹ Fasting may be required for some tests"

Department-Specific Precautions:

  • Cardiology: ECG prep, medication list, avoid caffeine
  • Neurology: MRI reports, symptom notes, adequate sleep
  • Orthopedic: X-rays, comfortable shoes, walking aids
  • Pediatrics: Vaccination records, growth chart, comfort toys
  • General: ID proof, medical records, insurance

5. πŸ‘¨β€βš•οΈ Find Doctors

  • Search by specialty
  • View doctor ratings
  • Check experience years
  • See availability

6. ⏱️ Wait Time Estimates

  • Current wait times by department
  • Crowd level indicators
  • Best time to visit recommendations

7. πŸ₯ Department Information

  • List all departments
  • Floor locations
  • Available services

8. πŸ“Š Crowd Predictions

  • Best times to visit
  • Peak hour warnings
  • Tomorrow's forecast

Management Mode Features

1. πŸ“Š Queue Statistics

Real-time operational data:

  • Total appointments today
  • Patients waiting
  • Patients in progress
  • Completed consultations
  • Completion rate
  • Department-wise breakdown

Example:

Admin: "Queue statistics"
Bot:
"πŸ“Š Live Queue Statistics:
πŸ“… Today's Overview:
β€’ Total Appointments: 45
β€’ ⏳ Waiting: 12
β€’ πŸ”„ In Progress: 8
β€’ βœ… Completed: 25
πŸ₯ Active Queues by Department:
β€’ Cardiology: 5 patients
β€’ Neurology: 3 patients
β€’ Orthopedic: 4 patients
⚑ Completion Rate: 55.6%"

2. πŸ“ˆ Today's Summary Report

Comprehensive daily overview:

  • Total appointments
  • Completion statistics
  • No-show rate
  • Active departments
  • Available doctors
  • Average wait time
  • System status indicator

Example:

Admin: "Today's summary"
Bot:
"πŸ“ˆ Today's Summary Report
πŸ“… March 15, 2024
πŸ‘₯ Appointments:
β€’ Total: 45
β€’ Completed: 25
β€’ No-shows: 2
β€’ Show Rate: 95.6%
πŸ₯ Operations:
β€’ Active Departments: 8
β€’ Available Doctors: 15
β€’ Avg Wait Time: ~25 min
πŸ’‘ Status: 🟒 Normal"

3. πŸ₯ Department Performance

Performance metrics by department:

  • Total appointments per department
  • Completion rates
  • No-show rates
  • Efficiency analysis

Example:

Admin: "Department performance"
Bot:
"πŸ“Š Department Performance Today:
β€’ Cardiology:
  Total: 15 | Completed: 10 | Rate: 66.7%
β€’ Neurology:
  Total: 12 | Completed: 8 | Rate: 66.7%
β€’ Orthopedic:
  Total: 10 | Completed: 5 | Rate: 50.0%"

4. πŸ‘¨β€βš•οΈ Doctor Availability

Staff availability tracking:

  • Number of available doctors
  • Number of unavailable doctors
  • List of currently available doctors
  • Department assignments

Example:

Admin: "Doctor availability"
Bot:
"πŸ‘¨β€βš•οΈ Doctor Availability:
βœ… Available: 15 doctors
❌ Unavailable: 3 doctors
Currently Available:
β€’ Dr. John Smith - Cardiology
β€’ Dr. Sarah Johnson - Neurology
β€’ Dr. Mike Brown - Orthopedic"

5. 🚨 High-Risk Patient Alerts

Priority patient identification:

  • Emergency cases
  • High-risk patients
  • Patients requiring immediate attention
  • Appointment times
  • Department assignments

Example:

Admin: "High-risk patients"
Bot:
"🚨 High-Risk Patients Today:
Found 3 high-priority cases:
β€’ John Doe - Cardiology (10:00 AM)
β€’ Jane Smith - Neurology (11:30 AM)
β€’ Bob Wilson - Emergency (09:45 AM)
⚠️ These patients require immediate attention.
πŸ’‘ Consider prioritizing in queue management."

6. ⚠️ No-Show Predictions

ML-powered predictions:

  • Identify high no-show risk appointments
  • Risk percentage for each patient
  • Proactive reminder suggestions

Example:

Admin: "No-show predictions"
Bot:
"⚠️ No-Show Risk Analysis:
High-risk appointments: 3/45
β€’ Patient A - 10:00 AM (Risk: 65%)
β€’ Patient B - 02:30 PM (Risk: 58%)
β€’ Patient C - 04:00 PM (Risk: 52%)
πŸ’‘ Consider sending reminder SMS to these patients."

7. πŸ“‰ Crowd Forecast

Predictive analytics:

  • Tomorrow's crowd predictions
  • Hour-by-hour forecast
  • Peak time identification
  • Staffing recommendations

Example:

Admin: "Crowd forecast"
Bot:
"πŸ“Š Crowd Forecast for Tomorrow:
March 16, 2024
🟒 8:00 AM: Low
🟑 10:00 AM: Medium
🟠 12:00 PM: High
🟑 2:00 PM: Medium
🟒 4:00 PM: Low
πŸ’‘ Recommendations:
β€’ Schedule more staff during peak hours
β€’ Prepare for high-volume periods
β€’ Consider opening additional counters"

How Role Detection Works

Automatic Detection

The chatbot automatically detects user role based on:

  1. Authentication Status: Checks if user is logged in
  2. User Type: Checks current_user.is_admin()
  3. Context: Uses session and user data

Role Assignment

if current_user.is_authenticated:
    if current_user.is_admin():
        role = "admin"  # Management Mode
    else:
        role = "patient"  # Patient Mode
else:
    role = "patient"  # Default to Patient Mode

Comparison Table

Feature Patient Mode Management Mode
Book Appointments βœ… Yes ❌ No
Check Status βœ… Yes (own) ❌ No
Estimated Time βœ… Yes ❌ No
Precautions βœ… Yes ❌ No
Find Doctors βœ… Yes βœ… Yes
Wait Times βœ… Yes βœ… Yes
Queue Statistics ❌ No βœ… Yes
Today's Summary ❌ No βœ… Yes
Dept Performance ❌ No βœ… Yes
Doctor Availability ❌ No βœ… Yes
High-Risk Alerts ❌ No βœ… Yes
No-Show Predictions ❌ No βœ… Yes
Crowd Forecast βœ… Limited βœ… Detailed

Testing the Role-Based System

Test as Patient

  1. Login as patient: test@patient.com / test123
  2. Open chatbot
  3. Try these commands:
    • "Hello"
    • "Book appointment"
    • "Check my status"
    • "What's my estimated time?"
    • "Precautions for cardiology"
    • "Find a doctor"

Test as Admin

  1. Login as admin: admin@hospital.com / admin123
  2. Open chatbot
  3. Try these commands:
    • "Hello"
    • "Queue statistics"
    • "Today's summary"
    • "High-risk patients"
    • "Department performance"
    • "Doctor availability"
    • "No-show predictions"
    • "Crowd forecast"

Technical Implementation

Files Modified/Created

Created:

  • βœ… app/services/chatbot_handlers.py - Patient and Management handlers

Modified:

  • βœ… app/services/chatbot_service.py - Role-based routing
  • βœ… app/routes/chatbot.py - User role detection

Key Classes

class HospitalChatbot:
    - process_message() - Main entry point
    - _handle_patient_intent() - Route patient requests
    - _handle_management_intent() - Route management requests
    - _detect_intent() - Role-based intent detection

class PatientHandlers:
    - handle_estimated_time() - Appointment timing
    - handle_precautions() - Health advice

class ManagementHandlers:
    - handle_queue_stats() - Queue analytics
    - handle_today_summary() - Daily reports
    - handle_high_risk_patients() - Priority alerts

Benefits

For Patients

βœ… Personalized assistance for their specific needs βœ… Estimated timing reduces uncertainty βœ… Precautions help them prepare properly βœ… Easy booking process βœ… Status tracking without calling

For Management

βœ… Real-time analytics for decision making βœ… Performance metrics for optimization βœ… Risk alerts for proactive management βœ… Predictive insights for planning βœ… Operational efficiency improvements


Future Enhancements

Phase 2 (Potential)

  1. Patient Mode:

    • Complete booking through chat
    • Payment integration
    • Medical history access
    • Prescription reminders
    • Lab report notifications
  2. Management Mode:

    • Staff scheduling assistance
    • Resource allocation suggestions
    • Financial analytics
    • Patient satisfaction metrics
    • Automated report generation

Summary

The role-based chatbot system provides:

βœ… Two distinct modes for different user types βœ… 8 patient features for personal assistance βœ… 7 management features for operations βœ… Automatic role detection based on login βœ… Context-aware responses for each role βœ… Real-time data integration with ML models βœ… Production-ready implementation

This enhancement makes the chatbot more useful and relevant to each user type, improving overall system efficiency and user satisfaction.