Skip to contents

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.

Value

The cohort table.

Examples

# \donttest{
library(PatientProfiles)
library(CohortConstructor)
cdm <- mockPatientProfiles()
cdm$cohort1 |> exitAtDeath()
#> # Source:   table<main.cohort1> [10 x 4]
#> # Database: DuckDB v1.0.0 [unknown@Linux 6.5.0-1025-azure:R 4.4.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    2          5 1966-05-05        1970-11-15     
#>  2                    2          3 1939-07-24        1944-01-14     
#>  3                    1          9 1940-05-01        1945-06-29     
#>  4                    3          2 1918-06-14        1921-11-28     
#>  5                    3          8 1921-10-07        1931-05-01     
#>  6                    3          7 1962-05-14        1964-03-08     
#>  7                    2          4 1949-03-07        1951-05-08     
#>  8                    1         10 1948-08-08        1952-03-27     
#>  9                    3          6 1966-09-27        1975-03-05     
#> 10                    1          1 1943-11-26        1949-06-21     
# }