Skip to contents

In this vignette we’ll show how requirements related to patient demographics can be applied to a cohort. Again we’ll use the Eunomia synthetic data.

con <- DBI::dbConnect(duckdb::duckdb(), dbdir = eunomiaDir())
cdm <- CDMConnector::cdmFromCon(con, cdmSchema = "main", 
                    writeSchema = "main", writePrefix = "my_study_")

Let’s start by creating a cohort of people with a fracture. We’ll first look for codes that might represent a fracture and the build a cohort using these codes, setting cohort exit to 180 days after the fracture.

fracture_codes <- getCandidateCodes(cdm, "fracture")
fracture_codes <- list("fracture" = fracture_codes$concept_id)
cdm$fracture <- conceptCohort(cdm = cdm, 
                                 conceptSet = fracture_codes, 
                                 name = "fracture")

summary_attrition <- summariseCohortAttrition(cdm$fracture)
plotCohortAttrition(summary_attrition)
%0 2->3 3->4 4->5 7->8 9->10 11->12 1 Database: Synthea Cohort name: fracture 2 N subjects = 1,596 N records = 2,522 3 N subjects = 1,596 N records = 2,522 4 N subjects = 1,596 N records = 2,522 5 N subjects = 1,596 N records = 2,445 6 Initial qualifying events 7 Record start <= record end 8 N subjects = 0 N records = 0 9 Record in observation 10 N subjects = 0 N records = 0 11 Merge overlapping records 12 N subjects = 0 N records = 77

Restrict cohort by age

We can choose a specific age range for individuals in our cohort using requireAge() from CohortConstructor.

cdm$fracture <- cdm$fracture |> 
  requireAge(indexDate = "cohort_start_date",
             ageRange = list(c(18, 100)))

summary_attrition <- summariseCohortAttrition(cdm$fracture)
plotCohortAttrition(summary_attrition)
%0 2->3 3->4 4->5 5->6 8->9 10->11 12->13 14->15 1 Database: Synthea Cohort name: fracture 2 N subjects = 1,596 N records = 2,522 3 N subjects = 1,596 N records = 2,522 4 N subjects = 1,596 N records = 2,522 5 N subjects = 1,596 N records = 2,445 6 N subjects = 859 N records = 1,148 7 Initial qualifying events 8 Record start <= record end 9 N subjects = 0 N records = 0 10 Record in observation 11 N subjects = 0 N records = 0 12 Merge overlapping records 13 N subjects = 0 N records = 77 14 Age requirement: 18 to 100 15 N subjects = 737 N records = 1,297

Note that by default individuals are filtered based on the age they were when they entered the cohort.

Restrict cohort by sex

We can also specify a sex criteria for individuals in our cohort using requireSex() from CohortConstructor.

cdm$fracture <- cdm$fracture |> 
  requireSex(sex = "Female")

summary_attrition <- summariseCohortAttrition(cdm$fracture)
plotCohortAttrition(summary_attrition)
%0 2->3 3->4 4->5 5->6 6->7 9->10 11->12 13->14 15->16 17->18 1 Database: Synthea Cohort name: fracture 2 N subjects = 1,596 N records = 2,522 3 N subjects = 1,596 N records = 2,522 4 N subjects = 1,596 N records = 2,522 5 N subjects = 1,596 N records = 2,445 6 N subjects = 859 N records = 1,148 7 N subjects = 447 N records = 604 8 Initial qualifying events 9 Record start <= record end 10 N subjects = 0 N records = 0 11 Record in observation 12 N subjects = 0 N records = 0 13 Merge overlapping records 14 N subjects = 0 N records = 77 15 Age requirement: 18 to 100 16 N subjects = 737 N records = 1,297 17 Sex requirement: Female 18 N subjects = 412 N records = 544

Restrict cohort by number of prior observations

We can also specify a minimum number of days of prior observations for each individual using requirePriorObservation() from CohortConstructor.

cdm$fracture <- cdm$fracture |> 
  requirePriorObservation(indexDate = "cohort_start_date",
                          minPriorObservation = 365)

summary_attrition <- summariseCohortAttrition(cdm$fracture)
plotCohortAttrition(summary_attrition)
%0 2->3 3->4 4->5 5->6 6->7 7->8 10->11 12->13 14->15 16->17 18->19 20->21 1 Database: Synthea Cohort name: fracture 2 N subjects = 1,596 N records = 2,522 3 N subjects = 1,596 N records = 2,522 4 N subjects = 1,596 N records = 2,522 5 N subjects = 1,596 N records = 2,445 6 N subjects = 859 N records = 1,148 7 N subjects = 447 N records = 604 8 N subjects = 447 N records = 604 9 Initial qualifying events 10 Record start <= record end 11 N subjects = 0 N records = 0 12 Record in observation 13 N subjects = 0 N records = 0 14 Merge overlapping records 15 N subjects = 0 N records = 77 16 Age requirement: 18 to 100 17 N subjects = 737 N records = 1,297 18 Sex requirement: Female 19 N subjects = 412 N records = 544 20 Prior observation requirement: 365 days 21 N subjects = 0 N records = 0

As well as specifying a minimum amount of prior observation, we can require some mimimum amount of follow-up by using requireFutureObservation() in a similar way.

Applying multiple demographic requirements to a cohort

We can implement multiple demographic requirements at the same time by using the more general requireDemographics() function.

cdm$fracture <- conceptCohort(cdm = cdm, 
                                 conceptSet = fracture_codes, 
                                 name = "fracture") |> 
  requireDemographics(indexDate = "cohort_start_date",
                      ageRange = c(18,100),
                      sex = "Female",
                      minPriorObservation = 365, 
                      minFutureObservation = 30)

summary_attrition <- summariseCohortAttrition(cdm$fracture)
plotCohortAttrition(summary_attrition)
%0 2->3 3->4 4->5 5->6 6->7 7->8 8->9 11->12 13->14 15->16 17->18 19->20 21->22 23->24 1 Database: Synthea Cohort name: fracture 2 N subjects = 1,596 N records = 2,522 3 N subjects = 1,596 N records = 2,522 4 N subjects = 1,596 N records = 2,522 5 N subjects = 1,596 N records = 2,445 6 N subjects = 859 N records = 1,148 7 N subjects = 447 N records = 604 8 N subjects = 447 N records = 604 9 N subjects = 445 N records = 598 10 Initial qualifying events 11 Record start <= record end 12 N subjects = 0 N records = 0 13 Record in observation 14 N subjects = 0 N records = 0 15 Merge overlapping records 16 N subjects = 0 N records = 77 17 Age requirement: 18 to 100 18 N subjects = 737 N records = 1,297 19 Sex requirement: Female 20 N subjects = 412 N records = 544 21 Prior observation requirement: 365 days 22 N subjects = 0 N records = 0 23 Future observation requirement: 30 days 24 N subjects = 2 N records = 6