Skip to contents

Builds the same feature row as score_cohort() for a single visit_occurrence_id, but takes the LATEST vital or lab recorded between admission and as_of instead of the admission-day value, for discharge-alert hooks. Utilization history, age and extra_features are as in extract_velocity_features(); validation, imputation, blending and calibration are those of score_cohort(). Mirror of Python omop_etl.encounter.score_encounter.

Usage

score_encounter(
  con,
  visit_occurrence_id,
  bundle,
  as_of = NULL,
  extra_features = NULL,
  on_violation = "raise",
  risk_tiers = NULL,
  concepts = NULL,
  explain = FALSE,
  top_k = 5L
)

Arguments

con

DuckDB DBI connection to the OMOP CDM.

visit_occurrence_id

The encounter to score.

bundle

A model_bundle or a bundle directory (load once and reuse it in a long-running service).

as_of

Only measurements on or before this date count. Default: the earlier of the visit end date and today. CDM 5.4 end dates cannot be NULL, so for a live open stay with a placeholder end date pass as_of = Sys.Date().

extra_features

Optional data.frame keyed by subject_id + cohort_start_date.

on_violation

"raise", "clip" or "nullify".

risk_tiers

Optional list(list(name =, min =), ...) replacing the bundle's tiers (see fit_capacity_thresholds()).

concepts

Overrides for VELOCITY_CONCEPTS.

explain

If TRUE, add top_drivers: the top_k patient-specific risk contributors (feature, name, value, signed impact on the probability), see explain_rows().

top_k

Number of drivers.

Value

A list: visit_occurrence_id, person_id, prob, risk_tier, as_of, features (the values scored), measurement_dates (date of the latest reading behind each lab/vital; absent = none found) and validation (contract summary).