Skip to content

Commit

Permalink
update sqlite test external counts table
Browse files Browse the repository at this point in the history
  • Loading branch information
cebarboza committed Sep 19, 2024
1 parent abae4f1 commit 1c13de0
Showing 1 changed file with 33 additions and 32 deletions.
65 changes: 33 additions & 32 deletions tests/testthat/test-other.R
Original file line number Diff line number Diff line change
Expand Up @@ -159,39 +159,40 @@ test_that("enforceMinCellValue works with vector of minimum values", {
})

test_that("Creating and checking externalConceptCounts table", {
if (dbms == "sqlite") {
# Creating externalConceptCounts
sql_lite_path <- file.path(test_path(), databaseFile)
connectionDetails <- createConnectionDetails(dbms= "sqlite", server = sql_lite_path)
connection <- connect(connectionDetails)
cdmDatabaseSchema <- "main"
CohortDiagnostics::createConceptCountsTable(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema,
tempEmulationSchema = NULL,
conceptCountsTable = "concept_counts",
conceptCountsDatabaseSchema = cdmDatabaseSchema,
conceptCountsTableIsTemp = FALSE,
removeCurrentTable = TRUE)

concept_counts_info <- querySql(connection, "PRAGMA table_info(concept_counts)")
expect_equal(concept_counts_info$NAME, c( "concept_id", "concept_count", "concept_subjects", "vocabulary_version"))

# Creating externalConceptCounts
sql_lite_path <- file.path(test_path(), "4448testEunomia.sqlite")
connectionDetails <- createConnectionDetails(dbms= "sqlite", server = sql_lite_path)
connection <- connect(connectionDetails)
cdmDatabaseSchema <- "main"
CohortDiagnostics::createConceptCountsTable(connectionDetails = connectionDetails,
cdmDatabaseSchema = cdmDatabaseSchema,
tempEmulationSchema = NULL,
conceptCountsTable = "concept_counts",
conceptCountsDatabaseSchema = cdmDatabaseSchema,
conceptCountsTableIsTemp = FALSE,
removeCurrentTable = TRUE)

concept_counts_info <- querySql(connection, "PRAGMA table_info(concept_counts)")
expect_equal(concept_counts_info$NAME, c( "concept_id", "concept_count", "concept_subjects", "vocabulary_version"))

# Checking vocab version matches
useExternalConceptCountsTable <- TRUE
conceptCountsTable <- "concept_counts"
conceptCountsTable <- conceptCountsTable
dataSourceInfo <- getCdmDataSourceInformation(connection = connection, cdmDatabaseSchema = cdmDatabaseSchema)
vocabVersion <- dataSourceInfo$vocabularyVersion
vocabVersionExternalConceptCountsTable <- renderTranslateQuerySql(
connection = connection,
sql = "SELECT DISTINCT vocabulary_version FROM @work_database_schema.@concept_counts_table;",
work_database_schema = cdmDatabaseSchema,
concept_counts_table = conceptCountsTable,
snakeCaseToCamelCase = TRUE,
tempEmulationSchema = getOption("sqlRenderTempEmulationSchena")
)

expect_equal(vocabVersion, vocabVersionExternalConceptCountsTable[1,1])
# Checking vocab version matches
useExternalConceptCountsTable <- TRUE
conceptCountsTable <- "concept_counts"
conceptCountsTable <- conceptCountsTable
dataSourceInfo <- getCdmDataSourceInformation(connection = connection, cdmDatabaseSchema = cdmDatabaseSchema)
vocabVersion <- dataSourceInfo$vocabularyVersion
vocabVersionExternalConceptCountsTable <- renderTranslateQuerySql(
connection = connection,
sql = "SELECT DISTINCT vocabulary_version FROM @work_database_schema.@concept_counts_table;",
work_database_schema = cdmDatabaseSchema,
concept_counts_table = conceptCountsTable,
snakeCaseToCamelCase = TRUE,
tempEmulationSchema = getOption("sqlRenderTempEmulationSchena")
)

expect_equal(vocabVersion, vocabVersionExternalConceptCountsTable[1,1])
}

})

Expand Down

0 comments on commit 1c13de0

Please sign in to comment.