From a05ea0780700bf031794fddeed2f50c84209670d Mon Sep 17 00:00:00 2001 From: Anthony Sena Date: Tue, 5 Nov 2024 11:57:15 -0500 Subject: [PATCH] Add option to hook into cohort SQL for customization --- R/StrategusModule.R | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/R/StrategusModule.R b/R/StrategusModule.R index 8e4f7d49..30534be7 100644 --- a/R/StrategusModule.R +++ b/R/StrategusModule.R @@ -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,