From 54966a81e15e3418b3dcca3193130977cce0a84f Mon Sep 17 00:00:00 2001 From: Anthony Sena Date: Wed, 1 May 2024 12:36:45 -0400 Subject: [PATCH] Update stats query to address Oracle issue. Expand platform tests --- R/CohortStats.R | 2 +- tests/testthat/helper.R | 1 + tests/testthat/test-dbms-platforms.R | 32 +++++++++++++++++++++++++++- 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/R/CohortStats.R b/R/CohortStats.R index bac6a14..f9caa5d 100644 --- a/R/CohortStats.R +++ b/R/CohortStats.R @@ -153,7 +153,7 @@ getStatsTable <- function(connectionDetails, } ParallelLogger::logInfo("- Fetching data from ", table) - sql <- "SELECT {@database_id != ''}?{CAST('@database_id' as VARCHAR(255)) as database_id,} * FROM @cohort_database_schema.@table" + sql <- "SELECT {@database_id != ''}?{CAST('@database_id' as VARCHAR(255)) as database_id,} t.* FROM @cohort_database_schema.@table t" data <- DatabaseConnector::renderTranslateQuerySql( sql = sql, connection = connection, diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 5b0365a..122d3b9 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -134,6 +134,7 @@ getPlatformConnectionDetails <- function(dbmsPlatform) { } return(list( + dbmsPlatform = dbmsPlatform, connectionDetails = connectionDetails, cohortDatabaseSchema = cohortDatabaseSchema, cohortTable = cohortTable, diff --git a/tests/testthat/test-dbms-platforms.R b/tests/testthat/test-dbms-platforms.R index 7b7908c..e8425ed 100644 --- a/tests/testthat/test-dbms-platforms.R +++ b/tests/testthat/test-dbms-platforms.R @@ -34,7 +34,37 @@ testPlatform <- function(dbmsDetails) { incrementalFolder = file.path(outputFolder, "RecordKeeping", dbmsDetails$connectionDetails$dbms) ) expect_equal(nrow(cohortsGenerated), nrow(cohortsWithStats)) - + + # Get the cohort counts + cohortCounts <- getCohortCounts( + connectionDetails = dbmsDetails$connectionDetails, + cohortDatabaseSchema = dbmsDetails$cohortDatabaseSchema, + cohortTable = cohortTableNames$cohortTable, + databaseId = dbmsDetails$dbmsPlatform, + cohortDefinitionSet = cohortsWithStats + ) + expect_equal(nrow(cohortsGenerated), nrow(cohortCounts)) + + # Insert the inclusion rule names before exporting the stats tables + insertInclusionRuleNames( + connectionDetails = dbmsDetails$connectionDetails, + cohortDefinitionSet = cohortsWithStats, + cohortDatabaseSchema = dbmsDetails$cohortDatabaseSchema, + cohortInclusionTable = cohortTableNames$cohortInclusionTable + ) + + exportCohortStatsTables( + connectionDetails = dbmsDetails$connectionDetails, + cohortTableNames = cohortTableNames, + cohortDatabaseSchema = dbmsDetails$cohortDatabaseSchema, + cohortStatisticsFolder = file.path(outputFolder, dbmsDetails$dbmsPlatform), + snakeCaseToCamelCase = FALSE, + fileNamesInSnakeCase = TRUE, + incremental = TRUE, + incrementalFolder = file.path(outputFolder, "RecordKeeping", dbmsDetails$connectionDetails$dbms), + databaseId = dbmsDetails$dbmsPlatform + ) + subsetOperations <- list( createCohortSubset( cohortIds = 2,