
It creates column to indicate the date overlap information between a table and a concept
Source:R/addConceptIntersect.R
addConceptIntersectDate.RdIt creates column to indicate the date overlap information between a table and 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.
Examples
# \donttest{
library(PatientProfiles)
library(omopgenerics, warn.conflicts = TRUE)
library(dplyr, warn.conflicts = TRUE)
cdm <- mockPatientProfiles(source = "duckdb")
#> duckdb keeps downloaded extensions and secrets in a temporary directory:
#> ℹ /tmp/Rtmp1nF3JK/duckdb
#> This is removed when the R session ends.
#> • Extensions are re-downloaded each session.
#> • Secrets are lost.
#> ℹ Run duckdb(shared_home = TRUE) (or create ~/.duckdb) to keep them (suitable for most users).
#> ℹ Run duckdb(shared_home = FALSE) to accept the temporary directory (and silence this message).
#> ℹ See ?duckdb_storage for details and alternatives.
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 |>
addConceptIntersectDate(conceptSet = list("acetaminophen" = 1125315))
#> Warning: ! `codelist` cast to integers.
#> # A query: ?? x 5
#> # Database: DuckDB 1.5.5 [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 4 1925-04-29 1927-10-04
#> 2 2 5 2010-10-10 2012-03-21
#> 3 2 10 1989-11-30 1994-02-24
#> 4 3 7 1922-12-20 1939-02-12
#> 5 1 9 1953-08-05 1964-11-29
#> 6 2 1 1957-11-18 1959-03-25
#> 7 3 3 1984-08-17 1985-02-17
#> 8 1 8 2006-09-02 2009-06-16
#> 9 3 6 1974-08-07 1982-10-15
#> 10 3 2 1981-06-08 1982-12-05
#> # ℹ 1 more variable: acetaminophen_0_to_inf <date>
# }