Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Address Issue 162 improve version support #174

Merged
merged 3 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
181 changes: 46 additions & 135 deletions R/CreateCDMIndexAndConstraintScripts.r
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
#' function \code{createConnectionDetails} in the
#' \code{DatabaseConnector} package.
#' @param cdmSchema The name of the CDM database schema. Requires read and write permissions to this database. On SQL
#' Server, this should specifiy both the database and the schema,
#' Server, this should specify both the database and the schema,
#' so for example 'cdm_instance.dbo'.
#' @param cdmVersion Your CDM version. Currently "5.3.1" and "6.0.0" are supported.
#' @param cdmVersion Your CDM version. Currently "5.3.1" and "5.4.0" are supported.
#' @param githubTag An optional github tag from which to pull the DDL script.
#' Currently "v5.3.1", "v5.3.1_fixes", "v6.0.0", and "v6.0.0_fixes" are supported. The default is NULL.
#' Currently "v5.3.1" and "v5.4.0" are supported. The default is NULL.
#'
#' @details This function creates SQL scripts for the indices and constraints on tables in a CDM by referring to the
#' correct SQL DDL script in the OHDSI CommonDataModel repo. The database platform is
Expand All @@ -29,13 +29,13 @@
{
supportedDbs <-
c("oracle", "postgresql", "pdw", "netezza", "sql server")
supportedVersions <- c("5.3.1", "6.0.0")
supportedVersions <- c("5.3.1", "5.4.0")
supportedTags <-
c("v5.3.1", "v6.0.0", "v5.3.1_fixes", "v6.0.0_fixes")
c("v5.3.1", "v5.4.0")
rdbms <- tolower(connectionDetails$dbms)

if (!(cdmVersion %in% supportedVersions)) {
stop("Unsupported CDM specified. Supported CDM versions are \"5.3.1\" and \"6.0.0\"")
stop("Unsupported CDM specified. Supported CDM versions are \"5.3.1\" and \"5.4.0\"")
}

if (!(rdbms %in% supportedDbs)) {
Expand All @@ -46,17 +46,17 @@

if (!is.null(githubTag) && !(githubTag %in% supportedTags)) {
stop(
"Unrecognized github tag. Supported values are \"v5.3.1\", \"v6.0.0\", \"v5.3.1_fixes\", and \"v6.0.0_fixes\""
"Unrecognized github tag. Supported values are \"v5.3.1\" and \"v5.4.0\""
)
}

if (cdmVersion == "5.3.1" &&
!(githubTag %in% c("v5.3.1", "v5.3.1_fixes"))) {
!(githubTag %in% c("v5.3.1"))) {

Check warning on line 54 in R/CreateCDMIndexAndConstraintScripts.r

View workflow job for this annotation

GitHub Actions / lintr-job

file=R/CreateCDMIndexAndConstraintScripts.r,line=54,col=8,[indentation_linter] Indentation should be 10 spaces but is 8 spaces.
stop("cdmVersion and githubTag mismatch.")
}

if (cdmVersion == "6.0.0" &&
!(githubTag %in% c("v6.0.0", "v6.0.0_fixes"))) {
if (cdmVersion == "5.4.0" &&
!(githubTag %in% c("v5.4.0"))) {

Check warning on line 59 in R/CreateCDMIndexAndConstraintScripts.r

View workflow job for this annotation

GitHub Actions / lintr-job

file=R/CreateCDMIndexAndConstraintScripts.r,line=59,col=8,[indentation_linter] Indentation should be 10 spaces but is 8 spaces.
stop("cdmVersion and githubTag mismatch.")
}

Expand All @@ -74,34 +74,16 @@
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1/Oracle/OMOP%20CDM%20oracle%20constraints.txt"
)
} else if (githubTag == "v5.3.1_fixes") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1_fixes/Oracle/OMOP%20CDM%20oracle%20v5_3_1%20primary%20keys.sql"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1_fixes/Oracle/OMOP%20CDM%20oracle%20v5_3_1%20constraints.sql"
)
}
} else if (cdmVersion == "6.0.0") {
if (is.null(githubTag) || githubTag == "v6.0.0") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0.0/Oracle/OMOP%20CDM%20oracle%20pk%20indexes.txt"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0.0/Oracle/OMOP%20CDM%20oracle%20constraints.txt"
)
} else if (githubTag == "v6.0.0_fixes") {
} else if (cdmVersion == "5.4.0") {
if (is.null(githubTag) || githubTag == "v5.4.0") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0_fixes/Oracle/OMOP%20CDM%20oracle%20pk%20indexes.txt"
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.4.0/inst/ddl/5.4/oracle/OMOPCDM_oracle_5.4_indices.sql"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0_fixes/Oracle/OMOP%20CDM%20oracle%20constraints.txt"
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.4.0/inst/ddl/5.4/oracle/OMOPCDM_oracle_5.4_constraints.sql"
)
}
}
Expand All @@ -116,34 +98,16 @@
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1/PostgreSQL/OMOP%20CDM%20postgresql%20constraints.txt"
)
} else if (githubTag == "v5.3.1_fixes") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1_fixes/PostgreSQL/OMOP%20CDM%20postgresql%20v5_3_1%20primary%20keys.sql"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1_fixes/PostgreSQL/OMOP%20CDM%20postgresql%20v5_3_1%20constraints.sql"
)
}
} else if (cdmVersion == "6.0.0") {
if (is.null(githubTag) || githubTag == "v6.0.0") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0.0/PostgreSQL/OMOP%20CDM%20postgresql%20pk%20indexes.txt"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0.0/PostgreSQL/OMOP%20CDM%20postgresql%20constraints.txt"
)
} else if (githubTag == "v6.0.0_fixes") {
} else if (cdmVersion == "5.4.0") {
if (is.null(githubTag) || githubTag == "v5.4.0") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0_fixes/PostgreSQL/OMOP%20CDM%20postgresql%20pk%20indexes.txt"
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.4.0/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_indices.sql"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0_fixes/PostgreSQL/OMOP%20CDM%20postgresql%20constraints.txt"
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.4.0/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_constraints.sql"
)
}
}
Expand All @@ -158,34 +122,16 @@
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1/ParallelDataWarehouse/OMOP%20CDM%20pdw%20constraints.txt"
)
} else if (githubTag == "v5.3.1_fixes") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1_fixes/ParallelDataWarehouse/OMOP%20CDM%20pdw%20v5_3_1%20indices.sql"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1_fixes/ParallelDataWarehouse/OMOP%20CDM%20pdw%20v5_3_1%20constraints.sql"
)
}
} else if (cdmVersion == "6.0.0") {
if (is.null(githubTag) || githubTag == "v6.0.0") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0.0/ParallelDataWarehouse/OMOP%20CDM%20pdw%20pk%20indexes.txt"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0.0/ParallelDataWarehouse/OMOP%20CDM%20pdw%20constraints.txt"
)
} else if (githubTag == "v6.0.0_fixes") {
} else if (cdmVersion == "5.4.0") {
if (is.null(githubTag) || githubTag == "v5.4.0") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0_fixes/ParallelDataWarehouse/OMOP%20CDM%20pdw%20pk%20indexes.txt"
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.4.0/inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_indices.sql"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0_fixes/ParallelDataWarehouse/OMOP%20CDM%20pdw%20constraints.txt"
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.4.0/inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_constraints.sql"
)
}
}
Expand All @@ -196,22 +142,12 @@
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1/Netezza/OMOP%20CDM%20netezza%20primary%20keys.txt"
)
} else if (githubTag == "v5.3.1_fixes") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1_fixes/Netezza/OMOP%20CDM%20netezza%20v5_3_1%20primary%20keys.sql"
)
}
} else if (cdmVersion == "6.0.0") {
if (is.null(githubTag) || githubTag == "v6.0.0") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0.0/Netezza/OMOP%20CDM%20netezza%20primary%20keys.txt"
)
} else if (githubTag == "v6.0.0_fixes") {
} else if (cdmVersion == "5.4.0") {
if (is.null(githubTag) || githubTag == "v5.4.0") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0_fixes/Netezza/OMOP%20CDM%20netezza%20primary%20keys.txt"
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.4.0/inst/ddl/5.4/netezza/OMOPCDM_netezza_5.4_primary_keys.sql"
)
}
}
Expand All @@ -226,34 +162,16 @@
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1/Sql%20Server/OMOP%20CDM%20sql%20server%20constraints.txt"
)
} else if (githubTag == "v5.3.1_fixes") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1_fixes/Sql%20Server/OMOP%20CDM%20sql%20server%20v5_3_1%20primary%20keys.sql"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.3.1_fixes/Sql%20Server/OMOP%20CDM%20sql%20server%20v5_3_1%20constraints.sql"
)
}
} else if (cdmVersion == "6.0.0") {
if (is.null(githubTag) || githubTag == "v6.0.0") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0.0/Sql%20Server/OMOP%20CDM%20sql%20server%20pk%20indexes.txt"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0.0/Sql%20Server/OMOP%20CDM%20sql%20server%20constraints.txt"
)
} else if (githubTag == "v6.0.0_fixes") {
} else if (cdmVersion == "5.4.0") {
if (is.null(githubTag) || githubTag == "v5.4.0") {
webResponseInd <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0_fixes/Sql%20Server/OMOP%20CDM%20sql%20server%20pk%20indexes.txt"
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.4.0/inst/ddl/5.4/sql_server/OMOPCDM_sql_server_5.4_indices.sql"
)
webResponseCon <-
httr::GET(
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v6.0_fixes/Sql%20Server/OMOP%20CDM%20sql%20server%20constraints.txt"
"https://raw.githubusercontent.com/OHDSI/CommonDataModel/v5.4.0/inst/ddl/5.4/sql_server/OMOPCDM_sql_server_5.4_primary_keys.sql"
)
}
}
Expand All @@ -267,30 +185,23 @@
indexDDL <- toupper(indexDDL)
constraintDDL <- toupper(constraintDDL)

