Skip to contents

Compute the number of days of prior observation in the current observation period at a certain date

Usage

addPriorObservation(
  x,
  indexDate = "cohort_start_date",
  priorObservationName = "prior_observation",
  priorObservationType = "days",
  name = NULL
)

Arguments

x

Table with individuals in the cdm.

indexDate

Variable in x that contains the date to compute the prior observation.

priorObservationName

name of the new column to be added.

priorObservationType

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

name

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

Value

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

Examples

# \donttest{
cdm <- mockPatientProfiles()

cdm$cohort1 |>
  addPriorObservation()
#> # Source:   table<og_121_1740755725> [?? 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          1 1954-09-17        1984-04-11     
#>  2                    1          2 1999-01-18        2001-02-28     
#>  3                    3          3 1989-04-19        1998-05-29     
#>  4                    2          4 1962-09-17        1964-12-07     
#>  5                    1          5 1962-01-27        1962-10-26     
#>  6                    1          6 1986-11-03        2004-10-29     
#>  7                    3          7 1946-02-28        1948-06-11     
#>  8                    1          8 1927-02-03        1927-08-13     
#>  9                    1          9 1918-05-14        1918-12-12     
#> 10                    1         10 1938-01-17        1938-12-13     
#> # ℹ 1 more variable: prior_observation <int>

mockDisconnect(cdm = cdm)
# }