Class for automating the creation of bulk cohorts
Class for automating the creation of bulk cohorts
namename for this template definition that describes the cohorts it creation
sqlArgsoptional arguments for sql
templateSqlsql template
translateSqltranslate the sql for different platforms
referencesdata.frame of name/id references for cohort template that aligns with cohort set
new()CohortTemplateDefinition$new(settings)settingsSettings of object to load seealso createCohortTemplateDefinition To alter the execution, override this function in a subclass. This translates and executes the sql of the cohort definition Note that calling this function will generate the cohorts but will not do so in an incremental manner. Checksums and timestamps will, however, be added to the generation table ever want to call this function outside of a testing environment. It is best practice to always use the standard runCohortGeneration/generateCohortSet pipeline to ensure validity of execution steps.
executeTemplateSql()CohortTemplateDefinition$executeTemplateSql(
connection,
cohortDatabaseSchema,
cdmDatabaseSchema,
cohortTableNames,
vocabularyDatabaseSchema = cdmDatabaseSchema,
tempEmulationSchema = getOption("sqlRenderTempEmulationSchema")
)connectionAn object of type connection as created using the
connect function in the
DatabaseConnector package. Can be left NULL if connectionDetails
is provided, in which case a new connection will be opened at the start
of the function, and closed when the function finishes.
cohortDatabaseSchemaSchema name where your cohort tables reside. Note that for SQL Server, this should include both the database and schema name, for example 'scratch.dbo'.
cohortDatabaseSchemaSchema name where your cohort tables reside. Note that for SQL Server, this should include both the database and schema name, for example 'scratch.dbo'.
cdmDatabaseSchemaSchema name where your patient-level data in OMOP CDM format resides. Note that for SQL Server, this should include both the database and schema name, for example 'cdm_data.dbo'.
cohortTableNamesThe names of the cohort tables. See getCohortTableNames
for more details.
vocabularyDatabaseSchemavocabulary database schema
tempEmulationSchemacdm temp emulation schema get template references data.frame
getTemplateReferences()Returns data.frame of references get the name of the definition
CohortTemplateDefinition$getTemplateReferences()
getName()Name field get the generated id of the template definition
CohortTemplateDefinition$getName()
getId()this is not the cohort ids and is based off of the checksum of the template definition get checksum
CohortTemplateDefinition$getId()
getChecksum()Get the hash of the definition (generated when class is instantiated) to list
CohortTemplateDefinition$getChecksum()
toList()Used for serializing the definition to json
CohortTemplateDefinition$toList()
toJson()json serialized form of the template definition save to disk
CohortTemplateDefinition$toJson()
saveTemplate()Save object to specified json path
CohortTemplateDefinition$saveTemplate(filePath)filePathFile path to save json serialized from
clone()The objects of this class are cloneable with this method.
CohortTemplateDefinition$clone(deep = FALSE)deepWhether to make a deep clone.
This class provides a framework for automating the creation of bulk cohorts by defining template SQL queries and associated callbacks to execute them. This is useful when defining lots of exposure or outcomes for cohorts that are very general in nature. For example, all RxNorm ingredient cohorts, all ATC ingredient cohorts or all SNOMED condition occurrences with > x diagnosis codes.
These cohorts can then be subsetted with common cohort subset operations such as limiting to specific age, gender, or observation criteria, should this be excluded from the cohort definition. However, when applying operations in bulk it may be more efficient to include such definitions within the template sql itself.
This approach is also useful for cohorts that can not based on ATLAS/CirceDefinitions alone.
CURRENTLY NOT SUPPORTED: * Saving definitions that use runtime arguments on a per cdm basis. This creates a challenge for running the same cohort across different databases. Furthermore, saving information within the CDM schema in a shared OHDSI study is not desirable.