Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Integration Demo for UI Classification Improvements. | |
| Demonstrates the complete workflow from classification to display to verification. | |
| This shows how all components work together in the enhanced system. | |
| """ | |
| import sys | |
| import os | |
| sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'src')) | |
| from interface.enhanced_results_display_manager import EnhancedResultsDisplayManager | |
| from core.provider_summary_generator import ProviderSummary, ProviderSummaryGenerator | |
| from core.improved_classification_prompt_manager import ImprovedClassificationPromptManager | |
| from core.conversation_logger import ConversationLogger | |
| from core.spiritual_state import SpiritualState, SpiritualAssessment | |
| def main(): | |
| """Run integration demo.""" | |
| print("π UI Classification Improvements Integration Demo") | |
| print("=" * 60) | |
| # Initialize components | |
| print("\n1. Initializing enhanced components...") | |
| display_manager = EnhancedResultsDisplayManager() | |
| summary_generator = ProviderSummaryGenerator() | |
| classification_manager = ImprovedClassificationPromptManager() | |
| print(" β Enhanced Results Display Manager") | |
| print(" β Provider Summary Generator") | |
| print(" β Improved Classification Prompt Manager") | |
| # Demonstrate enhanced classification | |
| print("\n2. Testing enhanced classification criteria...") | |
| # Test explicit red indicators | |
| red_indicators = classification_manager.get_explicit_red_indicators() | |
| print(f" π Explicit RED indicators ({len(red_indicators)}):") | |
| for indicator in red_indicators: | |
| print(f" β’ {indicator}") | |
| # Test updated red flag definition | |
| red_definition = classification_manager.get_updated_red_flag_definition() | |
| print(f"\n π΄ Updated RED flag definition:") | |
| print(f" {red_definition}") | |
| # Demonstrate classification validation | |
| print("\n3. Testing classification validation...") | |
| # Valid classification | |
| valid_result = classification_manager.create_classification_result( | |
| classification="red", | |
| confidence=0.85, | |
| indicators=["doubt about meaning of suffering"], | |
| reasoning="Patient questioning meaning of suffering - explicit red indicator", | |
| red_flag_indicators=["doubt about meaning of suffering"] | |
| ) | |
| print(f" β Valid classification: {valid_result.classification} (valid: {valid_result.is_valid})") | |
| # Invalid classification that gets corrected | |
| invalid_result = classification_manager.create_classification_result( | |
| classification="invalid", | |
| confidence=2.0, | |
| indicators=[], | |
| reasoning="" | |
| ) | |
| print(f" π§ Corrected classification: {invalid_result.classification} (valid: {invalid_result.is_valid})") | |
| # Demonstrate enhanced display formatting | |
| print("\n4. Testing enhanced display formatting...") | |
| # Create test provider summary | |
| test_summary = ProviderSummary( | |
| patient_name="Demo Patient", | |
| patient_phone="555-0123", | |
| classification="RED", | |
| confidence=0.85, | |
| indicators=["loss of meaning", "spiritual distress", "questioning faith"], | |
| reasoning="Patient expressing significant spiritual concerns and loss of meaning", | |
| severity_level="HIGH", | |
| urgency_level="IMMEDIATE", | |
| situation_description="Patient experiencing existential crisis following medical diagnosis", | |
| recommended_actions=[ | |
| "Contact patient within 2-4 hours", | |
| "Assess immediate safety and support needs", | |
| "Provide spiritual care resources" | |
| ], | |
| medical_context={ | |
| "age": 45, | |
| "gender": "individual", | |
| "conditions": ["chronic illness", "recent diagnosis"] | |
| } | |
| ) | |
| # Format AI analysis section | |
| ai_analysis_html = display_manager.format_ai_analysis_section( | |
| classification="RED", | |
| indicators=test_summary.indicators, | |
| reasoning=test_summary.reasoning, | |
| confidence=test_summary.confidence | |
| ) | |
| print(" β AI Analysis section formatted") | |
| print(f" Length: {len(ai_analysis_html)} characters") | |
| # Format patient message section | |
| patient_message_html = display_manager.format_patient_message_section( | |
| "I just don't see the point in anything anymore. My life feels meaningless since my diagnosis." | |
| ) | |
| print(" β Patient Message section formatted") | |
| print(f" Length: {len(patient_message_html)} characters") | |
| # Format provider summary section | |
| provider_summary_html = display_manager.format_provider_summary_section(test_summary) | |
| print(" β Provider Summary section formatted") | |
| print(f" Length: {len(provider_summary_html)} characters") | |
| # Test coherent paragraph formatting | |
| print("\n5. Testing coherent paragraph formatting...") | |
| coherent_paragraph = summary_generator.format_coherent_paragraph(test_summary) | |
| print(" β Coherent paragraph generated") | |
| print(f" Length: {len(coherent_paragraph)} characters") | |
| print(f" Preview: {coherent_paragraph[:100]}...") | |
| # Test combined results | |
| print("\n6. Testing combined results formatting...") | |
| combined_html = display_manager.format_combined_results( | |
| ai_analysis={ | |
| 'classification': 'RED', | |
| 'indicators': test_summary.indicators, | |
| 'reasoning': test_summary.reasoning, | |
| 'confidence': test_summary.confidence | |
| }, | |
| patient_message="I just don't see the point in anything anymore. My life feels meaningless since my diagnosis.", | |
| provider_summary=test_summary | |
| ) | |
| print(" β Combined results formatted") | |
| print(f" Length: {len(combined_html)} characters") | |
| # Test conversation logging integration | |
| print("\n7. Testing conversation logging integration...") | |
| logger = ConversationLogger(patient_name="Demo Patient") | |
| # Log test conversation | |
| assessment = SpiritualAssessment( | |
| state=SpiritualState.RED, | |
| confidence=0.85, | |
| indicators=["loss of meaning", "spiritual distress"], | |
| reasoning="Patient expressing significant spiritual concerns" | |
| ) | |
| logger.log_exchange( | |
| "I just don't see the point in anything anymore", | |
| "I understand this is a very difficult time for you", | |
| assessment | |
| ) | |
| print(f" β Conversation logged: {len(logger.entries)} entries") | |
| # Test error handling | |
| print("\n8. Testing error handling and recovery...") | |
| # Create problematic summary | |
| problematic_summary = ProviderSummary( | |
| patient_name="[Patient Name]", # Placeholder | |
| patient_phone="[Phone Number]", # Placeholder | |
| classification="RED", | |
| confidence=1.5, # Invalid confidence | |
| reasoning="", # Empty reasoning | |
| indicators=[] # No indicators | |
| ) | |
| # Display manager should handle this gracefully | |
| error_display = display_manager.format_provider_summary_section(problematic_summary) | |
| print(" β Error handling works - graceful degradation") | |
| print(f" Error display length: {len(error_display)} characters") | |
| # Summary | |
| print("\n" + "=" * 60) | |
| print("π INTEGRATION DEMO COMPLETED SUCCESSFULLY!") | |
| print("\nπ Demonstrated Features:") | |
| print(" β Enhanced classification with explicit red indicators") | |
| print(" β Updated red flag definition and validation") | |
| print(" β Enhanced display formatting with visual separation") | |
| print(" β Coherent paragraph formatting for Medical Brain compatibility") | |
| print(" β Combined results with proper section separation") | |
| print(" β Conversation logging integration") | |
| print(" β Error handling and graceful degradation") | |
| print("\nπ All UI Classification Improvements are working correctly!") | |
| print(" Ready for production use in the medical assistant system.") | |
| if __name__ == "__main__": | |
| main() |