Skip to content

Commit

Permalink
Release v1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena authored Nov 26, 2024
2 parents 612859f + bda7af6 commit 1cb0577
Show file tree
Hide file tree
Showing 20 changed files with 191 additions and 24 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: Strategus
Type: Package
Title: Coordinate and Execute OHDSI HADES Modules
Version: 1.0.0
Date: 2024-10-08
Version: 1.1.0
Date: 2024-11-26
Authors@R: c(
person("Anthony", "Sena", email = "[email protected]", role = c("aut", "cre")),
person("Martijn", "Schuemie", email = "[email protected]", role = c("aut")),
Expand Down
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Strategus 1.1.0
===============
- Inject cohort schema and table into `createCohortBasedCovariateSettings` (#181)
- Provide hook to optimize cohort SQL construction (#179)
- Fixes broken links in R6 class documentation (#183)

Strategus 1.0.0
===============

Expand Down
7 changes: 3 additions & 4 deletions R/Module-PatientLevelPrediction.R
Original file line number Diff line number Diff line change
Expand Up @@ -156,10 +156,9 @@ PatientLevelPredictionModule <- R6::R6Class(
}
),
private = list(
.setCovariateSchemaTable = function(
modelDesignList,
cohortDatabaseSchema,
cohortTable) {
.setCovariateSchemaTable = function(modelDesignList,
cohortDatabaseSchema,
cohortTable) {
if (inherits(modelDesignList, "modelDesign")) {
modelDesignList <- list(modelDesignList)
}
Expand Down
16 changes: 8 additions & 8 deletions R/Settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ addModuleSpecifications <- function(analysisSpecifications, moduleSpecifications
#' Add Characterization module specifications to analysis specifications
#'
#' @template analysisSpecifications
#' @param moduleSpecifications Created by the \href{../../docs/reference/CharacterizationModule.html#method-CharacterizationModule-createModuleSpecifications}{\code{CharacterizationModule$createModuleSpecifications()}} function.
#' @param moduleSpecifications Created by the \href{../reference/CharacterizationModule.html#method-CharacterizationModule-createModuleSpecifications}{\code{CharacterizationModule$createModuleSpecifications()}} function.
#'
#' @return
#' Returns the `analysisSpecifications` object with the module specifications added.
Expand All @@ -81,7 +81,7 @@ addCharacterizationModuleSpecifications <- function(analysisSpecifications, modu
#' Add Cohort Diagnostics module specifications to analysis specifications
#'
#' @template analysisSpecifications
#' @param moduleSpecifications Created by the \href{../../docs/reference/CohortDiagnosticsModule.html#method-CohortDiagnosticsModule-createModuleSpecifications}{\code{CohortDiagnosticsModule$createModuleSpecifications()}} function.
#' @param moduleSpecifications Created by the \href{../reference/CohortDiagnosticsModule.html#method-CohortDiagnosticsModule-createModuleSpecifications}{\code{CohortDiagnosticsModule$createModuleSpecifications()}} function.
#'
#' @return
#' Returns the `analysisSpecifications` object with the module specifications added.
Expand All @@ -100,7 +100,7 @@ addCohortDiagnosticsModuleSpecifications <- function(analysisSpecifications, mod
#' Add Cohort Generator module specifications to analysis specifications
#'
#' @template analysisSpecifications
#' @param moduleSpecifications Created by the \href{../../docs/reference/CohortGeneratorModule.html#method-CohortGeneratorModule-createModuleSpecifications}{\code{CohortGeneratorModule$createModuleSpecifications()}} function.
#' @param moduleSpecifications Created by the \href{../reference/CohortGeneratorModule.html#method-CohortGeneratorModule-createModuleSpecifications}{\code{CohortGeneratorModule$createModuleSpecifications()}} function.
#'
#' @return
#' Returns the `analysisSpecifications` object with the module specifications added.
Expand All @@ -119,7 +119,7 @@ addCohortGeneratorModuleSpecifications <- function(analysisSpecifications, modul
#' Add Cohort Incidence module specifications to analysis specifications
#'
#' @template analysisSpecifications
#' @param moduleSpecifications Created by the \href{../../docs/reference/CohortIncidenceModule.html#method-CohortIncidenceModule-createModuleSpecifications}{\code{CohortIncidenceModule$createModuleSpecifications()}} function.
#' @param moduleSpecifications Created by the \href{../reference/CohortIncidenceModule.html#method-CohortIncidenceModule-createModuleSpecifications}{\code{CohortIncidenceModule$createModuleSpecifications()}} function.
#'
#' @return
#' Returns the `analysisSpecifications` object with the module specifications added.
Expand All @@ -138,7 +138,7 @@ addCohortIncidenceModuleSpecifications <- function(analysisSpecifications, modul
#' Add Cohort Method module specifications to analysis specifications
#'
#' @template analysisSpecifications
#' @param moduleSpecifications Created by the \href{../../docs/reference/CohortMethodModule.html#method-CohortMethodModule-createModuleSpecifications}{\code{CohortMethodModule$createModuleSpecifications()}} function.
#' @param moduleSpecifications Created by the \href{../reference/CohortMethodModule.html#method-CohortMethodModule-createModuleSpecifications}{\code{CohortMethodModule$createModuleSpecifications()}} function.
#'
#' @return
#' Returns the `analysisSpecifications` object with the module specifications added.
Expand All @@ -157,7 +157,7 @@ addCohortMethodeModuleSpecifications <- function(analysisSpecifications, moduleS
#' Add Evidence Synthesis module specifications to analysis specifications
#'
#' @template analysisSpecifications
#' @param moduleSpecifications Created by the \href{../../docs/reference/EvidenceSynthesisModule.html#method-EvidenceSynthesisModule-createModuleSpecifications}{\code{EvidenceSynthesisModule$createModuleSpecifications()}} function.
#' @param moduleSpecifications Created by the \href{../reference/EvidenceSynthesisModule.html#method-EvidenceSynthesisModule-createModuleSpecifications}{\code{EvidenceSynthesisModule$createModuleSpecifications()}} function.
#'
#' @return
#' Returns the `analysisSpecifications` object with the module specifications added.
Expand All @@ -176,7 +176,7 @@ addEvidenceSynthesisModuleSpecifications <- function(analysisSpecifications, mod
#' Add Patient Level Prediction module specifications to analysis specifications
#'
#' @template analysisSpecifications
#' @param moduleSpecifications Created by the \href{../../docs/reference/PatientLevelPredictionModule.html#method-PatientLevelPredictionModule-createModuleSpecifications}{\code{PatientLevelPredictionModule$createModuleSpecifications()}} function.
#' @param moduleSpecifications Created by the \href{../reference/PatientLevelPredictionModule.html#method-PatientLevelPredictionModule-createModuleSpecifications}{\code{PatientLevelPredictionModule$createModuleSpecifications()}} function.
#'
#' @return
#' Returns the `analysisSpecifications` object with the module specifications added.
Expand All @@ -195,7 +195,7 @@ addPatientLevelPredictionModuleSpecifications <- function(analysisSpecifications
#' Add Self Controlled Case Series Module module specifications to analysis specifications
#'
#' @template analysisSpecifications
#' @param moduleSpecifications Created by the \href{../../docs/reference/SelfControlledCaseSeriesModule.html#method-SelfControlledCaseSeriesModule-createModuleSpecifications}{\code{SelfControlledCaseSeriesModule$createModuleSpecifications()}} function.
#' @param moduleSpecifications Created by the \href{../reference/SelfControlledCaseSeriesModule.html#method-SelfControlledCaseSeriesModule-createModuleSpecifications}{\code{SelfControlledCaseSeriesModule$createModuleSpecifications()}} function.
#'
#' @return
#' Returns the `analysisSpecifications` object with the module specifications added.
Expand Down
85 changes: 85 additions & 0 deletions R/StrategusModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,30 @@ StrategusModule <- R6::R6Class(
}
private$jobContext$settings <- moduleSpecification$settings

# Make sure that the covariate settings for the analysis are updated
# to reflect the location of the cohort tables if we are executing
# on a CDM.
if (inherits(executionSettings, "CdmExecutionSettings")) {
private$jobContext$settings <- .replaceCovariateSettings(
moduleSettings = private$jobContext$settings,
executionSettings = executionSettings
)
}

# Assemble the job context from the analysis specification
# for the given module.
private$jobContext$sharedResources <- analysisSpecifications$sharedResources
private$jobContext$moduleExecutionSettings <- executionSettings
private$jobContext$moduleExecutionSettings$resultsSubFolder <- file.path(private$jobContext$moduleExecutionSettings$resultsFolder, self$moduleName)
if (!dir.exists(private$jobContext$moduleExecutionSettings$resultsSubFolder)) {
dir.create(private$jobContext$moduleExecutionSettings$resultsSubFolder, showWarnings = F, recursive = T)
}

if (is(private$jobContext$moduleExecutionSettings, "ExecutionSettings")) {
private$jobContext$moduleExecutionSettings$workSubFolder <- file.path(private$jobContext$moduleExecutionSettings$workFolder, self$moduleName)
if (!dir.exists(private$jobContext$moduleExecutionSettings$workSubFolder)) {
dir.create(private$jobContext$moduleExecutionSettings$workSubFolder, showWarnings = F, recursive = T)
}
}
},
.getModuleSpecification = function(analysisSpecifications, moduleName) {
Expand Down Expand Up @@ -217,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 Expand Up @@ -294,3 +320,62 @@ StrategusModule <- R6::R6Class(
}
)
)

# Utility function to set the cohort table & schema on
# createCohortBasedCovariateSettings with information from
# the execution settings (Issue #181)
.replaceCovariateSettingsCohortTableNames <- function(covariateSettings, executionSettings) {
errorMessages <- checkmate::makeAssertCollection()
checkmate::assertList(covariateSettings, min.len = 1, add = errorMessages)
checkmate::assertClass(executionSettings, "CdmExecutionSettings", add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)

.replaceProperties <- function(s) {
if (inherits(s, "covariateSettings") && "fun" %in% names(attributes(s))) {
if (attr(s, "fun") == "getDbCohortBasedCovariatesData") {
# Set the covariateCohortDatabaseSchema & covariateCohortTable values
s$covariateCohortDatabaseSchema <- executionSettings$workDatabaseSchema
s$covariateCohortTable <- executionSettings$cohortTableNames$cohortTable
}
}
return(s)
}
if (is.null(names(covariateSettings))) {
# List of lists
modifiedCovariateSettings <- lapply(covariateSettings, .replaceProperties)
} else {
# Plain list
modifiedCovariateSettings <- .replaceProperties(covariateSettings)
}
return(modifiedCovariateSettings)
}

.replaceCovariateSettings <- function(moduleSettings, executionSettings) {
errorMessages <- checkmate::makeAssertCollection()
checkmate::assertList(moduleSettings, min.len = 1, add = errorMessages)
checkmate::assertClass(executionSettings, "CdmExecutionSettings", add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)

# A helper function to perform the replacement
replaceHelper <- function(x) {
if (is.list(x) && inherits(x, "covariateSettings")) {
# If the element is a list and of type covariate settings
# replace the cohort table names
return(.replaceCovariateSettingsCohortTableNames(x, executionSettings))
} else if (is.list(x)) {
# If the element is a list, recurse on each element
# Keep the original attributes by saving them before modification
attrs <- attributes(x)
newList <- lapply(x, replaceHelper)
# Restore attributes to the new list
attributes(newList) <- attrs
return(newList)
} else {
# If the element is not a list or "covariateSettings", return it as is
return(x)
}
}

# Call the helper function on the input list
return(replaceHelper(moduleSettings))
}
Binary file modified extras/Strategus.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions extras/rdms/schema_meta.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1067,10 +1067,10 @@
<table name="plp_model_designs" comments="PatientLevelPredictionModule: Model designs">
<column name="model_design_id" comments="a unique identifier for the model design settings"/>
<column name="target_id" comments="the identifier for the target cohort id">
<foreignKey table="cg_cohort_definition" column="cohort_definition_id"/>
<foreignKey table="plp_cohorts" column="cohort_definition_id"/>
</column>
<column name="outcome_id" comments="the identifier for the outcome cohort id">
<foreignKey table="cg_cohort_definition" column="cohort_definition_id"/>
<foreignKey table="plp_cohorts" column="cohort_definition_id"/>
</column>
<column name="tar_id" comments="the identifier for the time at risk setting"/>
<column name="plp_data_setting_id" comments="the identifier for the plp data setting"/>
Expand Down
Binary file modified inst/doc/CreatingAnalysisSpecification.pdf
Binary file not shown.
Binary file modified inst/doc/ExecuteStrategus.pdf
Binary file not shown.
Binary file modified inst/doc/IntroductionToStrategus.pdf
Binary file not shown.
Binary file modified inst/doc/WorkingWithResults.pdf
Binary file not shown.
2 changes: 1 addition & 1 deletion man/addCharacterizationModuleSpecifications.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/addCohortDiagnosticsModuleSpecifications.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/addCohortGeneratorModuleSpecifications.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/addCohortIncidenceModuleSpecifications.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/addCohortMethodeModuleSpecifications.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/addEvidenceSynthesisModuleSpecifications.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/addPatientLevelPredictionModuleSpecifications.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/addSelfControlledCaseSeriesModuleSpecifications.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 1cb0577

Please sign in to comment.