diff --git a/.github/workflows/R_CMD_check_Hades.yml b/.github/workflows/R_CMD_check_Hades.yml index 266cc52a7..52f905c20 100644 --- a/.github/workflows/R_CMD_check_Hades.yml +++ b/.github/workflows/R_CMD_check_Hades.yml @@ -3,10 +3,11 @@ on: push: branches: - - '**' + - develop + - main pull_request: branches: - - '**' + - main name: R-CMD-check diff --git a/.github/workflows/R_CMD_check_Hades_minor.yml b/.github/workflows/R_CMD_check_Hades_minor.yml new file mode 100644 index 000000000..ab750dc70 --- /dev/null +++ b/.github/workflows/R_CMD_check_Hades_minor.yml @@ -0,0 +1,128 @@ +#Designed to be a fast github actions check - longer running actions to only run on releases +on: + pull_request: + branches: + - '**' + - '!main' + +name: R-CMD-check-minor + +jobs: + R-CMD-check-minor: + runs-on: ${{ matrix.config.os }} + + name: ${{ matrix.config.os }} (${{ matrix.config.r }}) + + strategy: + max-parallel: 1 + fail-fast: false + matrix: + config: + - {os: windows-latest, r: 'release'} # Does not appear to have Java 32-bit, hence the --no-multiarch + - {os: macOS-latest, r: 'release'} + + env: + GITHUB_PAT: ${{ secrets.GH_TOKEN }} + BRANCH_NAME: ${{ github.head_ref || github.ref_name }} + R_REMOTES_NO_ERRORS_FROM_WARNINGS: true + RSPM: ${{ matrix.config.rspm }} + #CDM5_ORACLE_CDM_SCHEMA: ${{ secrets.CDM5_ORACLE_CDM_SCHEMA }} + #CDM5_ORACLE_OHDSI_SCHEMA: ${{ secrets.CDM5_ORACLE_OHDSI_SCHEMA }} + #CDM5_ORACLE_PASSWORD: ${{ secrets.CDM5_ORACLE_PASSWORD }} + #CDM5_ORACLE_SERVER: ${{ secrets.CDM5_ORACLE_SERVER }} + #CDM5_ORACLE_USER: ${{ secrets.CDM5_ORACLE_USER }} + CDM5_POSTGRESQL_CDM_SCHEMA: ${{ secrets.CDM5_POSTGRESQL_CDM_SCHEMA }} + CDM5_POSTGRESQL_OHDSI_SCHEMA: ${{ secrets.CDM5_POSTGRESQL_OHDSI_SCHEMA }} + CDM5_POSTGRESQL_PASSWORD: ${{ secrets.CDM5_POSTGRESQL_PASSWORD }} + CDM5_POSTGRESQL_SERVER: ${{ secrets.CDM5_POSTGRESQL_SERVER }} + CDM5_POSTGRESQL_USER: ${{ secrets.CDM5_POSTGRESQL_USER }} + #CDM5_SQL_SERVER_CDM_SCHEMA: ${{ secrets.CDM5_SQL_SERVER_CDM_SCHEMA }} + #CDM5_SQL_SERVER_OHDSI_SCHEMA: ${{ secrets.CDM5_SQL_SERVER_OHDSI_SCHEMA }} + #CDM5_SQL_SERVER_PASSWORD: ${{ secrets.CDM5_SQL_SERVER_PASSWORD }} + #CDM5_SQL_SERVER_SERVER: ${{ secrets.CDM5_SQL_SERVER_SERVER }} + #CDM5_SQL_SERVER_USER: ${{ secrets.CDM5_SQL_SERVER_USER }} + #CDM5_REDSHIFT_CDM_SCHEMA: ${{ secrets.CDM5_REDSHIFT_CDM_SCHEMA }} + #CDM5_REDSHIFT_OHDSI_SCHEMA: ${{ secrets.CDM5_REDSHIFT_OHDSI_SCHEMA }} + #CDM5_REDSHIFT_PASSWORD: ${{ secrets.CDM5_REDSHIFT_PASSWORD }} + #CDM5_REDSHIFT_SERVER: ${{ secrets.CDM5_REDSHIFT_SERVER }} + #CDM5_REDSHIFT_USER: ${{ secrets.CDM5_REDSHIFT_USER }} + + steps: + - uses: actions/checkout@v2 + + - uses: r-lib/actions/setup-r@v1 + with: + r-version: ${{ matrix.config.r }} + + - uses: r-lib/actions/setup-tinytex@v1 + + - uses: r-lib/actions/setup-pandoc@v1 + + - name: Query dependencies + run: | + install.packages('remotes') + saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) + writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + shell: Rscript {0} + + - name: Cache R packages + if: runner.os != 'Windows' + uses: actions/cache@v2 + with: + path: ${{ env.R_LIBS_USER }} + key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} + restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- + + - name: Install system dependencies + if: runner.os == 'Linux' + run: | + while read -r cmd + do + eval sudo $cmd + done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') + + - name: Install libssh + if: runner.os == 'Linux' + run: | + sudo apt-get install libssh-dev + - name: Install dependencies + run: | + remotes::install_deps(dependencies = TRUE, INSTALL_opts=c("--no-multiarch")) + remotes::install_cran("rcmdcheck") + shell: Rscript {0} + + - name: Install covr + if: runner.os == 'macOS' + run: | + remotes::install_cran("covr") + shell: Rscript {0} + + - name: Remove check folder if exists + if: runner.os == 'macOS' + run: unlink("check", recursive = TRUE) + shell: Rscript {0} + + - name: Check + env: + _R_CHECK_CRAN_INCOMING_REMOTE_: false + run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--no-multiarch"), build_args = c("--no-manual"), error_on = "warning", check_dir = "check") + shell: Rscript {0} + + - name: Upload check results + if: failure() + uses: actions/upload-artifact@v2 + with: + name: ${{ runner.os }}-r${{ matrix.config.r }}-results + path: check + + - name: Upload source package + if: success() && runner.os == 'macOS' && github.event_name != 'pull_request' && github.ref == 'refs/heads/main' + uses: actions/upload-artifact@v2 + with: + name: package_tarball + path: check/*.tar.gz + + - name: Test coverage + if: runner.os == 'macOS' + run: covr::codecov() + shell: Rscript {0} diff --git a/DESCRIPTION b/DESCRIPTION index b6714de50..a64d41011 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: CohortDiagnostics Type: Package Title: Diagnostics for OHDSI Cohorts -Version: 3.1.1 -Date: 2022-07-20 +Version: 3.1.2 +Date: 2022-12-19 Authors@R: c( person("Gowtham", "Rao", email = "rao@ohdsi.org", role = c("aut", "cre")), person("Martijn", "Schuemie", email = "schuemie@ohdsi.org", role = c("aut")), diff --git a/NEWS.md b/NEWS.md index 30681ca75..7c5d05a72 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,10 @@ +CohortDiagnostics 3.1.2 +======================= +Bug Fixes: + +1. Removed package dependency snapshot capture as it was breaking on newer versions of R + + CohortDiagnostics 3.1.1 ======================= Changes: diff --git a/R/CohortCharacterizationDiagnostics.R b/R/CohortCharacterizationDiagnostics.R index e55132e98..690c81905 100644 --- a/R/CohortCharacterizationDiagnostics.R +++ b/R/CohortCharacterizationDiagnostics.R @@ -48,12 +48,15 @@ getCohortCharacteristics <- function(connectionDetails = NULL, covariateSettings = covariateSettings, aggregated = TRUE ) - }) + } + ) populationSize <- attr(x = featureExtractionOutput, which = "metaData")$populationSize populationSize <- - dplyr::tibble(cohortId = names(populationSize) %>% as.numeric(), - populationSize = populationSize) + dplyr::tibble( + cohortId = names(populationSize) %>% as.numeric(), + populationSize = populationSize + ) if (!"analysisRef" %in% names(results)) { results$analysisRef <- featureExtractionOutput$analysisRef @@ -82,8 +85,8 @@ getCohortCharacteristics <- function(connectionDetails = NULL, dplyr::mutate(p = sumValue / populationSize) if (nrow(covariates %>% - dplyr::filter(p > 1) %>% - dplyr::collect()) > 0) { + dplyr::filter(p > 1) %>% + dplyr::collect()) > 0) { stop( paste0( "During characterization, population size (denominator) was found to be smaller than features Value (numerator).", @@ -98,37 +101,37 @@ getCohortCharacteristics <- function(connectionDetails = NULL, dplyr::rename(mean = averageValue) %>% dplyr::select(-populationSize) - if (FeatureExtraction::isTemporalCovariateData(featureExtractionOutput)) { - covariates <- covariates %>% - dplyr::select( - cohortId, - timeId, - covariateId, - sumValue, - mean, - sd - ) - if (length(is.na(covariates$timeId)) > 0) { - covariates[is.na(covariates$timeId),]$timeId <- -1 - } - } else { - covariates <- covariates %>% - dplyr::mutate(timeId = 0) %>% - dplyr::select( - cohortId, - timeId, - covariateId, - sumValue, - mean, - sd - ) - } - if ("covariates" %in% names(results)) { - Andromeda::appendToTable(results$covariates, covariates) - } else { - results$covariates <- covariates + if (FeatureExtraction::isTemporalCovariateData(featureExtractionOutput)) { + covariates <- covariates %>% + dplyr::select( + cohortId, + timeId, + covariateId, + sumValue, + mean, + sd + ) + if (length(is.na(covariates$timeId)) > 0) { + covariates[is.na(covariates$timeId), ]$timeId <- -1 } + } else { + covariates <- covariates %>% + dplyr::mutate(timeId = 0) %>% + dplyr::select( + cohortId, + timeId, + covariateId, + sumValue, + mean, + sd + ) } + if ("covariates" %in% names(results)) { + Andromeda::appendToTable(results$covariates, covariates) + } else { + results$covariates <- covariates + } + } if ("covariatesContinuous" %in% names(featureExtractionOutput) && dplyr::pull(dplyr::count(featureExtractionOutput$covariatesContinuous)) > 0) { @@ -151,12 +154,14 @@ getCohortCharacteristics <- function(connectionDetails = NULL, sd ) if (length(is.na(covariates$timeId)) > 0) { - covariates[is.na(covariates$timeId),]$timeId <- -1 + covariates[is.na(covariates$timeId), ]$timeId <- -1 } } else { covariates <- covariates %>% - dplyr::mutate(sumValue = -1, - timeId = 0) %>% + dplyr::mutate( + sumValue = -1, + timeId = 0 + ) %>% dplyr::select( cohortId, timeId, @@ -179,10 +184,12 @@ getCohortCharacteristics <- function(connectionDetails = NULL, } delta <- Sys.time() - startTime - ParallelLogger::logInfo("Cohort characterization took ", - signif(delta, 3), - " ", - attr(delta, "units")) + ParallelLogger::logInfo( + "Cohort characterization took ", + signif(delta, 3), + " ", + attr(delta, "units") + ) return(results) } @@ -221,9 +228,10 @@ executeCohortCharacterization <- function(connection, ) if (!incremental) { - for (outputFile in c(covariateValueFileName, covariateValueContFileName, - covariateRefFileName, analysisRefFileName, timeRefFileName)) { - + for (outputFile in c( + covariateValueFileName, covariateValueContFileName, + covariateRefFileName, analysisRefFileName, timeRefFileName + )) { if (file.exists(outputFile)) { ParallelLogger::logInfo("Not in incremental mode - Removing file", outputFile, " and replacing") unlink(outputFile) @@ -309,10 +317,12 @@ executeCohortCharacterization <- function(connection, } } delta <- Sys.time() - startCohortCharacterization - ParallelLogger::logInfo("Running ", - jobName, - " took", - signif(delta, 3), - " ", - attr(delta, "units")) + ParallelLogger::logInfo( + "Running ", + jobName, + " took", + signif(delta, 3), + " ", + attr(delta, "units") + ) } diff --git a/R/CohortRelationship.R b/R/CohortRelationship.R index 00d10af4c..9ee7e252e 100644 --- a/R/CohortRelationship.R +++ b/R/CohortRelationship.R @@ -122,7 +122,7 @@ runCohortRelationshipDiagnostics <- package = utils::packageName() ) ) - + DatabaseConnector::renderTranslateExecuteSql( connection = connection, tempEmulationSchema = tempEmulationSchema, @@ -135,7 +135,7 @@ runCohortRelationshipDiagnostics <- cohort_database_schema = cohortDatabaseSchema, cohort_table = cohortTable ) - + DatabaseConnector::renderTranslateQuerySqlToAndromeda( connection = connection, tempEmulationSchema = tempEmulationSchema, @@ -210,13 +210,17 @@ executeCohortRelationshipDiagnostics <- function(connection, allCohortIds <- cohortDefinitionSet %>% dplyr::select(cohortId, checksum) %>% - dplyr::rename(targetCohortId = cohortId, - targetChecksum = checksum) %>% + dplyr::rename( + targetCohortId = cohortId, + targetChecksum = checksum + ) %>% dplyr::distinct() combinationsOfPossibleCohortRelationships <- allCohortIds %>% tidyr::crossing(allCohortIds %>% - dplyr::rename(comparatorCohortId = targetCohortId, - comparatorChecksum = targetChecksum)) %>% + dplyr::rename( + comparatorCohortId = targetCohortId, + comparatorChecksum = targetChecksum + )) %>% dplyr::filter(targetCohortId != comparatorCohortId) %>% dplyr::arrange(targetCohortId, comparatorCohortId) %>% dplyr::mutate(checksum = paste0(targetChecksum, comparatorChecksum)) @@ -230,7 +234,7 @@ executeCohortRelationshipDiagnostics <- function(connection, if (nrow(subset) > 0) { if (incremental && - (nrow(cohortDefinitionSet) - (length(subset$targetCohortId %>% unique()))) > 0) { + (nrow(cohortDefinitionSet) - (length(subset$targetCohortId %>% unique()))) > 0) { ParallelLogger::logInfo( sprintf( " - Skipping %s target cohorts in incremental mode because the relationships has already been computed with other cohorts.", @@ -240,12 +244,12 @@ executeCohortRelationshipDiagnostics <- function(connection, } if (incremental && - (nrow(combinationsOfPossibleCohortRelationships) - ( - nrow( - combinationsOfPossibleCohortRelationships %>% + (nrow(combinationsOfPossibleCohortRelationships) - ( + nrow( + combinationsOfPossibleCohortRelationships %>% dplyr::filter(targetCohortId %in% c(subset$targetCohortId)) - ) - )) > 0) { + ) + )) > 0) { ParallelLogger::logInfo( sprintf( " - Skipping %s combinations in incremental mode because these were previously computed.", @@ -333,7 +337,7 @@ executeCohortRelationshipDiagnostics <- function(connection, timeExecution( exportFolder, "runCohortRelationshipDiagnostics", - c(subset[start:end,]$targetCohortId %>% unique(), subset[start:end,]$comparatorCohortId %>% unique()), + c(subset[start:end, ]$targetCohortId %>% unique(), subset[start:end, ]$comparatorCohortId %>% unique()), parent = "executeCohortRelationshipDiagnostics", expr = { output <- @@ -342,10 +346,12 @@ executeCohortRelationshipDiagnostics <- function(connection, cohortDatabaseSchema = cohortDatabaseSchema, tempEmulationSchema = tempEmulationSchema, cohortTable = cohortTable, - targetCohortIds = subset[start:end,]$targetCohortId %>% unique(), - comparatorCohortIds = subset[start:end,]$comparatorCohortId %>% unique(), - relationshipDays = dplyr::tibble(startDay = temporalStartDays, - endDay = temporalEndDays) + targetCohortIds = subset[start:end, ]$targetCohortId %>% unique(), + comparatorCohortIds = subset[start:end, ]$comparatorCohortId %>% unique(), + relationshipDays = dplyr::tibble( + startDay = temporalStartDays, + endDay = temporalEndDays + ) ) } ) @@ -364,26 +370,28 @@ executeCohortRelationshipDiagnostics <- function(connection, ) recordTasksDone( - cohortId = subset[start:end,]$targetCohortId, - comparatorId = subset[start:end,]$comparatorCohortId, - targetChecksum = subset[start:end,]$targetChecksum, - comparatorChecksum = subset[start:end,]$comparatorChecksum, + cohortId = subset[start:end, ]$targetCohortId, + comparatorId = subset[start:end, ]$comparatorCohortId, + targetChecksum = subset[start:end, ]$targetChecksum, + comparatorChecksum = subset[start:end, ]$comparatorChecksum, task = "runCohortRelationship", - checksum = subset[start:end,]$checksum, + checksum = subset[start:end, ]$checksum, recordKeepingFile = recordKeepingFile, incremental = incremental ) deltaIteration <- Sys.time() - startCohortRelationship - ParallelLogger::logInfo(" - Running Cohort Relationship iteration with batchsize ", - batchSize, - " from row number ", - start, - " to ", - end, - " took ", - signif(deltaIteration, 3), - " ", - attr(deltaIteration, "units")) + ParallelLogger::logInfo( + " - Running Cohort Relationship iteration with batchsize ", + batchSize, + " from row number ", + start, + " to ", + end, + " took ", + signif(deltaIteration, 3), + " ", + attr(deltaIteration, "units") + ) } } else { ParallelLogger::logInfo(" - Skipping in incremental mode.") diff --git a/R/ConceptSets.R b/R/ConceptSets.R index 10c42f91f..36d63fae9 100644 --- a/R/ConceptSets.R +++ b/R/ConceptSets.R @@ -125,7 +125,7 @@ combineConceptSetsFromCohorts <- function(cohorts) { conceptSetCounter <- 0 for (i in (1:nrow(cohorts))) { - cohort <- cohorts[i,] + cohort <- cohorts[i, ] sql <- extractConceptSetsSqlFromCohortSql(cohortSql = cohort$sql) json <- @@ -197,13 +197,13 @@ mergeTempTables <- ) sql <- SqlRender::translate(sql, - targetDialect = connection@dbms, - tempEmulationSchema = tempEmulationSchema + targetDialect = connection@dbms, + tempEmulationSchema = tempEmulationSchema ) DatabaseConnector::executeSql(connection, - sql, - progressBar = FALSE, - reportOverallTime = FALSE + sql, + progressBar = FALSE, + reportOverallTime = FALSE ) # Drop temp tables: @@ -212,13 +212,13 @@ mergeTempTables <- sprintf("TRUNCATE TABLE %s;\nDROP TABLE %s;", tempTable, tempTable) sql <- SqlRender::translate(sql, - targetDialect = connection@dbms, - tempEmulationSchema = tempEmulationSchema + targetDialect = connection@dbms, + tempEmulationSchema = tempEmulationSchema ) DatabaseConnector::executeSql(connection, - sql, - progressBar = FALSE, - reportOverallTime = FALSE + sql, + progressBar = FALSE, + reportOverallTime = FALSE ) } } @@ -261,13 +261,13 @@ instantiateUniqueConceptSets <- function(uniqueConceptSets, sqlSubset <- SqlRender::render(sqlSubset, vocabulary_database_schema = vocabularyDatabaseSchema) sqlSubset <- SqlRender::translate(sqlSubset, - targetDialect = connection@dbms, - tempEmulationSchema = tempEmulationSchema + targetDialect = connection@dbms, + tempEmulationSchema = tempEmulationSchema ) DatabaseConnector::executeSql(connection, - sqlSubset, - progressBar = FALSE, - reportOverallTime = FALSE + sqlSubset, + progressBar = FALSE, + reportOverallTime = FALSE ) } utils::setTxtProgressBar(pb, 1) @@ -298,7 +298,7 @@ getCodeSetIds <- function(criterionList) { return(NULL) } else { return(dplyr::tibble(domain = names(criterionList), codeSetIds = codeSetIds) - %>% filter(!is.na(codeSetIds))) + %>% filter(!is.na(codeSetIds))) } } @@ -386,8 +386,8 @@ runConceptSetDiagnostics <- function(connection, ) uniqueConceptSets <- - conceptSets[!duplicated(conceptSets$uniqueConceptSetId),] %>% - dplyr::select(-cohortId, -conceptSetId) + conceptSets[!duplicated(conceptSets$uniqueConceptSetId), ] %>% + dplyr::select(-cohortId, -conceptSetId) timeExecution( exportFolder, @@ -403,11 +403,11 @@ runConceptSetDiagnostics <- function(connection, tempEmulationSchema = tempEmulationSchema, conceptSetsTable = "#inst_concept_sets" ) - }) + } + ) if ((runIncludedSourceConcepts && nrow(subsetIncluded) > 0) || (runOrphanConcepts && nrow(subsetOrphans) > 0)) { - timeExecution( exportFolder, taskName = "createConceptCountsTable", @@ -422,7 +422,8 @@ runConceptSetDiagnostics <- function(connection, conceptCountsTable = conceptCountsTable, conceptCountsTableIsTemp = conceptCountsTableIsTemp ) - }) + } + ) } if (runIncludedSourceConcepts) { timeExecution( @@ -431,7 +432,6 @@ runConceptSetDiagnostics <- function(connection, cohortIds = NULL, parent = "runConceptSetDiagnostics", expr = { - # Included concepts ------------------------------------------------------------------ ParallelLogger::logInfo("Fetching included source concepts") # TODO: Disregard empty cohorts in tally: @@ -465,7 +465,7 @@ runConceptSetDiagnostics <- function(connection, tempEmulationSchema = tempEmulationSchema, snakeCaseToCamelCase = TRUE ) %>% - tidyr::tibble() + tidyr::tibble() counts <- counts %>% dplyr::rename(uniqueConceptSetId = conceptSetId) %>% @@ -560,7 +560,8 @@ runConceptSetDiagnostics <- function(connection, )) } } - }) + } + ) } if (runBreakdownIndexEvents) { @@ -595,7 +596,6 @@ runConceptSetDiagnostics <- function(connection, cohortIds = cohort$cohortId, parent = "runConceptSetDiagnostics", expr = { - cohortDefinition <- RJSONIO::fromJSON(cohort$json, digits = 23) primaryCodesetIds <- @@ -603,7 +603,7 @@ runConceptSetDiagnostics <- function(connection, cohortDefinition$PrimaryCriteria$CriteriaList, getCodeSetIds ) %>% - dplyr::bind_rows() + dplyr::bind_rows() if (nrow(primaryCodesetIds) == 0) { warning( "No primary event criteria concept sets found for cohort id: ", @@ -612,13 +612,13 @@ runConceptSetDiagnostics <- function(connection, return(tidyr::tibble()) } primaryCodesetIds <- primaryCodesetIds %>% dplyr::filter(domain %in% - c(domains$domain %>% unique())) + c(domains$domain %>% unique())) if (nrow(primaryCodesetIds) == 0) { warning( "Primary event criteria concept sets found for cohort id: ", cohort$cohortId, " but,", "\nnone of the concept sets belong to the supported domains.", "\nThe supported domains are:\n", paste(domains$domain, - collapse = ", " + collapse = ", " ) ) return(tidyr::tibble()) @@ -643,7 +643,7 @@ runConceptSetDiagnostics <- function(connection, primaryCodesetIds <- dplyr::bind_rows(primaryCodesetIds) getCounts <- function(row) { - domain <- domains[domains$domain == row$domain,] + domain <- domains[domains$domain == row$domain, ] sql <- SqlRender::loadRenderTranslateSql( "CohortEntryBreakdown.sql", @@ -681,7 +681,7 @@ runConceptSetDiagnostics <- function(connection, store_table = "#breakdown", snakeCaseToCamelCase = TRUE ) %>% - tidyr::tibble() + tidyr::tibble() if (!is.null(conceptIdTable)) { sql <- "INSERT INTO @concept_id_table (concept_id) SELECT DISTINCT concept_id @@ -711,8 +711,8 @@ runConceptSetDiagnostics <- function(connection, counts <- lapply(split(primaryCodesetIds, 1:nrow(primaryCodesetIds)), getCounts) %>% - dplyr::bind_rows() %>% - dplyr::arrange(conceptCount) + dplyr::bind_rows() %>% + dplyr::arrange(conceptCount) if (nrow(counts) > 0) { counts$cohortId <- cohort$cohortId @@ -724,7 +724,8 @@ runConceptSetDiagnostics <- function(connection, return(dplyr::tibble()) } return(counts) - }) + } + ) } data <- @@ -794,7 +795,7 @@ runConceptSetDiagnostics <- function(connection, # [OPTIMIZATION idea] can we modify the sql to do this for all uniqueConceptSetId in one query using group by? data <- list() for (i in (1:nrow(uniqueConceptSets))) { - conceptSet <- uniqueConceptSets[i,] + conceptSet <- uniqueConceptSets[i, ] ParallelLogger::logInfo( "- Finding orphan concepts for concept set '", conceptSet$conceptSetName, @@ -807,7 +808,6 @@ runConceptSetDiagnostics <- function(connection, parent = "runConceptSetDiagnostics", cohortIds = paste("concept_set-", conceptSet$name), expr = { - data[[i]] <- .findOrphanConcepts( connection = connection, cdmDatabaseSchema = cdmDatabaseSchema, @@ -835,7 +835,8 @@ runConceptSetDiagnostics <- function(connection, reportOverallTime = FALSE ) } - }) + } + ) sql <- "TRUNCATE TABLE @orphan_concept_table;\nDROP TABLE @orphan_concept_table;" DatabaseConnector::renderTranslateExecuteSql( @@ -940,16 +941,16 @@ runConceptSetDiagnostics <- function(connection, tempEmulationSchema = tempEmulationSchema, snakeCaseToCamelCase = TRUE ) %>% - dplyr::tibble() %>% - dplyr::rename(uniqueConceptSetId = codesetId) %>% - dplyr::inner_join(conceptSets, - by = "uniqueConceptSetId" - ) %>% - dplyr::select( - cohortId, - conceptSetId, - conceptId - ) + dplyr::tibble() %>% + dplyr::rename(uniqueConceptSetId = codesetId) %>% + dplyr::inner_join(conceptSets, + by = "uniqueConceptSetId" + ) %>% + dplyr::select( + cohortId, + conceptSetId, + conceptId + ) resolvedConceptIds <- makeDataExportable( x = resolvedConceptIds, diff --git a/R/DataSourceInformation.R b/R/DataSourceInformation.R index 72f66db48..de9e2b785 100644 --- a/R/DataSourceInformation.R +++ b/R/DataSourceInformation.R @@ -49,9 +49,11 @@ getCdmDataSourceInformation <- } } - if (!DatabaseConnector::existsTable(connection = connection, - databaseSchema = cdmDatabaseSchema, - tableName = "cdm_source")) { + if (!DatabaseConnector::existsTable( + connection = connection, + databaseSchema = cdmDatabaseSchema, + tableName = "cdm_source" + )) { warning("CDM Source table not found in CDM. Metadata on CDM source will be limited.") return(NULL) } @@ -90,9 +92,10 @@ getCdmDataSourceInformation <- sourceReleaseDate <- as.Date(NA) if ("sourceReleaseDate" %in% colnames(cdmDataSource)) { if (class(cdmDataSource$sourceReleaseDate) != "Date") { - try(sourceReleaseDate <- - max(as.Date(cdmDataSource$sourceReleaseDate)), - silent = TRUE + try( + sourceReleaseDate <- + max(as.Date(cdmDataSource$sourceReleaseDate)), + silent = TRUE ) } else { sourceReleaseDate <- max(as.Date(cdmDataSource$sourceReleaseDate)) diff --git a/R/ExportCharacterization.R b/R/ExportCharacterization.R index ead0585b8..d4d344ed7 100644 --- a/R/ExportCharacterization.R +++ b/R/ExportCharacterization.R @@ -55,7 +55,8 @@ exportCharacterization <- function(characteristics, sd = round(sd, digits = 4) ) %>% dplyr::select(-cohortEntries, -cohortSubjects) %>% - dplyr::distinct() %>% makeDataExportable( + dplyr::distinct() %>% + makeDataExportable( tableName = "temporal_covariate_value", minCellCount = minCellCount, databaseId = databaseId @@ -74,7 +75,7 @@ exportCharacterization <- function(characteristics, covariateId = covariateRef$covariateId ) - analysisRef <- makeDataExportable( + analysisRef <- makeDataExportable( x = characteristics$analysisRef, tableName = "temporal_analysis_ref", minCellCount = minCellCount @@ -109,12 +110,12 @@ exportCharacterization <- function(characteristics, if (!"covariatesContinuous" %in% names(characteristics)) { ParallelLogger::logInfo("No continuous characterization output for submitted cohorts") } else if (dplyr::pull(dplyr::count(characteristics$covariateRef)) > 0) { - characteristics$filteredCovariatesContinous <- makeDataExportable( - x = characteristics$covariatesContinuous, - tableName = "temporal_covariate_value_dist", - minCellCount = minCellCount, - databaseId = databaseId - ) + characteristics$filteredCovariatesContinous <- makeDataExportable( + x = characteristics$covariatesContinuous, + tableName = "temporal_covariate_value_dist", + minCellCount = minCellCount, + databaseId = databaseId + ) if (dplyr::pull(dplyr::count(characteristics$filteredCovariatesContinous)) > 0) { writeToCsv( diff --git a/R/InclusionRules.R b/R/InclusionRules.R index 21e08056e..5fb8dbea0 100644 --- a/R/InclusionRules.R +++ b/R/InclusionRules.R @@ -44,21 +44,23 @@ getInclusionStats <- function(connection, ParallelLogger::logInfo("Exporting inclusion rules with CohortGenerator") timeExecution(exportFolder, - "getInclusionStatsCohortGenerator", - parent = "getInclusionStats", - expr = - { - CohortGenerator::insertInclusionRuleNames( - connection = connection, - cohortDefinitionSet = subset, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortInclusionTable = cohortTableNames$cohortInclusionTable - ) + "getInclusionStatsCohortGenerator", + parent = "getInclusionStats", + expr = { + CohortGenerator::insertInclusionRuleNames( + connection = connection, + cohortDefinitionSet = subset, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortInclusionTable = cohortTableNames$cohortInclusionTable + ) - stats <- CohortGenerator::getCohortStats(connection = connection, - cohortTableNames = cohortTableNames, - cohortDatabaseSchema = cohortDatabaseSchema) - }) + stats <- CohortGenerator::getCohortStats( + connection = connection, + cohortTableNames = cohortTableNames, + cohortDatabaseSchema = cohortDatabaseSchema + ) + } + ) if (!is.null(stats)) { if ("cohortInclusionTable" %in% (names(stats))) { cohortInclusion <- makeDataExportable( diff --git a/R/Incremental.R b/R/Incremental.R index a54246030..34373f55b 100644 --- a/R/Incremental.R +++ b/R/Incremental.R @@ -179,7 +179,6 @@ writeToCsv.default <- function(data, fileName, incremental = FALSE, ...) { delim = "," ) } - } writeToCsv.tbl_Andromeda <- @@ -210,8 +209,8 @@ writeToCsv.tbl_Andromeda <- addChunk <- function(chunk) { if ("timeId" %in% colnames(chunk)) { - if (nrow(chunk[is.na(chunk$timeId),]) > 0) { - chunk[is.na(chunk$timeId),]$timeId <- 0 + if (nrow(chunk[is.na(chunk$timeId), ]) > 0) { + chunk[is.na(chunk$timeId), ]$timeId <- 0 } } else { chunk$timeId <- 0 @@ -266,7 +265,7 @@ saveIncremental <- function(data, fileName, ...) { lazy = FALSE ) if ((nrow(previousData)) > 0) { - if("database_id" %in% colnames(previousData)) { + if ("database_id" %in% colnames(previousData)) { previousData$database_id <- as.character(previousData$database_id) } diff --git a/R/Private.R b/R/Private.R index a1ed136e4..188b074ea 100644 --- a/R/Private.R +++ b/R/Private.R @@ -324,11 +324,13 @@ timeExecution <- function(exportFolder, eval(expr) execTime <- Sys.time() - start } - executionTimes <- data.frame(task = taskName, - startTime = start, - cohortIds = paste(cohortIds, collapse = ";"), - executionTime = execTime, - parent = paste(parent, collapse = "")) + executionTimes <- data.frame( + task = taskName, + startTime = start, + cohortIds = paste(cohortIds, collapse = ";"), + executionTime = execTime, + parent = paste(parent, collapse = "") + ) readr::write_csv(executionTimes, file = executionTimePath, append = file.exists(executionTimePath)) return(executionTimes) diff --git a/R/ResultsDataModel.R b/R/ResultsDataModel.R index 90b50118f..c908ab3ef 100644 --- a/R/ResultsDataModel.R +++ b/R/ResultsDataModel.R @@ -49,7 +49,7 @@ fixTableMetadataForBackwardCompatibility <- function(table, tableName) { if (!"metadata" %in% colnames(table)) { data <- list() for (i in (1:nrow(table))) { - data[[i]] <- table[i,] + data[[i]] <- table[i, ] colnamesDf <- colnames(data[[i]]) metaDataList <- list() for (j in (1:length(colnamesDf))) { @@ -99,7 +99,7 @@ checkFixColumnNames <- expectedNames <- tableSpecs %>% dplyr::select(columnName) %>% dplyr::anti_join(dplyr::filter(optionalNames, !columnName %in% observeredNames), - by = "columnName" + by = "columnName" ) %>% dplyr::arrange(columnName) %>% dplyr::pull() @@ -206,7 +206,7 @@ checkAndFixDuplicateRows <- specifications = getResultsDataModelSpecifications()) { primaryKeys <- specifications %>% dplyr::filter(tableName == !!tableName & - primaryKey == "Yes") %>% + primaryKey == "Yes") %>% dplyr::select(columnName) %>% dplyr::pull() duplicatedRows <- duplicated(table[, primaryKeys]) @@ -219,7 +219,7 @@ checkAndFixDuplicateRows <- sum(duplicatedRows) ) ) - return(table[!duplicatedRows,]) + return(table[!duplicatedRows, ]) } else { return(table) } @@ -233,7 +233,7 @@ appendNewRows <- if (nrow(data) > 0) { primaryKeys <- specifications %>% dplyr::filter(tableName == !!tableName & - primaryKey == "Yes") %>% + primaryKey == "Yes") %>% dplyr::select(columnName) %>% dplyr::pull() newData <- newData %>% @@ -245,14 +245,18 @@ appendNewRows <- # Private function for testing migrations in isolation .createDataModel <- function(connection, databaseSchema, tablePrefix) { sqlParams <- getPrefixedTableNames(tablePrefix) - sql <- do.call(SqlRender::loadRenderTranslateSql, - c(sqlParams, - list( - sqlFilename = "CreateResultsDataModel.sql", - packageName = utils::packageName(), - dbms = connection@dbms, - results_schema = databaseSchema - ))) + sql <- do.call( + SqlRender::loadRenderTranslateSql, + c( + sqlParams, + list( + sqlFilename = "CreateResultsDataModel.sql", + packageName = utils::packageName(), + dbms = connection@dbms, + results_schema = databaseSchema + ) + ) + ) DatabaseConnector::executeSql(connection, sql) } @@ -276,9 +280,11 @@ createResultsDataModel <- function(connectionDetails = NULL, on.exit(DatabaseConnector::disconnect(connection)) .createDataModel(connection, databaseSchema, tablePrefix) - migrateDataModel(connectionDetails = connectionDetails, - databaseSchema = databaseSchema, - tablePrefix = tablePrefix) + migrateDataModel( + connectionDetails = connectionDetails, + databaseSchema = databaseSchema, + tablePrefix = tablePrefix + ) } naToEmpty <- function(x) { @@ -360,7 +366,7 @@ uploadResults <- function(connectionDetails, primaryKey <- specifications %>% filter(tableName == !!tableName & - primaryKey == "Yes") %>% + primaryKey == "Yes") %>% select(columnName) %>% pull() @@ -459,8 +465,8 @@ uploadResults <- function(connectionDetails, if (!is.null(env$primaryKeyValuesInDb)) { primaryKeyValuesInChunk <- unique(chunk[env$primaryKey]) duplicates <- inner_join(env$primaryKeyValuesInDb, - primaryKeyValuesInChunk, - by = env$primaryKey + primaryKeyValuesInChunk, + by = env$primaryKey ) if (nrow(duplicates) != 0) { if ("database_id" %in% env$primaryKey || @@ -527,7 +533,6 @@ uploadResults <- function(connectionDetails, deleteFromServer <- function(connection, schema, tableName, keyValues, tablePrefix) { - createSqlStatement <- function(i) { sql <- paste0( "DELETE FROM ", @@ -537,7 +542,7 @@ deleteFromServer <- tableName, "\nWHERE ", paste(paste0( - colnames(keyValues), " = '", keyValues[i,], "'" + colnames(keyValues), " = '", keyValues[i, ], "'" ), collapse = " AND "), ";" ) @@ -591,9 +596,9 @@ deleteAllRecordsForDatabaseId <- function(connection, database_id = databaseId, ) DatabaseConnector::renderTranslateExecuteSql(connection, - sql, - progressBar = FALSE, - reportOverallTime = FALSE + sql, + progressBar = FALSE, + reportOverallTime = FALSE ) } } @@ -615,10 +620,11 @@ migrateDataModel <- function(connectionDetails, databaseSchema, tablePrefix = "" ParallelLogger::logInfo("Updating version number") updateVersionSql <- SqlRender::loadRenderTranslateSql("UpdateVersionNumber.sql", - packageName = utils::packageName(), - database_schema = databaseSchema, - table_prefix = tablePrefix, - dbms = connectionDetails$dbms) + packageName = utils::packageName(), + database_schema = databaseSchema, + table_prefix = tablePrefix, + dbms = connectionDetails$dbms + ) connection <- DatabaseConnector::connect(connectionDetails = connectionDetails) on.exit(DatabaseConnector::disconnect(connection)) @@ -638,9 +644,11 @@ migrateDataModel <- function(connectionDetails, databaseSchema, tablePrefix = "" #' @returns Instance of ResultModelManager::DataMigrationManager that has interface for converting existing data models #' @export getDataMigrator <- function(connectionDetails, databaseSchema, tablePrefix = "") { - ResultModelManager::DataMigrationManager$new(connectionDetails = connectionDetails, - databaseSchema = databaseSchema, - tablePrefix = tablePrefix, - migrationPath = "migrations", - packageName = utils::packageName()) + ResultModelManager::DataMigrationManager$new( + connectionDetails = connectionDetails, + databaseSchema = databaseSchema, + tablePrefix = tablePrefix, + migrationPath = "migrations", + packageName = utils::packageName() + ) } diff --git a/R/RunDiagnostics.R b/R/RunDiagnostics.R index c2e2b1236..0746b4175 100644 --- a/R/RunDiagnostics.R +++ b/R/RunDiagnostics.R @@ -227,12 +227,7 @@ executeDiagnostics <- function(cohortDefinitionSet, incremental = callingArgs$incremental, temporalCovariateSettings = callingArgs$temporalCovariateSettings ) %>% - RJSONIO::toJSON(digits = 23, pretty = TRUE) - - # take package dependency snapshot - packageDependencySnapShotJson <- - takepackageDependencySnapshot() %>% - RJSONIO::toJSON(digits = 23, pretty = TRUE) + RJSONIO::toJSON(digits = 23, pretty = TRUE) exportFolder <- normalizePath(exportFolder, mustWork = FALSE) incrementalFolder <- normalizePath(incrementalFolder, mustWork = FALSE) @@ -253,25 +248,25 @@ executeDiagnostics <- function(cohortDefinitionSet, errorMessage <- checkmate::makeAssertCollection() checkmate::assertList(cohortTableNames, null.ok = FALSE, types = "character", add = errorMessage, names = "named") checkmate::assertNames(names(cohortTableNames), - must.include = c( - "cohortTable", - "cohortInclusionTable", - "cohortInclusionResultTable", - "cohortInclusionStatsTable", - "cohortSummaryStatsTable", - "cohortCensorStatsTable" - ), - add = errorMessage + must.include = c( + "cohortTable", + "cohortInclusionTable", + "cohortInclusionResultTable", + "cohortInclusionStatsTable", + "cohortSummaryStatsTable", + "cohortCensorStatsTable" + ), + add = errorMessage ) checkmate::assertDataFrame(cohortDefinitionSet, add = errorMessage) checkmate::assertNames(names(cohortDefinitionSet), - must.include = c( - "json", - "cohortId", - "cohortName", - "sql" - ), - add = errorMessage + must.include = c( + "json", + "cohortId", + "cohortName", + "sql" + ), + add = errorMessage ) cohortTable <- cohortTableNames$cohortTable @@ -362,26 +357,32 @@ executeDiagnostics <- function(cohortDefinitionSet, # All temporal covariate settings objects must be covariateSettings checkmate::assert_true(all(lapply(temporalCovariateSettings, class) == c("covariateSettings")), add = errorMessage) - requiredCharacterisationSettings <- c("DemographicsGender", "DemographicsAgeGroup", "DemographicsRace", - "DemographicsEthnicity", "DemographicsIndexYear", "DemographicsIndexMonth", - "ConditionEraGroupOverlap", "DrugEraGroupOverlap", "CharlsonIndex", - "Chads2", "Chads2Vasc") + requiredCharacterisationSettings <- c( + "DemographicsGender", "DemographicsAgeGroup", "DemographicsRace", + "DemographicsEthnicity", "DemographicsIndexYear", "DemographicsIndexMonth", + "ConditionEraGroupOverlap", "DrugEraGroupOverlap", "CharlsonIndex", + "Chads2", "Chads2Vasc" + ) presentSettings <- temporalCovariateSettings[[1]][requiredCharacterisationSettings] if (!all(unlist(presentSettings))) { warning( "For cohort charcterization to display standardized results the following covariates must be present in your temporalCovariateSettings: \n\n", - paste(requiredCharacterisationSettings, collapse = ", ")) + paste(requiredCharacterisationSettings, collapse = ", ") + ) } - requiredTimeDistributionSettings <- c("DemographicsPriorObservationTime", - "DemographicsPostObservationTime", - "DemographicsTimeInCohort") + requiredTimeDistributionSettings <- c( + "DemographicsPriorObservationTime", + "DemographicsPostObservationTime", + "DemographicsTimeInCohort" + ) presentSettings <- temporalCovariateSettings[[1]][requiredTimeDistributionSettings] if (!all(unlist(presentSettings))) { warning( "For time distributions diagnostics to display standardized results the following covariates must be present in your temporalCovariateSettings: \n\n", - paste(requiredTimeDistributionSettings, collapse = ", ")) + paste(requiredTimeDistributionSettings, collapse = ", ") + ) } # forcefully set ConditionEraGroupStart and drugEraGroupStart to NULL @@ -389,26 +390,32 @@ executeDiagnostics <- function(cohortDefinitionSet, temporalCovariateSettings[[1]]$ConditionEraGroupStart <- NULL temporalCovariateSettings[[1]]$DrugEraGroupStart <- NULL - checkmate::assert_integerish(x = temporalCovariateSettings[[1]]$temporalStartDays, - any.missing = FALSE, - min.len = 1, - add = errorMessage) - checkmate::assert_integerish(x = temporalCovariateSettings[[1]]$temporalEndDays, - any.missing = FALSE, - min.len = 1, - add = errorMessage) + checkmate::assert_integerish( + x = temporalCovariateSettings[[1]]$temporalStartDays, + any.missing = FALSE, + min.len = 1, + add = errorMessage + ) + checkmate::assert_integerish( + x = temporalCovariateSettings[[1]]$temporalEndDays, + any.missing = FALSE, + min.len = 1, + add = errorMessage + ) checkmate::reportAssertions(collection = errorMessage) # Adding required temporal windows required in results viewer requiredTemporalPairs <- - list(c(-365, 0), - c(-30, 0), - c(-365, -31), - c(-30, -1), - c(0, 0), - c(1, 30), - c(31, 365), - c(-9999, 9999)) + list( + c(-365, 0), + c(-30, 0), + c(-365, -31), + c(-30, -1), + c(0, 0), + c(1, 30), + c(31, 365), + c(-9999, 9999) + ) for (p1 in requiredTemporalPairs) { found <- FALSE for (i in 1:length(temporalCovariateSettings[[1]]$temporalStartDays)) { @@ -444,17 +451,17 @@ executeDiagnostics <- function(cohortDefinitionSet, sort() cohortTableColumnNamesExpected <- getResultsDataModelSpecifications() %>% - dplyr::filter(tableName == "cohort") %>% - dplyr::pull(columnName) %>% - SqlRender::snakeCaseToCamelCase() %>% - sort() + dplyr::filter(tableName == "cohort") %>% + dplyr::pull(columnName) %>% + SqlRender::snakeCaseToCamelCase() %>% + sort() cohortTableColumnNamesRequired <- getResultsDataModelSpecifications() %>% - dplyr::filter(tableName == "cohort") %>% - dplyr::filter(isRequired == "Yes") %>% - dplyr::pull(columnName) %>% - SqlRender::snakeCaseToCamelCase() %>% - sort() + dplyr::filter(tableName == "cohort") %>% + dplyr::filter(isRequired == "Yes") %>% + dplyr::pull(columnName) %>% + SqlRender::snakeCaseToCamelCase() %>% + sort() expectedButNotObsevered <- setdiff(x = cohortTableColumnNamesExpected, y = cohortTableColumnNamesObserved) @@ -534,8 +541,8 @@ executeDiagnostics <- function(cohortDefinitionSet, } } vocabularyVersion <- getVocabularyVersion(connection, vocabularyDatabaseSchema) - - }) + } + ) cohortDefinitionSet$checksum <- computeChecksum(cohortDefinitionSet$sql) @@ -570,7 +577,8 @@ executeDiagnostics <- function(cohortDefinitionSet, snakeCaseToCamelCase = TRUE, tempEmulationSchema = tempEmulationSchema ) - }) + } + ) # Database metadata --------------------------------------------- saveDatabaseMetaData( databaseId = databaseId, @@ -600,7 +608,8 @@ executeDiagnostics <- function(cohortDefinitionSet, minCellCount = minCellCount, databaseId = databaseId ) - }) + } + ) if (nrow(cohortCounts) > 0) { instantiatedCohorts <- cohortCounts %>% @@ -639,7 +648,8 @@ executeDiagnostics <- function(cohortDefinitionSet, minCellCount = minCellCount, recordKeepingFile = recordKeepingFile ) - }) + } + ) } # Concept set diagnostics ----------------------------------------------- @@ -674,7 +684,8 @@ executeDiagnostics <- function(cohortDefinitionSet, conceptIdTable = "#concept_ids", recordKeepingFile = recordKeepingFile ) - }) + } + ) } # Time series ---------------------------------------------------------------------- @@ -700,7 +711,8 @@ executeDiagnostics <- function(cohortDefinitionSet, recordKeepingFile = recordKeepingFile, observationPeriodDateRange = observationPeriodDateRange ) - }) + } + ) } @@ -727,7 +739,8 @@ executeDiagnostics <- function(cohortDefinitionSet, recordKeepingFile = recordKeepingFile, incremental = incremental ) - }) + } + ) } # Incidence rates -------------------------------------------------------------------------------------- @@ -752,7 +765,8 @@ executeDiagnostics <- function(cohortDefinitionSet, recordKeepingFile = recordKeepingFile, incremental = incremental ) - }) + } + ) } # Cohort relationship --------------------------------------------------------------------------------- @@ -777,7 +791,8 @@ executeDiagnostics <- function(cohortDefinitionSet, recordKeepingFile = recordKeepingFile, incremental = incremental ) - }) + } + ) } # Temporal Cohort characterization --------------------------------------------------------------- @@ -813,7 +828,8 @@ executeDiagnostics <- function(cohortDefinitionSet, timeRefFileName = file.path(exportFolder, "temporal_time_ref.csv"), minCharacterizationMean = minCharacterizationMean ) - }) + } + ) } # Store information from the vocabulary on the concepts used ------------------------- @@ -821,8 +837,7 @@ executeDiagnostics <- function(cohortDefinitionSet, exportFolder, "exportConceptInformation", parent = "executeDiagnostics", - expr = - { + expr = { exportConceptInformation( connection = connection, cdmDatabaseSchema = cdmDatabaseSchema, @@ -831,15 +846,15 @@ executeDiagnostics <- function(cohortDefinitionSet, incremental = incremental, exportFolder = exportFolder ) - }) + } + ) # Delete unique concept ID table --------------------------------- ParallelLogger::logTrace("Deleting concept ID table") timeExecution( exportFolder, "DeleteConceptIdTable", parent = "executeDiagnostics", - expr = - { + expr = { sql <- "TRUNCATE TABLE @table;\nDROP TABLE @table;" DatabaseConnector::renderTranslateExecuteSql( connection = connection, @@ -849,7 +864,8 @@ executeDiagnostics <- function(cohortDefinitionSet, progressBar = FALSE, reportOverallTime = FALSE ) - }) + } + ) # Writing metadata file ParallelLogger::logInfo("Retrieving metadata information and writing metadata") @@ -925,7 +941,7 @@ executeDiagnostics <- function(cohortDefinitionSet, # 2 as.character(attr(delta, "units")), # 3 - packageDependencySnapShotJson, + "{}", # 4 callingArgsJson, # 5 @@ -996,7 +1012,8 @@ executeDiagnostics <- function(cohortDefinitionSet, parent = "executeDiagnostics", expr = { writeResultsZip(exportFolder, databaseId) - }) + } + ) ParallelLogger::logInfo( "Computing all diagnostics took ", diff --git a/R/Shiny.R b/R/Shiny.R index fa4031824..d00937df1 100644 --- a/R/Shiny.R +++ b/R/Shiny.R @@ -58,7 +58,6 @@ launchDiagnosticsExplorer <- function(sqliteDbPath = "MergedCohortDiagnosticsDat port = 80, launch.browser = FALSE, enableAnnotation = TRUE) { - if (is.null(shinyConfigPath)) { if (is.null(connectionDetails)) { sqliteDbPath <- normalizePath(sqliteDbPath) @@ -110,34 +109,36 @@ launchDiagnosticsExplorer <- function(sqliteDbPath = "MergedCohortDiagnosticsDat on.exit(options("CD-shiny-config" = NULL)) } - ensure_installed(c("checkmate", - "DatabaseConnector", - "dplyr", - "plyr", - "ggplot2", - "ggiraph", - "gtable", - "htmltools", - "lubridate", - "pool", - "purrr", - "scales", - "shiny", - "shinydashboard", - "shinyWidgets", - "shinyjs", - "shinycssloaders", - "stringr", - "SqlRender", - "tidyr", - "CirceR", - "rmarkdown", - "reactable", - "markdownInput", - "markdown", - "jsonlite", - "ggh4x", - "yaml")) + ensure_installed(c( + "checkmate", + "DatabaseConnector", + "dplyr", + "plyr", + "ggplot2", + "ggiraph", + "gtable", + "htmltools", + "lubridate", + "pool", + "purrr", + "scales", + "shiny", + "shinydashboard", + "shinyWidgets", + "shinyjs", + "shinycssloaders", + "stringr", + "SqlRender", + "tidyr", + "CirceR", + "rmarkdown", + "reactable", + "markdownInput", + "markdown", + "jsonlite", + "ggh4x", + "yaml" + )) appDir <- system.file("shiny", "DiagnosticsExplorer", package = utils::packageName()) @@ -229,7 +230,7 @@ createMergedResultsFile <- createDiagnosticsExplorerZip <- function(outputZipfile = file.path(getwd(), "DiagnosticsExplorer.zip"), sqliteDbPath = "MergedCohortDiagnosticsData.sqlite", shinyDirectory = system.file(file.path("shiny", "DiagnosticsExplorer"), - package = "CohortDiagnostics" + package = "CohortDiagnostics" ), overwrite = FALSE) { outputZipfile <- normalizePath(outputZipfile, mustWork = FALSE) diff --git a/R/TakePackageDependencySnapshot.R b/R/TakePackageDependencySnapshot.R deleted file mode 100644 index 4288acb0c..000000000 --- a/R/TakePackageDependencySnapshot.R +++ /dev/null @@ -1,98 +0,0 @@ -# Copyright 2022 Observational Health Data Sciences and Informatics -# -# This file is part of CohortDiagnostics -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -#' Take a snapshot of the R environment -#' -#' @details -#' This function records all versions used in the R environment as used by runCohortDiagnostics. -#' This function was borrowed from OhdsiRTools -#' -#' @return -#' A data frame listing all the dependencies of the root package and their version numbers, in the -#' order in which they should be installed. -#' -takepackageDependencySnapshot <- function() { - splitPackageList <- function(packageList) { - if (is.null(packageList)) { - return(c()) - } else { - return(strsplit( - gsub( - "\\([^)]*\\)", "", gsub(" ", "", gsub("\n", "", packageList)) - ), - "," - )[[1]]) - } - } - - fetchDependencies <- - function(package, - recursive = TRUE, - level = 0) { - description <- utils::packageDescription(package) - packages <- splitPackageList(description$Depends) - packages <- c(packages, splitPackageList(description$Imports)) - packages <- - c(packages, splitPackageList(description$LinkingTo)) - # Note: if we want to include suggests, we'll need to consider circular references packages <- - # c(packages, splitPackageList(description$Suggests)) - packages <- packages[packages != "R"] - packages <- data.frame( - name = packages, - level = rep( - level, - length(packages) - ), - stringsAsFactors = FALSE - ) - if (recursive && nrow(packages) > 0) { - all <- - lapply(packages$name, - fetchDependencies, - recursive = TRUE, - level = level + 1 - ) - dependencies <- do.call("rbind", all) - if (nrow(dependencies) > 0) { - packages <- rbind(packages, dependencies) - packages <- aggregate(level ~ name, packages, max) - } - } - return(packages) - } - - packages <- - fetchDependencies("CohortDiagnostics", recursive = TRUE) - packages <- packages[order(-packages$level), ] - getVersion <- function(package) { - return(utils::packageDescription(package)$Version) - } - versions <- - sapply(c(packages$name, "CohortDiagnostics"), getVersion) - snapshot <- data.frame( - package = names(versions), - version = as.vector(versions), - stringsAsFactors = FALSE - ) - s <- utils::sessionInfo() - rVersion <- data.frame( - package = "R", - version = paste(s$R.version$major, s$R.version$minor, sep = "."), - stringsAsFactors = FALSE - ) - snapshot <- rbind(rVersion, snapshot) - return(snapshot) -} diff --git a/R/TimeSeries.R b/R/TimeSeries.R index f35c23e33..682442dd2 100644 --- a/R/TimeSeries.R +++ b/R/TimeSeries.R @@ -124,8 +124,8 @@ runCohortTimeSeriesDiagnostics <- function(connectionDetails = NULL, by = clock::duration_months(3) ) ) %>% - dplyr::mutate(periodEnd = clock::add_months(x = periodBegin, n = 3) - 1) %>% - dplyr::mutate(calendarInterval = "q") + dplyr::mutate(periodEnd = clock::add_months(x = periodBegin, n = 3) - 1) %>% + dplyr::mutate(calendarInterval = "q") calendarMonth <- dplyr::tibble( @@ -135,8 +135,8 @@ runCohortTimeSeriesDiagnostics <- function(connectionDetails = NULL, by = clock::duration_months(1) ) ) %>% - dplyr::mutate(periodEnd = clock::add_months(x = periodBegin, n = 1) - 1) %>% - dplyr::mutate(calendarInterval = "m") + dplyr::mutate(periodEnd = clock::add_months(x = periodBegin, n = 1) - 1) %>% + dplyr::mutate(calendarInterval = "m") calendarYear <- dplyr::tibble( @@ -146,8 +146,8 @@ runCohortTimeSeriesDiagnostics <- function(connectionDetails = NULL, by = clock::duration_years(1) ) ) %>% - dplyr::mutate(periodEnd = clock::add_years(x = periodBegin, n = 1) - 1) %>% - dplyr::mutate(calendarInterval = "y") + dplyr::mutate(periodEnd = clock::add_years(x = periodBegin, n = 1) - 1) %>% + dplyr::mutate(calendarInterval = "y") timeSeriesDateRange <- dplyr::tibble( periodBegin = timeSeriesMinDate, @@ -162,9 +162,9 @@ runCohortTimeSeriesDiagnostics <- function(connectionDetails = NULL, calendarYear, timeSeriesDateRange ) %>% # calendarWeek - dplyr::distinct() %>% - dplyr::arrange(periodBegin, periodEnd, calendarInterval) %>% - dplyr::mutate(timeId = dplyr::row_number()) + dplyr::distinct() %>% + dplyr::arrange(periodBegin, periodEnd, calendarInterval) %>% + dplyr::mutate(timeId = dplyr::row_number()) ParallelLogger::logTrace(" - Inserting calendar periods") DatabaseConnector::insertTable( @@ -428,7 +428,7 @@ runCohortTimeSeriesDiagnostics <- function(connectionDetails = NULL, ) resultsInAndromeda$ageGroupGender <- resultsInAndromeda$ageGroupGender %>% - dplyr::mutate(seriesType = !!seriesId) + dplyr::mutate(seriesType = !!seriesId) Andromeda::appendToTable( resultsInAndromeda$allData, resultsInAndromeda$ageGroupGender @@ -452,7 +452,7 @@ runCohortTimeSeriesDiagnostics <- function(connectionDetails = NULL, dplyr::collect() %>% # temporal solution till fix of bug in andromeda on handling dates # periodBegin gets converted to integer dplyr::inner_join(resultsInAndromeda$calendarPeriods %>% dplyr::collect(), - by = c("timeId") + by = c("timeId") ) %>% dplyr::arrange( cohortId, @@ -520,7 +520,6 @@ executeTimeSeriesDiagnostics <- function(connection, recordKeepingFile, observationPeriodDateRange, batchSize = getOption("CohortDiagnostics-TimeSeries-batch-size", default = 20)) { - if (all(!runCohortTimeSeries, !runDataSourceTimeSeries)) { warning( "Both Datasource time series and cohort time series are set to FALSE. Skippping executeTimeSeriesDiagnostics." @@ -566,7 +565,7 @@ executeTimeSeriesDiagnostics <- function(connection, ) } - cohortIds <- subset[start:end,]$cohortId %>% unique() + cohortIds <- subset[start:end, ]$cohortId %>% unique() timeExecution( exportFolder, "runCohortTimeSeriesDiagnostics", @@ -598,12 +597,12 @@ executeTimeSeriesDiagnostics <- function(connection, data = data, fileName = outputFile, incremental = TRUE, - cohortId = subset[start:end,]$cohortId %>% unique() + cohortId = subset[start:end, ]$cohortId %>% unique() ) recordTasksDone( - cohortId = subset[start:end,]$cohortId %>% unique(), + cohortId = subset[start:end, ]$cohortId %>% unique(), task = "runCohortTimeSeries", - checksum = subset[start:end,]$checksum, + checksum = subset[start:end, ]$checksum, recordKeepingFile = recordKeepingFile, incremental = incremental ) @@ -623,8 +622,10 @@ executeTimeSeriesDiagnostics <- function(connection, recordKeepingFile = recordKeepingFile ) - if (all(nrow(subset) == 0, - incremental)) { + if (all( + nrow(subset) == 0, + incremental + )) { ParallelLogger::logInfo("Skipping Data Source Time Series in Incremental mode.") return(NULL) } diff --git a/docs/404.html b/docs/404.html index 653fa5c34..3dd8ed2c3 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/articles/CreatingAStudyPackage.html b/docs/articles/CreatingAStudyPackage.html index d7205370b..2950d8852 100644 --- a/docs/articles/CreatingAStudyPackage.html +++ b/docs/articles/CreatingAStudyPackage.html @@ -33,7 +33,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 @@ -97,7 +97,7 @@

