Skip to contents

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.

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
)

Arguments

x

Table with individuals in the cdm.

conceptSet

Concept set list.

field

Column in the standard omop table that you want to add.

indexDate

Variable in x that contains the date to compute the intersection.

censorDate

Whether to censor overlap events at a date column of x

window

Window to consider events in.

targetDate

Event date to use for the intersection.

order

'last' or 'first' to refer to which event consider if multiple events are present in the same window.

inObservation

If TRUE only records inside an observation period will be considered.

allowDuplicates

Whether to allow multiple records with same conceptSet, person_id and targetDate. If switched to TRUE, it can have a different and unpredictable behavior depending on the cdm_source.

nameStyle

naming of the added column or columns, should include required parameters.

name

Name of the new table, if NULL a temporary table is returned.

Value

Table with the `field` value obtained from the intersection

Examples

# \donttest{
library(PatientProfiles)
cdm <- mockPatientProfiles()
concept <- dplyr::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_
) |>
  dplyr::mutate(concept_name = paste0("concept: ", .data$concept_id))
cdm <- CDMConnector::insertTable(cdm, "concept", concept)

cdm$cohort1 |>
  addConceptIntersectField(
    conceptSet = list("acetaminophen" = 1125315),
    field = "drug_type_concept_id"
  )
#> Warning: ! `codelist` casted to integers.
#> # Source:   table<og_072_1740755690> [?? x 5]
#> # Database: DuckDB v1.2.0 [unknown@Linux 6.8.0-1021-azure:R 4.4.2/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          7 1968-06-16        1976-09-21     
#>  2                    2          6 1988-02-19        1998-02-14     
#>  3                    2         10 1956-12-14        1957-08-29     
#>  4                    1          8 1929-08-04        1935-12-22     
#>  5                    3          3 1923-01-15        1955-01-28     
#>  6                    3          4 1978-03-12        1979-09-05     
#>  7                    3          5 1958-04-10        1966-02-17     
#>  8                    3          2 1963-10-21        1977-05-08     
#>  9                    2          9 1937-05-15        1946-03-29     
#> 10                    2          1 1952-10-19        1971-07-29     
#> # ℹ 1 more variable: drug_type_concept_id_acetaminophen_0_to_inf <int>

mockDisconnect(cdm = cdm)
# }