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_120_1740755721> [?? 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                    3          4 1952-05-15        1970-09-16     
#>  2                    2          7 1941-08-13        1945-02-25     
#>  3                    1          1 1906-02-19        1906-03-10     
#>  4                    1          9 1970-06-23        1978-08-12     
#>  5                    1          5 1922-08-25        1927-05-15     
#>  6                    3          8 1984-01-12        1991-02-18     
#>  7                    1         10 1976-05-29        1982-06-11     
#>  8                    2          6 1954-04-20        1970-08-20     
#>  9                    3          2 1952-05-24        1954-01-04     
#> 10                    3          3 1909-11-17        1927-04-20     
#> # ℹ 1 more variable: observation_period_id <int>

mockDisconnect(cdm = cdm)
# }