Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle leap year birthdays in demographicsCohort #171

Open
edward-burn opened this issue May 22, 2024 · 2 comments · May be fixed by #172
Open

Handle leap year birthdays in demographicsCohort #171

edward-burn opened this issue May 22, 2024 · 2 comments · May be fixed by #172

Comments

@edward-burn
Copy link
Collaborator

@nmercadeb @catalamarti shouldn't min age be 18 in the case below?

library(CDMConnector)
library(CodelistGenerator)
library(PatientProfiles)
library(CohortConstructor)
#> 
#> Attaching package: 'CohortConstructor'
#> The following objects are masked from 'package:CDMConnector':
#> 
#>     intersectCohorts, unionCohorts
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

con <- DBI::dbConnect(duckdb::duckdb(), 
                      dbdir = eunomia_dir())
cdm <- cdm_from_con(con, cdm_schema = "main", 
                    write_schema = c(prefix = "my_study_", schema = "main"))

cdm$working_age_cohort <- demographicsCohort(cdm = cdm, 
                                             ageRange = c(18, 65), 
                                             name = "working_age_cohort")
#> ℹ Building new trimmed cohort
#> Adding birth date
#> Creating initial cohort
#> Trim age
#> ✔ Cohort trimmed

cdm$working_age_cohort |> 
  addAge(indexDate = "cohort_start_date") |> 
  summarise(min_start_age = min(age), 
            median_start_age = median(age), 
            max_start_age = max(age))
#> Warning: Missing values are always removed in SQL aggregation functions.
#> Use `na.rm = TRUE` to silence this warning
#> This warning is displayed once every 8 hours.
#> # Source:   SQL [1 x 3]
#> # Database: DuckDB v0.10.3-dev775 [eburn@Windows 10 x64:R 4.4.0/C:\Users\eburn\AppData\Local\Temp\RtmpUJzNcL\file48942f7e6037.duckdb]
#>   min_start_age median_start_age max_start_age
#>           <int>            <dbl>         <int>
#> 1            17               18            18

Created on 2024-05-22 with reprex v2.1.0

@nmercadeb
Copy link
Collaborator

This was one subject born on the 29th of February ahhaha
When calculating the 18th birthday by adding 18 years to date of birth we got 28th of February, solved by adding 1 day to these edge cases in PR 127

library(CDMConnector)
library(CodelistGenerator)
library(PatientProfiles)
library(CohortConstructor)
#> 
#> Attaching package: 'CohortConstructor'
#> The following objects are masked from 'package:CDMConnector':
#> 
#>     intersectCohorts, unionCohorts
library(dplyr)
#> Warning: package 'dplyr' was built under R version 4.2.3
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
con <- DBI::dbConnect(duckdb::duckdb(), 
                      dbdir = eunomia_dir())
cdm <- cdm_from_con(con, cdm_schema = "main", 
                    write_schema = c(prefix = "my_study_", schema = "main"))

cdm$working_age_cohort <- demographicsCohort(cdm = cdm, 
                                             ageRange = c(18, 65), 
                                             name = "working_age_cohort")
#> ℹ Building new trimmed cohort
#> Adding birth date
#> Creating initial cohort
#> Trim age
#> ✔ Cohort trimmed
cdm$working_age_cohort |> 
  addAge(indexDate = "cohort_start_date") |> 
  summarise(min_start_age = min(age), 
            median_start_age = median(age), 
            max_start_age = max(age))
#> Warning: Missing values are always removed in SQL aggregation functions.
#> Use `na.rm = TRUE` to silence this warning
#> This warning is displayed once every 8 hours.
#> # Source:   SQL [1 x 3]
#> # Database: DuckDB v0.10.1 [nmercade@Windows 10 x64:R 4.2.2/C:\Users\nmercade\AppData\Local\Temp\Rtmp8KaPeO\file242c567f7787.duckdb]
#>   min_start_age median_start_age max_start_age
#>           <dbl>            <dbl>         <dbl>
#> 1            18               18            18

Created on 2024-05-22 with reprex v2.1.0

@nmercadeb nmercadeb linked a pull request May 22, 2024 that will close this issue
@edward-burn
Copy link
Collaborator Author

Hmm I'm not sure if the issue is not actually that patient profiles should consider 28 Feb the person's birthday if born on a leap year....

@nmercadeb nmercadeb changed the title min age in demographicsCohort Handle leap year birthdays in demographicsCohort Oct 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants