Retrieve a cohort from ATLAS for use in All of Us

Description

Retrieves a cohort definition from ATLAS and generates the cohort in All of Us. Observation periods are first generated for each subject using the aou_observation_period() function.The resulting cohort is a table with the cohort start and end dates for each person_id.

Usage

aou_atlas_cohort(
  cohort_definition,
  cohort_sql,
  debug = FALSE,
  collect = FALSE,
  ...,
  con = getOption("aou.default.con")
)

Arguments

cohort_definition A cohort definition generated using getCohortDefinition() from ROhdsiWebApi
cohort_sql The cohort_sql generated using getCohortSql() from ROhdsiWebApi
debug Print the query to the console; useful for debugging.
collect Whether to bring the resulting table into local memory (collect = TRUE) as a dataframe or leave as a reference to a database table (for continued analysis using, e.g., dbplyr). Defaults to FALSE.
Further arguments passed along to collect() if collect = TRUE
con Connection to the allofus SQL database. Defaults to getOption("aou.default.con"), which is set automatically if you use aou_connect()

Details

The function is based on a similar function in https://github.com/cmayer2/r4aou with some tweaks to generate the appropriate observation periods and incorporate other package functions. Please see the online vignette for additional details.

Value

A dataframe if collect = TRUE; a reference to a remote database table if not. The SQL query used to generate the cohort is stored as an attribute.

Examples

library("allofus")


# generate a simple stroke cohort
# see https://atlas-demo.ohdsi.org/#/cohortdefinition/1788061
# If this cohort is not available, you can create one, or choose one already made.
# aou_cohort_example contains the results of
# cd <- ROhdsiWebApi::getCohortDefinition(1788061, "https://atlas-demo.ohdsi.org/WebAPI")
# for some cohorts, you must use the argument generateStats = FALSE or the cohort (its stats)
# can't be generated on All of Us
# cd_sql <- ROhdsiWebApi::getCohortSql(cd, "https://atlas-demo.ohdsi.org/WebAPI",
#                                                   generateStats = FALSE)

cohort <- aou_atlas_cohort(
  cohort_definition = aou_cohort_example$cd,
  cohort_sql = aou_cohort_example$cd_sql
)

# print query that was executed
cat(attr(cohort, "query"))