Constructs a leak-free 30-day readmission cohort directly in DuckDB SQL. Enforces adult inpatient stay, LOS >= 1 day, discharged alive, verified follow-up window (filtering right-censored lost-to-follow-up stays), reproducible index admission sampling, and disjoint lookback vs post-discharge outcome scoping.
Usage
build_readmission_cohort(
con,
cohort_id = 1,
outcome_cohort_id = NULL,
cohort_name = "Inpatient 30-Day Readmission Cohort",
cohort_description = NULL,
target_visit_concept_ids = 9201,
outcome_visit_concept_ids = 9201,
followup_window_days = 30,
grace_days = 0,
washin_days = 365,
index_selection_rule = "random",
random_state = 42,
require_verified_followup = TRUE,
table_name = NULL
)Arguments
- con
Active DuckDB DBI connection.
- cohort_id
Integer ID for target index cohort in OMOP
cohorttable (default 1).- outcome_cohort_id
Optional integer ID for materialized readmission outcome cohort.
- cohort_name
Display name for cohort_definition table.
- cohort_description
Description for cohort_definition table.
- target_visit_concept_ids
Integer vector of visit concepts defining index stay (default 9201).
- outcome_visit_concept_ids
Integer vector of visit concepts defining readmission (default 9201).
- followup_window_days
Follow-up window in days (default 30).
- grace_days
Grace days immediately post-discharge before outcome window begins (default 0).
- washin_days
Prior observation lookback requirement in days (default 365).
- index_selection_rule
"random" (reproducible seed), "first", or "last".
- random_state
Integer seed for reproducible random index sampling (default 42).
- require_verified_followup
Logical. Whether to filter out lost-to-follow-up patients (default TRUE).
- table_name
Optional character string to materialize the index cohort table with metadata.
Details
This is a thin wrapper over the shared study-cohort engine (see define_study_cohort(), which generalises
it): the legacy conventions (death from the death table and the index stay's own discharge disposition
4216643; follow-up evidenced by later visits, measurements, conditions or drug exposures; age as
calendar-year difference) are pinned here and covered by golden-file tests.
