Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to hook into cohort SQL for customization #180

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading