ehr
Telemetry for background EHR query step outcomes.
Module
Functions
report_bcva_derivation
def report_bcva_derivation( *, counts: Mapping[str, int], task_hash: str, non_acuity_codes: Mapping[str, int] | None = None, estimate_codes: Mapping[str, int] | None = None, unparsed_text_shapes: Mapping[str, int] | None = None, ccd_extra_field_shapes: Mapping[str, int] | None = None,) ‑> None:Send a BCVADerivationEvent, warning when any reading went unread.
Sent whenever the run counted anything, which is every run that built a patient record: a site whose EHR served no acuity still sends one, saying why. Never raises.
Arguments
counts: The run's counts, keyed asBCVADerivationEvent's fields.task_hash: The step's partition.non_acuity_codes: The codes of served observations no acuity reading came from, to their count. Only the most frequentBCVA_NON_ACUITY_CODES_LIMITare sent.estimate_codes: The codes estimated readings were taken from, to their count; capped the same way.unparsed_text_shapes: The masked shapes (acuity_text_shape) of the acuity text that would not convert, to their count; capped the same way. Shapes only: raw text must never reach this argument.ccd_extra_field_shapes: The masked shapes of the fields after a CCD reading that no rule reads, and, behindnon_reading:, of the CCD text that stated no reading, to their count; capped the same way. Shapes only, as forunparsed_text_shapes.
report_document_acuity
def report_document_acuity( *, counts: Mapping[str, int], shapes: Mapping[str, int], task_hash: str,) ‑> None:Send a DocumentAcuityEvent, warning when a CCD search went wrong.
Sent whenever any count is non-zero. Warns when a CCD search lost or could not read something, or when a CCD held no acuity although an acuity candidate was found in it. Never raises.
Arguments
counts: The run's counts, keyed asDocumentAcuityEvent's fields.shapes: The masked shapes seen, to their count. Only the most frequentBCVA_NON_ACUITY_CODES_LIMITare sent. Shapes only: raw text must never reach this argument.task_hash: The step's partition.
report_ehr_patient_listing
def report_ehr_patient_listing( *, outcome: str, listing_key: str, patients_listed: int = 0, duration_seconds: float | None = None, page_size: int | None = None, snapshot_age_seconds: float | None = None, error_type: str | None = None, error_classified: str | None = None, phase: str | None = None, listed_so_far: int | None = None,) ‑> None:Send an EHRPatientListingEvent at a severity matching the outcome.
Never raises.
Arguments
outcome: SeeEHRPatientListingEvent.outcome.listing_key: The listing the run served.patients_listed: Distinct patient IDs the run stored.duration_seconds: How long the run took.page_size: Patients requested per page.snapshot_age_seconds: Age of the fresh snapshot a stood-down run found.error_type: The exception class that ended a failed run.error_classified: SeeEHRPatientListingEvent.error_classified.phase: SeeEHRPatientListingEvent.phase.listed_so_far: SeeEHRPatientListingEvent.listed_so_far.
report_ehr_patient_listing_served
def report_ehr_patient_listing_served( *, outcome: str, listing_key: str, phase: str, may_wait: bool = False, reason: str | None = None, waited_seconds: float = 0.0, stale: bool | None = None, truncated_latest: bool | None = None, snapshot_age_seconds: float | None = None, patients_listed: int | None = None,) ‑> None:Send an EHRPatientListingServedEvent.
Unavailable is an error and a truncated newer listing warns. A deferred run is info: it is how every background run on a pod's first listing ends. A stale snapshot is info: serving one is the expected first run after each freshness window lapses. Never raises.
Arguments
outcome:"served","deferred"or"unavailable".listing_key: The listing the run read.phase:"background"or"interactive".may_wait: AlwaysFalsenow that no run waits; kept for the event's schema.reason: Why an unavailable listing was, when it was.waited_seconds: Always0.0, for the same reason.stale: Whether the served snapshot was stale.truncated_latest: Whether a newer listing was cut short.snapshot_age_seconds: Age of the served snapshot.patients_listed: Patients the served snapshot holds.
report_ehr_patient_listing_submitted
def report_ehr_patient_listing_submitted( *, outcome: str, reason: str, listing_key: str, error_type: str | None = None,) ‑> None:Send an EHRPatientListingSubmittedEvent; a failed submission is an error.
Never raises.
Arguments
outcome:"submitted"or"submit_failed".reason:"pre_warm"or"submission".listing_key: The listing submitted.error_type: The exception class of a failed submission.
report_ehr_provider_capability
def report_ehr_provider_capability( *, provider: str | None, backend: str, resource_type: str, capability: str, outcome: EHRProviderCapabilityOutcome, detail: str | None = None,) ‑> None:Send an EHRProviderCapabilityEvent, once per process per finding.
"supported" is info and every other outcome warns. A report repeating an
earlier one's provider, backend, resource type, capability and outcome is
not sent. Never raises.
Arguments
provider: The EHR provider.backend: The EHR backend.resource_type: The resource type searched.capability: What was tried.outcome: What the server did with it.detail: A short reason, such as an HTTP status or the cap.
report_ehr_query_outcome
def report_ehr_query_outcome( *, run_outcome: str, ehr_availability: str | None, records_stored: int, ehr_preflight_error: str | None = None, ehr_preflight_attempts: int | None = None, skipped_total_failure: int, skipped_unidentified: int, skipped_fresh: int, task_hash: str, lookups: EHRLookupSummary | None = None, stored_states: Mapping[str, int] | None = None,) ‑> None:Send an EHRQueryOutcomeEvent at a severity matching the outcome.
Never raises.
Arguments
run_outcome: The step'sEHRRunOutcomevalue.ehr_availability: What the preflight probe found, when one ran.records_stored: EHR rows the run persisted.ehr_preflight_error: Why the preflight's final attempt failed, as exception types and HTTP statuses;Nonewhen it did not fail.ehr_preflight_attempts: Probes the preflight made, when one ran.skipped_total_failure: Patients served from an older row.skipped_unidentified: Patients with no identity to query by.skipped_fresh: Patients whose stored row was still fresh.task_hash: The step's partition.lookups: Per-patient lookup outcomes,Nonewhen the step never reached the lookup loop (EHR not configured, preflight unavailable) or the summary could not be built.stored_states: The partition's patients by stored state (ehr_data_state_counts),Nonewhen they could not be read.
report_ehr_refresh_requested
def report_ehr_refresh_requested( *, applied: bool, lineages_due: int, source: str, requested_by: str | None = None,) ‑> None:Send an EHRRefreshRequestedEvent at info level.
Never raises.
Arguments
applied: Whether the request was recorded rather than absorbed by the cooldown.lineages_due: Lineages with an EHR step the standing request covers.source: Where the request came from, e.g."desktop"or"hub".requested_by: Who made the request, if known.
report_element_reads
def report_element_reads( *, unread: Mapping[tuple[str, str, str], int], recovered: Mapping[tuple[str, str, str], int], task_hash: str, stated_absent: Mapping[tuple[str, str, str], int] | None = None,) ‑> None:Send an EHRElementReadsEvent when a run met an element it could not use.
Sent whenever either mapping holds anything, at warning level when an element went unread and at info when every element was read, some through a fallback. Never raises.
Arguments
unread: Counts by(resource type, element, shape); shapes only, asbitfount.externals.ehr.element_shapesbuilds them.recovered: Counts by(resource type, element, how).task_hash: The step's partition.stated_absent: Counts by(resource type, element, reason), for elements the EHR stated there is no value for.