Skip to content

Commit

Permalink
New branch for testing patch
Browse files Browse the repository at this point in the history
  • Loading branch information
azimov committed Aug 14, 2024
1 parent 9eabd7d commit cbf145f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 55 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Imports:
SqlRender (>= 1.9.0),
stringr,
tidyr (>= 1.2.0),
CohortGenerator (>= 0.8.0),
CohortGenerator (>= 0.10.0),
remotes,
scales
Suggests:
Expand Down
104 changes: 55 additions & 49 deletions R/RunDiagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,11 @@ getDefaultCovariateSettings <- function() {
#' @param incremental Create only cohort diagnostics that haven't been created before?
#' @param incrementalFolder If \code{incremental = TRUE}, specify a folder where records are kept
#' of which cohort diagnostics has been executed.
#' @param runOnSample Logical. If TRUE, the function will operate on a sample of the data.
#' @param runFeatureExtractionOnSample Logical. If TRUE, the function will operate on a sample of the data.
#' Default is FALSE, meaning the function will operate on the full data set.
#'
#' @param sampleN Integer. The number of records to include in the sample if runOnSample is TRUE.
#' Default is 1000. Ignored if runOnSample is FALSE.
#' @param sampleN Integer. The number of records to include in the sample if runFeatureExtractionOnSample is TRUE.
#' Default is 1000. Ignored if runFeatureExtractionOnSample is FALSE.
#'
#' @param seed Integer. The seed for the random number generator used to create the sample.
#' This ensures that the same sample can be drawn again in future runs. Default is 64374.
Expand Down Expand Up @@ -228,7 +228,7 @@ executeDiagnostics <- function(cohortDefinitionSet,
irWashoutPeriod = 0,
incremental = FALSE,
incrementalFolder = file.path(exportFolder, "incremental"),
runOnSample = FALSE,
runFeatureExtractionOnSample = FALSE,
sampleN = 1000,
seed = 64374,
seedArgs = NULL,
Expand All @@ -250,7 +250,7 @@ executeDiagnostics <- function(cohortDefinitionSet,
incremental = callingArgs$incremental,
temporalCovariateSettings = callingArgs$temporalCovariateSettings
) %>%
RJSONIO::toJSON(digits = 23, pretty = TRUE)
RJSONIO::toJSON(digits = 23, pretty = TRUE)

exportFolder <- normalizePath(exportFolder, mustWork = FALSE)
incrementalFolder <- normalizePath(incrementalFolder, mustWork = FALSE)
Expand Down Expand Up @@ -279,25 +279,25 @@ executeDiagnostics <- function(cohortDefinitionSet,
errorMessage <- checkmate::makeAssertCollection()
checkmate::assertList(cohortTableNames, null.ok = FALSE, types = "character", add = errorMessage, names = "named")
checkmate::assertNames(names(cohortTableNames),
must.include = c(
"cohortTable",
"cohortInclusionTable",
"cohortInclusionResultTable",
"cohortInclusionStatsTable",
"cohortSummaryStatsTable",
"cohortCensorStatsTable"
),
add = errorMessage
must.include = c(
"cohortTable",
"cohortInclusionTable",
"cohortInclusionResultTable",
"cohortInclusionStatsTable",
"cohortSummaryStatsTable",
"cohortCensorStatsTable"
),
add = errorMessage
)
checkmate::assertDataFrame(cohortDefinitionSet, add = errorMessage)
checkmate::assertNames(names(cohortDefinitionSet),
must.include = c(
"json",
"cohortId",
"cohortName",
"sql"
),
add = errorMessage
must.include = c(
"json",
"cohortId",
"cohortName",
"sql"
),
add = errorMessage
)

cohortTable <- cohortTableNames$cohortTable
Expand Down Expand Up @@ -474,17 +474,17 @@ executeDiagnostics <- function(cohortDefinitionSet,
sort()
cohortTableColumnNamesExpected <-
getResultsDataModelSpecifications() %>%
dplyr::filter(.data$tableName == "cohort") %>%
dplyr::pull(.data$columnName) %>%
SqlRender::snakeCaseToCamelCase() %>%
sort()
dplyr::filter(.data$tableName == "cohort") %>%
dplyr::pull(.data$columnName) %>%
SqlRender::snakeCaseToCamelCase() %>%
sort()
cohortTableColumnNamesRequired <-
getResultsDataModelSpecifications() %>%
dplyr::filter(.data$tableName == "cohort") %>%
dplyr::filter(.data$isRequired == "Yes") %>%
dplyr::pull(.data$columnName) %>%
SqlRender::snakeCaseToCamelCase() %>%
sort()
dplyr::filter(.data$tableName == "cohort") %>%
dplyr::filter(.data$isRequired == "Yes") %>%
dplyr::pull(.data$columnName) %>%
SqlRender::snakeCaseToCamelCase() %>%
sort()

expectedButNotObsevered <-
setdiff(x = cohortTableColumnNamesExpected, y = cohortTableColumnNamesObserved)
Expand Down Expand Up @@ -549,23 +549,6 @@ executeDiagnostics <- function(cohortDefinitionSet,
}
}

if (runOnSample & !isTRUE(attr(cohortDefinitionSet, "isSampledCohortDefinition"))) {
cohortDefinitionSet <-
CohortGenerator::sampleCohortDefinitionSet(
connection = connection,
cohortDefinitionSet = cohortDefinitionSet,
tempEmulationSchema = tempEmulationSchema,
cohortDatabaseSchema = cohortDatabaseSchema,
cohortTableNames = cohortTableNames,
n = sampleN,
seed = seed,
seedArgs = seedArgs,
identifierExpression = sampleIdentifierExpression,
incremental = incremental,
incrementalFolder = incrementalFolder
)
}

## CDM source information----
timeExecution(
exportFolder,
Expand Down Expand Up @@ -871,17 +854,40 @@ executeDiagnostics <- function(cohortDefinitionSet,
cohortIds,
parent = "executeDiagnostics",
expr = {

feCohortDefinitionSet <- cohortDefinitionSet
feCohortTable <- cohortTable

if (runFeatureExtractionOnSample & !isTRUE(attr(cohortDefinitionSet, "isSampledCohortDefinition"))) {
feCohortTable <- cohortTableNames$cohortSampleTable
feCohortDefinitionSet <-
CohortGenerator::sampleCohortDefinitionSet(
connection = connection,
cohortDefinitionSet = cohortDefinitionSet,
tempEmulationSchema = tempEmulationSchema,
cohortDatabaseSchema = cohortDatabaseSchema,
cohortTableNames = cohortTableNames,
n = sampleN,
seed = seed,
seedArgs = seedArgs,
identifierExpression = sampleIdentifierExpression,
incremental = incremental,
incrementalFolder = incrementalFolder
)
}


executeCohortCharacterization(
connection = connection,
databaseId = databaseId,
exportFolder = exportFolder,
cdmDatabaseSchema = cdmDatabaseSchema,
cohortDatabaseSchema = cohortDatabaseSchema,
cohortTable = cohortTable,
cohortTable = feCohortTable,
covariateSettings = temporalCovariateSettings,
tempEmulationSchema = tempEmulationSchema,
cdmVersion = cdmVersion,
cohorts = cohortDefinitionSet,
cohorts = feCohortDefinitionSet,
cohortCounts = cohortCounts,
minCellCount = minCellCount,
instantiatedCohorts = instantiatedCohorts,
Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-1-ResultsDataModel.R
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ VALUES ('Synthea','Synthea','OHDSI Community','SyntheaTM is a Synthetic Patient
incremental = TRUE,
incrementalFolder = file.path(folder, "incremental"),
temporalCovariateSettings = temporalCovariateSettings,
runOnSample = TRUE
runFeatureExtractionOnSample = TRUE
)
},
"CDM Source table has more than one record while only one is expected."
Expand All @@ -149,7 +149,7 @@ VALUES ('Synthea','Synthea','OHDSI Community','SyntheaTM is a Synthetic Patient
incremental = TRUE,
incrementalFolder = file.path(folder, "incremental"),
temporalCovariateSettings = temporalCovariateSettings,
runOnSample = TRUE
runFeatureExtractionOnSample = TRUE
)
}

Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-2-againstCdm.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test_that("Cohort diagnostics in incremental mode", {
incremental = TRUE,
incrementalFolder = file.path(folder, "incremental"),
temporalCovariateSettings = temporalCovariateSettings,
runOnSample = TRUE
runFeatureExtractionOnSample = TRUE
)
)

Expand Down Expand Up @@ -76,7 +76,7 @@ test_that("Cohort diagnostics in incremental mode", {
incremental = TRUE,
incrementalFolder = file.path(folder, "incremental"),
temporalCovariateSettings = temporalCovariateSettings,
runOnSample = TRUE
runFeatureExtractionOnSample = TRUE
)
)
# generate sqlite file
Expand Down Expand Up @@ -123,7 +123,7 @@ test_that("Cohort diagnostics in incremental mode", {
incremental = FALSE,
incrementalFolder = file.path(folder, "incremental"),
temporalCovariateSettings = temporalCovariateSettings,
runOnSample = TRUE
runFeatureExtractionOnSample = TRUE
)
})

Expand Down

0 comments on commit cbf145f

Please sign in to comment.