Skip to contents

Same as addPriorObservation(), except query is not computed to a table.

Usage

addPriorObservationQuery(
  x,
  indexDate = "cohort_start_date",
  priorObservationName = "prior_observation",
  priorObservationType = "days",
  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.

priorObservationName

Name of the prior-observation column to add.

priorObservationType

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

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 prior observation of the individuals.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")
#> Warning: There are observation period end dates after the current date: 2026-07-24
#>  The latest max observation period end date found is 2031-10-09

cdm$cohort1 |>
  addPriorObservationQuery()
#> # 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          6 1942-05-09        1947-03-23     
#>  2                    2          3 1958-10-21        1967-09-20     
#>  3                    1          4 1913-04-25        1918-08-20     
#>  4                    2          1 1980-11-14        1987-09-13     
#>  5                    2          9 1980-06-09        1985-11-15     
#>  6                    3          2 1984-01-06        1987-09-01     
#>  7                    3         10 1905-06-27        1907-08-22     
#>  8                    3          5 1982-02-06        1985-03-05     
#>  9                    1          8 1951-09-24        1960-10-02     
#> 10                    1          7 1991-12-27        1997-03-18     
#> # ℹ 1 more variable: prior_observation <dbl>

# }