Skip to contents

It creates columns to indicate number of occurrences of intersection with a cohort

Usage

addCohortIntersectCount(
  x,
  targetCohortTable,
  targetCohortId = NULL,
  indexDate = "cohort_start_date",
  censorDate = NULL,
  targetStartDate = "cohort_start_date",
  targetEndDate = "cohort_end_date",
  window = list(c(0, Inf)),
  nameStyle = "{cohort_name}_{window_name}",
  name = NULL
)

Arguments

x

Table with individuals in the cdm.

targetCohortTable

name of the cohort that we want to check for overlap.

targetCohortId

vector of cohort definition ids to include.

indexDate

Variable in x that contains the date to compute the intersection.

censorDate

whether to censor overlap events at a specific date or a column date of x.

targetStartDate

date of reference in cohort table, either for start (in overlap) or on its own (for incidence).

targetEndDate

date of reference in cohort table, either for end (overlap) or NULL (if incidence).

window

window to consider events of.

nameStyle

naming of the added column or columns, should include required parameters.

name

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

Value

table with added columns with overlap information.

Examples

# \donttest{
cdm <- mockPatientProfiles()

cdm$cohort1 |>
  addCohortIntersectCount(
    targetCohortTable = "cohort2"
  )
#> # Source:   table<og_005_1734613780> [?? x 7]
#> # 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          4 1955-03-12        1960-11-22     
#>  2                    3         10 1966-01-03        1972-03-30     
#>  3                    3          3 1989-07-01        2019-09-08     
#>  4                    2          6 1958-06-17        1966-03-18     
#>  5                    2          9 1959-07-30        1976-08-28     
#>  6                    2          7 1973-01-14        1973-05-30     
#>  7                    3          2 2025-01-15        2025-02-20     
#>  8                    2          8 1925-03-26        1935-08-12     
#>  9                    3          1 1943-03-07        1943-10-04     
#> 10                    3          5 1947-03-30        1958-02-15     
#> # ℹ 3 more variables: cohort_3_0_to_inf <dbl>, cohort_1_0_to_inf <dbl>,
#> #   cohort_2_0_to_inf <dbl>

mockDisconnect(cdm = cdm)
# }