Skip to contents

Intersecting the cohort with columns of an OMOP table of user's choice. It will add an extra column to the cohort, indicating the intersected entries with the target columns in a window of the user's choice.

Usage

addTableIntersectField(
  x,
  tableName,
  field,
  indexDate = "cohort_start_date",
  censorDate = NULL,
  window = list(c(0, Inf)),
  targetDate = startDateColumn(tableName),
  order = "first",
  nameStyle = "{table_name}_{extra_value}_{window_name}"
)

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.

field

The columns from the table in tableName to intersect over. For example, if the user uses visit_occurrence in tableName then for field the possible options include visit_occurrence_id, visit_concept_id, visit_type_concept_id.

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 when intersecting with the chosen column.

targetDate

The dates in the target columns in tableName that the user may want to restrict to.

order

which record is considered in case of multiple records (only required for date and days options).

nameStyle

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

Value

table with added columns with intersect information.

Examples

# \donttest{
cdm <- mockPatientProfiles()
cdm$cohort1 %>%
  addTableIntersectField(
    tableName = "visit_occurrence",
    field = "visit_concept_id",
    order = "last",
    window = c(-Inf, -1)
  )
#> # Source:   table<og_146_1715898477> [10 x 5]
#> # Database: DuckDB v0.10.2 [unknown@Linux 6.5.0-1021-azure:R 4.4.0/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    2          9 2018-03-25        2041-06-14     
#>  2                    3          2 2067-11-18        2111-03-13     
#>  3                    1          7 1975-10-22        2047-09-18     
#>  4                    3          1 1943-10-07        1944-09-20     
#>  5                    2          5 2008-08-30        2063-02-08     
#>  6                    1         10 1944-02-07        1984-11-09     
#>  7                    1          4 2039-03-04        2048-12-13     
#>  8                    2          6 2092-08-12        2161-12-28     
#>  9                    1          3 1959-08-02        1999-10-22     
#> 10                    2          8 1991-01-08        1992-10-05     
#> # ℹ 1 more variable: visit_occurrence_visit_concept_id_minf_to_m1 <chr>
mockDisconnect(cdm = cdm)
# }