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_115_1750280293> [?? x 5]
#> # Database: DuckDB v1.3.0 [unknown@Linux 6.11.0-1015-azure:R 4.5.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    2          9 2000-12-17        2001-10-26     
#>  2                    3          4 1969-08-08        1984-11-18     
#>  3                    2          3 1917-06-21        1920-01-19     
#>  4                    3          6 1919-02-05        1969-06-16     
#>  5                    2          7 1970-02-28        1990-05-09     
#>  6                    3          2 1949-12-14        1950-03-12     
#>  7                    2          5 1976-09-08        2010-02-13     
#>  8                    2         10 1936-08-02        1943-02-19     
#>  9                    2          1 1923-11-11        1934-01-25     
#> 10                    1          8 1911-01-10        1929-09-15     
#> # ℹ 1 more variable: observation_period_id <int>

mockDisconnect(cdm = cdm)
# }