"""HTML renderers for Dental SOAP. Pure functions over validated HandoffOutput.""" from __future__ import annotations import hashlib import re from datetime import date from html import escape from schema import HandoffOutput DISCLAIMER = ( "This tool organizes patient-reported history. It does not diagnose, choose dental " "treatment, interpret imaging, or replace a licensed dentist." ) HARD_RULE_IDS = { "airway_or_deep_space_infection", "gca_jaw_claudication", "hypochlorite_accident", "neurologic_or_cardiac_mimic", } TIER_LABELS = { "emergency_now": "Emergency now", "urgent_medical": "Urgent medical", "same_day_urgent": "Same-day urgent", "emergency_or_same_day": "Emergency or same-day", "urgent_dental": "Urgent dental", "dentist_discussion": "Discuss with dentist", "none": "No urgent flag", } _TIER_PILL = { "emergency_now": "tier-emergency", "urgent_medical": "tier-emergency", "emergency_or_same_day": "tier-emergency", "same_day_urgent": "tier-urgent", "urgent_dental": "tier-urgent", "dentist_discussion": "tier-discuss", "none": "tier-discuss", } TOOTH_SVG = ( '' ) def tier_label(tier: str) -> str: return TIER_LABELS.get(tier, tier) def tier_pill(tier: str) -> str: cls = _TIER_PILL.get(tier, "tier-discuss") return f'{escape(tier_label(tier))}' def html_list(items: list[str], css_class: str = "") -> str: attr = f' class="{css_class}"' if css_class else "" return f"
Once you build your handoff, every answer is checked against deterministic clinical red-flag rules — computed from what you report, never guessed or hallucinated by the AI model.
{_ARABIC_EXTRA_QUESTIONS_NOTE}
' if untranslated > 0 else "" ) tracker = [_ARABIC_TRACKER[t] for t in output.after_visit_tracker if t in _ARABIC_TRACKER] tracker_html = ( "هذا ملخص لمساعدتك في التحضير للزيارة. لا يقدم تشخيصًا ولا يفسر الأشعة.
{_arabic_narrative(output.chief_concern)}
{_arabic_narrative(output.concise_summary)}
{safety}
' "يرجى طلب الرعاية الطبية فورًا — هذا تنبيه سلامة.
" if language in {"Arabic", "Bilingual"} else "" ) return f"""{escape(first.title)}
{escape(first.patient_message)}
{escape(first.clinician_question)}
Dental SOAP is pausing the normal handoff because a high-risk rule fired. This is not a diagnosis; it is a safety escalation to in-person care.
{escape(output.chief_concern)}
{escape(output.concise_summary)}
No urgent red flag was detected from the current story and structured fields. This does not rule out a dental problem; bring the handoff to a licensed dentist.
These warnings are computed from your answers, not guessed by the model.
", ] for flag in output.red_flags: evidence_items = "".join( f'