
It adds a custom column (field) from the intersection with a certain table subsetted by concept id. In general it is used to add the first value of a certain measurement.
Source:R/addConceptIntersect.R
addConceptIntersectField.RdIt adds a custom column (field) from the intersection with a certain table subsetted by concept id. In general it is used to add the first value of a certain measurement.
Usage
addConceptIntersectField(
x,
conceptSet,
field,
indexDate = "cohort_start_date",
censorDate = NULL,
window = list(c(0, Inf)),
targetDate = "event_start_date",
order = "first",
inObservation = TRUE,
allowDuplicates = FALSE,
nameStyle = "{field}_{concept_name}_{window_name}",
name = NULL,
type = "auto"
)Arguments
- x
A table containing individuals in a CDM reference.
- conceptSet
A named list of concept sets.
- 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.
- 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.- 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)
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 |>
addConceptIntersectField(
conceptSet = list("acetaminophen" = 1125315),
field = "drug_type_concept_id"
)
#> 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 1 1 1955-12-22 1965-09-28
#> 2 2 5 1984-03-25 1991-03-26
#> 3 1 9 1939-01-10 1940-07-17
#> 4 2 3 1966-01-19 1978-06-11
#> 5 2 4 1970-07-03 1971-04-06
#> 6 3 2 1940-01-20 1943-09-07
#> 7 2 7 1971-01-17 1976-01-30
#> 8 2 8 1958-10-26 1966-06-16
#> 9 3 6 1969-08-21 1970-04-13
#> 10 3 10 1974-03-26 1976-10-01
#> # ℹ 1 more variable: drug_type_concept_id_acetaminophen_0_to_inf <chr>
# }