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"""
Patient: {profile['name']}, {profile['age']} years old
Phone: {profile.get('phone', 'Not provided')}
Profile: {profile_name}
Status: Profile has been automatically applied to this session
✓ Ready to use in conversations and reports
Patient name cannot be empty
Patient: {name}, {int(age)} years old
Phone: {phone if phone else 'Not provided'}
Conditions: {conditions}
Primary Goal: {goal}
Profile settings have been updated for this session.