
Add the first or last concept event and its relative days
Source:R/addConceptEvent.R
addConceptEventDays.RdaddConceptEventDays() 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 days value represents that boundary.
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.- 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
indexDateto consider.- multipleEvents
How events occurring on the same date are handled. If
NULL, the first event in the original event order is returned. IfTRUE, 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.- 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
x with an event column and a days column of the requested type,
relative to indexDate, for every window.
Examples
# \donttest{
library(PatientProfiles)
cdm <- mockPatientProfiles(source = "duckdb")
cdm$cohort1 |>
addConceptEventDays(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 1 1 1932-01-03 1932-01-18
#> 2 3 2 2007-11-12 2012-03-31
#> 3 2 3 1917-04-28 1919-12-28
#> 4 3 4 1996-07-31 2003-02-24
#> 5 1 5 1943-06-23 1971-09-15
#> 6 3 6 1992-06-12 1993-07-13
#> 7 3 7 1937-04-30 1941-01-27
#> 8 2 8 1922-02-23 1934-11-19
#> 9 2 9 1944-10-07 1982-02-17
#> 10 3 10 1959-02-11 1968-01-15
#> # ℹ 2 more variables: event_0_to_inf <chr>, days_0_to_inf <dbl>
# }