Skip to content

Commit 153849c

Browse files
Merge pull request #504 from OHDSI/develop
Develop
2 parents bd4d98d + 2e601f2 commit 153849c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+443
-140
lines changed

DESCRIPTION

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: DataQualityDashboard
22
Type: Package
33
Title: Execute and View Data Quality Checks on OMOP CDM Database
4-
Version: 2.4.1
5-
Date: 2023-10-18
4+
Version: 2.5.0
5+
Date: 2023-11-04
66
Authors@R: c(
77
person("Katy", "Sadowski", email = "[email protected]", role = c("aut", "cre")),
88
person("Clair", "Blacketer", role = c("aut")),

NAMESPACE

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export(executeDqChecks)
55
export(listDqChecks)
66
export(reEvaluateThresholds)
77
export(viewDqDashboard)
8+
export(writeDBResultsToJson)
89
export(writeJsonResultsToCsv)
910
export(writeJsonResultsToTable)
1011
import(DatabaseConnector)

R/executeDqChecks.R

+8
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ executeDqChecks <- function(connectionDetails,
9494
stop("cdmVersion must contain a version of the form '5.X' where X is an integer between 2 and 4 inclusive.")
9595
}
9696

97+
if (sqlOnlyIncrementalInsert == TRUE && sqlOnly == FALSE) {
98+
stop("Set `sqlOnly` to TRUE in order to use `sqlOnlyIncrementalInsert` mode.")
99+
}
100+
97101
stopifnot(is.character(cdmDatabaseSchema), is.character(resultsDatabaseSchema), is.numeric(numThreads))
98102
stopifnot(is.character(cdmSourceName), is.logical(sqlOnly), is.character(outputFolder), is.logical(verboseMode))
99103
stopifnot(is.logical(writeToTable), is.character(checkLevels))
@@ -134,6 +138,10 @@ executeDqChecks <- function(connectionDetails,
134138
if (nrow(metadata) < 1) {
135139
stop("Please populate the cdm_source table before executing data quality checks.")
136140
}
141+
if (nrow(metadata) > 1) {
142+
metadata <- metadata[1, ]
143+
warning("The cdm_source table has more than 1 row. A single row from this table has been selected to populate DQD metadata.")
144+
}
137145
metadata$dqdVersion <- as.character(packageVersion("DataQualityDashboard"))
138146
DatabaseConnector::disconnect(connection)
139147
} else {

R/runCheck.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124

125125
dfs <- do.call(rbind, dfs)
126126

127-
if (sqlOnlyIncrementalInsert) {
127+
if (sqlOnly && sqlOnlyIncrementalInsert) {
128128
sqlToUnion <- dfs$query
129129
if (length(sqlToUnion) > 0) {
130130
.writeSqlOnlyQueries(sqlToUnion, sqlOnlyUnionCount, resultsDatabaseSchema, writeTableName, connectionDetails$dbms, outputFolder, checkDescription)

R/writeDBResultsTo.R

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# Copyright 2023 Observational Health Data Sciences and Informatics
2+
#
3+
# This file is part of DataQualityDashboard
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
#' Write DQD results database table to json
18+
#'
19+
#' @param connection A connection object
20+
#' @param resultsDatabaseSchema The fully qualified database name of the results schema
21+
#' @param cdmDatabaseSchema The fully qualified database name of the CDM schema
22+
#' @param writeTableName Name of DQD results table in the database to read from
23+
#' @param outputFolder The folder to output the json results file to
24+
#' @param outputFile The output filename of the json results file
25+
#'
26+
#' @export
27+
#'
28+
29+
writeDBResultsToJson <- function(connection,
30+
resultsDatabaseSchema,
31+
cdmDatabaseSchema,
32+
writeTableName,
33+
outputFolder,
34+
outputFile) {
35+
metadata <- DatabaseConnector::renderTranslateQuerySql(
36+
connection,
37+
sql = "select * from @cdmDatabaseSchema.cdm_source;",
38+
snakeCaseToCamelCase = TRUE,
39+
cdmDatabaseSchema = cdmDatabaseSchema
40+
)
41+
42+
checkResults <- DatabaseConnector::renderTranslateQuerySql(
43+
connection,
44+
sql = "select * from @resultsDatabaseSchema.@writeTableName;",
45+
snakeCaseToCamelCase = TRUE,
46+
resultsDatabaseSchema = resultsDatabaseSchema,
47+
writeTableName = writeTableName
48+
)
49+
50+
# Quick patch for missing value issues related to SQL Only Implementation
51+
checkResults["error"][checkResults["error"] == ""] <- NA
52+
checkResults["warning"][checkResults["warning"] == ""] <- NA
53+
checkResults["executionTime"][checkResults["executionTime"] == ""] <- "0 secs"
54+
checkResults["queryText"][checkResults["queryText"] == ""] <- "[Generated via SQL Only]"
55+
56+
overview <- .summarizeResults(
57+
checkResults = checkResults
58+
)
59+
60+
# Quick patch for non-camel-case column name
61+
names(checkResults)[names(checkResults) == "checkid"] <- "checkId"
62+
63+
allResults <- list(
64+
startTimestamp = Sys.time(),
65+
endTimestamp = Sys.time(),
66+
executionTime = "0 secs",
67+
CheckResults = checkResults,
68+
Metadata = metadata,
69+
Overview = overview
70+
)
71+
72+
.writeResultsToJson(
73+
allResults,
74+
outputFolder,
75+
outputFile
76+
)
77+
}

R/writeJsonResultsTo.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ writeJsonResultsToTable <- function(connectionDetails,
4747

4848
ParallelLogger::logInfo(sprintf("Writing results to table %s", tableName))
4949

50-
if ("unitConceptId" %in% colnames(df)) {
50+
if ("conceptId" %in% colnames(df)) {
5151
ddl <- SqlRender::loadRenderTranslateSql(
5252
sqlFilename = "result_table_ddl_concept.sql",
5353
packageName = "DataQualityDashboard",

_pkgdown.yml

+4
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ reference:
6363
desc: >
6464
Function to convert the case of a results JSON file between snakecase and camelcase
6565
contents: convertJsonResultsFileCase
66+
- title: "Write database results to a JSON file"
67+
desc: >
68+
Function to write DQD results from a database table into a JSON file
69+
contents: writeDBResultsToJson

docs/404.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/LICENSE-text.html

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/AddNewCheck.html

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/CheckStatusDefinitions.html

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/CheckTypeDescriptions.html

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/DataQualityDashboard.html

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/DqdForCohorts.html

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/articles/SqlOnly.html

+12-43
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)