Creating a study package

Gowtham A. Rao

-

2022-12-06

+

2022-12-19

Source: vignettes/CreatingAStudyPackage.Rmd @@ -186,7 +186,7 @@

option A: Using Hydra and ROhdsiW # please ensure you have the latest version of Hydra. As of 08/13/2021 - CohortDiagnostics support for Hydra is still in develop branch. # please check hydra release notes and update hydra remotes::install_github("OHDSI/Hydra", ref = "develop") -outputFolder <- "d:/temp/output" # location where you study package will be created +outputFolder <- "d:/temp/output" # location where you study package will be created ########## Please populate the information below ##################### @@ -208,62 +208,68 @@

option A: Using Hydra and ROhdsiW baseUrl <- Sys.getenv("baseUrl") # if you have security enabled, please authorize the use - example below # ROhdsiWebApi::authorizeWebApi(baseUrl, 'windows') -cohortIds <- c(22040, - 22042, - 22041, - 22039, - 22038, - 22037, - 22036, - 22035, - 22034, - 22033, - 22031, - 22032, - 22030, - 22028, - 22029) +cohortIds <- c( + 22040, + 22042, + 22041, + 22039, + 22038, + 22037, + 22036, + 22035, + 22034, + 22033, + 22031, + 22032, + 22030, + 22028, + 22029 +) ################# end of user input ############## webApiCohorts <- ROhdsiWebApi::getCohortDefinitionsMetaData(baseUrl = baseUrl) -studyCohorts <- webApiCohorts %>% - dplyr::filter(.data$id %in% cohortIds) +studyCohorts <- webApiCohorts %>% + dplyr::filter(.data$id %in% cohortIds) # compile them into a data table cohortDefinitionsArray <- list() for (i in (1:nrow(studyCohorts))) { - cohortDefinition <- - ROhdsiWebApi::getCohortDefinition(cohortId = studyCohorts$id[[i]], - baseUrl = baseUrl) - cohortDefinitionsArray[[i]] <- list( - id = studyCohorts$id[[i]], - createdDate = studyCohorts$createdDate[[i]], - modifiedDate = studyCohorts$createdDate[[i]], - logicDescription = studyCohorts$description[[i]], - name = stringr::str_trim(stringr::str_squish(cohortDefinition$name)), - expression = cohortDefinition$expression - ) + cohortDefinition <- + ROhdsiWebApi::getCohortDefinition( + cohortId = studyCohorts$id[[i]], + baseUrl = baseUrl + ) + cohortDefinitionsArray[[i]] <- list( + id = studyCohorts$id[[i]], + createdDate = studyCohorts$createdDate[[i]], + modifiedDate = studyCohorts$createdDate[[i]], + logicDescription = studyCohorts$description[[i]], + name = stringr::str_trim(stringr::str_squish(cohortDefinition$name)), + expression = cohortDefinition$expression + ) } tempFolder <- tempdir() unlink(x = tempFolder, recursive = TRUE, force = TRUE) dir.create(path = tempFolder, showWarnings = FALSE, recursive = TRUE) -specifications <- list(id = 1, - version = version, - name = name, - packageName = packageName, - skeletonVersion = skeletonVersion, - createdBy = createdBy, - createdDate = createdDate, - modifiedBy = modifiedBy, - modifiedDate = modifiedDate, - skeletonType = skeletonType, - organizationName = organizationName, - description = description, - cohortDefinitions = cohortDefinitionsArray) +specifications <- list( + id = 1, + version = version, + name = name, + packageName = packageName, + skeletonVersion = skeletonVersion, + createdBy = createdBy, + createdDate = createdDate, + modifiedBy = modifiedBy, + modifiedDate = modifiedDate, + skeletonType = skeletonType, + organizationName = organizationName, + description = description, + cohortDefinitions = cohortDefinitionsArray +) jsonFileName <- paste0(file.path(tempFolder, "CohortDiagnosticsSpecs.json")) write(x = specifications %>% RJSONIO::toJSON(pretty = TRUE, digits = 23), file = jsonFileName) @@ -280,13 +286,13 @@

