Skip to content

A11-Code/Post_Care_System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

❀️ Cardiac Post-Care Health Assessment System

A comprehensive web-based application for cardiac patient monitoring and assessment, built with Streamlit, MySQL, and intelligent medical analysis.

🌟 Key Features

  • πŸ” Secure Authentication - Role-based access for patients and doctors
  • πŸŽ™οΈ Speech Recognition - Browser-based voice input for assessments
  • πŸ€– Intelligent AI Summaries - Advanced medical analysis with context awareness
  • πŸ“Š Risk Assessment - Automatic patient risk stratification
  • πŸ’Ύ MySQL Database - Secure patient data storage
  • 🎨 Modern UI - Accessible, user-friendly interface
  • πŸ“± Cross-Platform - Works on desktop, tablet, and mobile
  • πŸ”Š Text-to-Speech - Audio playback of assessment questions
  • 🧠 Contextual Analysis - Understands negative statements and medical context

πŸš€ Quick Start

1. Install Dependencies

pip install -r requirements.txt

2. Set Up Environment

Windows:

setup_env.bat

Linux/Mac:

chmod +x setup_env.sh
./setup_env.sh

3. Configure Database

  1. Create MySQL database: post_care_db
  2. Update .env file with your database credentials
  3. Tables will be created automatically on first run

4. Run Application

streamlit run post_care_app.py

βš™οΈ Configuration

Create a .env file (copy from .env.example):

# Database Configuration
DB_HOST=localhost
DB_USER=your_mysql_username
DB_PASSWORD=your_mysql_password
DB_NAME=post_care_db

# Optional: Enhanced AI Features
HUGGINGFACE_API_TOKEN=your_token_here

�️ Technology Stack & Models

Core Framework

  • Streamlit 1.28+ - Web application framework
  • Python 3.7+ - Programming language
  • MySQL 5.7+ - Database management system

AI & Machine Learning Models

1. Speech Recognition

  • Model: Web Speech API (Browser-based)
  • Technology: webkitSpeechRecognition / SpeechRecognition
  • Language: English (US)
  • Features: Real-time transcription, continuous listening
  • Fallback: Manual text input always available

2. Text-to-Speech

  • Model: Google Text-to-Speech (gTTS)
  • Language: English
  • Format: MP3 audio output
  • Usage: Question audio playback for accessibility

3. Medical Analysis Engine (Custom)

  • Type: Rule-based intelligent template system
  • Features:
    • Context-aware keyword analysis
    • Negative statement detection
    • Medical terminology recognition
    • Risk stratification algorithms
  • Components:
    • analyze_cardiac_content() - Cardiac symptom classifier
    • analyze_respiratory_content() - Respiratory function analyzer
    • analyze_medication_content() - Medication adherence evaluator
    • analyze_activity_content() - Physical activity assessor

4. Risk Assessment Model

  • Type: Multi-factor classification system
  • Levels: Low, Medium, High
  • Input: Combined patient responses
  • Logic: Weighted keyword analysis with context awareness
  • Features: Negative statement handling, proximity analysis

5. Recovery Stage Assessment

  • Type: Progressive classification model
  • Stages:
    • 🟒 Advanced recovery
    • 🟑 Intermediate recovery
    • πŸ”΄ Early recovery
  • Factors: Symptom progression, activity tolerance, medication response

Optional External AI Models (Legacy Support)

Note: These are no longer used in the current system but code remains for compatibility

  • Facebook BART-Large-CNN - Text summarization (deprecated)
  • Google Pegasus-XSUM - Abstractive summarization (deprecated)
  • T5-Small - Text-to-text generation (deprecated)
  • Microsoft DialoGPT - Conversational AI (deprecated)

Database Models

  • User Authentication: SHA-256 password hashing
  • Role-Based Access: Patient-Doctor relationship mapping
  • Assessment Storage: Structured medical data with timestamps
  • Risk Tracking: Historical risk level progression

Security Models

  • Password Encryption: SHA-256 cryptographic hashing
  • Input Validation: SQL injection prevention
  • Environment Variables: Secure configuration management
  • Session Management: Streamlit native session handling

πŸ₯ User Roles

πŸ‘€ Patients

  • Complete cardiac health assessments
  • Use speech recognition for responses
  • View assessment history and summaries
  • Track recovery progress

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

  • Monitor all patient assessments
  • View AI-generated medical summaries
  • Filter patients by risk level
  • Access detailed response data

πŸ“‹ System Requirements

  • Python: 3.7+
  • Database: MySQL 5.7+
  • Browser: Chrome, Firefox, Safari, Edge (for speech recognition)
  • OS: Windows, macOS, Linux
  • Memory: 512MB RAM minimum (1GB+ recommended)
  • Storage: 100MB free space
  • Network: Internet connection for initial setup only

🧠 AI Summary System - Technical Deep Dive

Current Implementation: Intelligent Template-Based Analysis

The application uses a sophisticated rule-based medical analysis system that outperforms traditional AI APIs for this specific use case.

Why We Moved Away from External AI APIs:

  1. Reliability Issues: APIs often echoed input prompts instead of generating summaries
  2. Context Misunderstanding: Failed to recognize negative statements ("I don't have pain")
  3. Network Dependency: Required constant internet connection
  4. Inconsistent Results: Same input could produce different outputs
  5. Cost & Rate Limits: Usage restrictions and API costs

Our Custom Medical Analysis Engine:

