Skip to content

Commit eb5466d

Browse files
Updated
1 parent 3aabc99 commit eb5466d

File tree

681 files changed

+179055
-4
lines changed

Some content is hidden

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

681 files changed

+179055
-4
lines changed

data/CommonDataModel/.Rbuildignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
^.*\.Rproj$
2+
^\.Rproj\.user$
3+
^LICENSE\.md$
4+
.github/*
5+
extras/*
6+
docs/*
7+
rmd/*
8+
^CRAN-SUBMISSION$
9+
^cran-comments\.md$

data/CommonDataModel/.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.Rproj.user
2+
.Rhistory
3+
.RData
4+
.Ruserdata
5+
extras/CodeToRun.R
6+
7+
# OS generated files #
8+
######################
9+
.DS_Store
10+
.DS_Store?
11+
._*
12+
.Spotlight-V100
13+
.Trashes
14+
ehthumbs.db
15+
Thumbs.db
16+
extras/codeToRun.R
17+
output/
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Version: 1.0.1
2+
Date: 2024-10-01 17:22:58 UTC
3+
SHA: 17b2d139c7e982c33cd8abb2ea7db0cd104e756a
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
Version: 1.0
2+
3+
RestoreWorkspace: Default
4+
SaveWorkspace: Default
5+
AlwaysSaveHistory: Default
6+
7+
EnableCodeIndexing: Yes
8+
UseSpacesForTab: Yes
9+
NumSpacesForTab: 2
10+
Encoding: UTF-8
11+
12+
RnwWeave: Sweave
13+
LaTeX: XeLaTeX
14+
15+
AutoAppendNewline: Yes
16+
StripTrailingWhitespace: Yes
17+
18+
BuildType: Package
19+
PackageUseDevtools: Yes
20+
PackageInstallArgs: --no-multiarch --with-keep.source
21+
PackageRoxygenize: rd,collate,namespace

data/CommonDataModel/DESCRIPTION

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Package: CommonDataModel
2+
Type: Package
3+
Title: OMOP CDM DDL and Documentation Generator
4+
Version: 1.0.1
5+
Authors@R: person(given = "Clair",
6+
family = "Blacketer",
7+
role = c("aut", "cre"),
8+
email = "mblacke@its.jnj.com")
9+
Maintainer: Clair Blacketer <mblacke@its.jnj.com>
10+
Description: Generates the scripts required to create an Observational Medical Outcomes Partnership (OMOP) Common Data Model (CDM) database and associated documentation for supported database platforms. Leverages the 'SqlRender' package to convert the Data Definition Language (DDL) script written in parameterized Structured Query Language (SQL) to the other supported dialects.
11+
License: Apache License 2.0
12+
Encoding: UTF-8
13+
LazyData: true
14+
Depends:
15+
DatabaseConnector,
16+
SqlRender,
17+
rJava
18+
Imports:
19+
rmarkdown,
20+
stringr,
21+
DBI,
22+
dplyr,
23+
readr
24+
Suggests:
25+
knitr,
26+
testthat (>= 3.0.0),
27+
RSQLite,
28+
withr
29+
NeedsCompilation: no
30+
RoxygenNote: 7.2.3
31+
Config/testthat/edition: 3

data/CommonDataModel/NAMESPACE

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Generated by roxygen2: do not edit by hand
2+
3+
export(buildRelease)
4+
export(buildReleaseZip)
5+
export(createDdl)
6+
export(createForeignKeys)
7+
export(createPrimaryKeys)
8+
export(downloadCurrentDdl)
9+
export(executeDdl)
10+
export(listSupportedDialects)
11+
export(listSupportedVersions)
12+
export(parseWiki)
13+
export(writeDdl)
14+
export(writeForeignKeys)
15+
export(writeIndex)
16+
export(writePrimaryKeys)
17+
import(DatabaseConnector)
18+
import(SqlRender)
19+
import(rJava)
20+
importFrom(utils,download.file)
21+
importFrom(utils,read.csv)
22+
importFrom(utils,write.csv)

data/CommonDataModel/NEWS.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CommonDataModel v5.4.2
2+
======================
3+
4+
Bigfixes:
5+
6+
1. Removed package test that was causing issues with downstream dependencies (test-BuildRelease.R)
7+
8+
Documentation:
9+
10+
1. Updated documentation for the OMOP Common Data Model based on the April Olympians 2024 initiative.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#' @import rJava
2+
#' @import DatabaseConnector
3+
#' @import SqlRender
4+
NULL
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Copyright 2017 Observational Health Data Sciences and Informatics
2+
#
3+
# This file is part of DDLGeneratr
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+
18+
#' Parse Wiki files
19+
#'
20+
#' @description
21+
#' Parses all .md files in the specified location (or any subfolders), extracting definitions
22+
#' of the Common Data Model.
23+
#'
24+
#' @param mdFilesLocation Path to the root folder of the Wiki repository.
25+
#' @param output_file Path to where the output CSV file should be written.
26+
#' @return CSV files with the OMOP CDM specifications.
27+
#' @importFrom utils write.csv
28+
#' @export
29+
parseWiki <- function(mdFilesLocation, output_file) {
30+
# mdFilesLocation <- "../CommonDataModel.wiki"
31+
files <- list.files(mdFilesLocation, pattern = ".*\\.md", recursive = TRUE, full.names = TRUE)
32+
file <- files[18]
33+
parseTableRow <- function(row) {
34+
cells <- stringr::str_trim(stringr::str_split(row, "\\|")[[1]])
35+
if (substr(row, 1, 1) == "|") {
36+
cells <- cells[2:5]
37+
}
38+
return(data.frame(field = tolower(cells[1]),
39+
required = cells[2],
40+
type = toupper(cells[3]),
41+
description = cells[4]))
42+
}
43+
44+
parseMdFile <- function(file) {
45+
text <- readChar(file, file.info(file)$size)
46+
lines <- stringr::str_split(text, "\n")[[1]]
47+
lines <- stringr::str_trim(lines)
48+
tableStart <- grep("\\s*field\\s*\\|\\s*required\\s*\\|\\s*type\\s*\\|\\s*description\\s*", tolower(lines))
49+
if (length(tableStart) > 1)
50+
stop("More than one table definition found in ", file)
51+
52+
if (length(tableStart) == 1) {
53+
tableName <- basename(file)
54+
tableName <- tolower(stringr::str_sub(tableName, 1, -4))
55+
writeLines(paste("Parsing table", tableName))
56+
tableStart <- tableStart + 2
57+
tableEnd <- c(which(lines == ""), length(lines) + 1)
58+
tableEnd <- min(tableEnd[tableEnd > tableStart]) - 1
59+
tableDefinition <- lapply(lines[tableStart:tableEnd], parseTableRow)
60+
tableDefinition <- do.call(rbind, tableDefinition)
61+
tableDefinition$table <- tableName
62+
return(tableDefinition)
63+
} else {
64+
return(NULL)
65+
}
66+
}
67+
tableDefinitions <- lapply(files, parseMdFile)
68+
tableDefinitions <- do.call(rbind, tableDefinitions)
69+
write.csv(tableDefinitions, output_file, row.names = FALSE)
70+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Copyright 2019 Observational Health Data Sciences and Informatics
2+
#
3+
# This file is part of CdmDdlBase
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+
#' Create OMOP CDM SQL files
18+
#'
19+
#' Writes DDL, ForeignKey, PrimaryKey and index SQL files for given cdmVersion
20+
#' and targetDialect to the 'ddl' folder in specified output folder.
21+
#'
22+
#' @param cdmVersions The versions of the CDM you are creating, e.g. 5.3, 5.4.
23+
#' Defaults to all supported CDM versions.
24+
#' @param targetDialects A character vector of target dialects.
25+
#' Defaults to all supported dialects.
26+
#' @param outputfolder The base folder where the SQL files will be written.
27+
#' Subfolders will be created for each cdmVersion and targetDialect.
28+
#' @return Writes DDL, ForeignKey, PrimaryKey and index SQL files for given cdmVersion
29+
#' and targetDialect to the 'ddl' folder in specified output folder.
30+
#' @export
31+
buildRelease <- function(cdmVersions = listSupportedVersions(),
32+
targetDialects = listSupportedDialects(),
33+
outputfolder = file.path(tempdir(), "inst", "ddl")){
34+
basefolder <- outputfolder
35+
for (cdmVersion in cdmVersions) {
36+
for (targetDialect in targetDialects) {
37+
outputfolder <- file.path(basefolder, cdmVersion, gsub(" ", "_", targetDialect))
38+
39+
writeDdl(targetDialect = targetDialect,
40+
cdmVersion = cdmVersion,
41+
outputfolder = outputfolder)
42+
43+
writePrimaryKeys(targetDialect = targetDialect,
44+
cdmVersion = cdmVersion,
45+
outputfolder = outputfolder)
46+
47+
writeForeignKeys(targetDialect = targetDialect,
48+
cdmVersion = cdmVersion,
49+
outputfolder = outputfolder)
50+
51+
writeIndex(targetDialect = targetDialect,
52+
cdmVersion = cdmVersion,
53+
outputfolder = outputfolder)
54+
}
55+
}
56+
}
57+
58+
#' Create OMOP CDM release zip
59+
#'
60+
#' First calls \code{buildReleaseZips} for given cdmVersions and targetDialects.
61+
#' This writes the ddl sql files to the ddl folder.
62+
#' Then zips all written ddl files into a release zip to given output folder.
63+
#'
64+
#' If no (or multiple) targetDialect is given,
65+
#' then one zip is written with the files of all supported dialects.
66+
#'
67+
#' @param cdmVersion The version of the CDM you are creating, e.g. 5.3, 5.4.
68+
#' Defaults to all supported CDM versions.
69+
#' @param targetDialect The target dialect. Defaults to all supported dialects.
70+
#' @param outputfolder The output folder. Defaults to "output"
71+
#' @return A character string containing the OHDSQL DDL
72+
#' @export
73+
#' @examples
74+
#'\dontrun{
75+
#' buildReleaseZip(cdmVersion='5.3', targetDialect='sql server', outputfolder='.')
76+
#'}
77+
buildReleaseZip <- function(cdmVersion,
78+
targetDialect = listSupportedDialects(),
79+
outputfolder = file.path(tempdir(), "output")){
80+
# argument checks
81+
stopifnot(is.character(cdmVersion), length(cdmVersion) == 1, cdmVersion %in% listSupportedVersions())
82+
83+
if (!dir.exists(outputfolder)) {
84+
dir.create(outputfolder)
85+
}
86+
87+
files <- c()
88+
for (dialect in targetDialect) {
89+
buildRelease(cdmVersion, dialect, outputfolder = outputfolder)
90+
files <- c(files, list.files(file.path(outputfolder, cdmVersion, gsub(" ", "_", dialect)),
91+
pattern = ".*\\.sql$",
92+
full.names = TRUE))
93+
}
94+
95+
if (length(targetDialect) == 1) {
96+
zipName <- file.path(outputfolder, paste0("OMOPCDM", "_", gsub(" ", "_", targetDialect), "_", cdmVersion, '.zip'))
97+
} else {
98+
zipName <- file.path(outputfolder, paste0("OMOPCDM", "_", cdmVersion, '.zip'))
99+
}
100+
101+
DatabaseConnector::createZipFile(zipFile = zipName, files = files)
102+
}

0 commit comments

Comments
 (0)