# enhanced_display_integration.py """ Integration module for Enhanced Results Display Manager. This module provides integration functions to connect the enhanced display components with the existing chat interface and result processing system. Requirements: 1.1, 1.2, 7.1, 7.2 """ from typing import Optional, Dict, Any, List, Tuple import html from src.interface.enhanced_results_display_manager import ( EnhancedResultsDisplayManager, EnhancedDisplayConfig ) from src.interface.visual_separation_manager import VisualSeparationManager from src.interface.provider_summary_formatter import ProviderSummaryFormatter from src.core.provider_summary_generator import ProviderSummary from src.core.spiritual_state import SpiritualAssessment class EnhancedDisplayIntegration: """ Integration class for enhanced display components. Provides a unified interface for integrating enhanced display functionality with the existing chat interface and result processing system. """ def __init__(self, config: Optional[EnhancedDisplayConfig] = None): """ Initialize the enhanced display integration. Args: config: Optional configuration for display formatting """ self.display_manager = EnhancedResultsDisplayManager(config) self.visual_manager = VisualSeparationManager() self.summary_formatter = ProviderSummaryFormatter() def format_chat_response( self, assessment: Optional[SpiritualAssessment] = None, patient_message: Optional[str] = None, provider_summary: Optional[ProviderSummary] = None, show_ai_analysis: bool = True ) -> str: """ Format a complete chat response with enhanced display. Args: assessment: Optional spiritual assessment from AI analysis patient_message: Optional patient message to display provider_summary: Optional provider summary for RED flags show_ai_analysis: Whether to show AI analysis section Returns: Formatted HTML string for display in chat interface Requirements: 1.1, 1.2, 7.1, 7.2 """ # Prepare AI analysis data if available and requested ai_analysis = None if assessment and show_ai_analysis: ai_analysis = { "classification": assessment.state.value.upper(), "indicators": assessment.indicators, "reasoning": assessment.reasoning, "confidence": assessment.confidence } # Format combined results return self.display_manager.format_combined_results( ai_analysis=ai_analysis, patient_message=patient_message, provider_summary=provider_summary ) def format_provider_summary_coherent( self, summary: ProviderSummary ) -> str: """ Format provider summary as coherent paragraph. Args: summary: Provider summary to format Returns: Coherent paragraph formatted summary Requirements: 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 2.8 """ return self.summary_formatter.format_from_provider_summary(summary) def create_section_with_styling( self, content: str, section_type: str, title: Optional[str] = None, icon: Optional[str] = None ) -> str: """ Create a styled section with consistent formatting. Args: content: The content to display section_type: Type of section (ai_analysis, patient_message, provider_summary) title: Optional custom title for the section icon: Optional custom icon for the section Returns: Styled HTML section Requirements: 7.1, 7.2, 7.3 """ # Get appropriate styling if section_type == "ai_analysis": styling = self.visual_manager.create_ai_analysis_styling() default_title = "AI Analysis" default_icon = "🤖" elif section_type == "patient_message": styling = self.visual_manager.create_patient_message_styling() default_title = "Patient Message" default_icon = "💬" elif section_type == "provider_summary": styling = self.visual_manager.create_provider_summary_styling() default_title = "Provider Summary" default_icon = "📋" else: # Default styling styling = { "container": "padding: 10px; margin: 10px 0; border: 1px solid #ddd; border-radius: 4px;" } default_title = "Content" default_icon = "📄" # Use provided title/icon or defaults section_title = title or default_title section_icon = icon or default_icon # Build styled section return f"""
{section_icon} {section_title}
{html.escape(content) if isinstance(content, str) else content}
""" def get_classification_badge(self, classification: str) -> str: """ Get a styled classification badge. Args: classification: The classification level (RED/YELLOW/GREEN) Returns: HTML badge for the classification Requirements: 7.3 """ styling = self.visual_manager.get_classification_styling(classification) return f""" {classification.upper()} FLAG """ def get_urgency_badge(self, urgency_level: str) -> str: """ Get a styled urgency badge. Args: urgency_level: The urgency level (IMMEDIATE/URGENT/STANDARD) Returns: HTML badge for the urgency level Requirements: 7.3 """ styling = self.visual_manager.get_urgency_styling(urgency_level) return f""" {urgency_level.upper()} """ def create_content_separator(self, separator_type: str = "section_break") -> str: """ Create a content separator. Args: separator_type: Type of separator (light, medium, heavy, section_break) Returns: HTML separator Requirements: 7.4, 7.5 """ separators = self.visual_manager.generate_section_separators() return separators.get(separator_type, separators["section_break"]) def format_multiple_sections(self, sections: List[Dict[str, Any]]) -> str: """ Format multiple content sections with consistent styling. Args: sections: List of section dictionaries with 'type' and 'content' keys Returns: Combined HTML with all sections and separators Requirements: 7.1, 7.2, 7.4, 7.5 """ return self.visual_manager.apply_consistent_formatting(sections) # Convenience function for easy integration def create_enhanced_display_integration( config: Optional[EnhancedDisplayConfig] = None ) -> EnhancedDisplayIntegration: """ Create an enhanced display integration instance. Args: config: Optional configuration for display formatting Returns: Configured EnhancedDisplayIntegration instance """ return EnhancedDisplayIntegration(config) # Example usage functions for demonstration def example_format_ai_analysis_result( classification: str, indicators: List[str], reasoning: str, confidence: float = None ) -> str: """ Example function showing how to format AI analysis results. Args: classification: Classification result (RED/YELLOW/GREEN) indicators: List of distress indicators reasoning: AI reasoning for classification confidence: Optional confidence score Returns: Formatted HTML for AI analysis display """ integration = create_enhanced_display_integration() return integration.display_manager.format_ai_analysis_section( classification=classification, indicators=indicators, reasoning=reasoning, confidence=confidence ) def example_format_patient_message(message: str) -> str: """ Example function showing how to format patient messages. Args: message: Patient's message content Returns: Formatted HTML for patient message display """ integration = create_enhanced_display_integration() return integration.display_manager.format_patient_message_section(message) def example_format_complete_response( patient_message: str, classification: str, indicators: List[str], reasoning: str, provider_summary: Optional[ProviderSummary] = None ) -> str: """ Example function showing complete response formatting. Args: patient_message: Patient's message classification: AI classification result indicators: Distress indicators reasoning: AI reasoning provider_summary: Optional provider summary for RED flags Returns: Complete formatted response with all sections """ integration = create_enhanced_display_integration() # Create AI analysis data ai_analysis = { "classification": classification, "indicators": indicators, "reasoning": reasoning, "confidence": 0.85 } return integration.display_manager.format_combined_results( ai_analysis=ai_analysis, patient_message=patient_message, provider_summary=provider_summary )