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

Arguments

x

A table containing individuals in a CDM reference.

tableName

Names of one or more OMOP CDM tables to intersect with.

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.

window

Window or windows of time relative to indexDate to consider.

targetStartDate

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

targetEndDate

Name or names of end-date columns in the target tables to use for the intersection. If NULL, the target is treated as a point event.

inObservation

If TRUE, only records that occur during an observation period are considered.

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

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 indicate presence (1 or TRUE), no intersection (0 or FALSE), or NA if the individual is not in observation at any time of the window. The representation depends on type.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addTableIntersectFlag(tableName = "visit_occurrence")
#> # A query:  ?? x 5
#> # 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          8 1925-09-18        1926-12-10     
#>  2                    3          3 2007-05-20        2020-06-07     
#>  3                    1         10 1975-09-02        1979-05-05     
#>  4                    2          1 1967-08-31        1968-05-28     
#>  5                    2          5 1933-04-22        1936-12-04     
#>  6                    2          2 1939-03-28        1948-01-24     
#>  7                    1          6 1978-11-03        1979-02-17     
#>  8                    1          9 1948-07-25        1954-02-07     
#>  9                    1          4 1986-06-20        1988-05-28     
#> 10                    2          7 1956-02-19        1957-10-24     
#> # ℹ 1 more variable: visit_occurrence_0_to_inf <dbl>

# }