Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| # enhanced_display_demo.py | |
| """ | |
| Demonstration of Enhanced Results Display Manager functionality. | |
| This script shows how to use the enhanced display components to format | |
| different types of content with improved visual separation and styling. | |
| Requirements: 1.1, 1.2, 7.1, 7.2 | |
| """ | |
| import sys | |
| import os | |
| # Add project root to Python path | |
| project_root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | |
| if project_root not in sys.path: | |
| sys.path.insert(0, project_root) | |
| from src.interface.enhanced_display_integration import ( | |
| create_enhanced_display_integration, | |
| example_format_ai_analysis_result, | |
| example_format_patient_message, | |
| example_format_complete_response | |
| ) | |
| from src.interface.enhanced_results_display_manager import EnhancedDisplayConfig | |
| from src.interface.provider_summary_formatter import PatientData, ClassificationData | |
| from unittest.mock import Mock | |
| from src.core.provider_summary_generator import ProviderSummary | |
| def demo_ai_analysis_formatting(): | |
| """Demonstrate AI analysis section formatting.""" | |
| print("=" * 60) | |
| print("AI ANALYSIS SECTION FORMATTING DEMO") | |
| print("=" * 60) | |
| # Example 1: RED flag analysis | |
| red_result = example_format_ai_analysis_result( | |
| classification="RED", | |
| indicators=["Loss of meaning and purpose", "Spiritual crisis", "Hopelessness"], | |
| reasoning="Patient expressed deep existential concerns and loss of faith, indicating active spiritual distress requiring immediate attention.", | |
| confidence=0.92 | |
| ) | |
| print("RED Flag Analysis:") | |
| print(red_result) | |
| print("\n" + "-" * 40 + "\n") | |
| # Example 2: YELLOW flag analysis | |
| yellow_result = example_format_ai_analysis_result( | |
| classification="YELLOW", | |
| indicators=["Mild distress", "Uncertainty"], | |
| reasoning="Patient shows some signs of spiritual questioning but unclear if it constitutes distress.", | |
| confidence=0.65 | |
| ) | |
| print("YELLOW Flag Analysis:") | |
| print(yellow_result) | |
| print("\n" + "-" * 40 + "\n") | |
| # Example 3: GREEN flag analysis | |
| green_result = example_format_ai_analysis_result( | |
| classification="GREEN", | |
| indicators=[], | |
| reasoning="Normal medical conversation with no spiritual distress indicators detected." | |
| ) | |
| print("GREEN Flag Analysis:") | |
| print(green_result) | |
| def demo_patient_message_formatting(): | |
| """Demonstrate patient message section formatting.""" | |
| print("\n" + "=" * 60) | |
| print("PATIENT MESSAGE SECTION FORMATTING DEMO") | |
| print("=" * 60) | |
| # Example messages | |
| messages = [ | |
| "I'm feeling lost and don't know what to believe anymore.", | |
| "The doctors say I'm getting better, but I feel empty inside.", | |
| "I just want to understand why this happened to me.", | |
| "Thank you for listening. It helps to talk about these things." | |
| ] | |
| for i, message in enumerate(messages, 1): | |
| print(f"Patient Message {i}:") | |
| result = example_format_patient_message(message) | |
| print(result) | |
| print("\n" + "-" * 40 + "\n") | |
| def demo_provider_summary_formatting(): | |
| """Demonstrate provider summary formatting.""" | |
| print("\n" + "=" * 60) | |
| print("PROVIDER SUMMARY FORMATTING DEMO") | |
| print("=" * 60) | |
| integration = create_enhanced_display_integration() | |
| # Create sample patient data | |
| patient_data = PatientData( | |
| name="Sarah Johnson", | |
| age=34, | |
| gender="female", | |
| phone="(555) 234-5678", | |
| medical_history=["Breast cancer", "Chemotherapy treatment", "Anxiety"], | |
| expressed_concerns=["Fear of death", "Loss of faith", "Family burden"], | |
| patient_input="I don't understand why God would let this happen to me and my children" | |
| ) | |
| classification_data = ClassificationData( | |
| classification="RED", | |
| spiritual_concern_type="existential crisis related to illness", | |
| consent_given=True | |
| ) | |
| # Format as coherent paragraph | |
| coherent_summary = integration.summary_formatter.format_enhanced_summary( | |
| patient_data, classification_data | |
| ) | |
| print("Medical Brain Summary:") | |
| print(coherent_summary) | |
| print("\n" + "-" * 40 + "\n") | |
| # Create mock provider summary for enhanced display | |
| mock_summary = Mock(spec=ProviderSummary) | |
| mock_summary.patient_name = "Sarah Johnson" | |
| mock_summary.patient_phone = "(555) 234-5678" | |
| mock_summary.urgency_level = "URGENT" | |
| mock_summary.follow_up_timeline = "Within 24 hours" | |
| mock_summary.situation_description = "Patient experiencing existential crisis related to cancer diagnosis" | |
| mock_summary.indicators = ["Fear of death", "Loss of faith", "Family burden"] | |
| # Format as enhanced display section | |
| enhanced_display = integration.display_manager.format_provider_summary_section(mock_summary) | |
| print("Enhanced Display Summary:") | |
| print(enhanced_display) | |
| def demo_complete_response_formatting(): | |
| """Demonstrate complete response formatting with all sections.""" | |
| print("\n" + "=" * 60) | |
| print("COMPLETE RESPONSE FORMATTING DEMO") | |
| print("=" * 60) | |
| # Create mock provider summary | |
| mock_summary = Mock(spec=ProviderSummary) | |
| mock_summary.patient_name = "Michael Chen" | |
| mock_summary.patient_phone = "(555) 345-6789" | |
| mock_summary.urgency_level = "IMMEDIATE" | |
| mock_summary.follow_up_timeline = "Immediately" | |
| mock_summary.situation_description = "Patient expressing suicidal ideation and spiritual crisis" | |
| mock_summary.indicators = ["Suicidal thoughts", "Loss of hope", "Spiritual abandonment"] | |
| # Format complete response | |
| complete_response = example_format_complete_response( | |
| patient_message="I just can't take this anymore. What's the point of going on?", | |
| classification="RED", | |
| indicators=["Suicidal ideation", "Hopelessness", "Spiritual crisis"], | |
| reasoning="Patient expressing clear suicidal ideation combined with spiritual distress. Immediate intervention required.", | |
| provider_summary=mock_summary | |
| ) | |
| print("Complete Response with All Sections:") | |
| print(complete_response) | |
| def demo_visual_separation(): | |
| """Demonstrate visual separation and styling features.""" | |
| print("\n" + "=" * 60) | |
| print("VISUAL SEPARATION AND STYLING DEMO") | |
| print("=" * 60) | |
| integration = create_enhanced_display_integration() | |
| # Demonstrate classification badges | |
| print("Classification Badges:") | |
| red_badge = integration.get_classification_badge("RED") | |
| yellow_badge = integration.get_classification_badge("YELLOW") | |
| green_badge = integration.get_classification_badge("GREEN") | |
| print(f"RED: {red_badge}") | |
| print(f"YELLOW: {yellow_badge}") | |
| print(f"GREEN: {green_badge}") | |
| print("\n" + "-" * 40 + "\n") | |
| # Demonstrate urgency badges | |
| print("Urgency Badges:") | |
| immediate_badge = integration.get_urgency_badge("IMMEDIATE") | |
| urgent_badge = integration.get_urgency_badge("URGENT") | |
| standard_badge = integration.get_urgency_badge("STANDARD") | |
| print(f"IMMEDIATE: {immediate_badge}") | |
| print(f"URGENT: {urgent_badge}") | |
| print(f"STANDARD: {standard_badge}") | |
| print("\n" + "-" * 40 + "\n") | |
| # Demonstrate separators | |
| print("Content Separators:") | |
| separators = ["light", "medium", "heavy", "section_break"] | |
| for sep_type in separators: | |
| separator = integration.create_content_separator(sep_type) | |
| print(f"{sep_type.upper()} separator:") | |
| print(separator) | |
| print() | |
| def demo_custom_configuration(): | |
| """Demonstrate custom configuration options.""" | |
| print("\n" + "=" * 60) | |
| print("CUSTOM CONFIGURATION DEMO") | |
| print("=" * 60) | |
| # Create custom configuration | |
| custom_config = EnhancedDisplayConfig( | |
| ai_analysis_icon="🔍", | |
| patient_message_icon="📝", | |
| provider_summary_icon="🏥", | |
| section_separator="***", | |
| use_color_coding=True, | |
| classification_colors={ | |
| "RED": "#cc0000", | |
| "YELLOW": "#ff9900", | |
| "GREEN": "#009900" | |
| } | |
| ) | |
| # Create integration with custom config | |
| custom_integration = create_enhanced_display_integration(custom_config) | |
| # Format example with custom styling | |
| custom_result = custom_integration.display_manager.format_ai_analysis_section( | |
| classification="RED", | |
| indicators=["Custom styling example"], | |
| reasoning="This demonstrates custom configuration options.", | |
| confidence=0.95 | |
| ) | |
| print("Custom Configuration Result:") | |
| print(custom_result) | |
| def main(): | |
| """Run all demonstration functions.""" | |
| print("ENHANCED RESULTS DISPLAY MANAGER DEMONSTRATION") | |
| print("=" * 60) | |
| print("This demo shows the enhanced display components in action.") | |
| print("Note: HTML output is shown as raw HTML for demonstration purposes.") | |
| print("In a real application, this would be rendered in a web browser.") | |
| try: | |
| demo_ai_analysis_formatting() | |
| demo_patient_message_formatting() | |
| demo_provider_summary_formatting() | |
| demo_complete_response_formatting() | |
| demo_visual_separation() | |
| demo_custom_configuration() | |
| print("\n" + "=" * 60) | |
| print("DEMONSTRATION COMPLETE") | |
| print("=" * 60) | |
| print("All enhanced display components are working correctly!") | |
| except Exception as e: | |
| print(f"\nError during demonstration: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| return 1 | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) |