if (githubTag == "v5.3.1_fixes") {
indexDDL <-
SqlRender::render(sql = indexDDL, CDMDATABASESCHEMA = cdmSchema)
constraintDDL <-
SqlRender::render(sql = constraintDDL, CDMDATABASESCHEMA = cdmSchema)
} else {
indexDDL <- gsub(" ON ", " ON @CDM_SCHEMA.", indexDDL)
indexDDL <-
gsub("ALTER TABLE", "ALTER TABLE @CDM_SCHEMA.", indexDDL)
indexDDL <- gsub("@CDM_SCHEMA. ", "@CDM_SCHEMA.", indexDDL)
indexDDL <-
SqlRender::render(indexDDL, CDM_SCHEMA = cdmSchema)
indexDDL <-
SqlRender::translate(indexDDL, targetDialect = rdbms)

constraintDDL <-
gsub("ALTER TABLE", "ALTER TABLE @CDM_SCHEMA.", constraintDDL)
constraintDDL <-
gsub("@CDM_SCHEMA. ", "@CDM_SCHEMA.", constraintDDL)
constraintDDL <-
SqlRender::render(constraintDDL, CDM_SCHEMA = cdmSchema)
constraintDDL <-
SqlRender::translate(constraintDDL, targetDialect = rdbms)
}
indexDDL <- gsub(" ON ", " ON @CDM_SCHEMA.", indexDDL)
indexDDL <-
gsub("ALTER TABLE", "ALTER TABLE @CDM_SCHEMA.", indexDDL)
indexDDL <- gsub("@CDM_SCHEMA. ", "@CDM_SCHEMA.", indexDDL)
indexDDL <-
SqlRender::render(indexDDL, CDM_SCHEMA = cdmSchema)
indexDDL <-
SqlRender::translate(indexDDL, targetDialect = rdbms)

