Skip to contents

It creates column to indicate the count overlap information between a table and a concept

Usage

addConceptIntersectCount(
  x,
  conceptSet,
  indexDate = "cohort_start_date",
  censorDate = NULL,
  window = list(c(0, Inf)),
  targetStartDate = "event_start_date",
  targetEndDate = "event_end_date",
  inObservation = TRUE,
  nameStyle = "{concept_name}_{window_name}",
  name = NULL,
  type = "numeric"
)

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 x on which to censor follow-up. If NULL, no censoring is applied.

window

Window or windows of time relative to indexDate to consider.

targetStartDate

Name or names of start-date columns in the target tables to use for the intersection.

targetEndDate

Name or names of end-date columns in the target tables to use for the intersection. If NULL, the target is treated as a point event.

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 tableName is 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".

Value

The original table (x) with one added column per intersection with the desired conceptSet in a specific window. One column will be created for each combination of window and conceptSet. The value of the column will be the number of intersections in the desired window, or NA if the individual is not in observation at any time in the window.

Examples

# \donttest{
library(PatientProfiles)
library(omopgenerics, warn.conflicts = TRUE)
#> 
#> Attaching package: ‘omopgenerics’
#> The following object is masked from ‘package:stats’:
#> 
#>     filter
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 |>
  addConceptIntersectCount(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          3 1930-11-18        1964-12-24     
#>  2                    3          2 1965-04-22        1965-07-05     
#>  3                    3          4 1929-02-16        1930-09-19     
#>  4                    2          7 1955-04-19        1957-01-20     
#>  5                    3          6 1941-02-22        1951-12-23     
#>  6                    1          1 1977-03-13        1984-12-06     
#>  7                    2          5 1913-06-07        1927-07-13     
#>  8                    3          9 1981-03-29        1981-07-13     
#>  9                    2          8 1985-07-16        2012-02-22     
#> 10                    2         10 1946-08-05        1949-09-20     
#> # ℹ 1 more variable: acetaminophen_0_to_inf <dbl>

# }