Skip to contents

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

Usage

addPriorObservation(
  x,
  cdm = lifecycle::deprecated(),
  indexDate = "cohort_start_date",
  priorObservationName = "prior_observation",
  priorObservationType = "days"
)

Arguments

x

Table with individuals in the cdm.

cdm

A cdm_reference object.

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".

Value

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

Examples

# \donttest{
cdm <- mockPatientProfiles()

cdm$cohort1 %>%
  addPriorObservation()
#> # Source:   table<og_153_1714466079> [2 x 5]
#> # Database: DuckDB v0.10.1 [unknown@Linux 6.5.0-1018-azure:R 4.4.0/:memory:]
#>   cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                  <dbl>      <dbl> <date>            <date>         
#> 1                    1          1 2020-01-01        2020-04-01     
#> 2                    1          1 2020-06-01        2020-08-01     
#> # ℹ 1 more variable: prior_observation <dbl>
CDMConnector::cdmDisconnect(cdm = cdm)
# }