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 [10 x 5]
#> # Database: DuckDB v1.1.2 [unknown@Linux 6.5.0-1025-azure:R 4.4.2/:memory:]
#>    cohort_definition_id subject_id cohort_start_date cohort_end_date
#>                   <int>      <int> <date>            <date>         
#>  1                    1          4 1971-09-27        1973-01-15     
#>  2                    1          6 1962-02-23        1966-12-24     
#>  3                    1          9 1933-05-29        1938-08-25     
#>  4                    3         10 1911-09-06        1925-12-25     
#>  5                    1          1 1979-09-10        1982-09-10     
#>  6                    3          2 1944-01-15        1952-01-20     
#>  7                    2          7 1977-07-27        1997-12-15     
#>  8                    1          3 1948-02-24        1950-08-03     
#>  9                    1          8 1933-05-09        1938-02-16     
#> 10                    2          5 1914-05-22        1937-10-07     
#> # ℹ 1 more variable: observation_period_id <int>
mockDisconnect(cdm = cdm)
# }