Title: | OMOP CDM DDL and Documentation Generator |
---|---|
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. |
Authors: | Clair Blacketer [aut, cre] |
Maintainer: | Clair Blacketer <[email protected]> |
License: | Apache License 2.0 |
Version: | 1.0.1 |
Built: | 2024-11-01 06:27:08 UTC |
Source: | CRAN |
Writes DDL, ForeignKey, PrimaryKey and index SQL files for given cdmVersion and targetDialect to the 'ddl' folder in specified output folder.
buildRelease( cdmVersions = listSupportedVersions(), targetDialects = listSupportedDialects(), outputfolder = file.path(tempdir(), "inst", "ddl") )
buildRelease( cdmVersions = listSupportedVersions(), targetDialects = listSupportedDialects(), outputfolder = file.path(tempdir(), "inst", "ddl") )
cdmVersions |
The versions of the CDM you are creating, e.g. 5.3, 5.4. Defaults to all supported CDM versions. |
targetDialects |
A character vector of target dialects. Defaults to all supported dialects. |
outputfolder |
The base folder where the SQL files will be written. Subfolders will be created for each cdmVersion and targetDialect. |
Writes DDL, ForeignKey, PrimaryKey and index SQL files for given cdmVersion and targetDialect to the 'ddl' folder in specified output folder.
First calls 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.
buildReleaseZip( cdmVersion, targetDialect = listSupportedDialects(), outputfolder = file.path(tempdir(), "output") )
buildReleaseZip( cdmVersion, targetDialect = listSupportedDialects(), outputfolder = file.path(tempdir(), "output") )
cdmVersion |
The version of the CDM you are creating, e.g. 5.3, 5.4. Defaults to all supported CDM versions. |
targetDialect |
The target dialect. Defaults to all supported dialects. |
outputfolder |
The output folder. Defaults to "output" |
If no (or multiple) targetDialect is given, then one zip is written with the files of all supported dialects.
A character string containing the OHDSQL DDL
## Not run: buildReleaseZip(cdmVersion='5.3', targetDialect='sql server', outputfolder='.') ## End(Not run)
## Not run: buildReleaseZip(cdmVersion='5.3', targetDialect='sql server', outputfolder='.') ## End(Not run)
The createDdl, createForeignKeys, and createPrimaryKeys functions each return a character string containing their respective DDL SQL code in OHDSQL dialect for a specific CDM version. The SQL they generate needs to be rendered and translated before it can be executed.
createDdl(cdmVersion) createPrimaryKeys(cdmVersion) createForeignKeys(cdmVersion)
createDdl(cdmVersion) createPrimaryKeys(cdmVersion) createForeignKeys(cdmVersion)
cdmVersion |
The version of the CDM you are creating, e.g. 5.3, 5.4 |
The DDL SQL code is created from a two csv files that detail the OMOP CDM Specifications. These files also form the basis of the CDM documentation and the Data Quality Dashboard.
A character string containing the OHDSQL DDL
A string containing the OHDSQL for creation of primary keys in the OMOP CDM.
A string containing the OHDSQL for creation of foreign keys in the OMOP CDM.
createPrimaryKeys()
: createPrimaryKeys Returns a string containing the OHDSQL for creation of primary keys in the OMOP CDM.
createForeignKeys()
: createForeignKeys Returns a string containing the OHDSQL for creation of foreign keys in the OMOP CDM.
## Not run: ddl <- createDdl("5.4") pk <- createPrimaryKeys("5.4") fk <- createForeignKeys("5.4") ## End(Not run)
## Not run: ddl <- createDdl("5.4") pk <- createPrimaryKeys("5.4") fk <- createForeignKeys("5.4") ## End(Not run)
Get current DDL sitting on the main branch
downloadCurrentDdl( githubPath = "OHDSI/CommonDataModel", pathToCsv = "Sql%20Server/OMOP%20CDM%20sql%20server%20ddl.txt", outputFile = paste0("inst/sql/sql_server/OMOP CDM ddl ", Sys.Date(), ".sql") )
downloadCurrentDdl( githubPath = "OHDSI/CommonDataModel", pathToCsv = "Sql%20Server/OMOP%20CDM%20sql%20server%20ddl.txt", outputFile = paste0("inst/sql/sql_server/OMOP CDM ddl ", Sys.Date(), ".sql") )
githubPath |
The path for the GitHub repo containing the package (e.g. 'OHDSI/CommonDataModel'). |
pathToCsv |
The path for the snapshot inside the package. |
outputFile |
The path where the file should be saved. |
This function gets the current ddl on the CDM main branch. It will be taken from the Sql Server folder.
The default location is
inst/settings/currentOmopDdl.sql
.
The current DDL sitting on the main branch of the CommonDataModel repository.
## Not run: downloadCurrentDdl("OHDSI/CommonDataModel", pathToCsv="Sql%20Server/OMOP%20CDM%20sql%20server%20ddl.txt") ## End(Not run)
## Not run: downloadCurrentDdl("OHDSI/CommonDataModel", pathToCsv="Sql%20Server/OMOP%20CDM%20sql%20server%20ddl.txt") ## End(Not run)
This function will generate the DDL for a specific dbms and CDM version and then execute the DDL on a database.
executeDdl( connectionDetails, cdmVersion, cdmDatabaseSchema, executeDdl = TRUE, executePrimaryKey = TRUE, executeForeignKey = TRUE, ... )
executeDdl( connectionDetails, cdmVersion, cdmDatabaseSchema, executeDdl = TRUE, executePrimaryKey = TRUE, executeForeignKey = TRUE, ... )
connectionDetails |
An object of class connectionDetails as created by the DatabaseConnector::createConnectionDetails function. |
cdmVersion |
The version of the CDM you are creating, e.g. 5.3, 5.4 |
cdmDatabaseSchema |
The schema of the CDM instance where the DDL will be run. For example, this would be "ohdsi.dbo" when testing on sql server. |
executeDdl |
Should the DDL be executed? TRUE or FALSE |
executePrimaryKey |
Should the primary keys be added? TRUE or FALSE |
executeForeignKey |
Should the foreign keys be added? TRUE or FALSE |
... |
Other arguments passed on to DatabaseConnector::executeSql. (This allows the user to set the path to errorReportFile.) |
Writes the fully specified DDLs, primary keys, foreign keys, and indices to a file and then executes on a database.
## Not run: executeDdl(connectionDetails = connectionDetails, cdmVersion = "5.4", cdmDatabaseSchema = "myCdm") ## End(Not run)
## Not run: executeDdl(connectionDetails = connectionDetails, cdmVersion = "5.4", cdmDatabaseSchema = "myCdm") ## End(Not run)
List RDBMS dialects supported by this package
listSupportedDialects()
listSupportedDialects()
A list containing the supported Structured Query Language (SQL) dialects.
List CDM versions supported by this package
listSupportedVersions()
listSupportedVersions()
A character vector containing the supported Common Data Model (CDM) versions in major.minor format.
Parses all .md files in the specified location (or any subfolders), extracting definitions of the Common Data Model.
parseWiki(mdFilesLocation, output_file)
parseWiki(mdFilesLocation, output_file)
mdFilesLocation |
Path to the root folder of the Wiki repository. |
output_file |
Path to where the output CSV file should be written. |
CSV files with the OMOP CDM specifications.
Write the DDL to a SQL file. The SQL will be rendered (parameters replaced) and translated to the target SQL dialect. By default the @cdmDatabaseSchema parameter is kept in the SQL file and needs to be replaced before execution.
writeDdl( targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema" ) writePrimaryKeys( targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema" ) writeForeignKeys( targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema" ) writeIndex( targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema" )
writeDdl( targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema" ) writePrimaryKeys( targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema" ) writeForeignKeys( targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema" ) writeIndex( targetDialect, cdmVersion, outputfolder, cdmDatabaseSchema = "@cdmDatabaseSchema" )
targetDialect |
The dialect of the target database. Support dialects are specified by SqlRender::listSupportedDialects |
cdmVersion |
The version of the CDM you are creating, e.g. 5.3, 5.4 |
outputfolder |
The directory or folder where the SQL file should be saved. |
cdmDatabaseSchema |
The schema of the CDM instance where the DDL will be run. For example, this would be "ohdsi.dbo" when testing on sql server. Defaults to "@cdmDatabaseSchema" |
Writes SQL file with the OMOP CDM DDL for the specified CDM version and target dialect in the output folder.
Writes a SQL file with the primary keys for the OMOP CDM based on the specified target dialect and CDM version.
Writes a SQL file with the foreign keys for the OMOP CDM based on the specified target dialect and CDM version.
Writes a SQL file with the indices for the OMOP CDM based on the specified target dialect and CDM version.
writePrimaryKeys()
: writePrimaryKeys Write the SQL code that creates the primary keys to a file.
writeForeignKeys()
: writeForeignKeys Write the SQL code that creates the foreign keys to a file.
writeIndex()
: writeIndex Write the rendered and translated sql that creates recommended indexes to a file.