if (FALSE) {
# This function is for developers who are creating cohort_table
# objects in their packages. The function should accept a cdm_reference
# object as the first argument and return a cdm_reference object with the
# cohort table added. The second argument should be `name` which will be
# the prefix for the database tables, the name of the cohort table in the
# database and the name of the cohort table in the cdm object.
# Other optional arguments can be added after the first two.
generateCustomCohort <- function(cdm, name, ...) {
# accept a cdm_reference object as input
checkmate::assertClass(cdm, "cdm_reference")
con <- attr(cdm, "dbcon")
# Create the tables in the database however you like
# All the tables should be prefixed with `name`
# The cohort table should be called `name` in the database
# Create the dplyr table references
cohort_ref <- dplyr::tbl(con, name)
cohort_set <- dplyr::tbl(con, paste0(name, "_set"))
cohort_attrition_ref <- dplyr::tbl(con, paste0(name, "_attrition"))
cohort_count_ref <- dplyr::tbl(con, paste0(name, "_count"))
# add to the cdm
cdm[[name]] <- cohort_ref
# create the generated cohort set object using the constructor
cdm[[name]] <- newGeneratedCohortSet(
cdm[[name]],
cohortSetRef = cohort_set_ref,
cohortAttritionRef = cohort_attrition_ref,
cohortCountRef = cohort_count_ref)
return(cdm)
}
}
Run the code above in your browser using DataLab