Skip to contents

Compute the number of days till the end of the observation period at a certain date

Usage

addFutureObservation(
  x,
  indexDate = "cohort_start_date",
  futureObservationName = "future_observation",
  futureObservationType = "days",
  name = NULL,
  type = "numeric"
)

Arguments

x

A table containing individuals in a CDM reference.

indexDate

Name of a date column in x, or a single date to use for all rows, used as the reference date.

futureObservationName

Name of the future-observation column to add.

futureObservationType

Whether to return a "date" or a number of "days".

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

cohort table with added column containing future observation of the individuals.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addFutureObservation()
#> # 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          4 1942-09-09        1948-06-27     
#>  2                    3          5 1933-01-30        1933-10-31     
#>  3                    1          6 1972-08-03        1975-06-30     
#>  4                    2          1 1949-09-04        1960-01-17     
#>  5                    2         10 1908-07-25        1914-10-03     
#>  6                    1          7 1933-04-30        1942-07-07     
#>  7                    3          9 2008-12-15        2013-04-09     
#>  8                    2          3 1932-05-25        1932-07-13     
#>  9                    1          8 1982-02-22        1988-09-04     
#> 10                    2          2 2000-11-12        2010-10-26     
#> # ℹ 1 more variable: future_observation <dbl>

# }