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

name

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

Value

Table with the current observation period id added.

Examples

# \donttest{
cdm <- mockPatientProfiles()
cdm$cohort1 %>%
  addObservationPeriodId()
#> # Source:   table<og_131_1731175179> [10 x 5]
#> # Database: DuckDB v1.1.2 [unknown@Linux 6.5.0-1025-azure:R 4.4.2/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          7 1963-09-01        1970-06-15     
#>  2                    3          4 1967-10-29        1982-02-25     
#>  3                    3          9 1969-04-02        2003-01-13     
#>  4                    2          2 1988-03-12        1989-06-19     
#>  5                    1          5 1914-06-18        1915-06-05     
#>  6                    3         10 1967-11-15        1985-06-29     
#>  7                    1          3 1919-09-25        1945-11-26     
#>  8                    3          1 1978-01-28        1979-09-11     
#>  9                    3          8 1949-04-18        1952-07-19     
#> 10                    2          6 1941-09-17        1952-02-12     
#> # ℹ 1 more variable: observation_period_id <int>
mockDisconnect(cdm = cdm)
# }