Skip to contents

Labs named in acute_lab_subset (lactate, troponin, blood gases, ...) are only meaningful during the stay, so they are always drawn from [cohort_start_date, cohort_end_date]. The remaining labs (HbA1c, creatinine, ...) use routine_window so a value measured shortly before admission is not lost. Both blocks use the same selection_rule and are returned side by side, one row per (subject_id, cohort_start_date). Mirror of omop_etl.features.extract_inpatient_labs in Python.

Usage

extract_inpatient_labs(
  con,
  cohort_table = "cohort",
  cohort_id = NULL,
  lab_specs = NULL,
  selection_rule = "last_in_stay",
  acute_lab_subset = NULL,
  routine_window = "lookback",
  routine_lookback_days = 365,
  outlier_bounds = NULL,
  format = "df"
)

Arguments

con, cohort_table, cohort_id

As in extract_measurements() (the cohort needs subject_id, cohort_start_date and cohort_end_date).

lab_specs

Named list lab_name -> LOINC codes or concept ids. Default: CORE_14_LAB_PANEL plus ACUTE_LAB_PANEL.

selection_rule

"last_in_stay" (closest to discharge), "first_in_stay", "mean", "median", "min", "max" or "worst" (direction per lab in WORST_LAB_DIRECTION).

acute_lab_subset

Names in lab_specs treated as acute (stay window only). NULL (default): the ACUTE_LAB_PANEL names present in lab_specs. An explicit vector must be a subset of lab_specs.

routine_window

Window for the non-acute labs: "stay", "lookback" (the routine_lookback_days before admission, excluding the stay) or "all" (everything up to discharge).

routine_lookback_days

Days for the "lookback" window.

outlier_bounds

Named list lab_name -> c(low, high); NULL uses the physiologic bounds used by extract_standard_labs(). Pass list() to disable. Readings outside the bounds are dropped before selection.

format

"df" or "arrow".

Value

A data.frame (or Arrow Table).