"""HTML builders for Clarke frontend screens.""" from __future__ import annotations from datetime import date from html import escape from typing import Any def _open_patient_click_js(index: int) -> str: """Return debug-friendly JS snippet for dashboard patient button clicks. Args: index (int): Dashboard patient-card index. Returns: str: Inline JS IIFE for HTML onclick attributes. """ return ( "(function(){" f"var el=document.getElementById('hidden-select-{index}');" "if(!el){return;}" "if(el.tagName==='BUTTON'){el.click();}else{" "var btn=el.querySelector('button');" "if(btn){btn.click();}" "}" "})()" ) def build_global_style_block() -> str: """Return the global CSS block injected via gr.HTML. Args: None: This function has no runtime inputs. Returns: str: Complete style tag with animation keyframes and resets. """ return """ """ def build_dashboard_html(clinic_payload: dict[str, Any], completed_patients: list[int] | None = None) -> str: """Render the S1 dashboard markup with top gradient and white card area. Args: clinic_payload (dict[str, Any]): Clinic roster and clinician metadata. Returns: str: Complete HTML markup for the dashboard screen. """ clinician = clinic_payload.get("clinician", {}) _today = date.today().strftime("%d %B %Y") completed_lookup = set(completed_patients or []) cards: list[str] = [] for index, patient in enumerate(clinic_payload.get("patients", [])): click_js = _open_patient_click_js(index) completed = index in completed_lookup card_style = "opacity:0.55;" if completed else "" hover_class = "completed-patient-card" if completed else "" badge = "
✓ Complete
" if completed else "" button_markup = ( f"" if completed else f"" ) cards.append( f"""
{badge}
{escape(str(patient.get('time', '--:--')))}
{escape(str(patient.get('name', 'Unknown patient')))}
{escape(str(patient.get('age', '')))} · {escape(str(patient.get('sex', '')))}
{escape(str(patient.get('summary', '')))}
{button_markup}
""" ) return f"""
Clarke
🔍
{escape(str(clinician.get('name', 'Dr. Sarah Chen')))} {escape(str(clinician.get('specialty', 'General Practice')))} — {escape(_today)}
{''.join(cards)}
""" def build_status_badge_html(label: str, color: str) -> str: """Build a rounded status badge. Args: label (str): Badge text. color (str): Accent color hex. Returns: str: Badge HTML markup. """ return f"
{escape(label)}
" class _RenderedFragment: """Lightweight rendered fragment container for legacy test compatibility.""" def __init__(self, value: str) -> None: """Store rendered HTML fragment value.""" self.value = value def build_patient_card(patient: dict[str, Any]) -> _RenderedFragment: """Build a legacy patient card fragment for tests and compatibility helpers.""" markup = f"
{escape(str(patient.get('name', 'Unknown patient')))}
" return _RenderedFragment(markup) def build_status_badge(status: str) -> _RenderedFragment: """Build a legacy status badge fragment for tests and compatibility helpers.""" css_class = "clarke-badge-review" if status == "ready" else "clarke-badge" return _RenderedFragment(f"{escape(status)}")