This functions changes cohort end date to subject's death date. In the case were this generates overlapping records in the cohort, those overlapping entries will be merged.
Usage
exitAtDeath(
cohort,
cohortId = NULL,
requireDeath = FALSE,
name = tableName(cohort)
)
Arguments
- cohort
A cohort table in a cdm reference.
- cohortId
Vector identifying which cohorts to modify (cohort_definition_id or cohort_name). If NULL, all cohorts will be used; otherwise, only the specified cohorts will be modified, and the rest will remain unchanged.
- requireDeath
If TRUE, subjects without a death record will be dropped, while if FALSE their end date will be left as is.
- name
Name of the new cohort table created in the cdm object.
Examples
# \donttest{
library(PatientProfiles)
library(CohortConstructor)
cdm <- mockPatientProfiles()
cdm$cohort1 |> exitAtDeath()
#> # Source: table<main.cohort1> [?? x 4]
#> # Database: DuckDB v1.1.3 [unknown@Linux 6.8.0-1017-azure:R 4.4.2/:memory:]
#> cohort_definition_id subject_id cohort_start_date cohort_end_date
#> <int> <int> <date> <date>
#> 1 3 2 1918-06-14 1921-11-28
#> 2 3 8 1921-10-07 1931-05-01
#> 3 1 9 1940-05-01 1945-06-29
#> 4 3 7 1962-05-14 1964-03-08
#> 5 1 10 1948-08-08 1952-03-27
#> 6 2 4 1949-03-07 1951-05-08
#> 7 3 6 1966-09-27 1975-03-05
#> 8 1 1 1943-11-26 1949-06-21
#> 9 2 5 1966-05-05 1970-11-15
#> 10 2 3 1939-07-24 1944-01-14
# }