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

Value

Table with the current observation period id added.

Examples

# \donttest{
library(PatientProfiles)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addObservationPeriodIdQuery()
#> # Source:   SQL [?? 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                    2          8 1910-06-19        1915-06-11     
#>  2                    3          2 1945-04-27        1945-10-01     
#>  3                    1         10 1968-09-08        1978-04-28     
#>  4                    3          6 1955-04-24        1967-03-03     
#>  5                    3          4 1952-04-24        1969-06-17     
#>  6                    1          1 1943-04-28        1960-12-01     
#>  7                    1          7 1938-10-16        1942-05-27     
#>  8                    3          3 1996-02-16        2018-07-11     
#>  9                    3          9 1916-07-09        1927-04-18     
#> 10                    3          5 1925-04-26        1931-01-08     
#> # ℹ 1 more variable: observation_period_id <int>

# }