Skip to contents

[Experimental] Same as addBirthday(), except query is not computed to a table.

The function accounts for leap years and corrects the invalid dates to the next valid date.

Usage

addBirthdayQuery(
  x,
  birthdayName = "birthday",
  birthday = 0,
  ageMissingMonth = 1,
  ageMissingDay = 1,
  ageImposeMonth = FALSE,
  ageImposeDay = FALSE,
  ageUnit = "years"
)

Arguments

x

A table containing individuals in a CDM reference.

birthdayName

Name of the birthday column to add.

birthday

Day of birth to add.

ageMissingMonth

Month of the year assigned when month of birth is missing.

ageMissingDay

Day of the month assigned when day of birth is missing.

ageImposeMonth

If TRUE, month of birth is treated as missing for all individuals.

ageImposeDay

If TRUE, day of birth is treated as missing for all individuals.

ageUnit

Unit in which to express age: "years", "months", or "days".

Value

The table with a query that add the new column containing the birth day.

Examples

# \donttest{
library(PatientProfiles)
library(dplyr)

cdm <- mockPatientProfiles(source = "duckdb")

cdm$cohort1 |>
  addBirthdayQuery() |>
  glimpse()
#> Rows: ??
#> Columns: 5
#> $ cohort_definition_id <int> 2, 3, 2, 1, 1, 2, 2, 1, 3, 3
#> $ subject_id           <int> 5, 9, 7, 4, 8, 10, 3, 1, 2, 6
#> $ cohort_start_date    <date> 1949-02-12, 1950-05-18, 1934-08-23, 1942-01-08, 1…
#> $ cohort_end_date      <date> 1979-11-11, 1954-03-23, 1945-12-07, 1944-07-01, 1…
#> $ birthday             <date> 1937-01-01, 1940-01-01, 1920-01-01, 1925-01-01, 

cdm$cohort1 |>
  addBirthdayQuery(birthday = 5) |>
  glimpse()
#> Rows: ??
#> Columns: 5
#> $ cohort_definition_id <int> 2, 3, 2, 1, 1, 2, 2, 1, 3, 3
#> $ subject_id           <int> 5, 9, 7, 4, 8, 10, 3, 1, 2, 6
#> $ cohort_start_date    <date> 1949-02-12, 1950-05-18, 1934-08-23, 1942-01-08, 1…
#> $ cohort_end_date      <date> 1979-11-11, 1954-03-23, 1945-12-07, 1944-07-01, 1…
#> $ birthday             <date> 1942-01-01, 1945-01-01, 1925-01-01, 1930-01-01, 
# }