Skip to contents

Add the ordinal number of the observation period associated that a given date is in.

Usage

addObservationPeriodId(
  x,
  indexDate = "cohort_start_date",
  nameObservationPeriodId = "observation_period_id",
  name = NULL
)

Arguments

x

Table with individuals in the cdm.

indexDate

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

nameObservationPeriodId

Name of the new column.

name

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

Value

Table with the current observation period id added.

Examples

# \donttest{
library(PatientProfiles)

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

cdm$cohort1 |>
  addObservationPeriodId()
#> # Source:   table<og_137_1775495318> [?? x 5]
#> # Database: DuckDB 1.5.1 [unknown@Linux 6.17.0-1008-azure:R 4.5.3/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          5 1961-06-30        1967-12-12     
#>  2                    3          4 1929-07-16        1932-05-12     
#>  3                    1          8 1990-01-23        2007-11-08     
#>  4                    3          2 1992-11-08        1993-11-30     
#>  5                    3          1 1962-05-22        1975-07-13     
#>  6                    1          6 2015-03-17        2032-07-02     
#>  7                    2         10 1995-01-31        1997-05-05     
#>  8                    1          7 1985-03-04        1989-03-24     
#>  9                    1          9 1964-07-26        1966-05-27     
#> 10                    1          3 1986-10-24        1988-05-01     
#> # ℹ 1 more variable: observation_period_id <int>

# }