-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #457 from OHDSI/develop
Develop
- Loading branch information
Showing
63 changed files
with
8,398 additions
and
158 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Package: DataQualityDashboard | ||
Type: Package | ||
Title: Execute and View Data Quality Checks on OMOP CDM Database | ||
Version: 2.2.0 | ||
Date: 2023-05-05 | ||
Version: 2.3.0 | ||
Date: 2023-05-21 | ||
Authors@R: c( | ||
person("Katy", "Sadowski", email = "[email protected]", role = c("aut", "cre")), | ||
person("Clair", "Blacketer", role = c("aut")), | ||
|
@@ -27,7 +27,7 @@ Imports: | |
dplyr, | ||
jsonlite, | ||
rJava, | ||
SqlRender (>= 1.6.0), | ||
SqlRender (>= 1.10.1), | ||
plyr, | ||
stringr, | ||
rlang, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Copyright 2023 Observational Health Data Sciences and Informatics | ||
# | ||
# This file is part of DataQualityDashboard | ||
# | ||
# 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. | ||
|
||
#' @title Convert JSON results file case | ||
#' | ||
#' @description Convert a DQD JSON results file between camelcase and (all-caps) snakecase. Enables viewing of pre-v.2.1.0 results files in later DQD versions, and vice versa | ||
#' | ||
#' @param jsonFilePath Path to the JSON results file to be converted | ||
#' @param writeToFile Whether or not to write the converted results back to a file (must be either TRUE or FALSE) | ||
#' @param outputFolder The folder to output the converted JSON results file to | ||
#' @param outputFile (OPTIONAL) File to write converted results JSON object to. Default is name of input file with a "_camel" or "_snake" postfix | ||
#' @param targetCase Case into which the results file parameters should be converted (must be either "camel" or "snake") | ||
#' | ||
#' @returns DQD results object (a named list) | ||
#' | ||
#' @importFrom jsonlite fromJSON | ||
#' @importFrom SqlRender snakeCaseToCamelCase camelCaseToSnakeCase | ||
#' @importFrom dplyr rename_with | ||
#' @importFrom tools file_path_sans_ext | ||
#' | ||
#' @export | ||
|
||
convertJsonResultsFileCase <- function( | ||
jsonFilePath, | ||
writeToFile, | ||
outputFolder = NA, | ||
outputFile = "", | ||
targetCase) { | ||
if (!any(targetCase %in% c("camel", "snake"))) { | ||
stop("targetCase must be either 'camel' or 'snake'.") | ||
} | ||
stopifnot(is.logical(writeToFile)) | ||
if (writeToFile && is.na(outputFolder)) { | ||
stop("You must specify an output folder if writing to file.") | ||
} | ||
|
||
results <- jsonlite::fromJSON(jsonFilePath) | ||
|
||
if ("numViolatedRows" %in% names(results$CheckResults) && targetCase == "camel") { | ||
warning("File is already in camelcase! No conversion will be performed.") | ||
return(results) | ||
} | ||
if ("NUM_VIOLATED_ROWS" %in% names(results$CheckResults) && targetCase == "snake") { | ||
warning("File is already in snakecase! No conversion will be performed.") | ||
return(results) | ||
} | ||
|
||
if (targetCase == "camel") { | ||
swapFunction <- SqlRender::snakeCaseToCamelCase | ||
} else { | ||
swapFunction <- function(x) { | ||
toupper(SqlRender::camelCaseToSnakeCase(x)) | ||
} | ||
} | ||
|
||
results$Metadata <- dplyr::rename_with(results$Metadata, swapFunction) | ||
results$CheckResults <- dplyr::rename_with(results$CheckResults, swapFunction, -c("checkId")) | ||
|
||
if (writeToFile) { | ||
if (nchar(outputFile) == 0) { | ||
jsonFile <- tools::file_path_sans_ext(basename(jsonFilePath)) | ||
outputFile <- paste(jsonFile, "_", targetCase, ".json", sep = "") | ||
} | ||
.writeResultsToJson(results, outputFolder, outputFile) | ||
} | ||
|
||
return(results) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.