
It creates column to indicate the days of difference from an index date to a concept
Source:R/addConceptIntersect.R
addConceptIntersectDays.RdIt creates column to indicate the days of difference from an index date to a concept
Arguments
- x
A table containing individuals in a CDM reference.
- conceptSet
A named list of concept sets.
- 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.
- order
Which record to use when multiple records occur in a window:
"first"or"last".- 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
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)
library(omopgenerics, warn.conflicts = TRUE)
library(dplyr, warn.conflicts = TRUE)
cdm <- mockPatientProfiles(source = "duckdb")
concept <- tibble(
concept_id = c(1125315),
domain_id = "Drug",
vocabulary_id = NA_character_,
concept_class_id = "Ingredient",
standard_concept = "S",
concept_code = NA_character_,
valid_start_date = as.Date("1900-01-01"),
valid_end_date = as.Date("2099-01-01"),
invalid_reason = NA_character_
) |>
mutate(concept_name = paste0("concept: ", .data$concept_id))
cdm <- insertTable(cdm, "concept", concept)
cdm$cohort1 |>
addConceptIntersectDays(conceptSet = list("acetaminophen" = 1125315))
#> Warning: ! `codelist` cast to integers.
#> # 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 3 2 2004-09-20 2008-07-11
#> 2 1 1 1921-04-01 1929-11-18
#> 3 1 9 1993-11-03 2017-02-18
#> 4 3 3 1948-07-21 1953-11-23
#> 5 2 10 1981-03-09 1991-09-22
#> 6 2 7 1953-06-10 1975-04-06
#> 7 1 6 1943-03-09 1944-08-27
#> 8 1 5 1979-07-03 1994-07-04
#> 9 2 4 1934-05-03 1938-01-29
#> 10 3 8 1980-07-25 1981-02-22
#> # ℹ 1 more variable: acetaminophen_0_to_inf <dbl>
# }