From b2029cd7c83075a4a5565b07bd49493efc8f914e Mon Sep 17 00:00:00 2001 From: Admin_mschuemi Date: Thu, 12 Oct 2023 05:26:34 -0400 Subject: [PATCH] Trying to adapt shiny viewer to new ShinyAppBuilder interface --- NEWS.md | 1 + R/Viewer.R | 11 +---- extras/MultiAnalysesVignetteDataFetch.R | 55 +++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 9 deletions(-) diff --git a/NEWS.md b/NEWS.md index deafa169..f5eba7ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -15,6 +15,7 @@ Changes: 6. The results schema specifications of the `exportToCsv()` function has changed: - Removed the `attrition_fraction` and `attrition_diagnostic` fields from the `cm_diagnostics_summary ` table. + - Added the `target_estimator` field to the `cm_result` add `cm_interaction_result` tables. - Added the `generalizability_max_sdm` and `generalizabiltiy_diagnostic` fields to the `cm_diagnostics_summary` table. - Added the `mean_before`, `mean_after`, `target_std_diff`, `comparator_std_diff`, and `target_comparator_std_diff` fields to both the `cm_covariate_balance` and `cm_shared_covariate_balance` tables. diff --git a/R/Viewer.R b/R/Viewer.R index 8df13b59..7a170a98 100644 --- a/R/Viewer.R +++ b/R/Viewer.R @@ -208,10 +208,7 @@ launchResultsViewer <- function(connectionDetails, databaseSchema) { ensureInstalled("ShinyAppBuilder") ensureInstalled("markdown") - aboutModule <- ShinyAppBuilder::createDefaultAboutConfig( - resultDatabaseDetails = NULL, - useKeyring = TRUE - ) + aboutModule <- ShinyAppBuilder::createDefaultAboutConfig() resultDatabaseDetails <- list( dbms = connectionDetails$dbms, tablePrefix = 'cm_', @@ -220,13 +217,9 @@ launchResultsViewer <- function(connectionDetails, databaseSchema) { schema = databaseSchema, databaseTable = 'DATABASE_META_DATA' ) - cohortMethodModule <- ShinyAppBuilder::createDefaultCohortMethodConfig( - resultDatabaseDetails = resultDatabaseDetails, - useKeyring = TRUE - ) + cohortMethodModule <- ShinyAppBuilder::createDefaultCohortMethodConfig() shinyAppConfig <- ShinyAppBuilder::initializeModuleConfig() %>% ShinyAppBuilder::addModuleConfig(aboutModule) %>% - # addModuleConfig(cohortGeneratorModule) %>% ShinyAppBuilder::addModuleConfig(cohortMethodModule) connectionHandler <- ResultModelManager::ConnectionHandler$new(connectionDetails) ShinyAppBuilder::viewShiny(shinyAppConfig, connectionHandler) diff --git a/extras/MultiAnalysesVignetteDataFetch.R b/extras/MultiAnalysesVignetteDataFetch.R index 238c4d20..145015af 100644 --- a/extras/MultiAnalysesVignetteDataFetch.R +++ b/extras/MultiAnalysesVignetteDataFetch.R @@ -311,3 +311,58 @@ insertExportedResultsInSqlite(sqliteFileName = file.path(folder, "export", "resu exportFolder = file.path(folder, "export"), cohorts = cohorts) launchResultsViewerUsingSqlite(sqliteFileName = file.path(folder, "export", "results.sqlite")) + +# Upload results to SQLite using RMM ------------------------------------------- +databaseFile <- file.path(folder, "export", "CohortMethodResults.sqlite") +connectionDetails <- DatabaseConnector::createConnectionDetails( + dbms = "sqlite", + server = databaseFile +) +createResultsDataModel( + connectionDetails = connectionDetails, + databaseSchema = "main", + tablePrefix = "" +) +uploadResults( + connectionDetails = connectionDetails, + schema = "main", + zipFileName = file.path(folder, "export", "Results_MDCD.zip"), + purgeSiteDataBeforeUploading = FALSE +) +# Add cohort and database tables: +connection <- DatabaseConnector::connect(connectionDetails) +cohorts <- data.frame( + cohortId = c( + 1118084, + 1124300, + 192671), + cohortName = c( + "Celecoxib", + "Diclofenac", + "GI Bleed" + ) +) +DatabaseConnector::insertTable( + connection = connection, + databaseSchema = "main", + tableName = "cg_cohort_definition", + data = cohorts, + dropTableIfExists = TRUE, + createTable = TRUE, + camelCaseToSnakeCase = TRUE +) +databases <- tibble( + database_id = "MDCR", + cdm_source_name = "Merative Marketscan MDCR", + cdm_source_abbreviation = "MDCR" +) +DatabaseConnector::insertTable( + connection = connection, + databaseSchema = "main", + tableName = "databases", + data = databases, + dropTableIfExists = TRUE, + createTable = TRUE +) +DatabaseConnector::disconnect(connection) +