constraintDDL <-
gsub("ALTER TABLE", "ALTER TABLE @CDM_SCHEMA.", constraintDDL)
constraintDDL <-
gsub("@CDM_SCHEMA. ", "@CDM_SCHEMA.", constraintDDL)
constraintDDL <-
SqlRender::render(constraintDDL, CDM_SCHEMA = cdmSchema)
constraintDDL <-
SqlRender::translate(constraintDDL, targetDialect = rdbms)

# Save the translated sql ddl to be run at a later time
if (!dir.exists("output")) {
Expand Down
10 changes: 5 additions & 5 deletions R/backupCDM.r
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#' \code{DatabaseConnector} package.
#' @param cdmSchema The name of the database schema that contains the CDM.
#' Requires read and write permissions to this database. On SQL
#' Server, this should specifiy both the database and the schema,
#' Server, this should specify both the database and the schema,
#' so for example 'cdm_instance.dbo'.
#' @param cdmVersion The version of your CDM. Currently "5.3.1" and "6.0.1".
#' @param cdmVersion The version of your CDM. Currently "5.3.1" and "5.4.0".
#'
#'@export

Expand All @@ -18,10 +18,10 @@ backupCDM <- function(connectionDetails, cdmSchema, cdmVersion)
{
if (cdmVersion == "5.3.1")
sqlFilePath <- "cdm_version/v531"
else if (cdmVersion == "6.0.0")
sqlFilePath <- "cdm_version/v600"
else if (cdmVersion == "5.4.0")
sqlFilePath <- "cdm_version/v540"
else
stop("Unsupported CDM specified. Supported CDM versions are \"5.3.1\" and \"6.0.0\"")
stop("Unsupported CDM specified. Supported CDM versions are \"5.3.1\" and \"5.4.0\"")


sql <- SqlRender::loadRenderTranslateSql(
Expand Down
10 changes: 5 additions & 5 deletions R/createPrunedTables.r
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#'
#' @param cdmSchema The name of the database schema that contains the CDM.
#' Requires read and write permissions to this database. On SQL
#' Server, this should specifiy both the database and the schema,
#' Server, this should specify both the database and the schema,
#' so for example 'cdm_instance.dbo'.
#' @param eventConceptId A vector of concept_ids returned from \code{getEventConceptId}.
#' @param cdmVersion The version of your CDM. Currently "5.3.1" and "6.0.0".
#' @param cdmVersion The version of your CDM. Currently "5.3.1" and "5.4.0".
#'
#'@export

Expand All @@ -25,10 +25,10 @@ createPrunedTables <-
{
if (cdmVersion == "5.3.1")
sqlFilePath <- "cdm_version/v531"
else if (cdmVersion == "6.0.0")
sqlFilePath <- "cdm_version/v600"
else if (cdmVersion == "5.4.0")
sqlFilePath <- "cdm_version/v540"
else
stop("Unsupported CDM specified. Supported CDM versions are \"5.3.1\" and \"6.0.0\"")
stop("Unsupported CDM specified. Supported CDM versions are \"5.3.1\" and \"5.4.0\"")

sql <- SqlRender::loadRenderTranslateSql(
sqlFileName = paste0(sqlFilePath, "/create_pruned_tables.sql"),
Expand Down
10 changes: 5 additions & 5 deletions R/getEventConceptId.r
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#'
#' @param cdmSchema The name of the database schema that contains the CDM.
#' Requires read and write permissions to this database. On SQL
#' Server, this should specifiy both the database and the schema,
#' Server, this should specify both the database and the schema,
#' so for example 'cdm_instance.dbo'.
#' @param cdmVersion The version of your CDM. Currently "5.3.1" and "6.0.0".
#' @param cdmVersion The version of your CDM. Currently "5.3.1" and "5.4.0".
#'
#'@export

Expand All @@ -19,10 +19,10 @@ getEventConceptId <-
{
if (cdmVersion == "5.3.1")
sqlFilePath <- "cdm_version/v531"
else if (cdmVersion == "6.0.0")
sqlFilePath <- "cdm_version/v600"
else if (cdmVersion == "5.4.0")
sqlFilePath <- "cdm_version/v540"
else
stop("Unsupported CDM specified. Supported CDM versions are \"5.3.1\" and \"6.0.0\"")
stop("Unsupported CDM specified. Supported CDM versions are \"5.3.1\" and \"5.4.0\"")

sql <- SqlRender::loadRenderTranslateSql(
sqlFileName = paste0(sqlFilePath, "/get_event_concept_id.sql"),
Expand Down
4 changes: 2 additions & 2 deletions R/pruneCDM.r
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#' \code{DatabaseConnector} package.
#' @param cdmSchema The name of the database schema that contains the CDM.
#' Requires read and write permissions to this database. On SQL
#' Server, this should specifiy both the database and the schema,
#' Server, this should specify both the database and the schema,
#' so for example 'cdm_instance.dbo'.
#' @param cdmVersion The version of your CDM. Currently "5.3.1" and "6.0.0".
#' @param cdmVersion The version of your CDM. Currently "5.3.1" and "5.4.0".
#'
#'@export

Expand Down
Loading
Loading