Skip to content

Commit

Permalink
Add option to hook into cohort SQL for customization (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena authored Nov 26, 2024
1 parent 5eaa4e9 commit ae52a3e
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 @@ -233,11 +233,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 ae52a3e

Please sign in to comment.