Skip to contents

addConceptEventDate() finds the first or last event from a set of concepts in each window. When no event is observed before the applicable boundary, the event is reported as "end_of_observation" if the observation period boundary is reached or "censor" if the window boundary or censorDate is reached. The date value represents that boundary.

Usage

addConceptEventDate(
  x,
  conceptSet,
  indexDate = "cohort_start_date",
  censorDate = NULL,
  targetDate = "event_start_date",
  order = "first",
  window = list(c(0, Inf)),
  multipleEvents = NULL,
  nameStyle = "{value}_{window_name}",
  name = NULL
)

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.

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

window

Window or windows of time relative to indexDate to consider.

multipleEvents

How events occurring on the same date are handled. If NULL, the first event in the original event order is returned. If TRUE, all simultaneous event names are sorted alphabetically and joined with "; ". A character vector gives priority to the specified event names; the first matching name is returned, with unspecified names following in alphabetical order. Boundary labels ("censor" and "end_of_observation") are never combined with event names.

nameStyle

Naming pattern for the added columns. It must contain {value} and can also contain {window_name}.

name

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

Value

x with an event column and a date column for every window.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addConceptEventDate(conceptSet = list(acetaminophen = 1125315L))
#> # A query:  ?? x 6
#> # 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                    2          1 1974-02-01        1978-11-22     
#>  2                    1          2 1947-02-10        1948-07-31     
#>  3                    3          3 1981-08-06        2004-04-15     
#>  4                    1          4 1927-04-11        1930-10-30     
#>  5                    3          5 1927-05-03        1932-11-27     
#>  6                    1          6 1980-06-02        1981-07-31     
#>  7                    2          7 1930-06-07        1945-06-25     
#>  8                    3          8 1965-06-12        1965-10-24     
#>  9                    1          9 1955-06-29        1956-02-01     
#> 10                    1         10 1953-06-01        1954-11-05     
#> # ℹ 2 more variables: event_0_to_inf <chr>, date_0_to_inf <date>
# }