Skip to contents

It creates a column with the field of a desired intersection

Usage

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

Arguments

x

A table containing individuals in a CDM reference.

targetCohortTable

Name of the cohort table to intersect with.

field

Name or names of columns in the target tables to add to x.

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

table with added columns with overlap information.

Examples

# \donttest{
library(PatientProfiles)
library(dplyr)

cdm <- mockPatientProfiles(source = "duckdb")
#> Warning: There are observation period end dates after the current date: 2026-07-24
#>  The latest max observation period end date found is 2028-07-21

cdm$cohort2 <- cdm$cohort2 |>
  mutate(even = if_else(subject_id %% 2, "yes", "no")) |>
  compute(name = "cohort2")

cdm$cohort1 |>
  addCohortIntersectFlag(
    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          6 1945-01-10        1946-03-23     
#>  2                    2         10 1960-01-11        1963-09-20     
#>  3                    1          1 1964-12-22        1978-04-03     
#>  4                    3          3 1970-12-05        1976-09-10     
#>  5                    1          9 1983-02-27        2005-08-08     
#>  6                    1          2 1982-05-26        1998-12-12     
#>  7                    2          7 1965-09-17        1968-09-05     
#>  8                    1          5 1938-03-26        1938-04-06     
#>  9                    1          8 1959-12-18        1960-10-30     
#> 10                    2          4 1956-01-11        1957-08-07     
#> # ℹ 3 more variables: cohort_3_0_to_inf <dbl>, cohort_1_0_to_inf <dbl>,
#> #   cohort_2_0_to_inf <dbl>

# }