diff --git a/NAMESPACE b/NAMESPACE index bbe5d360..821244e4 100755 --- a/NAMESPACE +++ b/NAMESPACE @@ -34,6 +34,7 @@ export(runMissingAnalyses) export(showReportTypes) export(sumAcrossYears) export(tsCompleteYears) +import(DBI) import(DatabaseConnector) import(ParallelLogger) import(SqlRender) diff --git a/R/exportToAres.R b/R/exportToAres.R index edae1f92..9bd30dcc 100644 --- a/R/exportToAres.R +++ b/R/exportToAres.R @@ -1898,38 +1898,36 @@ generateQualityCompleteness <- function(connection, resultsDatabaseSchema) { } #' @title exportToAres -#' +#' #' @description #' \code{exportToAres} Exports Achilles statistics for ARES #' #' @details #' Creates export files #' -#' #' @param connectionDetails An R object of type ConnectionDetail (details for the function that contains server info, database type, optionally username/password, port) #' @param cdmDatabaseSchema Name of the database schema that contains the OMOP CDM. #' @param resultsDatabaseSchema Name of the database schema that contains the Achilles analysis files. Default is cdmDatabaseSchema #' @param outputPath A folder location to save the JSON files. Default is current working folder #' @param vocabDatabaseSchema string name of database schema that contains OMOP Vocabulary. Default is cdmDatabaseSchema. On SQL Server, this should specifiy both the database and the schema, so for example 'results.dbo'. +#' @param outputFormat default or alternatively "duckdb" to use parquet and duckdb formats. #' @param reports vector of reports to run, c() defaults to all reports #' #' See \code{showReportTypes} for a list of all report types #' #' @return none #' +#'@import DBI #'@importFrom data.table fwrite #'@importFrom dplyr ntile desc #'@export -#' -library("DBI") - exportToAres <- function( connectionDetails, cdmDatabaseSchema, resultsDatabaseSchema, vocabDatabaseSchema, outputPath, - outputFormat, + outputFormat = "default", reports = c()) { conn <- DatabaseConnector::connect(connectionDetails) @@ -1966,21 +1964,17 @@ exportToAres <- function( data.table::fwrite(currentTable$totalRecordsData, file = paste0(sourceOutputPath, "/datadensity-total.csv")) data.table::fwrite(currentTable$domainAggregates, file = paste0(sourceOutputPath, "/records-by-domain.csv")) - # data density - records per person currentTable <- generateDataDensityRecordsPerPerson(conn, resultsDatabaseSchema) data.table::fwrite(currentTable, file = paste0(sourceOutputPath, "/datadensity-records-per-person.csv")) - # data density - concepts per person currentTable <- generateDataDensityConceptsPerPerson(conn, resultsDatabaseSchema) data.table::fwrite(currentTable, file = paste0(sourceOutputPath, "/datadensity-concepts-per-person.csv")) - # data density - domains per person currentTable <- generateDataDensityDomainsPerPerson(conn, resultsDatabaseSchema) data.table::fwrite(currentTable, file = paste0(sourceOutputPath, "/datadensity-domains-per-person.csv")) - } if (length(reports) == 0 || (length(reports) > 0 && ("domain" %in% reports || "concept" %in% reports))) { @@ -1989,84 +1983,69 @@ exportToAres <- function( currentTable <- generateAOMetadataReport(conn, cdmDatabaseSchema, sourceOutputPath) data.table::fwrite(currentTable, file = paste0(sourceOutputPath, "/metadata.csv")) - # cdm source writeLines("Generating cdm source report") currentTable <- generateAOCdmSourceReport(conn, cdmDatabaseSchema, sourceOutputPath) data.table::fwrite(currentTable, file = paste0(sourceOutputPath, "/cdmsource.csv")) - # domain summary - observation period writeLines("Generating observation period reports") currentTable <- generateAOObservationPeriodReport(conn, cdmDatabaseSchema, resultsDatabaseSchema, vocabDatabaseSchema, sourceOutputPath) filename <- file.path(sourceOutputPath, "observationperiod.json") write(jsonlite::toJSON(currentTable), filename) - # death report writeLines("Generating death report") currentTable <- generateAODeathReport(conn, cdmDatabaseSchema, resultsDatabaseSchema, vocabDatabaseSchema, sourceOutputPath) filename <- file.path(sourceOutputPath, "death.json") write(jsonlite::toJSON(currentTable), filename) - writeLines("Generating domain summary reports") # domain summary - conditions dataConditions <- generateDomainSummaryConditions(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataConditions, file = paste0(sourceOutputPath, "/domain-summary-condition_occurrence.csv")) - # domain summary - condition eras dataConditionEra <- generateDomainSummaryConditionEras(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataConditionEra, file = paste0(sourceOutputPath, "/domain-summary-condition_era.csv")) - # domain summary - drugs dataDrugs <- generateDomainSummaryDrugs(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataDrugs, file = paste0(sourceOutputPath, "/domain-summary-drug_exposure.csv")) - # domain stratification by drug type concept dataDrugType <- generateDomainDrugStratification(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataDrugType, file = paste0(sourceOutputPath, "/domain-drug-stratification.csv")) - # domain summary - drug era dataDrugEra <- generateDomainSummaryDrugEra(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataDrugEra, file = paste0(sourceOutputPath, "/domain-summary-drug_era.csv")) - # domain summary - measurements dataMeasurements <- generateDomainSummaryMeasurements(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataMeasurements, file = paste0(sourceOutputPath, "/domain-summary-measurement.csv")) - # domain summary - observations dataObservations <- generateDomainSummaryObservations(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataObservations, file = paste0(sourceOutputPath, "/domain-summary-observation.csv")) - # domain summary - visit details dataVisitDetails <- generateDomainSummaryVisitDetails(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataVisitDetails, file = paste0(sourceOutputPath, "/domain-summary-visit_detail.csv")) - # domain summary - visits dataVisits <- generateDomainSummaryVisits(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataVisits, file = paste0(sourceOutputPath, "/domain-summary-visit_occurrence.csv")) - # domain stratification by visit concept currentTable <- generateDomainVisitStratification(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(currentTable, file = paste0(sourceOutputPath, "/domain-visit-stratification.csv")) - # domain summary - procedures dataProcedures <- generateDomainSummaryProcedures(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataProcedures, file = paste0(sourceOutputPath, "/domain-summary-procedure_occurrence.csv")) - # domain summary - devices dataDevices <- generateDomainSummaryDevices(conn, resultsDatabaseSchema, vocabDatabaseSchema) data.table::fwrite(dataDevices, file = paste0(sourceOutputPath, "/domain-summary-device_exposure.csv")) @@ -2090,8 +2069,6 @@ exportToAres <- function( writeLines("Generating achilles performance report") currentTable <- generateAOAchillesPerformanceReport(conn, cdmDatabaseSchema, resultsDatabaseSchema, vocabDatabaseSchema, sourceOutputPath) data.table::fwrite(currentTable, file.path(sourceOutputPath, "achilles-performance.csv")) - - } if (length(reports) == 0 || (length(reports) > 0 && "concept" %in% reports)) { diff --git a/man/achilles.Rd b/man/achilles.Rd index 8b826dd9..cdfe0055 100644 --- a/man/achilles.Rd +++ b/man/achilles.Rd @@ -117,12 +117,12 @@ of Achilles when supplied \code{analysisIds}.} \item{excludeAnalysisIds}{(OPTIONAL) A vector containing the set of Achilles analyses to exclude.} -\item{sqlDialect}{(OPTIONAL) String to be used when specifying sqlOnly = TRUE and -NOT supplying the \code{connectionDetails} parameter. -if the \code{connectionDetails} parameter is supplied, \code{sqlDialect} -is ignored. If the \code{connectionDetails} parameter is not supplied, -\code{sqlDialect} must be supplied to enable \code{SqlRender} -to translate properly. \code{sqlDialect} takes the value normally +\item{sqlDialect}{(OPTIONAL) String to be used when specifying sqlOnly = TRUE and +NOT supplying the \code{connectionDetails} parameter. +if the \code{connectionDetails} parameter is supplied, \code{sqlDialect} +is ignored. If the \code{connectionDetails} parameter is not supplied, +\code{sqlDialect} must be supplied to enable \code{SqlRender} +to translate properly. \code{sqlDialect} takes the value normally supplied to connectionDetails$dbms. Default = NULL.} } \value{ @@ -141,10 +141,10 @@ connectionDetails <- createConnectionDetails(dbms = "sql server", server = "some achillesResults <- achilles(connectionDetails = connectionDetails, cdmDatabaseSchema = "cdm", resultsDatabaseSchema = "results", - scratchDatabaseSchema = "scratch", - sourceName = "Some Source", - cdmVersion = "5.3", - numThreads = 10, + scratchDatabaseSchema = "scratch", + sourceName = "Some Source", + cdmVersion = "5.3", + numThreads = 10, outputFolder = "output") } diff --git a/man/createIndices.Rd b/man/createIndices.Rd index ae954741..d81a922f 100755 --- a/man/createIndices.Rd +++ b/man/createIndices.Rd @@ -35,7 +35,7 @@ Default = TRUE} achilles_results and achilles_results_dist.} } \value{ -A collection of queries that were executed to drop any existing indices and create new indicies as +A collection of queries that were executed to drop any existing indices and create new indicies as specified. } \description{ diff --git a/man/exportToAres.Rd b/man/exportToAres.Rd index 103321f2..78df96e2 100644 --- a/man/exportToAres.Rd +++ b/man/exportToAres.Rd @@ -10,6 +10,7 @@ exportToAres( resultsDatabaseSchema, vocabDatabaseSchema, outputPath, + outputFormat = NULL, reports = c() ) } @@ -24,6 +25,8 @@ exportToAres( \item{outputPath}{A folder location to save the JSON files. Default is current working folder} +\item{outputFormat}{Unassigned for default, alternatively "duckdb" to use parquet and duckdb formats.} + \item{reports}{vector of reports to run, c() defaults to all reports See \code{showReportTypes} for a list of all report types}