Skip to contents

Add the ordinal number of the observation period associated that a given date is in. Result is not computed, only query is added.

Usage

addObservationPeriodIdQuery(
  x,
  indexDate = "cohort_start_date",
  nameObservationPeriodId = "observation_period_id"
)

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.

Value

Table with the current observation period id added.

Examples

# \donttest{
cdm <- mockPatientProfiles()

cdm$cohort1 |>
  addObservationPeriodIdQuery()
#> # Source:   SQL [?? x 5]
#> # Database: DuckDB v1.2.0 [unknown@Linux 6.8.0-1021-azure:R 4.4.2/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          4 1986-06-20        1998-09-25     
#>  2                    1         10 1926-11-21        1943-06-27     
#>  3                    1          3 1947-05-08        1953-08-15     
#>  4                    3          2 1971-07-05        1974-02-16     
#>  5                    1          8 1903-08-31        1907-05-18     
#>  6                    3          6 1954-01-06        1964-09-26     
#>  7                    3          9 1972-04-30        1975-04-20     
#>  8                    2          5 2009-10-06        2009-12-20     
#>  9                    2          7 1989-11-13        1991-08-07     
#> 10                    3          1 1946-03-09        1979-08-11     
#> # ℹ 1 more variable: observation_period_id <int>

mockDisconnect(cdm = cdm)
# }