Skip to contents

Compute a flag intersect with an omop table

Usage

addTableIntersectFlag(
  x,
  tableName,
  indexDate = "cohort_start_date",
  censorDate = NULL,
  window = list(c(0, Inf)),
  targetStartDate = startDateColumn(tableName),
  targetEndDate = endDateColumn(tableName),
  inObservation = TRUE,
  nameStyle = "{table_name}_{window_name}",
  name = NULL
)

Arguments

x

Table with individuals in the cdm.

tableName

Name of the table to intersect with. Options: visit_occurrence, condition_occurrence, drug_exposure, procedure_occurrence, device_exposure, measurement, observation, drug_era, condition_era, specimen, episode.

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.

window

window to consider events in.

targetStartDate

Column name with start date for comparison.

targetEndDate

Column name with end date for comparison.

inObservation

If TRUE only records inside an observation period will be considered.

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

The original table (x) with one added column per intersection with the desired table in a specific window. One column will be created for each combination of window and table. The value of the column can either be: 1 to indicate presence of the intersection, 0 to indicate no intersection or NA if the individual is not in observation at any time of the window.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addTableIntersectFlag(tableName = "visit_occurrence")
#> # Source:   table<og_165_1775495350> [?? x 5]
#> # Database: DuckDB 1.5.1 [unknown@Linux 6.17.0-1008-azure:R 4.5.3/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          7 1992-12-11        1996-05-03     
#>  2                    3          1 1994-08-06        2011-03-22     
#>  3                    3          9 1980-10-19        1993-11-24     
#>  4                    1         10 1913-04-20        1918-03-28     
#>  5                    2          8 1949-02-07        1958-01-20     
#>  6                    2          6 1958-03-19        1958-11-15     
#>  7                    3          2 2007-05-03        2008-09-09     
#>  8                    2          3 1962-03-25        1978-12-16     
#>  9                    3          5 1982-06-23        1983-09-03     
#> 10                    2          4 1991-05-25        1996-08-30     
#> # ℹ 1 more variable: visit_occurrence_0_to_inf <dbl>

# }