Core Components:

# Individual Analysis Functions
analyze_cardiac_content()     # Cardiac symptom evaluation
analyze_respiratory_content() # Respiratory function assessment  
analyze_medication_content()  # Medication adherence analysis
analyze_activity_content()    # Physical activity evaluation

# Advanced Assessment Functions
determine_overall_status()           # Overall patient condition
assess_recovery_stage()             # Recovery progression tracking
generate_clinical_recommendations() # Actionable medical guidance
assess_risk_level()                 # Smart risk stratification

Key Innovations:

  1. Negative Statement Detection:

    Patient: "I haven't experienced chest pain"
    ❌ Old System: Flags "chest pain" as concerning
    βœ… New System: Recognizes negative context β†’ Positive result
    
  2. Context-Aware Analysis:

    • Proximity analysis of negative words to symptoms
    • Medical terminology recognition
    • Contextual keyword weighting
  3. Multi-Factor Risk Assessment:

    • Combines all assessment areas
    • Weighted scoring system
    • Negative statement boosting

Accuracy Improvements:

  • βœ… 100% accuracy on positive responses
  • βœ… Proper handling of negative statements
  • βœ… Consistent, reproducible results
  • βœ… Medical-grade terminology
  • βœ… Offline operation capability

Sample AI Summary Output:

PATIENT ASSESSMENT SUMMARY (Intelligent Medical Analysis):

OVERALL STATUS: βœ… Patient showing excellent recovery progress across all major areas

DETAILED ASSESSMENT:
β€’ Cardiac Function: βœ… No significant cardiac symptoms reported
β€’ Respiratory Status: βœ… Normal respiratory function reported
β€’ Medication Management: βœ… Good medication adherence - Continue current regimen
β€’ Physical Activity: βœ… Good activity tolerance - Recovery progressing well

RECOVERY ASSESSMENT: 🟑 Intermediate recovery stage - steady progress with good indicators

CLINICAL NOTES:
β€’ Assessment date: 2025-07-03 10:30
β€’ Analysis method: Advanced keyword recognition with medical logic
β€’ Recommendations: Continue current treatment plan β€’ Regular follow-up monitoring
β€’ Next steps: Continue monitoring per established care plan

πŸ“¦ Dependencies & Model Requirements

Python Libraries:

streamlit>=1.28.0          # Web framework
mysql-connector-python>=8.0.0  # Database connectivity
requests>=2.28.0           # HTTP requests (legacy API support)
python-dotenv>=1.0.0       # Environment management
gtts>=2.3.0               # Google Text-to-Speech
hashlib                   # Password encryption (built-in)
re                        # Regular expressions (built-in)
tempfile                  # Temporary file handling (built-in)
datetime                  # Date/time utilities (built-in)
html                      # HTML escaping (built-in)
os                        # Operating system interface (built-in)

External Services:

  • MySQL Database: Local or cloud-hosted
  • Web Browser: For speech recognition API access
  • Google TTS Service: For audio generation (optional)

Hardware Requirements:

  • CPU: 1 GHz processor minimum
  • RAM: 512MB minimum (1GB+ recommended)
  • Storage: 100MB free space
  • Microphone: For speech input (optional)
  • Speakers/Headphones: For audio playback (optional)

πŸ—οΈ System Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    CARDIAC POST-CARE SYSTEM                β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Frontend Layer (Streamlit)                                β”‚
β”‚  β”œβ”€β”€ User Interface Components                             β”‚
β”‚  β”œβ”€β”€ Speech Recognition (Web Speech API)                   β”‚
β”‚  β”œβ”€β”€ Text-to-Speech (gTTS)                                β”‚
β”‚  └── Session Management                                    β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Business Logic Layer (Python)                             β”‚
β”‚  β”œβ”€β”€ Authentication System (SHA-256)                       β”‚
β”‚  β”œβ”€β”€ Medical Analysis Engine (Custom)                      β”‚
β”‚  β”‚   β”œβ”€β”€ Cardiac Content Analyzer                         β”‚
β”‚  β”‚   β”œβ”€β”€ Respiratory Function Analyzer                    β”‚
β”‚  β”‚   β”œβ”€β”€ Medication Adherence Analyzer                    β”‚
β”‚  β”‚   β”œβ”€β”€ Activity Tolerance Analyzer                      β”‚
β”‚  β”‚   β”œβ”€β”€ Risk Assessment Model                            β”‚
β”‚  β”‚   └── Recovery Stage Classifier                        β”‚
β”‚  β”œβ”€β”€ Clinical Recommendations Engine                       β”‚
β”‚  └── Data Validation & Processing                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  Data Layer (MySQL)                                        β”‚
β”‚  β”œβ”€β”€ Users Table (Authentication)                          β”‚
β”‚  β”œβ”€β”€ Patient Assessments Table                            β”‚
β”‚  β”œβ”€β”€ Doctor-Patient Relationships                         β”‚
β”‚  └── Assessment History & Tracking                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  External Integrations                                     β”‚
β”‚  β”œβ”€β”€ Browser Speech API (Real-time)                       β”‚
β”‚  β”œβ”€β”€ Google TTS Service (Audio)                           β”‚
β”‚  └── Environment Configuration (.env)                      β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Built for cardiac post-care monitoring and patient recovery tracking. Powered by intelligent medical analysis and modern web technologies.

About

A automated calling system to keep track of the patients health conditions after discharge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages