diff --git a/inst/sql/sql_server/createCodeCountsTable.sql b/inst/sql/sql_server/createCodeCountsTable.sql index e59f64f..2af48d6 100644 --- a/inst/sql/sql_server/createCodeCountsTable.sql +++ b/inst/sql/sql_server/createCodeCountsTable.sql @@ -44,6 +44,8 @@ temp_concept_ancestor AS ( SELECT DISTINCT maps_to_concept_id, calendar_year, gender_concept_id, age_decile, record_counts FROM @resultsDatabaseSchema.@stratifiedCodeCountsTable + -- do not take if maps_to_concept_id is a standard concept + WHERE concept_id != maps_to_concept_id ) GROUP BY maps_to_concept_id diff --git a/inst/testdata/data/FinnGenR13_countsOnly.sqlite b/inst/testdata/data/FinnGenR13_countsOnly.sqlite index 1487bdf..c5674d8 100644 Binary files a/inst/testdata/data/FinnGenR13_countsOnly.sqlite and b/inst/testdata/data/FinnGenR13_countsOnly.sqlite differ diff --git a/inst/testdata/data/createTestingData.R b/inst/testdata/data/createTestingData.R index 2fd761c..8ebad55 100644 --- a/inst/testdata/data/createTestingData.R +++ b/inst/testdata/data/createTestingData.R @@ -7,7 +7,8 @@ source("tests/testthat/setup.R") conceptIds <- c( 317009, # Snomed: Asthma 45596282, # ICD10: Asthma - 21601855 # ATC level 4: C10AA (Statins) + 21601855, # ATC level 4: C10AA (Statins) + 320136 # Disorder of respiratory …# big ) CDMdbHandler <- HadesExtras_createCDMdbHandlerFromList(test_cohortTableHandlerConfig, loadConnectionChecksLevel = "basicChecks") @@ -17,7 +18,6 @@ helper_createSqliteDatabaseFromDatabase( pathToSqliteDatabase = "inst/testdata/data/FinnGenR13_countsOnly.sqlite" ) - # Test connection <- DatabaseConnector::connect(DatabaseConnector::createConnectionDetails(dbms = "sqlite", server = "inst/testdata/data/FinnGenR13_countsOnly.sqlite")) @@ -30,6 +30,13 @@ dplyr::tbl(connection, "concept") |> dplyr::pull(n) |> expect_gt(0) +dplyr::tbl(connection, "concept") |> + dplyr::count(concept_id) |> + dplyr::filter(n > 1) |> + dplyr::count() |> + dplyr::pull(n) |> + expect_equal(0) + dplyr::tbl(connection, "concept_ancestor") |> dplyr::count() |> dplyr::pull(n) |> @@ -40,7 +47,27 @@ dplyr::tbl(connection, "code_counts") |> dplyr::pull(n) |> expect_gt(0) +dplyr::tbl(connection, "code_counts") |> + dplyr::count(concept_id) |> + dplyr::filter(n > 1) |> + dplyr::count() |> + dplyr::pull(n) |> + expect_equal(0) + + dplyr::tbl(connection, "stratified_code_counts") |> dplyr::count() |> dplyr::pull(n) |> expect_gt(0) + + +# +Sys.setenv(HADESEXTAS_TESTING_ENVIRONMENT = "OnlyCounts-FinnGen") +source("tests/testthat/setup.R") + +CDMdbHandler <- HadesExtras_createCDMdbHandlerFromList(test_cohortTableHandlerConfig, loadConnectionChecksLevel = "basicChecks") + +conceptId <- 317009 + +report.html <- createReport(conceptId, CDMdbHandler, showsMappings = FALSE) +browseURL(report.html) diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 2f3005b..dce4805 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -90,7 +90,7 @@ if (testingDatabase %in% c("AtlasDevelopment-DBI")) { pathToYalmFile = system.file("testdata", "config", "atlasDev_databasesConfig.yml", package = "ROMOPAPI") ) - test_cohortTableHandlerConfig <- test_databasesConfig[[1]]$cohortTableHandler + test_cohortTableHandlerConfig <- test_databasesConfig[[2]]$cohortTableHandler } diff --git a/tests/testthat/test-getConceptsWithCodeCounts.R b/tests/testthat/test-getConceptsWithCodeCounts.R index 4230141..c968959 100644 --- a/tests/testthat/test-getConceptsWithCodeCounts.R +++ b/tests/testthat/test-getConceptsWithCodeCounts.R @@ -51,7 +51,7 @@ test_that("getConceptsWithCodeCounts works", { # Check that all concept_ids are unique result |> - dplyr::count(concept_id) |> + dplyr::count(concept_id, sort = TRUE) |> dplyr::filter(n > 1) |> nrow() |> expect_equal(0)