option A: Using Hydra and ROhdsiW #### get the skeleton from github # download.file(url = "https://github.com/OHDSI/SkeletonCohortDiagnosticsStudy/archive/refs/heads/main.zip", # destfile = file.path(tempFolder, 'skeleton.zip')) -# unzip(zipfile = file.path(tempFolder, 'skeleton.zip'), +# unzip(zipfile = file.path(tempFolder, 'skeleton.zip'), # overwrite = TRUE, # exdir = file.path(tempFolder, "skeleton") # ) # fileList <- list.files(path = file.path(tempFolder, "skeleton"), full.names = TRUE, recursive = TRUE, all.files = TRUE) -# DatabaseConnector::createZipFile(zipFile = file.path(tempFolder, 'skeleton.zip'), -# files = fileList, +# DatabaseConnector::createZipFile(zipFile = file.path(tempFolder, 'skeleton.zip'), +# files = fileList, # rootFolder = list.dirs(file.path(tempFolder, 'skeleton'), recursive = FALSE)) ############################################################## @@ -301,13 +307,14 @@

option A: Using Hydra and ROhdsiW hydraSpecificationFromFile <- Hydra::loadSpecifications(fileName = jsonFileName) unlink(x = outputFolder, recursive = TRUE) dir.create(path = outputFolder, showWarnings = FALSE, recursive = TRUE) -Hydra::hydrate(specifications = hydraSpecificationFromFile, - outputFolder = outputFolder +Hydra::hydrate( + specifications = hydraSpecificationFromFile, + outputFolder = outputFolder ) # for advanced user using skeletons outside of Hydra # Hydra::hydrate(specifications = hydraSpecificationFromFile, -# outputFolder = outputFolder, +# outputFolder = outputFolder, # skeletonFileName = file.path(tempFolder, 'skeleton.zip') # ) diff --git a/docs/articles/DatabaseModeInDiagnosticsExplorer.html b/docs/articles/DatabaseModeInDiagnosticsExplorer.html index c0e4afcb6..409421e5e 100644 --- a/docs/articles/DatabaseModeInDiagnosticsExplorer.html +++ b/docs/articles/DatabaseModeInDiagnosticsExplorer.html @@ -33,7 +33,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 @@ -97,7 +97,7 @@

Database mode in Diagnostics Explorer

Gowtham Rao

-

2022-12-06

+

2022-12-19

Source: vignettes/DatabaseModeInDiagnosticsExplorer.Rmd diff --git a/docs/articles/RunningCohortDiagnostics.html b/docs/articles/RunningCohortDiagnostics.html index 19b970613..645569673 100644 --- a/docs/articles/RunningCohortDiagnostics.html +++ b/docs/articles/RunningCohortDiagnostics.html @@ -33,7 +33,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 @@ -97,7 +97,7 @@

Running Cohort Diagnostics

Gowtham Rao and James P. Gilbert

-

2022-12-06

+

2022-12-19

Source: vignettes/RunningCohortDiagnostics.Rmd @@ -122,8 +122,8 @@

pre-requisitesROhdsiWebApi package to download cohort definitions from an ATLAS instance:

-remotes::install_github('OHDSI/Eunomia')
-remotes::install_github('OHDSI/ROhdsiWebApi')
+remotes::install_github("OHDSI/Eunomia") +remotes::install_github("OHDSI/ROhdsiWebApi")
@@ -139,10 +139,12 @@

Configuring the connection to
 library(CohortDiagnostics)
 
-connectionDetails <- createConnectionDetails(dbms = "postgresql",
-                                             server = "localhost/ohdsi",
-                                             user = "joe",
-                                             password = "supersecret")
+connectionDetails <- createConnectionDetails( + dbms = "postgresql", + server = "localhost/ohdsi", + user = "joe", + password = "supersecret" +)

For the purposes of this example, we will use the Eunomia test CDM package that is in an Sqlite database stored locally.

@@ -181,10 +183,12 @@ 

Loading cohort references from the OMOP Common Data Model format.

 library(CohortDiagnostics)
-cohortDefinitionSet <- CohortGenerator::getCohortDefinitionSet(settingsFileName = "Cohorts.csv",
-                                                               jsonFolder = "cohorts",
-                                                               sqlFolder = "sql/sql_server",
-                                                               packageName = "CohortDiagnostics")
+cohortDefinitionSet <- CohortGenerator::getCohortDefinitionSet( + settingsFileName = "Cohorts.csv", + jsonFolder = "cohorts", + sqlFolder = "sql/sql_server", + packageName = "CohortDiagnostics" +)

Looking at this data.frame of Cohorts you will see the sql and json for these cohorts:

@@ -204,11 +208,13 @@ 

Loading cohort references from We # Set up url baseUrl <- "https://atlas.hosting.com/WebAPI" # list of cohort ids -cohortIds <- c(18345,18346) +cohortIds <- c(18345, 18346) -cohortDefinitionSet <- ROhdsiWebApi::exportCohortDefinitionSet(baseUrl = baseUrl, - cohortIds = cohortIds, - generateStats = TRUE)

+cohortDefinitionSet <- ROhdsiWebApi::exportCohortDefinitionSet( + baseUrl = baseUrl, + cohortIds = cohortIds, + generateStats = TRUE +)

Consult the ROhdsiWebApi documentation for details on authentication to your atlas instance. Please note that in order to generate inclusion rules statistics (a useful diagnostic tool) the parameter @@ -226,18 +232,22 @@

Using CohortGenerator to i cohortTableNames <- CohortGenerator::getCohortTableNames(cohortTable = cohortTable) # Next create the tables on the database -CohortGenerator::createCohortTables(connectionDetails = connectionDetails, - cohortTableNames = cohortTableNames, - cohortDatabaseSchema = "main", - incremental = FALSE) +CohortGenerator::createCohortTables( + connectionDetails = connectionDetails, + cohortTableNames = cohortTableNames, + cohortDatabaseSchema = "main", + incremental = FALSE +) # Generate the cohort set -CohortGenerator::generateCohortSet(connectionDetails= connectionDetails, - cdmDatabaseSchema = cdmDatabaseSchema, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTableNames = cohortTableNames, - cohortDefinitionSet = cohortDefinitionSet, - incremental = FALSE) +CohortGenerator::generateCohortSet( + connectionDetails = connectionDetails, + cdmDatabaseSchema = cdmDatabaseSchema, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTableNames = cohortTableNames, + cohortDefinitionSet = cohortDefinitionSet, + incremental = FALSE +)

Note, that the above code will delete an existing table. However, incremental mode can be used when setting the parameter incremental = TRUE.

@@ -259,13 +269,14 @@

Executing cohort diagnostics
 executeDiagnostics(cohortDefinitionSet,
-                   connectionDetails = connectionDetails,
-                   cohortTable = cohortTable,
-                   cohortDatabaseSchema = cohortDatabaseSchema,
-                   cdmDatabaseSchema = cdmDatabaseSchema,
-                   exportFolder = exportFolder,
-                   databaseId = "MyCdm",
-                   minCellCount = 5)
+ connectionDetails = connectionDetails, + cohortTable = cohortTable, + cohortDatabaseSchema = cohortDatabaseSchema, + cdmDatabaseSchema = cdmDatabaseSchema, + exportFolder = exportFolder, + databaseId = "MyCdm", + minCellCount = 5 +)

Cohort Statistics Table Clean up @@ -274,9 +285,11 @@

Cohort Statistics Table Clean up
-CohortGenerator::dropCohortStatsTables(connectionDetails = connectionDetails,
-                                       cohortDatabaseSchema = cohortDatabaseSchema,
-                                       cohortTableNames = cohortTableNames)
+CohortGenerator::dropCohortStatsTables( + connectionDetails = connectionDetails, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTableNames = cohortTableNames +)

diff --git a/docs/articles/ViewingResultsUsingDiagnosticsExplorer.html b/docs/articles/ViewingResultsUsingDiagnosticsExplorer.html index 50bf23ffe..04af855d1 100644 --- a/docs/articles/ViewingResultsUsingDiagnosticsExplorer.html +++ b/docs/articles/ViewingResultsUsingDiagnosticsExplorer.html @@ -33,7 +33,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2
@@ -97,7 +97,7 @@

Viewing results using Diagnostics Explorer

Gowtham Rao

-

2022-12-06

+

2022-12-19

Source: vignettes/ViewingResultsUsingDiagnosticsExplorer.Rmd diff --git a/docs/articles/WhatIsCohortDiagnostics.html b/docs/articles/WhatIsCohortDiagnostics.html index 2e10d13f1..28dcf0f6b 100644 --- a/docs/articles/WhatIsCohortDiagnostics.html +++ b/docs/articles/WhatIsCohortDiagnostics.html @@ -33,7 +33,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 @@ -97,7 +97,7 @@

What is Cohort Diagnostics?

Gowtham Rao

-

2022-12-06

+

2022-12-19

Source: vignettes/WhatIsCohortDiagnostics.Rmd diff --git a/docs/articles/index.html b/docs/articles/index.html index 561bf2513..1b44b4839 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/authors.html b/docs/authors.html index 7d9c1e724..23ae44098 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/index.html b/docs/index.html index 2bb5d9bcd..f996a2927 100644 --- a/docs/index.html +++ b/docs/index.html @@ -39,7 +39,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/news/index.html b/docs/news/index.html index a6b61a274..d57c4df65 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 @@ -72,6 +72,11 @@

Changelog

Source: NEWS.md +
+ +

Bug Fixes:

+
  1. Removed package dependency snapshot capture as it was breaking on newer versions of R
  2. +

Changes:

diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 227a7fe6e..0b8c7f096 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -7,5 +7,5 @@ articles: RunningCohortDiagnostics: RunningCohortDiagnostics.html ViewingResultsUsingDiagnosticsExplorer: ViewingResultsUsingDiagnosticsExplorer.html WhatIsCohortDiagnostics: WhatIsCohortDiagnostics.html -last_built: 2022-12-06T21:26Z +last_built: 2022-12-20T00:46Z diff --git a/docs/reference/CohortDiagnostics-package.html b/docs/reference/CohortDiagnostics-package.html index 117984ced..49e7e7bff 100644 --- a/docs/reference/CohortDiagnostics-package.html +++ b/docs/reference/CohortDiagnostics-package.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2
diff --git a/docs/reference/checkInputFileEncoding.html b/docs/reference/checkInputFileEncoding.html index 188894a1a..65764abf8 100644 --- a/docs/reference/checkInputFileEncoding.html +++ b/docs/reference/checkInputFileEncoding.html @@ -18,7 +18,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/createDiagnosticsExplorerZip.html b/docs/reference/createDiagnosticsExplorerZip.html index c86032d9d..e80a6695b 100644 --- a/docs/reference/createDiagnosticsExplorerZip.html +++ b/docs/reference/createDiagnosticsExplorerZip.html @@ -20,7 +20,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/createMergedResultsFile.html b/docs/reference/createMergedResultsFile.html index 986542882..a9f04e857 100644 --- a/docs/reference/createMergedResultsFile.html +++ b/docs/reference/createMergedResultsFile.html @@ -19,7 +19,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/createResultsDataModel.html b/docs/reference/createResultsDataModel.html index bd171264b..1ef9b5d09 100644 --- a/docs/reference/createResultsDataModel.html +++ b/docs/reference/createResultsDataModel.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/executeDiagnostics.html b/docs/reference/executeDiagnostics.html index 5da955790..c902b770b 100644 --- a/docs/reference/executeDiagnostics.html +++ b/docs/reference/executeDiagnostics.html @@ -22,7 +22,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/getCdmDataSourceInformation.html b/docs/reference/getCdmDataSourceInformation.html index e90a48a1a..cda6a62fb 100644 --- a/docs/reference/getCdmDataSourceInformation.html +++ b/docs/reference/getCdmDataSourceInformation.html @@ -18,7 +18,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/getCohortCounts.html b/docs/reference/getCohortCounts.html index cae29104e..124bebee4 100644 --- a/docs/reference/getCohortCounts.html +++ b/docs/reference/getCohortCounts.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/getDataMigrator.html b/docs/reference/getDataMigrator.html index eb9ed6fb4..a5dc48237 100644 --- a/docs/reference/getDataMigrator.html +++ b/docs/reference/getDataMigrator.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/getDefaultCovariateSettings.html b/docs/reference/getDefaultCovariateSettings.html index cb45443c6..cfa9ea96f 100644 --- a/docs/reference/getDefaultCovariateSettings.html +++ b/docs/reference/getDefaultCovariateSettings.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/getDefaultVocabularyTableNames.html b/docs/reference/getDefaultVocabularyTableNames.html index 8c736f259..e99b3359d 100644 --- a/docs/reference/getDefaultVocabularyTableNames.html +++ b/docs/reference/getDefaultVocabularyTableNames.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/getResultsDataModelSpecifications.html b/docs/reference/getResultsDataModelSpecifications.html index 4e0bcae52..a60460a6c 100644 --- a/docs/reference/getResultsDataModelSpecifications.html +++ b/docs/reference/getResultsDataModelSpecifications.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/index.html b/docs/reference/index.html index d5c87ca1f..efaccf446 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 @@ -135,10 +135,6 @@

All functions runCohortTimeSeriesDiagnostics()

Given a set of instantiated cohorts get time series for the cohorts.

- -

takepackageDependencySnapshot()

- -

Take a snapshot of the R environment

timeExecution()

