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

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()
#> # Source:   table<og_117_1757798553> [?? x 5]
#> # Database: DuckDB 1.3.3-dev231 [unknown@Linux 6.11.0-1018-azure:R 4.5.1/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    3          4 1958-10-15        1975-03-18     
#>  2                    3          7 1949-05-17        1956-05-09     
#>  3                    2          1 1989-09-19        1992-07-03     
#>  4                    2          6 1931-12-17        1932-02-15     
#>  5                    3          9 1920-07-31        1924-12-28     
#>  6                    2          3 1974-06-23        1979-12-09     
#>  7                    3          5 1940-10-17        1943-04-05     
#>  8                    1          8 1956-01-25        1956-04-03     
#>  9                    2         10 1969-01-31        1969-03-17     
#> 10                    1          2 1973-03-03        1983-04-12     
#> # ℹ 1 more variable: observation_period_id <int>

# }