Skip to contents

Date of cohorts that are present in a certain window

Usage

addCohortIntersectDate(
  x,
  targetCohortTable,
  targetCohortId = NULL,
  indexDate = "cohort_start_date",
  censorDate = NULL,
  targetDate = "cohort_start_date",
  order = "first",
  window = c(0, Inf),
  nameStyle = "{cohort_name}_{window_name}",
  name = NULL
)

Arguments

x

A table containing individuals in a CDM reference.

targetCohortTable

Name of the cohort table to intersect with.

targetCohortId

Cohort definition IDs to include from targetCohortTable. If NULL, all cohorts are included.

indexDate

Name of a date column in x, or a single date to use for all rows, used as the reference date.

censorDate

Date or name of a date column in x on which to censor follow-up. If NULL, no censoring is applied.

targetDate

Name or names of date columns in the target tables to use for the intersection.

order

Which record to use when multiple records occur in a window: "first" or "last".

window

Window or windows of time relative to indexDate to consider.

nameStyle

Naming pattern for the added column or columns. It should include the required formatting variables. If more than one tableName is provided, it must include {table_name}.

name

Name of the new table. If NULL, a temporary table is returned.

Value

x along with additional columns for each cohort of interest.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addCohortIntersectDate(targetCohortTable = "cohort2")
#> # A query:  ?? x 7
#> # Database: DuckDB 1.5.4 [unknown@Linux 6.17.0-1020-azure:R 4.6.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          1 1915-09-16        1951-02-24     
#>  2                    2          5 1951-06-22        1953-10-17     
#>  3                    1          8 1984-12-13        1985-03-01     
#>  4                    1          3 2005-07-09        2007-07-01     
#>  5                    2          2 1994-10-15        1999-05-15     
#>  6                    2          4 2016-03-17        2020-11-05     
#>  7                    2          6 1999-11-08        2001-04-23     
#>  8                    2          9 1960-02-06        1960-07-31     
#>  9                    1         10 1972-02-19        1989-06-01     
#> 10                    1          7 1986-07-04        1990-08-06     
#> # ℹ 3 more variables: cohort_1_0_to_inf <date>, cohort_2_0_to_inf <date>,
#> #   cohort_3_0_to_inf <date>

# }