
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.
Source:R/addTableIntersect.R
addTableIntersectField.RdIntersecting 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),
inObservation = TRUE,
order = "first",
allowDuplicates = FALSE,
nameStyle = "{table_name}_{field}_{window_name}",
name = NULL,
type = "auto"
)Arguments
- x
A table containing individuals in a CDM reference.
- tableName
Names of one or more OMOP CDM tables to intersect with.
- field
Name or names of columns in the target tables to add to
x.- 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
xon which to censor follow-up. IfNULL, no censoring is applied.- window
Window or windows of time relative to
indexDateto consider.- targetDate
Name or names of date columns in the target tables to use for the intersection.
- inObservation
If
TRUE, only records that occur during an observation period are considered.- order
Which record to use when multiple records occur in a window:
"first"or"last".- allowDuplicates
Whether to allow multiple records for the same person, target, and date. If
TRUE, multiple values are collapsed into a semicolon-separated character value; otherwise, duplicates result in an error.- nameStyle
Naming pattern for the added column or columns. It should include the required formatting variables. If more than one
tableNameis 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".
Examples
# \donttest{
library(PatientProfiles)
cdm <- mockPatientProfiles(source = "duckdb")
cdm$cohort1 |>
addTableIntersectField(
tableName = "visit_occurrence",
field = "visit_concept_id",
order = "last",
window = c(-Inf, -1)
)
#> # 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 7 1967-08-16 1969-10-08
#> 2 3 4 1984-05-30 1991-05-11
#> 3 2 1 1951-10-09 1963-06-30
#> 4 1 6 1976-04-22 1983-07-31
#> 5 2 9 1937-04-22 1938-04-25
#> 6 3 5 1954-04-11 1956-06-16
#> 7 2 8 1938-06-12 1940-01-08
#> 8 3 10 1950-02-18 1976-01-11
#> 9 2 3 1988-10-20 1996-12-11
#> 10 1 2 1941-03-15 1961-07-26
#> # ℹ 1 more variable: visit_occurrence_visit_concept_id_minf_to_m1 <int>
# }