|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
from __future__ import annotations |
|
|
from typing import Any, Dict, Callable |
|
|
import json |
|
|
import streamlit as st |
|
|
|
|
|
|
|
|
def _get_st(): |
|
|
try: |
|
|
import streamlit as _st |
|
|
return _st |
|
|
except Exception: |
|
|
return None |
|
|
|
|
|
|
|
|
def _dialog_or_fallback(title: str) -> Callable[[Callable[[], None]], None]: |
|
|
"""Return a callable context renderer that works even if st.dialog() is unsupported.""" |
|
|
st = _get_st() |
|
|
if st is None: |
|
|
|
|
|
def no_op(fn: Callable[[], None]) -> None: |
|
|
fn() |
|
|
return no_op |
|
|
|
|
|
|
|
|
if hasattr(st, "dialog") and callable(getattr(st, "dialog")): |
|
|
def wrapper(fn: Callable[[], None]) -> None: |
|
|
try: |
|
|
with st.dialog(title): |
|
|
fn() |
|
|
except Exception: |
|
|
|
|
|
st.subheader(title) |
|
|
fn() |
|
|
return wrapper |
|
|
|
|
|
|
|
|
def wrapper(fn: Callable[[], None]) -> None: |
|
|
st.subheader(title) |
|
|
with st.expander("Preview", expanded=True): |
|
|
fn() |
|
|
return wrapper |
|
|
|
|
|
|
|
|
def show_consult_note_preview(note_md: str) -> None: |
|
|
"""Render a consult note preview safely (modal or fallback).""" |
|
|
st = _get_st() |
|
|
renderer = _dialog_or_fallback("Consult Note Preview") |
|
|
|
|
|
def body() -> None: |
|
|
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 safely (modal or fallback).""" |
|
|
st = _get_st() |
|
|
renderer = _dialog_or_fallback("837 Claim Preview") |
|
|
|
|
|
def body() -> None: |
|
|
if st is not None: |
|
|
st.code(json.dumps(claim, indent=2), language="json") |
|
|
|
|
|
renderer(body) |
|
|
|
|
|
|