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

A table containing individuals in a CDM reference.

indexDate

Name of a date column in x, or a single date to use for all rows, used as the reference date.

nameObservationPeriodId

Name of the observation-period ID column to add.

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

cdm$cohort1 |>
  addObservationPeriodId()
#> # A query:  ?? x 5
#> # Database: DuckDB 1.5.4 [unknown@Linux 6.17.0-1020-azure:R 4.6.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    3          6 1972-04-23        1982-01-26     
#>  2                    2          3 1979-03-04        1985-05-07     
#>  3                    3          9 1979-07-28        1980-06-23     
#>  4                    2          2 1970-12-09        1973-09-16     
#>  5                    2          8 1946-07-17        1949-09-10     
#>  6                    3          1 1986-11-11        1993-10-22     
#>  7                    2          4 1930-12-31        1948-12-13     
#>  8                    1          5 1978-03-18        1993-06-12     
#>  9                    3         10 1935-12-31        1949-08-05     
#> 10                    3          7 1975-08-18        1976-02-06     
#> # ℹ 1 more variable: observation_period_id <int>

# }