Skip to contents

It creates columns to indicate the number of days between the current table and a target cohort

Usage

addCohortIntersectDays(
  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,
  type = "numeric"
)

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.

type

Type of the created column(s). Counts, days, age, and observation durations can be "numeric" or "integer". Flag columns can also be "logical". Field columns can use "auto" to preserve the source type, or can be converted to "numeric", "integer", "logical", or "character".

Value

x along with additional columns for each cohort of interest.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addCohortIntersectDays(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                    2          7 1972-02-01        1977-12-17     
#>  2                    3          3 1985-07-10        1990-12-20     
#>  3                    2          1 1952-09-13        1963-01-20     
#>  4                    2          9 1972-06-24        1981-08-05     
#>  5                    3         10 1973-10-10        1976-06-01     
#>  6                    1          4 1990-03-02        1999-04-29     
#>  7                    2          5 1996-07-06        1999-01-18     
#>  8                    2          8 1945-07-29        1947-06-30     
#>  9                    3          6 1918-01-04        1938-01-20     
#> 10                    3          2 1966-01-05        1966-08-17     
#> # ℹ 3 more variables: cohort_1_0_to_inf <dbl>, cohort_3_0_to_inf <dbl>,
#> #   cohort_2_0_to_inf <dbl>

# }