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_118_1757798558> [?? x 5]
#> # Database: DuckDB 1.3.3-dev231 [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          9 1969-12-08        1975-05-31     
#>  2                    2          8 1952-08-16        1956-12-12     
#>  3                    3         10 1960-06-19        1963-05-06     
#>  4                    1          7 1926-09-11        1927-07-16     
#>  5                    2          5 1966-03-05        1966-03-24     
#>  6                    3          3 1926-02-23        1947-09-13     
#>  7                    3          2 1979-05-04        1979-07-28     
#>  8                    2          1 1965-08-28        1977-06-03     
#>  9                    3          4 1953-08-17        1954-12-06     
#> 10                    2          6 1938-02-13        1939-12-23     
#> # ℹ 1 more variable: prior_observation <int>

# }