Skip to content

Commit

Permalink
Add option to hook into cohort SQL for customization
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena committed Nov 5, 2024
1 parent 612859f commit a05ea07
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions R/StrategusModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,21 @@ StrategusModule <- R6::R6Class(
if (length(cohortDefinitions) <= 0) {
stop("No cohort definitions found")
}
# Provide hook to allow for custom SQL generation based on the Circe-be
# generated SQL
cohortSqlOptimizationFunction <- getOption("strategus.cohortSqlOptimizationFunction")
useCohortSqlOptimizationFunction <- is.function(cohortSqlOptimizationFunction)
if (isTRUE(useCohortSqlOptimizationFunction)) {
private$.message("Constructing cohort definition set and using strategus.cohortSqlOptimizationFunction")
}
cohortDefinitionSet <- CohortGenerator::createEmptyCohortDefinitionSet()
for (i in 1:length(cohortDefinitions)) {
cohortJson <- cohortDefinitions[[i]]$cohortDefinition
cohortExpression <- CirceR::cohortExpressionFromJson(cohortJson)
cohortSql <- CirceR::buildCohortQuery(cohortExpression, options = CirceR::createGenerateOptions(generateStats = generateStats))
if (isTRUE(useCohortSqlOptimizationFunction)) {
cohortSql <- cohortSqlOptimizationFunction(cohortSql)
}
cohortDefinitionSet <- rbind(cohortDefinitionSet, data.frame(
cohortId = as.double(cohortDefinitions[[i]]$cohortId),
cohortName = cohortDefinitions[[i]]$cohortName,
Expand Down

0 comments on commit a05ea07

Please sign in to comment.