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{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addPriorObservation()
#> # Source:   table<og_126_1761733704> [?? x 5]
#> # Database: DuckDB 1.4.1 [unknown@Linux 6.11.0-1018-azure:R 4.5.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    3          2 1957-01-14        1959-04-12     
#>  2                    2          5 1927-08-13        1927-08-13     
#>  3                    1          4 1943-02-02        1949-05-13     
#>  4                    2          6 1935-09-15        1942-05-18     
#>  5                    1          9 1959-03-09        1961-02-08     
#>  6                    2          1 1967-02-05        1968-01-06     
#>  7                    3          7 1948-08-06        1980-02-28     
#>  8                    2          8 1919-11-17        1921-04-10     
#>  9                    2          3 1977-03-05        1979-04-04     
#> 10                    2         10 1988-09-21        2008-06-13     
#> # ℹ 1 more variable: prior_observation <int>

# }