diff --git a/DESCRIPTION b/DESCRIPTION index 8e1d2c50..39e7a303 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: OhdsiShinyModules Type: Package Title: Repository of Shiny Modules for OHDSI Result Viewers -Version: 2.1.2 +Version: 2.1.4 Author: Jenna Reps Maintainer: Jenna Reps Description: Install this package to access useful shiny modules for building shiny apps to explore results using the OHDSI tools . @@ -56,4 +56,4 @@ Suggests: Remotes: ohdsi/CirceR, ohdsi/ResultModelManager -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/NEWS.md b/NEWS.md index cca40436..22e484a7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,12 @@ +OhdsiShinyModules v2.1.4 +======================== +Fixed missing call to dplyr in CohortDiagnostics load up + +OhdsiShinyModules v2.1.3 +======================== +Hotfix release to fix issue with cohort diagnostics reports hanging on load when using `DatabaseConnector::dbListTables` +on postgres backends + OhdsiShinyModules v2.1.2 ======================== Fixed bug in cohort diagnostics incidence rate plots not showing for different strata diff --git a/R/cohort-diagnostics-characterization.R b/R/cohort-diagnostics-characterization.R index 02a88887..27a8f105 100644 --- a/R/cohort-diagnostics-characterization.R +++ b/R/cohort-diagnostics-characterization.R @@ -1014,7 +1014,7 @@ cohortDiagCharacterizationModule <- function( "Concept Id" = "tcr.concept_id", "Analysis Name" = "tar.analysis_name", "Covariate Name" = "tcr.covariate_name", - "Database" = "db.database_name" + "Database" = "db.cdm_source_name" ) for (i in 1:length(timeIds)) { @@ -1047,17 +1047,18 @@ cohortDiagCharacterizationModule <- function( shiny::updateSelectInput(inputId = "sortByRawTemporal", choices = sortChoices, selected = "mean1") + #### Testing fix for main.Database error when viewing shiny app. sqlt <- " SELECT @select_stament FROM @results_database_schema.@table_prefixtemporal_covariate_ref tcr INNER JOIN @results_database_schema.@table_prefixtemporal_analysis_ref tar ON tar.analysis_id = tcr.analysis_id INNER JOIN @results_database_schema.@table_prefixtemporal_covariate_value tcv ON tcr.covariate_id = tcv.covariate_id - INNER JOIN @results_database_schema.@database_table db ON db.database_id = tcv.database_id + INNER JOIN @results_database_schema.DATABASE_META_DATA db ON db.database_id = tcv.database_id WHERE tcr.covariate_id IS NOT NULL " - selectSt <- "db.database_name, + selectSt <- "db.cdm_source_name, tcr.covariate_name, tar.analysis_name, is_binary, @@ -1080,8 +1081,9 @@ cohortDiagCharacterizationModule <- function( } tplSql <- paste(tplSql, collapse = ", \n") + ### Edit to resolve column name in db. groupClause <- SqlRender::render(" - GROUP BY db.database_name, tcr.covariate_name, tar.analysis_name, tcr.concept_id, is_binary + GROUP BY db.cdm_source_name, tcr.covariate_name, tar.analysis_name, tcr.concept_id, is_binary HAVING @having_clasuse ", having_clasuse = paste(havingSql, collapse = " OR\n")) diff --git a/R/cohort-diagnostics-main.R b/R/cohort-diagnostics-main.R index 7c557d0e..d7a14e1f 100644 --- a/R/cohort-diagnostics-main.R +++ b/R/cohort-diagnostics-main.R @@ -14,14 +14,29 @@ # See the License for the specific language governing permissions and # limitations under the License. +.availableTables <- function(connectionHandler, schema) { + if (connectionHandler$dbms() == "postgresql") { + sql <- "SELECT table_name FROM information_schema.tables where table_schema = '@schema'" + tables <- connectionHandler$queryDb(sql, schema = schema) |> + dplyr::pull("tableName") |> + tolower() + return(tables) + } + + return( + DatabaseConnector::getTableNames(connectionHandler$getConnection(), + databaseSchema = schema) |> + tolower() + ) +} + # NOTE: here it would be nice to use dbplyr tables - this would allow lazy loading of resources # however, renaming the columns causes an error and its not obvious how it could be resolved loadResultsTable <- function(dataSource, tableName, required = FALSE, cdTablePrefix = "") { selectTableName <- paste0(cdTablePrefix, tableName) resultsTablesOnServer <- - tolower(DatabaseConnector::dbListTables(dataSource$connectionHandler$getConnection(), - schema = dataSource$schema)) + tolower(.availableTables(dataSource$connectionHandler, dataSource$schema)) if (required || selectTableName %in% resultsTablesOnServer) { if (tableIsEmpty(dataSource, selectTableName)) { @@ -30,10 +45,9 @@ loadResultsTable <- function(dataSource, tableName, required = FALSE, cdTablePre tryCatch( { - table <- DatabaseConnector::dbReadTable( - dataSource$connectionHandler$getConnection(), - paste(dataSource$schema, selectTableName, sep = ".") - ) + table <- dataSource$connectionHandler$queryDb("SELECT * FROM @schema.@table", + schema = dataSource$schema, + table = selectTableName) }, error = function(err) { stop( @@ -44,8 +58,7 @@ loadResultsTable <- function(dataSource, tableName, required = FALSE, cdTablePre ) } ) - colnames(table) <- - SqlRender::snakeCaseToCamelCase(colnames(table)) + return(table) } @@ -70,13 +83,38 @@ tableIsEmpty <- function(dataSource, tableName) { return(nrow(row) == 0) } +postgresEnabledReports <- function(connectionHandler, schema, tbls) { + + sql <- " + select c.relname as table_name + from pg_class c + inner join pg_namespace n on n.oid = c.relnamespace + where c.relkind = 'r' + and n.nspname not in ('information_schema','pg_catalog') + and c.reltuples != 0 + and n.nspname = '@schema' + " + + return(connectionHandler$queryDb(sql, schema = schema) %>% dplyr::pull("tableName")) +} + #' Get enable cd reports from available data -#' @param dataSource C +#' @param dataSource Cohort diagnostics data source #' @export getEnabledCdReports <- function(dataSource) { + + if (dataSource$connectionHandler$dbms() == "postgresql") { + tbls <- dataSource$dataModelSpecifications$tableName %>% unique() + possible <- paste0(dataSource$cdTablePrefix, tbls) + available <- postgresEnabledReports(dataSource$connectionHandler, dataSource$schema) + enabledReports <- c(tbls[possible %in% available], "cohort", "database") %>% + unique() %>% + SqlRender::snakeCaseToCamelCase() + return(enabledReports) + } + enabledReports <- c() - resultsTables <- tolower(DatabaseConnector::dbListTables(dataSource$connectionHandler$getConnection(), - schema = dataSource$schema)) + resultsTables <- .availableTables(dataSource$connectionHandler, schema = dataSource$schema) for (table in dataSource$dataModelSpecifications$tableName %>% unique()) { if (dataSource$prefixTable(table) %in% resultsTables) { @@ -87,7 +125,7 @@ getEnabledCdReports <- function(dataSource) { } enabledReports <- c(enabledReports, "cohort", "database") - enabledReports + return(enabledReports) } #' Create a CD data source from a database @@ -181,8 +219,7 @@ createCdDatabaseDataSource <- function( schema = resultDatabaseSettings$schema, vocabularyDatabaseSchema = resultDatabaseSettings$vocabularyDatabaseSchema, dbms = connectionHandler$dbms(), - resultsTablesOnServer = tolower(DatabaseConnector::dbListTables(connectionHandler$getConnection(), - schema = resultDatabaseSettings$schema)), + resultsTablesOnServer = .availableTables(connectionHandler, resultDatabaseSettings$schema), cdTablePrefix = resultDatabaseSettings$cdTablePrefix, prefixTable = function(tableName) { paste0(resultDatabaseSettings$cdTablePrefix, tableName) }, prefixVocabTable = function(tableName) { @@ -375,9 +412,9 @@ getResultsTemporalTimeRef <- function(dataSource) { #' @param dataSource dataSource optionally created with createCdDatabaseDataSource #' @export cohortDiagnosticsServer <- function(id, - connectionHandler, - resultDatabaseSettings, - dataSource = NULL) { + connectionHandler, + resultDatabaseSettings, + dataSource = NULL) { ns <- shiny::NS(id) checkmate::assertClass(dataSource, "CdDataSource", null.ok = TRUE) @@ -668,7 +705,7 @@ cohortDiagnosticsServer <- function(id, selectedDatabaseIds = selectedDatabaseIds) cohortDiagCharacterizationModule(id = "characterization", - dataSource = dataSource) + dataSource = dataSource) compareCohortCharacterizationModule(id = "compareCohortCharacterization", dataSource = dataSource) diff --git a/docs/404.html b/docs/404.html index f062b816..ede78397 100644 --- a/docs/404.html +++ b/docs/404.html @@ -6,7 +6,7 @@ Page not found (404) • OhdsiShinyModules - + @@ -32,7 +32,7 @@ OhdsiShinyModules - 2.1.2 + 2.1.4 @@ -112,7 +112,7 @@

Page not found (404)

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.9.

diff --git a/docs/authors.html b/docs/authors.html index 1dd691c0..111959ba 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -1,5 +1,5 @@ -Authors and Citation • OhdsiShinyModulesAuthors and Citation • OhdsiShinyModules @@ -17,7 +17,7 @@ OhdsiShinyModules - 2.1.2 + 2.1.4 @@ -66,7 +66,7 @@
@@ -85,13 +85,13 @@

Citation

Reps J (2024). OhdsiShinyModules: Repository of Shiny Modules for OHDSI Result Viewers. -R package version 2.1.2. +R package version 2.1.4.

@Manual{,
   title = {OhdsiShinyModules: Repository of Shiny Modules for OHDSI Result Viewers},
   author = {Jenna Reps},
   year = {2024},
-  note = {R package version 2.1.2},
+  note = {R package version 2.1.4},
 }
@@ -105,7 +105,7 @@

Citation

-

Site built with pkgdown 2.0.7.

+

Site built with pkgdown 2.0.9.

diff --git a/docs/index.html b/docs/index.html index 1fb8ab5e..93b3088b 100644 --- a/docs/index.html +++ b/docs/index.html @@ -6,7 +6,7 @@ Repository of Shiny Modules for OHDSI Result Viewers • OhdsiShinyModules - + @@ -33,7 +33,7 @@ OhdsiShinyModules - 2.1.2 + 2.1.4 @@ -123,7 +123,7 @@

Installationhere for configuring your R environment, including Java.

  • To install the latest stable version:

  • -
    install.packages(remotes)
    +
    install.packages('remotes')
     remotes::install_github('ohdsi/OhdsiShinyModules')
    @@ -213,7 +213,7 @@

    Developers

    -

    Site built with pkgdown 2.0.7.

    +

    Site built with pkgdown 2.0.9.

    diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 65abfb39..082aed1a 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,7 +1,7 @@ -pandoc: 3.1.1 -pkgdown: 2.0.7 +pandoc: 3.1.12.3 +pkgdown: 2.0.9 pkgdown_sha: ~ articles: AddingShinyModules: AddingShinyModules.html -last_built: 2024-01-25T16:37Z +last_built: 2024-04-25T21:46Z diff --git a/extras/OhdsiShinyModules.pdf b/extras/OhdsiShinyModules.pdf index 10ee1a02..4c92ae53 100644 Binary files a/extras/OhdsiShinyModules.pdf and b/extras/OhdsiShinyModules.pdf differ diff --git a/man/OhdsiShinyModules.Rd b/man/OhdsiShinyModules.Rd index 10f09f13..fe505b2c 100644 --- a/man/OhdsiShinyModules.Rd +++ b/man/OhdsiShinyModules.Rd @@ -2,6 +2,7 @@ % Please edit documentation in R/OhdsiShinyModules.R \docType{package} \name{OhdsiShinyModules} +\alias{OhdsiShinyModules-package} \alias{OhdsiShinyModules} \title{OhdsiShinyModules} \description{ diff --git a/man/getEnabledCdReports.Rd b/man/getEnabledCdReports.Rd index 5df49f6d..b48eee5d 100644 --- a/man/getEnabledCdReports.Rd +++ b/man/getEnabledCdReports.Rd @@ -7,7 +7,7 @@ getEnabledCdReports(dataSource) } \arguments{ -\item{dataSource}{C} +\item{dataSource}{Cohort diagnostics data source} } \description{ Get enable cd reports from available data