Constructs a standardized End of Life / Mortality cohort in DuckDB SQL. Supports four mortality ascertainment paradigms:
"in_hospital": Death during index stay (expired/died in hospital)."post_discharge": Death within (t_discharge + gap_days, t_discharge + mortality_window_days]."fixed_window": SARD-style EOL prediction within (t_index + gap_days, t_index + mortality_window_days]."composite_readmit_or_death": Clinical composite of acute readmission OR all-cause death post-discharge.
Resolves dual OMOP death sources:
deathtable:death_datelinked toperson_id.visit_occurrencetable:discharged_to_concept_id IN (4216643, 4155309)(Expired / Hospice).
This is a thin wrapper over the shared study-cohort engine (see define_study_cohort(), which generalises
it); its legacy conventions are pinned here and covered by golden-file tests.
Usage
build_end_of_life_cohort(
con,
cohort_id = 1,
outcome_cohort_id = 2,
cohort_name = "End of Life Cohort",
cohort_description = NULL,
mortality_type = "post_discharge",
target_visit_concept_ids = 9201,
outcome_visit_concept_ids = 9201,
mortality_window_days = 30,
gap_days = 0,
min_age = 18,
washin_days = 365,
require_verified_followup = TRUE,
index_selection_rule = "random",
random_state = 42,
table_name = NULL,
schema = "main",
overwrite = TRUE
)
build_mortality_cohort(
con,
cohort_id = 1,
outcome_cohort_id = 2,
cohort_name = "End of Life Cohort",
cohort_description = NULL,
mortality_type = "post_discharge",
target_visit_concept_ids = 9201,
outcome_visit_concept_ids = 9201,
mortality_window_days = 30,
gap_days = 0,
min_age = 18,
washin_days = 365,
require_verified_followup = TRUE,
index_selection_rule = "random",
random_state = 42,
table_name = NULL,
schema = "main",
overwrite = TRUE
)Arguments
- con
Active DuckDB DBI connection.
- cohort_id
Target cohort definition ID in OMOP
cohorttable (default 1).- outcome_cohort_id
Optional outcome cohort definition ID (default 2). Set NULL to skip outcome cohort table population.
- cohort_name
Display name for cohort_definition table.
- cohort_description
Detailed description for cohort_definition table.
- mortality_type
Mode of mortality ascertainment:
"in_hospital","post_discharge","fixed_window", or"composite_readmit_or_death".- target_visit_concept_ids
Visit concept IDs defining qualifying index encounters (default 9201: Inpatient). Set NULL for any visit.
- outcome_visit_concept_ids
Visit concept IDs defining readmissions for composite mode (default 9201).
- mortality_window_days
Number of days for mortality outcome window (default 30).
- gap_days
Days between index date / discharge and start of outcome window (default 0).
- min_age
Minimum patient age at index encounter (default 18).
- washin_days
Baseline continuous observation lookback requirement before index stay (default 365).
- require_verified_followup
Logical. If TRUE, excludes lost-to-follow-up patients without confirmed survival follow-up (default TRUE).
- index_selection_rule
"random"(reproducible seed),"first", or"last".- random_state
Seed for reproducible random sampling (default 42).
- table_name
Optional custom table name in DuckDB to materialize cohort records with metadata.
- schema
CDM schema containing tables (default "main").
- overwrite
Logical. If TRUE, cleans existing cohort and cohort_definition entries for cohort_id and outcome_cohort_id (default TRUE).
