Skip to main content

criteria

Datadog telemetry for the criteria_matching step.

Aggregates one run's evaluations into a single CriteriaMatchingSummaryEvent: per-criterion counts for the flat criteria, per-node counts for every criteria_tree node, and the derived signals that say when a config is too strict to match anyone.

Deliberately not re-exported from bitfount.telemetry's __init__. The steps layer imports that package (see steps/filters/_telemetry.py), so re-exporting a module that imports steps back would close a cycle. Imported directly by its caller instead, the same way bitfount.telemetry.ehr is.

NO PHI leaves this module. Every emitted field is a count, a configured value or a schema name. Observed values are read to compute counts — the near-bound comparison and the near-miss scan both have to look at the data — but nothing derived from a patient's own values is ever placed on the event. In particular no code string is emitted, configured or observed: a near-miss is reported as how many such codes exist, never which.

Module​

Functions​

build_criteria_matching_summary​

def build_criteria_matching_summary(    *,    evaluations: Sequence[CriteriaEvaluation],    cfg: CriteriaMatchConfig,    frame: pd.DataFrame | None = None,    empty_reason: str | None = None,) ‑> CriteriaMatchingSummaryEvent:

Aggregate one run's evaluations into the summary event.

Pure: builds and returns the event without sending it, so the aggregation can be tested without a handler.

Arguments

  • evaluations: Every row's evaluation from this run.
  • cfg: The criteria-matching config the run used.
  • frame: The assembled frame the criteria were evaluated against, for the near-miss scan. None skips that scan, as does the enable_criteria_near_miss_counts setting being off.
  • empty_reason: Why the run had nothing to assess, when it had nothing. Passed through so a run that evaluated nobody is distinguishable from one where nobody qualified — both otherwise report criteria_yes: 0.

Returns The populated CriteriaMatchingSummaryEvent.

report_criteria_matching_summary​

def report_criteria_matching_summary(    *,    evaluations: Sequence[CriteriaEvaluation],    cfg: CriteriaMatchConfig,    frame: pd.DataFrame | None = None,    empty_reason: str | None = None,) ‑> None:

Send the run's CriteriaMatchingSummaryEvent.

Never raises: telemetry must not be able to fail a criteria-matching run.

Arguments

  • evaluations: Every row's evaluation from this run.
  • cfg: The criteria-matching config the run used.
  • frame: The assembled frame, for the near-miss scan; optional.
  • empty_reason: Why the run had nothing to assess; see build_criteria_matching_summary.