Spaces:
Sleeping
Sleeping
| import gradio as gr | |
| from src.interface.session_manager import SimplifiedSessionData | |
| from src.core.core_classes import ClinicalBackground | |
| def load_profile(profile_name: str, session: SimplifiedSessionData): | |
| """Load predefined patient profile and apply it to the session.""" | |
| profiles = { | |
| "π€ Default Profile (Serhii)": { | |
| "name": "Serhii", | |
| "phone": "(555) 123-4567", | |
| "age": 52, | |
| "conditions": "Atrial fibrillation, Deep vein thrombosis, Obesity, Hypertension", | |
| "goal": "Weight reduction and cardiovascular fitness improvement", | |
| "exercise": "Swimming, Walking, Light cardio", | |
| "limitations": "Anticoagulation therapy, Post-thrombotic recovery" | |
| }, | |
| "π’ GREEN - Healthy Coping": { | |
| "name": "James", | |
| "phone": "(555) 234-5678", | |
| "age": 40, | |
| "conditions": "No chronic conditions, Excellent health", | |
| "goal": "Maintain fitness and wellness", | |
| "exercise": "Running, Gym, Sports", | |
| "limitations": "None" | |
| }, | |
| "π‘ YELLOW - Mild Distress": { | |
| "name": "Lisa", | |
| "phone": "(555) 345-6789", | |
| "age": 45, | |
| "conditions": "Hypertension, Mild anxiety, Sleep issues", | |
| "goal": "Manage stress and improve sleep quality", | |
| "exercise": "Yoga, Walking, Meditation", | |
| "limitations": "Stress-related fatigue, Occasional insomnia" | |
| }, | |
| "π‘ YELLOW - Grief & Loss": { | |
| "name": "Michael", | |
| "phone": "(555) 456-7890", | |
| "age": 58, | |
| "conditions": "Recent loss of spouse, Mild depression", | |
| "goal": "Process grief and rebuild routine", | |
| "exercise": "Gentle walking, Support groups", | |
| "limitations": "Low motivation, Emotional exhaustion" | |
| }, | |
| "π‘ YELLOW - Existential Questions": { | |
| "name": "Patricia", | |
| "phone": "(555) 567-8901", | |
| "age": 62, | |
| "conditions": "Chronic pain, Questioning life purpose", | |
| "goal": "Find meaning and manage chronic pain", | |
| "exercise": "Tai Chi, Meditation, Gentle stretching", | |
| "limitations": "Chronic pain, Existential concerns" | |
| }, | |
| "π‘ YELLOW - Spiritual Disconnection": { | |
| "name": "David", | |
| "phone": "(555) 678-9012", | |
| "age": 55, | |
| "conditions": "Loss of faith, Isolation from community", | |
| "goal": "Reconnect with spiritual community", | |
| "exercise": "Walking, Community activities", | |
| "limitations": "Spiritual disconnection, Social isolation" | |
| }, | |
| "π΄ RED - Crisis (Suicidal Risk)": { | |
| "name": "Thomas", | |
| "phone": "(555) 789-0123", | |
| "age": 35, | |
| "conditions": "Severe depression, Suicidal ideation", | |
| "goal": "Immediate crisis intervention and support", | |
| "exercise": "None - Crisis support priority", | |
| "limitations": "CRISIS - Suicidal thoughts, Immediate referral needed" | |
| }, | |
| "π΄ RED - Severe Hopelessness": { | |
| "name": "Jennifer", | |
| "phone": "(555) 890-1234", | |
| "age": 48, | |
| "conditions": "Major depression, Complete hopelessness", | |
| "goal": "Crisis stabilization and professional support", | |
| "exercise": "None - Medical intervention priority", | |
| "limitations": "CRISIS - Severe hopelessness, Unable to function" | |
| }, | |
| "π΄ RED - Spiritual Crisis": { | |
| "name": "Christopher", | |
| "phone": "(555) 901-2345", | |
| "age": 52, | |
| "conditions": "Moral injury, Spiritual crisis, Anger at God", | |
| "goal": "Spiritual crisis intervention and healing", | |
| "exercise": "None - Spiritual support priority", | |
| "limitations": "CRISIS - Spiritual crisis, Rage, Existential despair" | |
| }, | |
| "π« Cardiac Patient (Rehabilitation)": { | |
| "name": "John", | |
| "phone": "(555) 012-3456", | |
| "age": 65, | |
| "conditions": "Coronary artery disease, Hypertension, Hyperlipidemia", | |
| "goal": "Cardiac rehabilitation and risk factor management", | |
| "exercise": "Supervised walking, Cardiac rehab program", | |
| "limitations": "Recent MI, Limited exertion tolerance" | |
| }, | |
| "π©Έ Diabetic Patient (Management)": { | |
| "name": "Maria", | |
| "phone": "(555) 111-2222", | |
| "age": 58, | |
| "conditions": "Type 2 Diabetes, Obesity, Hypertension", | |
| "goal": "Blood sugar control and weight management", | |
| "exercise": "Moderate walking, Resistance training", | |
| "limitations": "Neuropathy, Retinopathy risk" | |
| }, | |
| "π₯ Post-Surgery (Recovery)": { | |
| "name": "Alex", | |
| "phone": "(555) 222-3333", | |
| "age": 45, | |
| "conditions": "Post-surgical recovery, Pain management", | |
| "goal": "Safe return to normal activities", | |
| "exercise": "Gentle mobility, Gradual progression", | |
| "limitations": "Surgical site healing, Limited ROM" | |
| }, | |
| "π§ Mental Health (Anxiety/Depression)": { | |
| "name": "Emma", | |
| "phone": "(555) 333-4444", | |
| "age": 35, | |
| "conditions": "Depression, Anxiety, Sedentary lifestyle", | |
| "goal": "Mood improvement through activity", | |
| "exercise": "Yoga, Walking, Group activities", | |
| "limitations": "Low motivation, Energy fluctuations" | |
| }, | |
| "π΄ Elderly Patient (Chronic Care)": { | |
| "name": "Robert", | |
| "phone": "(555) 444-5555", | |
| "age": 78, | |
| "conditions": "Arthritis, Osteoporosis, Hypertension", | |
| "goal": "Maintain independence and mobility", | |
| "exercise": "Tai Chi, Water aerobics, Balance training", | |
| "limitations": "Fall risk, Joint pain, Medication interactions" | |
| }, | |
| "π Athletic Patient (Injury/Training)": { | |
| "name": "Sarah", | |
| "phone": "(555) 555-6666", | |
| "age": 32, | |
| "conditions": "Mild hypertension, Overtraining syndrome", | |
| "goal": "Optimize performance and prevent injury", | |
| "exercise": "Running, Strength training, Cross-training", | |
| "limitations": "Overuse injuries, Recovery needs" | |
| } | |
| } | |
| profile = profiles.get(profile_name, profiles["π€ Default Profile (Serhii)"]) | |
| # Automatically apply the profile to the session | |
| if session and hasattr(session.app_instance, 'set_patient_info'): | |
| session.app_instance.set_patient_info( | |
| name=profile['name'], | |
| phone=profile.get('phone', '') | |
| ) | |
| # Update clinical_background for medical context | |
| session.app_instance.clinical_background = ClinicalBackground( | |
| patient_name=profile['name'], | |
| age=profile['age'], | |
| conditions=profile['conditions'].split(',') if isinstance(profile['conditions'], str) else profile['conditions'], | |
| primary_goal=profile['goal'], | |
| exercise_preferences=profile['exercise'].split(',') if isinstance(profile['exercise'], str) else profile['exercise'], | |
| exercise_limitations=profile['limitations'].split(',') if isinstance(profile['limitations'], str) else profile['limitations'] | |
| ) | |
| # Update conversation logger patient name | |
| if hasattr(session.app_instance, 'conversation_logger'): | |
| session.app_instance.conversation_logger.patient_name = profile['name'] | |
| print(f"DEBUG: Auto-applied profile - Name: {profile['name']}, Phone: {profile.get('phone', '')}") | |
| print(f"DEBUG: Clinical background updated - Age: {profile['age']}, Conditions: {profile['conditions']}") | |
| status = f"""<div style="padding: 1em; background-color: #ecfdf5; border-left: 4px solid #10b981; border-radius: 4px;"> | |
| <h4 style="color: #059669; margin-top: 0;">β Profile Loaded & Applied</h4> | |
| <p><strong>Patient:</strong> {profile['name']}, {profile['age']} years old</p> | |
| <p><strong>Phone:</strong> {profile.get('phone', 'Not provided')}</p> | |
| <p><strong>Profile:</strong> {profile_name}</p> | |
| <p><strong>Status:</strong> Profile has been automatically applied to this session</p> | |
| <p style="margin-bottom: 0; color: #059669;">β Ready to use in conversations and reports</p> | |
| </div>""" | |
| return ( | |
| profile['name'], | |
| profile.get('phone', ''), | |
| profile['age'], | |
| profile['conditions'], | |
| profile['goal'], | |
| profile['exercise'], | |
| profile['limitations'], | |
| status | |
| ) | |
| def save_profile(name: str, phone: str, age: float, conditions: str, goal: str, exercise: str, limitations: str, session: SimplifiedSessionData): | |
| """Save current profile settings and update app patient info.""" | |
| if not name.strip(): | |
| return """<div style="padding: 1em; background-color: #fef2f2; border-left: 4px solid #dc2626; border-radius: 4px;"> | |
| <h4 style="color: #dc2626; margin-top: 0;">β Error</h4> | |
| <p style="margin-bottom: 0;">Patient name cannot be empty</p> | |
| </div>""" | |
| # Update session's app instance patient info for provider summaries | |
| if session and hasattr(session.app_instance, 'set_patient_info'): | |
| session.app_instance.set_patient_info(name=name.strip(), phone=phone.strip() if phone else None) | |
| # Also update clinical_background for medical context | |
| session.app_instance.clinical_background = ClinicalBackground( | |
| patient_name=name.strip(), | |
| age=int(age) if age else None, | |
| conditions=conditions.strip().split(',') if conditions.strip() else [], | |
| primary_goal=goal.strip(), | |
| exercise_preferences=exercise.strip().split(',') if exercise.strip() else [], | |
| exercise_limitations=limitations.strip().split(',') if limitations.strip() else [] | |
| ) | |
| # Update conversation logger patient name | |
| if hasattr(session.app_instance, 'conversation_logger'): | |
| session.app_instance.conversation_logger.patient_name = name.strip() | |
| print(f"DEBUG: Updated patient info - Name: {name.strip()}, Phone: {phone.strip() if phone else None}") | |
| print(f"DEBUG: Updated clinical_background - Age: {int(age) if age else None}, Conditions: {conditions}") | |
| status = f"""<div style="padding: 1em; background-color: #ecfdf5; border-left: 4px solid #10b981; border-radius: 4px;"> | |
| <h4 style="color: #059669; margin-top: 0;">πΎ Profile Saved</h4> | |
| <p><strong>Patient:</strong> {name}, {int(age)} years old</p> | |
| <p><strong>Phone:</strong> {phone if phone else 'Not provided'}</p> | |
| <p><strong>Conditions:</strong> {conditions}</p> | |
| <p><strong>Primary Goal:</strong> {goal}</p> | |
| <p style="margin-bottom: 0;">Profile settings have been updated for this session.</p> | |
| </div>""" | |
| return status | |
| def reset_profile(session: SimplifiedSessionData): | |
| """Reset profile to default.""" | |
| # Reset session's app instance patient info | |
| if session and hasattr(session.app_instance, 'set_patient_info'): | |
| session.app_instance.set_patient_info(name="Serhii", phone="(555) 123-4567") | |
| # Also reset clinical_background | |
| session.app_instance.clinical_background = ClinicalBackground( | |
| patient_name="Serhii", | |
| age=52, | |
| conditions=["Atrial fibrillation", "Deep vein thrombosis", "Obesity", "Hypertension"], | |
| primary_goal="Weight reduction and cardiovascular fitness improvement", | |
| exercise_preferences=["Swimming", "Walking", "Light cardio"], | |
| exercise_limitations=["Anticoagulation therapy", "Post-thrombotic recovery"] | |
| ) | |
| # Update conversation logger patient name | |
| if hasattr(session.app_instance, 'conversation_logger'): | |
| session.app_instance.conversation_logger.patient_name = "Serhii" | |
| print("DEBUG: Reset patient info to default (Serhii)") | |
| return ( | |
| "Serhii", | |
| "(555) 123-4567", | |
| 52, | |
| "Atrial fibrillation, Deep vein thrombosis, Obesity, Hypertension", | |
| "Weight reduction and cardiovascular fitness improvement", | |
| "Swimming, Walking, Light cardio", | |
| "Anticoagulation therapy, Post-thrombotic recovery", | |
| "" | |
| ) | |