diff --git a/docs/reference/launchDiagnosticsExplorer.html b/docs/reference/launchDiagnosticsExplorer.html index 8db5887fa..594919ca6 100644 --- a/docs/reference/launchDiagnosticsExplorer.html +++ b/docs/reference/launchDiagnosticsExplorer.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/migrateDataModel.html b/docs/reference/migrateDataModel.html index f662c1c13..49ed48fce 100644 --- a/docs/reference/migrateDataModel.html +++ b/docs/reference/migrateDataModel.html @@ -19,7 +19,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/runCohortRelationshipDiagnostics.html b/docs/reference/runCohortRelationshipDiagnostics.html index a6cdb1028..865811640 100644 --- a/docs/reference/runCohortRelationshipDiagnostics.html +++ b/docs/reference/runCohortRelationshipDiagnostics.html @@ -18,7 +18,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/runCohortTimeSeriesDiagnostics.html b/docs/reference/runCohortTimeSeriesDiagnostics.html index 7cb258d32..a2ee8d540 100644 --- a/docs/reference/runCohortTimeSeriesDiagnostics.html +++ b/docs/reference/runCohortTimeSeriesDiagnostics.html @@ -25,7 +25,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/timeExecution.html b/docs/reference/timeExecution.html index 3453e1e6b..4660120fb 100644 --- a/docs/reference/timeExecution.html +++ b/docs/reference/timeExecution.html @@ -17,7 +17,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/docs/reference/uploadResults.html b/docs/reference/uploadResults.html index cd3b0e2c4..c1e45f2a5 100644 --- a/docs/reference/uploadResults.html +++ b/docs/reference/uploadResults.html @@ -19,7 +19,7 @@ CohortDiagnostics - 3.1.1 + 3.1.2 diff --git a/extras/CohortDiagnostics.pdf b/extras/CohortDiagnostics.pdf index 289499bd8..3a6f10116 100644 Binary files a/extras/CohortDiagnostics.pdf and b/extras/CohortDiagnostics.pdf differ diff --git a/inst/doc/RunningCohortDiagnostics.pdf b/inst/doc/RunningCohortDiagnostics.pdf index 1b2c559c4..072e180de 100644 Binary files a/inst/doc/RunningCohortDiagnostics.pdf and b/inst/doc/RunningCohortDiagnostics.pdf differ diff --git a/inst/doc/ViewingResultsUsingDiagnosticsExplorer.pdf b/inst/doc/ViewingResultsUsingDiagnosticsExplorer.pdf index 73992ab5b..ba9aa38a2 100644 Binary files a/inst/doc/ViewingResultsUsingDiagnosticsExplorer.pdf and b/inst/doc/ViewingResultsUsingDiagnosticsExplorer.pdf differ diff --git a/inst/doc/WhatIsCohortDiagnostics.pdf b/inst/doc/WhatIsCohortDiagnostics.pdf index 6fb627c36..5802d638c 100644 Binary files a/inst/doc/WhatIsCohortDiagnostics.pdf and b/inst/doc/WhatIsCohortDiagnostics.pdf differ diff --git a/inst/shiny/DiagnosticsExplorer/global.R b/inst/shiny/DiagnosticsExplorer/global.R index 3839a9ff9..baeaf411a 100644 --- a/inst/shiny/DiagnosticsExplorer/global.R +++ b/inst/shiny/DiagnosticsExplorer/global.R @@ -5,7 +5,7 @@ diagExpEnv$shinyConfigPath <- getOption("CD-shiny-config", default = "config.yml # Source all app files in to isolated namespace lapply(file.path("R", list.files("R", pattern = "*.R")), source, local = diagExpEnv) -diagExpEnv$appVersionNum <- "Version: 3.1.1" +diagExpEnv$appVersionNum <- "Version: 3.1.2" if (exists("shinySettings")) { diagExpEnv$shinySettings <- shinySettings @@ -20,3 +20,4 @@ if (exists("shinySettings")) { diagExpEnv$initializeEnvironment(diagExpEnv$shinySettings, envir = diagExpEnv) + diff --git a/inst/shiny/DiagnosticsExplorer/renv.lock b/inst/shiny/DiagnosticsExplorer/renv.lock index bcdcc3e08..c7ddd6eea 100644 --- a/inst/shiny/DiagnosticsExplorer/renv.lock +++ b/inst/shiny/DiagnosticsExplorer/renv.lock @@ -17,6 +17,23 @@ "Requirements": [], "Hash": "8f9ce74c6417d61f0782cbae5fd2b7b0" }, + "CirceR": { + "Package": "CirceR", + "Version": "1.2.0", + "Source": "GitHub", + "RemoteType": "github", + "RemoteHost": "api.github.com", + "RemoteRepo": "CirceR", + "RemoteUsername": "OHDSI", + "RemoteRef": "HEAD", + "RemoteSha": "38bf8b44d87f759dd4ba36835ce30627b3c24e6b", + "Requirements": [ + "R", + "RJSONIO", + "rJava" + ], + "Hash": "b8480aa484ebcee5551cfa77fac4b25c" + }, "DBI": { "Package": "DBI", "Version": "1.1.3", diff --git a/inst/sql/sql_server/UpdateVersionNumber.sql b/inst/sql/sql_server/UpdateVersionNumber.sql index 9bd9a9f9a..a7ed8c9fa 100644 --- a/inst/sql/sql_server/UpdateVersionNumber.sql +++ b/inst/sql/sql_server/UpdateVersionNumber.sql @@ -1,6 +1,7 @@ {DEFAULT @package_version = package_version} -{DEFAULT @version_number = '3.1.1'} +{DEFAULT @version_number = '3.1.2'} DELETE FROM @database_schema.@table_prefix@package_version; INSERT INTO @database_schema.@table_prefix@package_version (version_number) VALUES ('@version_number'); + diff --git a/man/takepackageDependencySnapshot.Rd b/man/takepackageDependencySnapshot.Rd deleted file mode 100644 index d146154cc..000000000 --- a/man/takepackageDependencySnapshot.Rd +++ /dev/null @@ -1,19 +0,0 @@ -% Generated by roxygen2: do not edit by hand -% Please edit documentation in R/TakePackageDependencySnapshot.R -\name{takepackageDependencySnapshot} -\alias{takepackageDependencySnapshot} -\title{Take a snapshot of the R environment} -\usage{ -takepackageDependencySnapshot() -} -\value{ -A data frame listing all the dependencies of the root package and their version numbers, in the -order in which they should be installed. -} -\description{ -Take a snapshot of the R environment -} -\details{ -This function records all versions used in the R environment as used by runCohortDiagnostics. -This function was borrowed from OhdsiRTools -} diff --git a/tests/testthat/helper.R b/tests/testthat/helper.R index 83f77b8bb..d3c3a5832 100644 --- a/tests/testthat/helper.R +++ b/tests/testthat/helper.R @@ -20,7 +20,6 @@ with_dbc_connection <- function(connection, code) { # Create a cohort definition set from test cohorts loadTestCohortDefinitionSet <- function(cohortIds = NULL) { - if (grepl("testthat", getwd())) { cohortPath <- "cohorts" } else { @@ -37,7 +36,7 @@ loadTestCohortDefinitionSet <- function(cohortIds = NULL) { if (!is.null(cohortIds)) { cohortDefinitionSet <- cohortDefinitionSet %>% dplyr::filter(cohortId %in% cohortIds) } - + cohortDefinitionSet$checksum <- computeChecksum(cohortDefinitionSet$sql) return(cohortDefinitionSet) @@ -86,7 +85,9 @@ createTestShinyDb <- function(connectionDetails = Eunomia::getEunomiaConnectionD incremental = FALSE ) - createMergedResultsFile(dataFolder = file.path(folder, "export"), - sqliteDbPath = outputPath, - overwrite = TRUE) + createMergedResultsFile( + dataFolder = file.path(folder, "export"), + sqliteDbPath = outputPath, + overwrite = TRUE + ) } diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 799c3017c..ca43ec520 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -32,7 +32,7 @@ skipCdmTests <- FALSE if (dbms == "sqlite") { connectionDetails <- Eunomia::getEunomiaConnectionDetails(databaseFile = "testEunomia.sqlite") - withr::defer( + withr::defer( { unlink("testEunomia.sqlite", recursive = TRUE, force = TRUE) }, diff --git a/tests/testthat/test-Characterization.R b/tests/testthat/test-Characterization.R index 8690ad8e7..271b7af50 100644 --- a/tests/testthat/test-Characterization.R +++ b/tests/testthat/test-Characterization.R @@ -5,7 +5,7 @@ test_that("Execute and export characterization", { with_dbc_connection(tConnection, { exportFolder <- tempfile() - recordKeepingFile <- tempfile(fileext="csv") + recordKeepingFile <- tempfile(fileext = "csv") dir.create(exportFolder) on.exit(unlink(exportFolder), add = TRUE) cohortTableNames <- CohortGenerator::getCohortTableNames(cohortTable = cohortTable) @@ -17,16 +17,22 @@ test_that("Execute and export characterization", { incremental = FALSE ) - on.exit({ - CohortGenerator::dropCohortStatsTables(connection = tConnection, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTableNames = cohortTableNames) + on.exit( + { + CohortGenerator::dropCohortStatsTables( + connection = tConnection, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTableNames = cohortTableNames + ) - DatabaseConnector::renderTranslateExecuteSql(tConnection, - "DROP TABLE @cohortDatabaseSchema.@cohortTable", - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTable = cohortTable) - }, add = TRUE) + DatabaseConnector::renderTranslateExecuteSql(tConnection, + "DROP TABLE @cohortDatabaseSchema.@cohortTable", + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTable = cohortTable + ) + }, + add = TRUE + ) # Generate the cohort set CohortGenerator::generateCohortSet( @@ -50,34 +56,36 @@ test_that("Execute and export characterization", { ) checkmate::expect_file_exists(file.path(exportFolder, "cohort_count.csv")) - executeCohortCharacterization(connection = tConnection, - databaseId = "Testdb", - exportFolder = exportFolder, - cdmDatabaseSchema = cdmDatabaseSchema, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTable = cohortTable, - covariateSettings = temporalCovariateSettings, - tempEmulationSchema = tempEmulationSchema, - cdmVersion = 5, - cohorts = cohortDefinitionSet[1:3,], - cohortCounts = cohortCounts, - minCellCount = 5, - instantiatedCohorts = cohortDefinitionSet$cohortId, - incremental = TRUE, - recordKeepingFile = recordKeepingFile, - task = "runTemporalCohortCharacterization", - jobName = "Temporal Cohort characterization") - + executeCohortCharacterization( + connection = tConnection, + databaseId = "Testdb", + exportFolder = exportFolder, + cdmDatabaseSchema = cdmDatabaseSchema, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTable = cohortTable, + covariateSettings = temporalCovariateSettings, + tempEmulationSchema = tempEmulationSchema, + cdmVersion = 5, + cohorts = cohortDefinitionSet[1:3, ], + cohortCounts = cohortCounts, + minCellCount = 5, + instantiatedCohorts = cohortDefinitionSet$cohortId, + incremental = TRUE, + recordKeepingFile = recordKeepingFile, + task = "runTemporalCohortCharacterization", + jobName = "Temporal Cohort characterization" + ) + # Check all files are created checkmate::expect_file_exists(file.path(exportFolder, "temporal_covariate_ref.csv")) checkmate::expect_file_exists(file.path(exportFolder, "temporal_analysis_ref.csv")) checkmate::expect_file_exists(file.path(exportFolder, "temporal_covariate_value.csv")) checkmate::expect_file_exists(file.path(exportFolder, "temporal_covariate_value_dist.csv")) checkmate::expect_file_exists(file.path(exportFolder, "temporal_time_ref.csv")) - + recordKeepingFileData <- readr::read_csv(file = recordKeepingFile, col_types = readr::cols()) testthat::expect_equal(object = nrow(recordKeepingFileData), expected = 3) - + # check if subset works subset <- subsetToRequiredCohorts( cohorts = cohortDefinitionSet, @@ -85,43 +93,46 @@ test_that("Execute and export characterization", { incremental = TRUE, recordKeepingFile = recordKeepingFile ) - - #should not have the cohorts that were previously run - testthat::expect_equal(object = nrow(subset %>% - dplyr::filter( - cohortId %in% c(cohortDefinitionSet[1:3, ]$cohortId) - )), - expected = 0) - + + # should not have the cohorts that were previously run + testthat::expect_equal( + object = nrow(subset %>% + dplyr::filter( + cohortId %in% c(cohortDefinitionSet[1:3, ]$cohortId) + )), + expected = 0 + ) + # finish the rest of characterization - executeCohortCharacterization(connection = tConnection, - databaseId = "Testdb", - exportFolder = exportFolder, - cdmDatabaseSchema = cdmDatabaseSchema, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTable = cohortTable, - covariateSettings = temporalCovariateSettings, - tempEmulationSchema = tempEmulationSchema, - cdmVersion = 5, - cohorts = cohortDefinitionSet, - cohortCounts = cohortCounts, - minCellCount = 5, - instantiatedCohorts = cohortDefinitionSet$cohortId, - incremental = TRUE, - recordKeepingFile = recordKeepingFile, - task = "runTemporalCohortCharacterization", - jobName = "Temporal Cohort characterization") - + executeCohortCharacterization( + connection = tConnection, + databaseId = "Testdb", + exportFolder = exportFolder, + cdmDatabaseSchema = cdmDatabaseSchema, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTable = cohortTable, + covariateSettings = temporalCovariateSettings, + tempEmulationSchema = tempEmulationSchema, + cdmVersion = 5, + cohorts = cohortDefinitionSet, + cohortCounts = cohortCounts, + minCellCount = 5, + instantiatedCohorts = cohortDefinitionSet$cohortId, + incremental = TRUE, + recordKeepingFile = recordKeepingFile, + task = "runTemporalCohortCharacterization", + jobName = "Temporal Cohort characterization" + ) + # Check no time ids are NA/NULL tdata <- readr::read_csv(file.path(exportFolder, "temporal_covariate_value_dist.csv")) expect_false(any(is.na(tdata$time_id) | is.null(tdata$time_id))) - + tdata <- readr::read_csv(file.path(exportFolder, "temporal_covariate_value.csv")) expect_false(any(is.na(tdata$time_id) | is.null(tdata$time_id))) - + # It would make no sense if there were NA values here tdata <- readr::read_csv(file.path(exportFolder, "temporal_time_ref.csv")) expect_false(any(is.na(tdata$time_id) | is.null(tdata$time_id))) - }) }) diff --git a/tests/testthat/test-DatabaseMigrations.R b/tests/testthat/test-DatabaseMigrations.R index 5459eee6f..1df57f481 100644 --- a/tests/testthat/test-DatabaseMigrations.R +++ b/tests/testthat/test-DatabaseMigrations.R @@ -1,20 +1,22 @@ if (dbms == "postgresql") { - resultsDatabaseSchema <- paste0("r", - gsub("[: -]", "", Sys.time(), perl = TRUE), - sample(1:100, 1)) + resultsDatabaseSchema <- paste0( + "r", + gsub("[: -]", "", Sys.time(), perl = TRUE), + sample(1:100, 1) + ) # Always clean up withr::defer( - { - pgConnection <- DatabaseConnector::connect(connectionDetails = connectionDetails) - sql <- "DROP SCHEMA IF EXISTS @resultsDatabaseSchema CASCADE;" - DatabaseConnector::renderTranslateExecuteSql( - sql = sql, - resultsDatabaseSchema = resultsDatabaseSchema, - connection = pgConnection - ) - DatabaseConnector::disconnect(pgConnection) - }, + { + pgConnection <- DatabaseConnector::connect(connectionDetails = connectionDetails) + sql <- "DROP SCHEMA IF EXISTS @resultsDatabaseSchema CASCADE;" + DatabaseConnector::renderTranslateExecuteSql( + sql = sql, + resultsDatabaseSchema = resultsDatabaseSchema, + connection = pgConnection + ) + DatabaseConnector::disconnect(pgConnection) + }, testthat::teardown_env() ) } @@ -27,34 +29,42 @@ test_that("Database Migrations execute without error", { if (dbms == "postgresql") { sql <- "CREATE SCHEMA @resultsDatabaseSchema;" - DatabaseConnector::renderTranslateExecuteSql(sql = sql, - resultsDatabaseSchema = resultsDatabaseSchema, - connection = connection) + DatabaseConnector::renderTranslateExecuteSql( + sql = sql, + resultsDatabaseSchema = resultsDatabaseSchema, + connection = connection + ) } else { resultsDatabaseSchema <- "main" } - migrator <- getDataMigrator(connectionDetails = connectionDetails, - databaseSchema = resultsDatabaseSchema, - tablePrefix = "cd_") + migrator <- getDataMigrator( + connectionDetails = connectionDetails, + databaseSchema = resultsDatabaseSchema, + tablePrefix = "cd_" + ) expect_true(migrator$check()) - .createDataModel(connection = connection, - databaseSchema = resultsDatabaseSchema, - tablePrefix = "cd_") + .createDataModel( + connection = connection, + databaseSchema = resultsDatabaseSchema, + tablePrefix = "cd_" + ) expect_false(all(migrator$getStatus()$executed)) - migrateDataModel(connectionDetails = connectionDetails, - databaseSchema = resultsDatabaseSchema, - tablePrefix = "cd_") + migrateDataModel( + connectionDetails = connectionDetails, + databaseSchema = resultsDatabaseSchema, + tablePrefix = "cd_" + ) expect_true(all(migrator$getStatus()$executed)) ## Reruning migrations should not cause an error - migrateDataModel(connectionDetails = connectionDetails, - databaseSchema = resultsDatabaseSchema, - tablePrefix = "cd_") - + migrateDataModel( + connectionDetails = connectionDetails, + databaseSchema = resultsDatabaseSchema, + tablePrefix = "cd_" + ) }) - diff --git a/tests/testthat/test-ResultsDataModel.R b/tests/testthat/test-ResultsDataModel.R index 7a0af1790..afa790962 100644 --- a/tests/testthat/test-ResultsDataModel.R +++ b/tests/testthat/test-ResultsDataModel.R @@ -296,12 +296,12 @@ test_that("No database file fails upload", { DatabaseConnector::createZipFile(testZipFile, "cohorts/CohortsToCreate.csv") expect_error( - uploadResults( + uploadResults( connectionDetails = connectionDetails, schema = "main", zipFileName = testZipFile, tablePrefix = "cd_" ), - regexp ="database metadata file not found - cannot upload results" + regexp = "database metadata file not found - cannot upload results" ) }) diff --git a/tests/testthat/test-againstCdm.R b/tests/testthat/test-againstCdm.R index ecb45fbef..54a2107ba 100644 --- a/tests/testthat/test-againstCdm.R +++ b/tests/testthat/test-againstCdm.R @@ -95,10 +95,11 @@ test_that("Cohort diagnostics in incremental mode", { } ## Repeat tests with incremental set to false to ensure better code coverage - withr::with_options(list("CohortDiagnostics-TimeSeries-batch-size" = 1, - "CohortDiagnostics-FE-batch-size" = 1, - "CohortDiagnostics-Relationships-batch-size" = 50), - { + withr::with_options(list( + "CohortDiagnostics-TimeSeries-batch-size" = 1, + "CohortDiagnostics-FE-batch-size" = 1, + "CohortDiagnostics-Relationships-batch-size" = 50 + ), { executeDiagnostics( connectionDetails = connectionDetails, cdmDatabaseSchema = cdmDatabaseSchema, diff --git a/tests/testthat/test-moduleCohortRelationship.R b/tests/testthat/test-moduleCohortRelationship.R index 25d317fd4..8b07d5636 100644 --- a/tests/testthat/test-moduleCohortRelationship.R +++ b/tests/testthat/test-moduleCohortRelationship.R @@ -1,20 +1,20 @@ test_that("Testing executeCohortRelationshipDiagnostics", { skip_if(skipCdmTests, "cdm settings not configured") - + # manually create cohort table and load to table # for the logic to work - there has to be some overlap of the comparator cohort over target cohort # note - we will not be testing offset in this test. it is expected to work as it is a simple substraction - + temporalStartDays <- c(0) temporalEndDays <- c(0) - + targetCohort <- dplyr::tibble( cohortDefinitionId = c(1), subjectId = c(1), cohortStartDate = c(as.Date("1900-01-15")), cohortEndDate = c(as.Date("1900-01-31")) ) # target cohort always one row - + comparatorCohort <- # all records here overlap with targetCohort dplyr::tibble( cohortDefinitionId = c(10, 10, 10), @@ -32,7 +32,7 @@ test_that("Testing executeCohortRelationshipDiagnostics", { as.Date("1900-01-31") ) ) - + cohort <- dplyr::bind_rows( targetCohort, comparatorCohort, @@ -41,16 +41,16 @@ test_that("Testing executeCohortRelationshipDiagnostics", { comparatorCohort %>% dplyr::mutate(cohortDefinitionId = 20) ) - + connectionCohortRelationship <- DatabaseConnector::connect(connectionDetails) - + # to do - with incremental = FALSE with_dbc_connection(connectionCohortRelationship, { sysTime <- as.numeric(Sys.time()) * 100000 tableName <- paste0("cr", sysTime) observationTableName <- paste0("op", sysTime) - + DatabaseConnector::insertTable( connection = connectionCohortRelationship, databaseSchema = cohortDatabaseSchema, @@ -62,7 +62,7 @@ test_that("Testing executeCohortRelationshipDiagnostics", { camelCaseToSnakeCase = TRUE, progressBar = FALSE ) - + cohortDefinitionSet <- cohort %>% dplyr::select(cohortDefinitionId) %>% @@ -78,20 +78,26 @@ test_that("Testing executeCohortRelationshipDiagnostics", { ) ))) %>% dplyr::ungroup() %>% - dplyr::mutate(sql = json, - checksum = CohortDiagnostics:::computeChecksum(json)) - - + dplyr::mutate( + sql = json, + checksum = CohortDiagnostics:::computeChecksum(json) + ) + + exportFolder <- tempdir() exportFile <- tempfile() - - unlink(x = exportFolder, - recursive = TRUE, - force = TRUE) - dir.create(path = exportFolder, - showWarnings = FALSE, - recursive = TRUE) - + + unlink( + x = exportFolder, + recursive = TRUE, + force = TRUE + ) + dir.create( + path = exportFolder, + showWarnings = FALSE, + recursive = TRUE + ) + CohortDiagnostics:::executeCohortRelationshipDiagnostics( connection = connectionCohortRelationship, databaseId = "testDataSourceName", @@ -111,16 +117,18 @@ test_that("Testing executeCohortRelationshipDiagnostics", { incremental = TRUE, batchSize = 2 ) - + recordKeepingFileData <- - readr::read_csv(file = paste0(exportFile, "recordKeeping"), - col_types = readr::cols()) - + readr::read_csv( + file = paste0(exportFile, "recordKeeping"), + col_types = readr::cols() + ) + # testing if check sum if written to field called targetChecksum testthat::expect_true("targetChecksum" %in% colnames(recordKeepingFileData)) testthat::expect_true("comparatorChecksum" %in% colnames(recordKeepingFileData)) testthat::expect_true("checksum" %in% colnames(recordKeepingFileData)) - + testthat::expect_equal( object = recordKeepingFileData %>% dplyr::filter(cohortId == 1) %>% @@ -131,22 +139,26 @@ test_that("Testing executeCohortRelationshipDiagnostics", { dplyr::filter(cohortId == 1) %>% dplyr::filter(comparatorId == 10) %>% dplyr::mutate( - checksum2 = paste0(targetChecksum, - comparatorChecksum) + checksum2 = paste0( + targetChecksum, + comparatorChecksum + ) ) %>% dplyr::pull(checksum2) ) - - - + + + ## testing if subset works - allCohortIds <- cohortDefinitionSet %>% + allCohortIds <- cohortDefinitionSet %>% dplyr::filter(cohortId %in% c(1, 10, 2)) %>% dplyr::select(cohortId, checksum) %>% - dplyr::rename(targetCohortId = cohortId, - targetChecksum = checksum) %>% + dplyr::rename( + targetCohortId = cohortId, + targetChecksum = checksum + ) %>% dplyr::distinct() - + combinationsOfPossibleCohortRelationships <- allCohortIds %>% tidyr::crossing( allCohortIds %>% @@ -158,34 +170,36 @@ test_that("Testing executeCohortRelationshipDiagnostics", { dplyr::filter(targetCohortId != comparatorCohortId) %>% dplyr::arrange(targetCohortId, comparatorCohortId) %>% dplyr::mutate(checksum = paste0(targetChecksum, comparatorChecksum)) - + subset <- CohortDiagnostics:::subsetToRequiredCombis( combis = combinationsOfPossibleCohortRelationships, task = "runCohortRelationship", incremental = TRUE, recordKeepingFile = paste0(exportFile, "recordKeeping") ) %>% dplyr::tibble() - + ### subset should not have the combinations in record keeping file shouldBeDfOfZeroRows <- subset %>% dplyr::inner_join( recordKeepingFileData %>% - dplyr::select(cohortId, - comparatorId) %>% + dplyr::select( + cohortId, + comparatorId + ) %>% dplyr::rename( targetCohortId = cohortId, comparatorCohortId = comparatorId ), by = c("targetCohortId", "comparatorCohortId") ) - + testthat::expect_equal( object = nrow(shouldBeDfOfZeroRows), expected = 0, info = "Looks like subset and record keeping file did not match." ) - - + + ## running again by adding cohort 2, to previously run 1 and 10 CohortDiagnostics:::executeCohortRelationshipDiagnostics( connection = connectionCohortRelationship, @@ -206,36 +220,44 @@ test_that("Testing executeCohortRelationshipDiagnostics", { incremental = TRUE, batchSize = 2 ) - + recordKeepingFileData2 <- - readr::read_csv(file = paste0(exportFile, "recordKeeping"), - col_types = readr::cols()) + readr::read_csv( + file = paste0(exportFile, "recordKeeping"), + col_types = readr::cols() + ) # record keeping file should have 6 combinations - for 3 cohorts - testthat::expect_equal(object = nrow(recordKeepingFileData2), - expected = 3 * 2 * 1) - - #record keeping file should have 4 additional combinations + testthat::expect_equal( + object = nrow(recordKeepingFileData2), + expected = 3 * 2 * 1 + ) + + # record keeping file should have 4 additional combinations testthat::expect_equal( object = recordKeepingFileData2 %>% dplyr::anti_join( recordKeepingFileData %>% - dplyr::select(cohortId, - comparatorId), + dplyr::select( + cohortId, + comparatorId + ), by = c("cohortId", "comparatorId") ) %>% nrow(), expected = 4 ) - + # check what happens for an unrelated cohort combination - allCohortIds <- cohortDefinitionSet %>% + allCohortIds <- cohortDefinitionSet %>% dplyr::filter(cohortId %in% c(2, 20)) %>% dplyr::select(cohortId, checksum) %>% - dplyr::rename(targetCohortId = cohortId, - targetChecksum = checksum) %>% + dplyr::rename( + targetCohortId = cohortId, + targetChecksum = checksum + ) %>% dplyr::distinct() - + combinationsOfPossibleCohortRelationships <- allCohortIds %>% tidyr::crossing( allCohortIds %>% @@ -247,34 +269,34 @@ test_that("Testing executeCohortRelationshipDiagnostics", { dplyr::filter(targetCohortId != comparatorCohortId) %>% dplyr::arrange(targetCohortId, comparatorCohortId) %>% dplyr::mutate(checksum = paste0(targetChecksum, comparatorChecksum)) - + subset <- CohortDiagnostics:::subsetToRequiredCombis( combis = combinationsOfPossibleCohortRelationships, task = "runCohortRelationship", incremental = TRUE, recordKeepingFile = paste0(exportFile, "recordKeeping") ) %>% dplyr::tibble() - + ### subset should be two rows in subsets that are not in record keeping file shouldBeTwoRows <- subset %>% dplyr::anti_join( recordKeepingFileData2 %>% - dplyr::select(cohortId, - comparatorId) %>% + dplyr::select( + cohortId, + comparatorId + ) %>% dplyr::rename( targetCohortId = cohortId, comparatorCohortId = comparatorId ), by = c("targetCohortId", "comparatorCohortId") ) - + testthat::expect_equal( object = nrow(shouldBeTwoRows), expected = 2, info = "Looks like subset and record keeping file did not match, Two new cohorts should have run." ) - - }) }) diff --git a/tests/testthat/test-moduleTimeSeries.R b/tests/testthat/test-moduleTimeSeries.R index fa238d77c..e60d299a5 100644 --- a/tests/testthat/test-moduleTimeSeries.R +++ b/tests/testthat/test-moduleTimeSeries.R @@ -1,9 +1,9 @@ test_that("Testing cohort time series execution", { skip_if(skipCdmTests, "cdm settings not configured") - + connectionTimeSeries <- DatabaseConnector::connect(connectionDetails) - + # to do - with incremental = FALSE with_dbc_connection(connectionTimeSeries, { cohort <- dplyr::tibble( @@ -22,11 +22,13 @@ test_that("Testing cohort time series execution", { as.Date("2005-09-15") ) ) - - cohort <- dplyr::bind_rows(cohort, - cohort %>% - dplyr::mutate(cohortDefinitionId = cohortDefinitionId * 1000)) - + + cohort <- dplyr::bind_rows( + cohort, + cohort %>% + dplyr::mutate(cohortDefinitionId = cohortDefinitionId * 1000) + ) + cohortDefinitionSet <- cohort %>% dplyr::select(cohortDefinitionId) %>% @@ -42,25 +44,33 @@ test_that("Testing cohort time series execution", { ) ))) %>% dplyr::ungroup() %>% - dplyr::mutate(sql = json, - checksum = as.character(CohortDiagnostics:::computeChecksum(json))) %>% + dplyr::mutate( + sql = json, + checksum = as.character(CohortDiagnostics:::computeChecksum(json)) + ) %>% dplyr::ungroup() - + exportFolder <- tempdir() exportFile <- tempfile() - - unlink(x = exportFolder, - recursive = TRUE, - force = TRUE) - dir.create(path = exportFolder, - showWarnings = FALSE, - recursive = TRUE) - + + unlink( + x = exportFolder, + recursive = TRUE, + force = TRUE + ) + dir.create( + path = exportFolder, + showWarnings = FALSE, + recursive = TRUE + ) + cohortTable <- - paste0("ct_", - gsub("[: -]", "", Sys.time(), perl = TRUE), - sample(1:100, 1)) - + paste0( + "ct_", + gsub("[: -]", "", Sys.time(), perl = TRUE), + sample(1:100, 1) + ) + DatabaseConnector::insertTable( connection = connectionTimeSeries, databaseSchema = cohortDatabaseSchema, @@ -72,7 +82,7 @@ test_that("Testing cohort time series execution", { camelCaseToSnakeCase = TRUE, progressBar = FALSE ) - + CohortDiagnostics:::executeTimeSeriesDiagnostics( connection = connectionTimeSeries, tempEmulationSchema = tempEmulationSchema, @@ -95,21 +105,23 @@ test_that("Testing cohort time series execution", { ), batchSize = 1 ) - + recordKeepingFileData <- - readr::read_csv(file = paste0(exportFile, "recordKeeping"), - col_types = readr::cols()) - + readr::read_csv( + file = paste0(exportFile, "recordKeeping"), + col_types = readr::cols() + ) + # testing if check sum is written testthat::expect_true("checksum" %in% colnames(recordKeepingFileData)) - + # result timeSeriesResults1 <- readr::read_csv( file = file.path(exportFolder, "time_series.csv"), col_types = readr::cols() ) - + subset <- CohortDiagnostics:::subsetToRequiredCohorts( cohorts = cohortDefinitionSet, task = "runCohortTimeSeries", @@ -117,18 +129,20 @@ test_that("Testing cohort time series execution", { recordKeepingFile = paste0(exportFile, "recordKeeping") ) %>% dplyr::arrange(cohortId) - - testthat::expect_equal(object = subset$cohortId, - expected = c(1000, 2000)) - - + + testthat::expect_equal( + object = subset$cohortId, + expected = c(1000, 2000) + ) + + # delete the previously written results file. To see if the previously executed cohorts will have results after deletion unlink( x = file.path(exportFolder, "time_series.csv"), recursive = TRUE, force = TRUE ) - + CohortDiagnostics:::executeTimeSeriesDiagnostics( connection = connectionTimeSeries, tempEmulationSchema = tempEmulationSchema, @@ -155,12 +169,11 @@ test_that("Testing cohort time series execution", { file = file.path(exportFolder, "time_series.csv"), col_types = readr::cols() ) - + testthat::expect_equal( object = resultsNew$cohort_id %>% unique() %>% sort(), expected = c(1000, 2000) ) - }) }) @@ -175,7 +188,6 @@ test_that("Testing time series logic", { # to do - with incremental = FALSE with_dbc_connection(connectionTimeSeries, { - # manually create cohort table and load to table # Cohort table has a total of four records, with each cohort id having two each # cohort 1 has one subject with two different cohort entries @@ -250,28 +262,32 @@ test_that("Testing time series logic", { test_that("Testing Data source time series execution", { skip_if(skipCdmTests, "cdm settings not configured") - + connectionTimeSeries <- DatabaseConnector::connect(connectionDetails) - + # to do - with incremental = FALSE with_dbc_connection(connectionTimeSeries, { - cohortDefinitionSet = dplyr::tibble( + cohortDefinitionSet <- dplyr::tibble( cohortId = -44819062, # cohort id is identified by an omop concept id https://athena.ohdsi.org/search-terms/terms/44819062 checksum = CohortDiagnostics:::computeChecksum(column = "data source time series") ) - + exportFolder <- tempdir() exportFile <- tempfile() - - unlink(x = exportFolder, - recursive = TRUE, - force = TRUE) - dir.create(path = exportFolder, - showWarnings = FALSE, - recursive = TRUE) - + + unlink( + x = exportFolder, + recursive = TRUE, + force = TRUE + ) + dir.create( + path = exportFolder, + showWarnings = FALSE, + recursive = TRUE + ) + executeTimeSeriesDiagnostics( connection = connectionTimeSeries, tempEmulationSchema = tempEmulationSchema, @@ -290,22 +306,24 @@ test_that("Testing Data source time series execution", { observationPeriodMaxDate = as.Date("2007-12-31") ) ) - + recordKeepingFileData <- - readr::read_csv(file = paste0(exportFile, "recordKeeping"), - col_types = readr::cols()) - + readr::read_csv( + file = paste0(exportFile, "recordKeeping"), + col_types = readr::cols() + ) + # testing if check sum is written testthat::expect_true("checksum" %in% colnames(recordKeepingFileData)) testthat::expect_equal(object = recordKeepingFileData$cohortId, expected = -44819062) - + # result dataSourceTimeSeriesResult <- readr::read_csv( file = file.path(exportFolder, "time_series.csv"), col_types = readr::cols() ) - + subset <- subsetToRequiredCohorts( cohorts = cohortDefinitionSet, task = "runDataSourceTimeSeries", @@ -313,9 +331,10 @@ test_that("Testing Data source time series execution", { recordKeepingFile = paste0(exportFile, "recordKeeping") ) %>% dplyr::arrange(cohortId) - - testthat::expect_equal(object = nrow(subset), - expected = 0) + + testthat::expect_equal( + object = nrow(subset), + expected = 0 + ) }) }) - diff --git a/vignettes/CreatingAStudyPackage.Rmd b/vignettes/CreatingAStudyPackage.Rmd index 8e695ec21..5794b1442 100644 --- a/vignettes/CreatingAStudyPackage.Rmd +++ b/vignettes/CreatingAStudyPackage.Rmd @@ -20,7 +20,8 @@ knitr::opts_chunk$set( cache = FALSE, comment = "#>", error = FALSE, - tidy = FALSE) + tidy = FALSE +) ``` # Introduction @@ -68,7 +69,7 @@ The skeleton cohort diagnostics study package is [here](https://github.com/OHDSI # please ensure you have the latest version of Hydra. As of 08/13/2021 - CohortDiagnostics support for Hydra is still in develop branch. # please check hydra release notes and update hydra remotes::install_github("OHDSI/Hydra", ref = "develop") -outputFolder <- "d:/temp/output" # location where you study package will be created +outputFolder <- "d:/temp/output" # location where you study package will be created ########## Please populate the information below ##################### @@ -90,62 +91,68 @@ library(magrittr) baseUrl <- Sys.getenv("baseUrl") # if you have security enabled, please authorize the use - example below # ROhdsiWebApi::authorizeWebApi(baseUrl, 'windows') -cohortIds <- c(22040, - 22042, - 22041, - 22039, - 22038, - 22037, - 22036, - 22035, - 22034, - 22033, - 22031, - 22032, - 22030, - 22028, - 22029) +cohortIds <- c( + 22040, + 22042, + 22041, + 22039, + 22038, + 22037, + 22036, + 22035, + 22034, + 22033, + 22031, + 22032, + 22030, + 22028, + 22029 +) ################# end of user input ############## webApiCohorts <- ROhdsiWebApi::getCohortDefinitionsMetaData(baseUrl = baseUrl) -studyCohorts <- webApiCohorts %>% - dplyr::filter(.data$id %in% cohortIds) +studyCohorts <- webApiCohorts %>% + dplyr::filter(.data$id %in% cohortIds) # compile them into a data table cohortDefinitionsArray <- list() for (i in (1:nrow(studyCohorts))) { - cohortDefinition <- - ROhdsiWebApi::getCohortDefinition(cohortId = studyCohorts$id[[i]], - baseUrl = baseUrl) - cohortDefinitionsArray[[i]] <- list( - id = studyCohorts$id[[i]], - createdDate = studyCohorts$createdDate[[i]], - modifiedDate = studyCohorts$createdDate[[i]], - logicDescription = studyCohorts$description[[i]], - name = stringr::str_trim(stringr::str_squish(cohortDefinition$name)), - expression = cohortDefinition$expression - ) + cohortDefinition <- + ROhdsiWebApi::getCohortDefinition( + cohortId = studyCohorts$id[[i]], + baseUrl = baseUrl + ) + cohortDefinitionsArray[[i]] <- list( + id = studyCohorts$id[[i]], + createdDate = studyCohorts$createdDate[[i]], + modifiedDate = studyCohorts$createdDate[[i]], + logicDescription = studyCohorts$description[[i]], + name = stringr::str_trim(stringr::str_squish(cohortDefinition$name)), + expression = cohortDefinition$expression + ) } tempFolder <- tempdir() unlink(x = tempFolder, recursive = TRUE, force = TRUE) dir.create(path = tempFolder, showWarnings = FALSE, recursive = TRUE) -specifications <- list(id = 1, - version = version, - name = name, - packageName = packageName, - skeletonVersion = skeletonVersion, - createdBy = createdBy, - createdDate = createdDate, - modifiedBy = modifiedBy, - modifiedDate = modifiedDate, - skeletonType = skeletonType, - organizationName = organizationName, - description = description, - cohortDefinitions = cohortDefinitionsArray) +specifications <- list( + id = 1, + version = version, + name = name, + packageName = packageName, + skeletonVersion = skeletonVersion, + createdBy = createdBy, + createdDate = createdDate, + modifiedBy = modifiedBy, + modifiedDate = modifiedDate, + skeletonType = skeletonType, + organizationName = organizationName, + description = description, + cohortDefinitions = cohortDefinitionsArray +) jsonFileName <- paste0(file.path(tempFolder, "CohortDiagnosticsSpecs.json")) write(x = specifications %>% RJSONIO::toJSON(pretty = TRUE, digits = 23), file = jsonFileName) @@ -162,13 +169,13 @@ write(x = specifications %>% RJSONIO::toJSON(pretty = TRUE, digits = 23), file = #### get the skeleton from github # download.file(url = "https://github.com/OHDSI/SkeletonCohortDiagnosticsStudy/archive/refs/heads/main.zip", # destfile = file.path(tempFolder, 'skeleton.zip')) -# unzip(zipfile = file.path(tempFolder, 'skeleton.zip'), +# unzip(zipfile = file.path(tempFolder, 'skeleton.zip'), # overwrite = TRUE, # exdir = file.path(tempFolder, "skeleton") # ) # fileList <- list.files(path = file.path(tempFolder, "skeleton"), full.names = TRUE, recursive = TRUE, all.files = TRUE) -# DatabaseConnector::createZipFile(zipFile = file.path(tempFolder, 'skeleton.zip'), -# files = fileList, +# DatabaseConnector::createZipFile(zipFile = file.path(tempFolder, 'skeleton.zip'), +# files = fileList, # rootFolder = list.dirs(file.path(tempFolder, 'skeleton'), recursive = FALSE)) ############################################################## @@ -183,17 +190,17 @@ write(x = specifications %>% RJSONIO::toJSON(pretty = TRUE, digits = 23), file = hydraSpecificationFromFile <- Hydra::loadSpecifications(fileName = jsonFileName) unlink(x = outputFolder, recursive = TRUE) dir.create(path = outputFolder, showWarnings = FALSE, recursive = TRUE) -Hydra::hydrate(specifications = hydraSpecificationFromFile, - outputFolder = outputFolder +Hydra::hydrate( + specifications = hydraSpecificationFromFile, + outputFolder = outputFolder ) # for advanced user using skeletons outside of Hydra # Hydra::hydrate(specifications = hydraSpecificationFromFile, -# outputFolder = outputFolder, +# outputFolder = outputFolder, # skeletonFileName = file.path(tempFolder, 'skeleton.zip') # ) unlink(x = tempFolder, recursive = TRUE, force = TRUE) - ``` diff --git a/vignettes/DatabaseModeInDiagnosticsExplorer.Rmd b/vignettes/DatabaseModeInDiagnosticsExplorer.Rmd index 8b6b5d195..f47afb438 100644 --- a/vignettes/DatabaseModeInDiagnosticsExplorer.Rmd +++ b/vignettes/DatabaseModeInDiagnosticsExplorer.Rmd @@ -20,7 +20,8 @@ knitr::opts_chunk$set( cache = FALSE, comment = "#>", error = FALSE, - tidy = FALSE) + tidy = FALSE +) ``` # Database mode @@ -70,4 +71,4 @@ databaseTableName: "database" # If you wish to enable annotation - not currently reccomended in multi-user environments enableAnnotation: FALSE enableAuthorization: FALSE -``` \ No newline at end of file +``` diff --git a/vignettes/RunningCohortDiagnostics.Rmd b/vignettes/RunningCohortDiagnostics.Rmd index 68eb10025..b4926203c 100644 --- a/vignettes/RunningCohortDiagnostics.Rmd +++ b/vignettes/RunningCohortDiagnostics.Rmd @@ -20,12 +20,12 @@ knitr::opts_chunk$set( cache = FALSE, comment = "#>", error = FALSE, - tidy = FALSE) + tidy = FALSE +) # Temp folders used to run the example exportFolder <- tempfile("CohortDiagnosticsTestExport") inclusionStatisticsFolder <- tempfile("inclusionStats") - ``` # Introduction This vignette discusses the process of generating a results set with `CohortDiagnostics` starting with cohort generation. @@ -37,8 +37,8 @@ For this example we will also be using the `Eunomia` test package. Optionally, you may install the `ROhdsiWebApi` package to download cohort definitions from an ATLAS instance: ```{r eval=FALSE} -remotes::install_github('OHDSI/Eunomia') -remotes::install_github('OHDSI/ROhdsiWebApi') +remotes::install_github("OHDSI/Eunomia") +remotes::install_github("OHDSI/ROhdsiWebApi") ``` # Configuring the connection to the server @@ -48,10 +48,12 @@ We need to tell R how to connect to the server where the data are. `CohortDiagno ```{r tidy=FALSE,eval=FALSE} library(CohortDiagnostics) -connectionDetails <- createConnectionDetails(dbms = "postgresql", - server = "localhost/ohdsi", - user = "joe", - password = "supersecret") +connectionDetails <- createConnectionDetails( + dbms = "postgresql", + server = "localhost/ohdsi", + user = "joe", + password = "supersecret" +) ``` For the purposes of this example, we will use the Eunomia test CDM package that is in an Sqlite database stored locally. ```{r results = FALSE,message = FALSE,warning=FALSE, message = FALSE,eval=FALSE} @@ -80,10 +82,12 @@ For example, the cohort diagnostics package includes an example set of cohort sq ```{r results = FALSE,message = FALSE,warning=FALSE,eval=FALSE} library(CohortDiagnostics) -cohortDefinitionSet <- CohortGenerator::getCohortDefinitionSet(settingsFileName = "Cohorts.csv", - jsonFolder = "cohorts", - sqlFolder = "sql/sql_server", - packageName = "CohortDiagnostics") +cohortDefinitionSet <- CohortGenerator::getCohortDefinitionSet( + settingsFileName = "Cohorts.csv", + jsonFolder = "cohorts", + sqlFolder = "sql/sql_server", + packageName = "CohortDiagnostics" +) ``` Looking at this data.frame of Cohorts you will see the sql and json for these cohorts: @@ -102,11 +106,13 @@ The following code demonstrates how to create a set of cohort references from AT # Set up url baseUrl <- "https://atlas.hosting.com/WebAPI" # list of cohort ids -cohortIds <- c(18345,18346) +cohortIds <- c(18345, 18346) -cohortDefinitionSet <- ROhdsiWebApi::exportCohortDefinitionSet(baseUrl = baseUrl, - cohortIds = cohortIds, - generateStats = TRUE) +cohortDefinitionSet <- ROhdsiWebApi::exportCohortDefinitionSet( + baseUrl = baseUrl, + cohortIds = cohortIds, + generateStats = TRUE +) ``` Consult the ROhdsiWebApi documentation for details on authentication to your atlas instance. Please note that in order to generate inclusion rules statistics (a useful diagnostic tool) the parameter `generateStats` @@ -122,18 +128,22 @@ For example, cohortTableNames <- CohortGenerator::getCohortTableNames(cohortTable = cohortTable) # Next create the tables on the database -CohortGenerator::createCohortTables(connectionDetails = connectionDetails, - cohortTableNames = cohortTableNames, - cohortDatabaseSchema = "main", - incremental = FALSE) +CohortGenerator::createCohortTables( + connectionDetails = connectionDetails, + cohortTableNames = cohortTableNames, + cohortDatabaseSchema = "main", + incremental = FALSE +) # Generate the cohort set -CohortGenerator::generateCohortSet(connectionDetails= connectionDetails, - cdmDatabaseSchema = cdmDatabaseSchema, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTableNames = cohortTableNames, - cohortDefinitionSet = cohortDefinitionSet, - incremental = FALSE) +CohortGenerator::generateCohortSet( + connectionDetails = connectionDetails, + cdmDatabaseSchema = cdmDatabaseSchema, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTableNames = cohortTableNames, + cohortDefinitionSet = cohortDefinitionSet, + incremental = FALSE +) ``` **Note, that the above code will delete an existing table**. However, incremental mode can be used when setting the parameter `incremental = TRUE`. @@ -154,22 +164,25 @@ exportFolder <- "export" Then we execute the function (using the default settings) as follows: ```{r results = FALSE,message = FALSE,warning=FALSE,eval=FALSE} executeDiagnostics(cohortDefinitionSet, - connectionDetails = connectionDetails, - cohortTable = cohortTable, - cohortDatabaseSchema = cohortDatabaseSchema, - cdmDatabaseSchema = cdmDatabaseSchema, - exportFolder = exportFolder, - databaseId = "MyCdm", - minCellCount = 5) + connectionDetails = connectionDetails, + cohortTable = cohortTable, + cohortDatabaseSchema = cohortDatabaseSchema, + cdmDatabaseSchema = cdmDatabaseSchema, + exportFolder = exportFolder, + databaseId = "MyCdm", + minCellCount = 5 +) ``` ## Cohort Statistics Table Clean up The above cohort generation process will create a number of residual tables. As the process is complete, these are no longer required and can be removed. ```{r eval=FALSE} -CohortGenerator::dropCohortStatsTables(connectionDetails = connectionDetails, - cohortDatabaseSchema = cohortDatabaseSchema, - cohortTableNames = cohortTableNames) +CohortGenerator::dropCohortStatsTables( + connectionDetails = connectionDetails, + cohortDatabaseSchema = cohortDatabaseSchema, + cohortTableNames = cohortTableNames +) ``` diff --git a/vignettes/ViewingResultsUsingDiagnosticsExplorer.Rmd b/vignettes/ViewingResultsUsingDiagnosticsExplorer.Rmd index 6a18b152d..ec2110c1e 100644 --- a/vignettes/ViewingResultsUsingDiagnosticsExplorer.Rmd +++ b/vignettes/ViewingResultsUsingDiagnosticsExplorer.Rmd @@ -20,7 +20,8 @@ knitr::opts_chunk$set( cache = FALSE, comment = "#>", error = FALSE, - tidy = FALSE) + tidy = FALSE +) ``` # Viewing the diagnostics @@ -65,4 +66,4 @@ We recommend the use of a database system, when file size of the cohort diagnost # Running over the network -If you want to run the application over the network then set `runOverNetwork = TRUE` while launching the application using 'launchDiagnosticsExplorer()'. This will make the shiny application available over your network (i.e. within your networks firewall). \ No newline at end of file +If you want to run the application over the network then set `runOverNetwork = TRUE` while launching the application using 'launchDiagnosticsExplorer()'. This will make the shiny application available over your network (i.e. within your networks firewall). diff --git a/vignettes/WhatIsCohortDiagnostics.Rmd b/vignettes/WhatIsCohortDiagnostics.Rmd index d41b2a5dc..00d97897a 100644 --- a/vignettes/WhatIsCohortDiagnostics.Rmd +++ b/vignettes/WhatIsCohortDiagnostics.Rmd @@ -20,7 +20,8 @@ knitr::opts_chunk$set( cache = FALSE, comment = "#>", error = FALSE, - tidy = FALSE) + tidy = FALSE +) ``` # Introduction @@ -43,4 +44,4 @@ Features - Break down index events into the specific concepts that triggered them. - Compute overlap between two cohorts. - Characterize cohorts, and compare these characterizations. Perform cohort comparison and temporal comparisons. -- Explore patient profiles of a random sample of subjects in a cohort. \ No newline at end of file +- Explore patient profiles of a random sample of subjects in a cohort.