2021-08-19 19:43:34 +00:00
|
|
|
# Copyright 2019 Observational Health Data Sciences and Informatics
|
|
|
|
#
|
|
|
|
# This file is part of CdmDdlBase
|
|
|
|
#
|
|
|
|
# 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.
|
|
|
|
|
|
|
|
#' Create OMOP CDM SQL files
|
|
|
|
#'
|
|
|
|
#' Writes DDL, ForeignKey, PrimaryKey and index SQL files for given cdmVersion
|
2024-03-28 19:31:24 +00:00
|
|
|
#' and targetDialect to the 'ddl' folder in specified output folder.
|
2021-08-19 19:43:34 +00:00
|
|
|
#'
|
2021-08-20 15:05:46 +00:00
|
|
|
#' @param cdmVersions The versions of the CDM you are creating, e.g. 5.3, 5.4.
|
2021-08-19 19:43:34 +00:00
|
|
|
#' Defaults to all supported CDM versions.
|
2021-08-20 15:05:46 +00:00
|
|
|
#' @param targetDialects A character vector of target dialects.
|
|
|
|
#' Defaults to all supported dialects.
|
|
|
|
#' @param outputfolder The base folder where the SQL files will be written.
|
|
|
|
#' Subfolders will be created for each cdmVersion and targetDialect.
|
2024-02-06 20:13:45 +00:00
|
|
|
#' @return Writes DDL, ForeignKey, PrimaryKey and index SQL files for given cdmVersion
|
2024-03-28 19:31:24 +00:00
|
|
|
#' and targetDialect to the 'ddl' folder in specified output folder.
|
2021-08-20 16:05:15 +00:00
|
|
|
#' @export
|
2021-08-20 15:05:46 +00:00
|
|
|
buildRelease <- function(cdmVersions = listSupportedVersions(),
|
|
|
|
targetDialects = listSupportedDialects(),
|
2024-02-06 20:13:45 +00:00
|
|
|
outputfolder = file.path(tempdir(), "inst", "ddl")){
|
2021-08-20 15:05:46 +00:00
|
|
|
basefolder <- outputfolder
|
|
|
|
for (cdmVersion in cdmVersions) {
|
|
|
|
for (targetDialect in targetDialects) {
|
|
|
|
outputfolder <- file.path(basefolder, cdmVersion, gsub(" ", "_", targetDialect))
|
|
|
|
|
2021-08-19 19:43:34 +00:00
|
|
|
writeDdl(targetDialect = targetDialect,
|
2021-08-20 15:05:46 +00:00
|
|
|
cdmVersion = cdmVersion,
|
|
|
|
outputfolder = outputfolder)
|
2021-08-19 19:43:34 +00:00
|
|
|
|
|
|
|
writePrimaryKeys(targetDialect = targetDialect,
|
2021-08-20 15:05:46 +00:00
|
|
|
cdmVersion = cdmVersion,
|
|
|
|
outputfolder = outputfolder)
|
2021-08-19 19:43:34 +00:00
|
|
|
|
|
|
|
writeForeignKeys(targetDialect = targetDialect,
|
2021-08-20 15:05:46 +00:00
|
|
|
cdmVersion = cdmVersion,
|
|
|
|
outputfolder = outputfolder)
|
2021-08-19 19:43:34 +00:00
|
|
|
|
|
|
|
writeIndex(targetDialect = targetDialect,
|
2021-08-20 15:05:46 +00:00
|
|
|
cdmVersion = cdmVersion,
|
|
|
|
outputfolder = outputfolder)
|
2021-08-19 19:43:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#' Create OMOP CDM release zip
|
|
|
|
#'
|
|
|
|
#' First calls \code{buildReleaseZips} for given cdmVersions and targetDialects.
|
|
|
|
#' This writes the ddl sql files to the ddl folder.
|
|
|
|
#' Then zips all written ddl files into a release zip to given output folder.
|
|
|
|
#'
|
|
|
|
#' If no (or multiple) targetDialect is given,
|
|
|
|
#' then one zip is written with the files of all supported dialects.
|
|
|
|
#'
|
|
|
|
#' @param cdmVersion The version of the CDM you are creating, e.g. 5.3, 5.4.
|
|
|
|
#' Defaults to all supported CDM versions.
|
|
|
|
#' @param targetDialect The target dialect. Defaults to all supported dialects.
|
|
|
|
#' @param outputfolder The output folder. Defaults to "output"
|
|
|
|
#' @return A character string containing the OHDSQL DDL
|
|
|
|
#' @export
|
|
|
|
#' @examples
|
2023-09-07 17:52:20 +00:00
|
|
|
#'\dontrun{
|
2021-08-19 19:43:34 +00:00
|
|
|
#' buildReleaseZip(cdmVersion='5.3', targetDialect='sql server', outputfolder='.')
|
2023-09-07 17:52:20 +00:00
|
|
|
#'}
|
2021-08-19 19:43:34 +00:00
|
|
|
buildReleaseZip <- function(cdmVersion,
|
|
|
|
targetDialect = listSupportedDialects(),
|
2024-02-06 20:13:45 +00:00
|
|
|
outputfolder = file.path(tempdir(), "output")){
|
2021-08-19 19:43:34 +00:00
|
|
|
# argument checks
|
|
|
|
stopifnot(is.character(cdmVersion), length(cdmVersion) == 1, cdmVersion %in% listSupportedVersions())
|
|
|
|
|
|
|
|
if (!dir.exists(outputfolder)) {
|
|
|
|
dir.create(outputfolder)
|
|
|
|
}
|
|
|
|
|
|
|
|
files <- c()
|
|
|
|
for (dialect in targetDialect) {
|
2021-08-20 15:05:46 +00:00
|
|
|
buildRelease(cdmVersion, dialect, outputfolder = outputfolder)
|
|
|
|
files <- c(files, list.files(file.path(outputfolder, cdmVersion, gsub(" ", "_", dialect)),
|
2021-08-19 19:43:34 +00:00
|
|
|
pattern = ".*\\.sql$",
|
|
|
|
full.names = TRUE))
|
|
|
|
}
|
|
|
|
|
|
|
|
if (length(targetDialect) == 1) {
|
|
|
|
zipName <- file.path(outputfolder, paste0("OMOPCDM", "_", gsub(" ", "_", targetDialect), "_", cdmVersion, '.zip'))
|
|
|
|
} else {
|
|
|
|
zipName <- file.path(outputfolder, paste0("OMOPCDM", "_", cdmVersion, '.zip'))
|
|
|
|
}
|
|
|
|
|
|
|
|
DatabaseConnector::createZipFile(zipFile = zipName, files = files)
|
|
|
|
}
|