# src/modal_templates.py from __future__ import annotations """Modal helpers for Streamlit previews with safe fallbacks.""" from typing import Callable, Dict, Any, Optional def _get_st(): try: import streamlit as st # type: ignore return st except Exception: return None def _dialog_or_fallback(title: str): """Return a callable that renders within st.dialog if available; else use an expander; else no-op.""" st = _get_st() if st is None: def no_op(body_fn: Callable[[], None]): return body_fn() return no_op if hasattr(st, "dialog"): def wrapper(body_fn: Callable[[], None]): with st.dialog(title): body_fn() return wrapper def wrapper(body_fn: Callable[[], None]): st.subheader(title) with st.expander("Preview", expanded=True): body_fn() return wrapper def show_consult_note_preview(note_md: str) -> None: """Render a consult note preview in a modal (or fallback).""" st = _get_st() renderer = _dialog_or_fallback("Consult Note Preview") def body(): if st is not None: st.markdown(note_md) renderer(body) def show_837_claim_preview(claim: Dict[str, Any]) -> None: """Render a claim (JSON) preview in a modal (or fallback).""" import json st = _get_st() renderer = _dialog_or_fallback("837 Claim Preview") def body(): if st is not None: st.code(json.dumps(claim, indent=2), language="json") renderer(body)