ehr_refresh
The pod-wide "refresh EHR data" request: recording it and reporting progress.
A refresh request is a rerun request (bitfount.flows.dag.rerun_requests) in
the ehr scope for every lineage. Every EHR lineage treats the rows it fetched
before that moment as stale, so the next sweep refetches them. This module
records the request behind a cooldown and counts how far the refetch has got;
it never touches ehr_data itself.
Module
Functions
ehr_refresh_status
def ehr_refresh_status(cache: CacheProtocol) ‑> EHRRefreshStatus:Report progress against the standing refresh request.
Each patient is counted once. Refetched: the EHR has answered for them
since the request, either with data or with a settled answer such as "no
such patient" (SETTLED_PATIENT_SCOPE_REASONS), whether that answer was
stored or withheld in favour of an older row. Failing: not refetched, and a
fetch since the request failed, whether its failure was stored as the
patient's row (no earlier row to keep) or withheld in favour of the older
row.
Arguments
cache: The pod's background cache.
Returns
Counts only; all zero with no requested_at when none has been made.
latest_ehr_refresh_at
def latest_ehr_refresh_at(cache: CacheProtocol) ‑> datetime | None:Return when the standing refresh request was made, if any.
Only a pod-wide ehr request is a refresh: an all request, or one for a
single lineage, reruns lineages without refetching anyone's EHR data.
Arguments
cache: The pod's background cache.
Returns
The request time (aware UTC), or None when none has been made.
request_ehr_refresh
def request_ehr_refresh( cache: CacheProtocol, *, now: datetime, source: str, requested_by: str | None = None,) ‑> RerunRequestOutcome:Record a pod-wide EHR refresh request, unless one is in its cooldown.
A request that arrives before EHR_REFRESH_COOLDOWN has passed since the
standing one (or at a clock earlier than it) writes nothing and reports the
standing request. Telemetry is emitted either way.
Arguments
cache: The pod's background cache.now: The request time; must be timezone-aware.source: Where the request came from, reported in telemetry (EHR_REFRESH_SOURCE_DESKTOPorEHR_REFRESH_SOURCE_HUB).requested_by: Who made the request, if known; reported in telemetry.
Returns The outcome, carrying the request now in force.
Raises
ValueError: If now is naive.
Classes
EHRRefreshStatus
class EHRRefreshStatus(requested_at: datetime | None, refetched: int, failing: int):How far the standing refresh request has got.
Attributes
requested_at: When it was made;Nonewhen none has been.refetched: Stored EHR rows refetched since then.failing: Patients whose fetch has failed since then.
EHRRefreshOutcome
class EHRRefreshOutcome(applied: bool, requested_at: datetime, lineages_due: int):What a rerun request did.
Attributes
applied: Whether the request was recorded;Falsewhen one inside the cooldown already stood.requested_at: When the request now in force was made, in UTC.lineages_due: Lineages that request covers.