Skip to main content

ehr

Whether the pod can reach its EHR, checked at start and on a ticker.

Module​

Functions​

attach_smart_backend_auth_if_missing​

def attach_smart_backend_auth_if_missing(    cfg: SMARTBackendEHRConfig, hub: BitfountHub,) ‑> SMARTBackendAuth:

Ensure SMART Backend auth and a shared refresh handler exist on cfg.

Classes​

EHRConnectivity​

class EHRConnectivity(ctx: PodContext, *, pod_vitals: _PodVitals):

The pod's EHR connection: token checks, FHIR liveness and cached status.

Variables​

  • cached_connected : bool - The last connectivity result, without checking again.
  • is_configured : bool - Check if EHR configuration is present.

    Returns: True if ehr_config is set, False otherwise.

  • is_connected : bool - Check if EHR is connected and accessible.

    This performs a multi-level check for EHRs requiring authentication:

  1. Verifies EHR secrets are configured (must be RefreshableJWT)
  2. Attempts to reach the FHIR endpoint (if ehr_config is available)
  3. Falls back to checking token expiry if FHIR check fails

For unauthenticated EHRs (such as FHIR Candle without SMART Launcher, or other internal/testing EHRs): the path for EHRs without credentials is handled separately from the main authenticated flow and the allow_no_ehr_secrets configuration must be True to enable this. If the secrets are None, or EHR secrets are missing or not RefreshableJWT, this method calls _check_fhir_endpoint_reachable_without_auth() (GET to the FHIR /metadata endpoint) and returns its result.

Returns: True if EHR connection is verified, False otherwise.

  • secrets : RefreshableJWT | None - The pod's externally-supplied EHR JWT secrets, if any.

    SMARTBackendEHRConfig deliberately returns None: it carries its own auth on the config object, and its consumers read that instead.

    Returns: The EHR RefreshableJWT, or None when none is configured, the configured secrets are of another type, or the config is SMART Backend.

Methods​


connectivity_tick​

async def connectivity_tick(self) ‑> None:

Check EHR connectivity and update cached status.

While the app leaves EHR token requests unanswered the check backs off, doubling its wait each time up to _UNANSWERED_BACKOFF_CAP_SECONDS; ticks that fall inside the wait are skipped. An app that answers that it has no EHR configured stands the check down entirely.

Raises

  • EHRTokenError: On an unrecoverable EHR token error, including the app having no EHR configured, to stop the ticker.
  • EHROrchestratorError: If the orchestrator's EHR token endpoint keeps failing, to stop the ticker.

run_initial_check​

async def run_initial_check(self) ‑> None:

Run a one-off EHR connectivity check at startup with a short timeout.

Sets _cached_ehr_connected. On timeout or exception we set it to False so startup continues; the background EHR thread will update it later.