Spaces:
Sleeping
Sleeping
File size: 10,385 Bytes
be1b5d2 |
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 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 |
# 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"""
<div style='{styling.get("container", "")}'>
<div style='{styling.get("header", "")}'>
<span style='{styling.get("icon", "")}'>{section_icon}</span>
<strong>{section_title}</strong>
</div>
<div style='{styling.get("content", "")}'>
{html.escape(content) if isinstance(content, str) else content}
</div>
</div>
"""
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"""
<span style='{styling["badge"]}'>
{classification.upper()} FLAG
</span>
"""
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"""
<span style='{styling["badge"]}'>
{urgency_level.upper()}
</span>
"""
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
) |