Spaces:
Sleeping
Sleeping
| # visual_separation_manager.py | |
| """ | |
| Visual Separation Manager for Enhanced UI Display. | |
| This module provides visual separation and styling management for different | |
| content types in the enhanced results display system. | |
| Requirements: 7.1, 7.2, 7.3, 7.4, 7.5 | |
| """ | |
| from typing import Dict, List, Optional | |
| from dataclasses import dataclass | |
| from enum import Enum | |
| class ContentType(Enum): | |
| """Types of content for visual styling.""" | |
| AI_ANALYSIS = "ai_analysis" | |
| PATIENT_MESSAGE = "patient_message" | |
| PROVIDER_SUMMARY = "provider_summary" | |
| SECTION_SEPARATOR = "section_separator" | |
| CONTENT_DIVIDER = "content_divider" | |
| class VisualStyle: | |
| """Visual styling configuration for content types.""" | |
| background_color: str | |
| border_color: str | |
| border_width: str = "2px" | |
| border_radius: str = "8px" | |
| padding: str = "15px" | |
| margin: str = "10px 0" | |
| text_color: str = "#333333" | |
| icon_color: str = "#666666" | |
| class VisualSeparationManager: | |
| """ | |
| Visual Separation Manager for enhanced content display. | |
| Provides consistent visual styling and separation for different types | |
| of content in the enhanced results display system. | |
| Requirements: 7.1, 7.2, 7.3, 7.4, 7.5 | |
| """ | |
| def __init__(self): | |
| """Initialize the visual separation manager with default styles.""" | |
| self._initialize_default_styles() | |
| def _initialize_default_styles(self) -> None: | |
| """Initialize default visual styles for different content types.""" | |
| self.styles = { | |
| ContentType.AI_ANALYSIS: VisualStyle( | |
| background_color="#fafafa", | |
| border_color="#6c757d", | |
| text_color="#333333", | |
| icon_color="#6c757d" | |
| ), | |
| ContentType.PATIENT_MESSAGE: VisualStyle( | |
| background_color="#f0f7ff", | |
| border_color="#4a90e2", | |
| text_color="#333333", | |
| icon_color="#4a90e2" | |
| ), | |
| ContentType.PROVIDER_SUMMARY: VisualStyle( | |
| background_color="#fff8f0", | |
| border_color="#dc3545", | |
| text_color="#333333", | |
| icon_color="#dc3545" | |
| ) | |
| } | |
| # Classification-specific colors | |
| self.classification_colors = { | |
| "RED": "#dc3545", | |
| "YELLOW": "#ffc107", | |
| "GREEN": "#28a745" | |
| } | |
| # Urgency-specific colors | |
| self.urgency_colors = { | |
| "IMMEDIATE": "#dc3545", | |
| "URGENT": "#fd7e14", | |
| "STANDARD": "#28a745" | |
| } | |
| def create_ai_analysis_styling(self) -> Dict[str, str]: | |
| """ | |
| Create styling configuration for AI analysis sections. | |
| Returns: | |
| Dictionary of CSS styling properties | |
| Requirements: 7.1, 7.3 | |
| """ | |
| style = self.styles[ContentType.AI_ANALYSIS] | |
| return { | |
| "container": f""" | |
| border: {style.border_width} solid {style.border_color}; | |
| border-radius: {style.border_radius}; | |
| padding: {style.padding}; | |
| margin: {style.margin}; | |
| background-color: {style.background_color}; | |
| """, | |
| "header": f""" | |
| display: flex; | |
| align-items: center; | |
| margin-bottom: 10px; | |
| color: {style.text_color}; | |
| font-weight: bold; | |
| """, | |
| "icon": f""" | |
| font-size: 1.2em; | |
| margin-right: 8px; | |
| color: {style.icon_color}; | |
| """, | |
| "content": f""" | |
| color: {style.text_color}; | |
| line-height: 1.4; | |
| """ | |
| } | |
| def create_patient_message_styling(self) -> Dict[str, str]: | |
| """ | |
| Create styling configuration for patient message sections. | |
| Returns: | |
| Dictionary of CSS styling properties | |
| Requirements: 7.2, 7.3 | |
| """ | |
| style = self.styles[ContentType.PATIENT_MESSAGE] | |
| return { | |
| "container": f""" | |
| border: {style.border_width} solid {style.border_color}; | |
| border-radius: {style.border_radius}; | |
| padding: {style.padding}; | |
| margin: {style.margin}; | |
| background-color: {style.background_color}; | |
| """, | |
| "header": f""" | |
| display: flex; | |
| align-items: center; | |
| margin-bottom: 10px; | |
| color: {style.border_color}; | |
| font-weight: bold; | |
| """, | |
| "icon": f""" | |
| font-size: 1.2em; | |
| margin-right: 8px; | |
| color: {style.icon_color}; | |
| """, | |
| "message_box": f""" | |
| padding: 8px; | |
| background-color: white; | |
| border-radius: 4px; | |
| border-left: 4px solid {style.border_color}; | |
| color: {style.text_color}; | |
| """ | |
| } | |
| def create_provider_summary_styling(self) -> Dict[str, str]: | |
| """ | |
| Create styling configuration for provider summary sections. | |
| Returns: | |
| Dictionary of CSS styling properties | |
| Requirements: 7.1, 7.2, 7.3 | |
| """ | |
| style = self.styles[ContentType.PROVIDER_SUMMARY] | |
| return { | |
| "container": f""" | |
| border: {style.border_width} solid {style.border_color}; | |
| border-radius: {style.border_radius}; | |
| padding: {style.padding}; | |
| margin: {style.margin}; | |
| background-color: {style.background_color}; | |
| """, | |
| "header": f""" | |
| display: flex; | |
| align-items: center; | |
| margin-bottom: 10px; | |
| color: {style.border_color}; | |
| font-weight: bold; | |
| """, | |
| "icon": f""" | |
| font-size: 1.2em; | |
| margin-right: 8px; | |
| color: {style.icon_color}; | |
| """, | |
| "info_box": f""" | |
| margin: 10px 0; | |
| padding: 8px; | |
| background-color: #f8f9fa; | |
| border-radius: 4px; | |
| """, | |
| "urgency_box": f""" | |
| margin: 5px 0; | |
| padding: 8px; | |
| background-color: #fff3cd; | |
| border-radius: 4px; | |
| border-left: 4px solid {style.border_color}; | |
| """ | |
| } | |
| def generate_section_separators(self) -> Dict[str, str]: | |
| """ | |
| Generate different types of section separators. | |
| Returns: | |
| Dictionary of separator HTML strings | |
| Requirements: 7.4, 7.5 | |
| """ | |
| return { | |
| "light": """ | |
| <div style='margin: 15px 0; border-top: 1px solid #e0e0e0;'></div> | |
| """, | |
| "medium": """ | |
| <div style='margin: 20px 0; text-align: center;'> | |
| <hr style='border: none; border-top: 2px solid #d0d0d0; width: 80%; margin: 0 auto;'> | |
| </div> | |
| """, | |
| "heavy": """ | |
| <div style='margin: 30px 0; text-align: center;'> | |
| <div style='display: inline-block; padding: 8px 16px; background-color: #f0f0f0; border-radius: 20px; color: #666; font-size: 0.8em;'> | |
| ● ● ● | |
| </div> | |
| </div> | |
| """, | |
| "section_break": """ | |
| <div style='margin: 25px 0; text-align: center;'> | |
| <hr style='border: none; border-top: 3px solid #ccc; width: 60%; margin: 0 auto;'> | |
| <div style='margin: 10px 0; color: #666; font-size: 0.9em; font-weight: bold;'>---</div> | |
| </div> | |
| """ | |
| } | |
| def apply_consistent_formatting(self, sections: List[Dict[str, str]]) -> str: | |
| """ | |
| Apply consistent formatting to multiple content sections. | |
| Args: | |
| sections: List of section dictionaries with 'type' and 'content' keys | |
| Returns: | |
| Combined HTML with consistent formatting and separation | |
| Requirements: 7.1, 7.2, 7.4, 7.5 | |
| """ | |
| if not sections: | |
| return "<div style='padding: 20px; text-align: center; color: #666;'>No content to display</div>" | |
| formatted_sections = [] | |
| separators = self.generate_section_separators() | |
| for i, section in enumerate(sections): | |
| section_type = section.get('type', 'unknown') | |
| content = section.get('content', '') | |
| # Apply appropriate styling based on section type | |
| if section_type == 'ai_analysis': | |
| styling = self.create_ai_analysis_styling() | |
| elif section_type == 'patient_message': | |
| styling = self.create_patient_message_styling() | |
| elif section_type == 'provider_summary': | |
| styling = self.create_provider_summary_styling() | |
| else: | |
| # Default styling for unknown types | |
| styling = { | |
| "container": "padding: 10px; margin: 10px 0; border: 1px solid #ddd; border-radius: 4px;" | |
| } | |
| # Wrap content in styled container | |
| formatted_content = f""" | |
| <div style='{styling.get("container", "")}'> | |
| {content} | |
| </div> | |
| """ | |
| formatted_sections.append(formatted_content) | |
| # Add separator between sections (but not after the last one) | |
| if i < len(sections) - 1: | |
| formatted_sections.append(separators["section_break"]) | |
| return "".join(formatted_sections) | |
| def get_classification_styling(self, classification: str) -> Dict[str, str]: | |
| """ | |
| Get styling specific to a classification level. | |
| Args: | |
| classification: The classification level (RED/YELLOW/GREEN) | |
| Returns: | |
| Dictionary of classification-specific styling | |
| Requirements: 7.3 | |
| """ | |
| color = self.classification_colors.get(classification.upper(), "#666666") | |
| return { | |
| "badge": f""" | |
| display: inline-block; | |
| padding: 4px 8px; | |
| background-color: {color}; | |
| color: white; | |
| border-radius: 12px; | |
| font-size: 0.8em; | |
| font-weight: bold; | |
| text-transform: uppercase; | |
| """, | |
| "border": f""" | |
| border-color: {color}; | |
| """, | |
| "text": f""" | |
| color: {color}; | |
| """, | |
| "background": f""" | |
| background-color: {color}15; | |
| """ | |
| } | |
| def get_urgency_styling(self, urgency_level: str) -> Dict[str, str]: | |
| """ | |
| Get styling specific to an urgency level. | |
| Args: | |
| urgency_level: The urgency level (IMMEDIATE/URGENT/STANDARD) | |
| Returns: | |
| Dictionary of urgency-specific styling | |
| Requirements: 7.3 | |
| """ | |
| color = self.urgency_colors.get(urgency_level.upper(), "#666666") | |
| return { | |
| "badge": f""" | |
| display: inline-block; | |
| padding: 4px 8px; | |
| background-color: {color}; | |
| color: white; | |
| border-radius: 12px; | |
| font-size: 0.8em; | |
| font-weight: bold; | |
| text-transform: uppercase; | |
| """, | |
| "border": f""" | |
| border-color: {color}; | |
| """, | |
| "text": f""" | |
| color: {color}; | |
| """, | |
| "accent": f""" | |
| border-left: 4px solid {color}; | |
| """ | |
| } | |
| def create_icon_styling(self, content_type: ContentType) -> str: | |
| """ | |
| Create icon styling for different content types. | |
| Args: | |
| content_type: The type of content for icon styling | |
| Returns: | |
| CSS styling string for icons | |
| Requirements: 7.3, 7.5 | |
| """ | |
| base_style = "font-size: 1.2em; margin-right: 8px;" | |
| if content_type in self.styles: | |
| color = self.styles[content_type].icon_color | |
| return f"{base_style} color: {color};" | |
| return f"{base_style} color: #666666;" |