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, with one exception. 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 single patient's own values is placed on the event, and no configured code string is emitted.

The exception is the near-miss codes: cohort codes in a configured code's category that the list does not hold. Each is named only when at least criteria_near_miss_min_patients distinct patients carry it, and only on a frame with a patient-id column to count them by. Nothing on the event is per patient, so a code that many share cannot be traced to any one of them. A rarer code is counted, never named.

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.