Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify patient profile loading and usage flow. | |
| Tests: | |
| 1. Profile data is properly loaded from predefined profiles | |
| 2. Patient info is set via set_patient_info() method | |
| 3. Patient info is used in Provider Summary generation | |
| 4. Patient info is used in Spiritual Care Message generation | |
| """ | |
| import sys | |
| import os | |
| # Add project root to path | |
| project_root = os.path.dirname(os.path.abspath(__file__)) | |
| sys.path.insert(0, project_root) | |
| from src.core.simplified_medical_app import SimplifiedMedicalApp | |
| from src.core.provider_summary_generator import ProviderSummary | |
| from src.core.spiritual_state import SpiritualAssessment, SpiritualState | |
| print("=" * 80) | |
| print("PATIENT PROFILE FLOW TEST") | |
| print("=" * 80) | |
| # Step 1: Initialize app (default patient from clinical_background) | |
| print("\n1️⃣ STEP 1: Initialize App") | |
| print("-" * 80) | |
| app = SimplifiedMedicalApp() | |
| print(f"✅ App initialized") | |
| print(f" Default patient from clinical_background: {app.clinical_background.patient_name}") | |
| print(f" Patient info (name): {app.patient_info.get('name')}") | |
| print(f" Patient info (phone): {app.patient_info.get('phone')}") | |
| # Step 2: Load a profile (simulate UI "Load Profile" button) | |
| print("\n2️⃣ STEP 2: Load Profile Data (Simulate UI)") | |
| print("-" * 80) | |
| profile = { | |
| "name": "Maria", | |
| "phone": "(555) 111-2222", | |
| "age": 58, | |
| "conditions": "Type 2 Diabetes, Obesity, Hypertension", | |
| "goal": "Blood sugar control and weight management" | |
| } | |
| print(f"Profile selected: Diabetic Patient") | |
| print(f" Name: {profile['name']}") | |
| print(f" Phone: {profile['phone']}") | |
| print(f" Age: {profile['age']}") | |
| print(f" Conditions: {profile['conditions']}") | |
| # Step 3: Save profile (simulate UI "Save Profile" button) | |
| print("\n3️⃣ STEP 3: Save Profile (Update App Patient Info)") | |
| print("-" * 80) | |
| app.set_patient_info(name=profile['name'], phone=profile['phone']) | |
| print(f"✅ Patient info updated via set_patient_info()") | |
| print(f" app.patient_info['name']: {app.patient_info.get('name')}") | |
| print(f" app.patient_info['phone']: {app.patient_info.get('phone')}") | |
| # Step 4: Generate Provider Summary (simulate RED flag scenario) | |
| print("\n4️⃣ STEP 4: Generate Provider Summary (Check Patient Info Usage)") | |
| print("-" * 80) | |
| # Create a mock assessment | |
| mock_assessment = SpiritualAssessment( | |
| state=SpiritualState.RED, | |
| confidence=0.85, | |
| reasoning="Patient expressing severe hopelessness and loss of meaning", | |
| indicators=["Hopelessness", "Loss of meaning", "Despair"] | |
| ) | |
| # Generate summary | |
| summary = app.provider_summary_generator.generate_summary( | |
| indicators=mock_assessment.indicators, | |
| reasoning=mock_assessment.reasoning, | |
| confidence=mock_assessment.confidence, | |
| patient_name=app.patient_info.get("name") or app.clinical_background.patient_name, | |
| patient_phone=app.patient_info.get("phone"), | |
| triage_questions=[], | |
| triage_responses=[], | |
| conversation_context="Patient discussed feeling overwhelmed with diabetes management" | |
| ) | |
| print(f"✅ Provider Summary generated") | |
| print(f" Patient Name in summary: {summary.patient_name}") | |
| print(f" Patient Phone in summary: {summary.patient_phone}") | |
| print(f" Classification: {summary.classification}") | |
| print(f" Confidence: {summary.confidence:.0%}") | |
| print(f" Severity: {summary.severity_level}") | |
| print(f" Indicators: {', '.join(summary.indicators)}") | |
| # Step 5: Generate Spiritual Care Message (check patient info in message) | |
| print("\n5️⃣ STEP 5: Generate Spiritual Care Message (Check Patient Info Usage)") | |
| print("-" * 80) | |
| care_message = app.provider_summary_generator.generate_spiritual_care_message( | |
| summary=summary, | |
| language="English" | |
| ) | |
| print(f"✅ Spiritual Care Message generated") | |
| print(f" Message length: {len(care_message)} characters") | |
| print(f" Patient name appears: {'Maria' in care_message}") | |
| print(f" Patient phone appears: {'(555) 111-2222' in care_message}") | |
| print("\n📧 MESSAGE PREVIEW (first 400 chars):") | |
| print("-" * 80) | |
| print(care_message[:400]) | |
| if len(care_message) > 400: | |
| print(f"\n... (truncated, {len(care_message) - 400} more characters)") | |
| # Step 6: Test with different profile | |
| print("\n6️⃣ STEP 6: Change Profile and Re-test") | |
| print("-" * 80) | |
| another_profile = { | |
| "name": "Thomas", | |
| "phone": "(555) 789-0123" | |
| } | |
| print(f"New profile: {another_profile['name']}") | |
| app.set_patient_info(name=another_profile['name'], phone=another_profile['phone']) | |
| summary2 = app.provider_summary_generator.generate_summary( | |
| indicators=["Suicidal ideation", "Severe depression"], | |
| reasoning="CRISIS - Patient expressing active suicidal thoughts", | |
| confidence=0.95, | |
| patient_name=app.patient_info.get("name") or app.clinical_background.patient_name, | |
| patient_phone=app.patient_info.get("phone"), | |
| triage_questions=["Are you having thoughts of hurting yourself?"], | |
| triage_responses=["Yes, I have been thinking about it a lot"], | |
| conversation_context="Patient disclosed active suicidal ideation" | |
| ) | |
| print(f"✅ Second summary generated") | |
| print(f" Patient Name: {summary2.patient_name}") | |
| print(f" Patient Phone: {summary2.patient_phone}") | |
| print(f" Urgency Level: {summary2.urgency_level}") | |
| # Final verification | |
| print("\n" + "=" * 80) | |
| print("VERIFICATION RESULTS") | |
| print("=" * 80) | |
| results = [] | |
| results.append(("Profile data loaded correctly", profile['name'] == "Maria")) | |
| results.append(("set_patient_info() updates patient_info", app.patient_info.get('name') == "Thomas")) | |
| results.append(("Patient name used in Provider Summary", summary.patient_name == "Maria")) | |
| results.append(("Patient phone used in Provider Summary", summary.patient_phone == "(555) 111-2222")) | |
| results.append(("Patient info appears in Care Message", "Maria" in care_message)) | |
| results.append(("Profile change works", summary2.patient_name == "Thomas")) | |
| all_passed = all(result[1] for result in results) | |
| for test_name, passed in results: | |
| status = "✅ PASS" if passed else "❌ FAIL" | |
| print(f"{status}: {test_name}") | |
| print("\n" + "=" * 80) | |
| if all_passed: | |
| print("🎉 ALL TESTS PASSED - Patient profile flow working correctly!") | |
| else: | |
| print("⚠️ SOME TESTS FAILED - Review implementation") | |
| print("=" * 80) | |