Spaces:
Sleeping
Sleeping
File size: 12,478 Bytes
17f3ad3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
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",
""
)
|