From f669358b36a049652eeac833c0bf11a2e5bf4e00 Mon Sep 17 00:00:00 2001 From: Evanette Burrows Date: Wed, 20 Dec 2023 15:25:35 -0500 Subject: [PATCH] Address Issue 162 improve version support (#174) * Update functions for supported OMOP versions --- R/CreateCDMIndexAndConstraintScripts.r | 181 +++++++------------------ R/backupCDM.r | 10 +- R/createPrunedTables.r | 10 +- R/getEventConceptId.r | 10 +- R/pruneCDM.r | 4 +- R/restoreCDMTables.r | 10 +- 6 files changed, 68 insertions(+), 157 deletions(-) diff --git a/R/CreateCDMIndexAndConstraintScripts.r b/R/CreateCDMIndexAndConstraintScripts.r index 737d259..a83facf 100644 --- a/R/CreateCDMIndexAndConstraintScripts.r +++ b/R/CreateCDMIndexAndConstraintScripts.r @@ -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 @@ -29,13 +29,13 @@ CreateCDMIndexAndConstraintScripts <- { 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)) { @@ -46,17 +46,17 @@ CreateCDMIndexAndConstraintScripts <- 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"))) { 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"))) { stop("cdmVersion and githubTag mismatch.") } @@ -74,34 +74,16 @@ CreateCDMIndexAndConstraintScripts <- 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" ) } } @@ -116,34 +98,16 @@ CreateCDMIndexAndConstraintScripts <- 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" ) } } @@ -158,34 +122,16 @@ CreateCDMIndexAndConstraintScripts <- 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" ) } } @@ -196,22 +142,12 @@ CreateCDMIndexAndConstraintScripts <- 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" ) } } @@ -226,34 +162,16 @@ CreateCDMIndexAndConstraintScripts <- 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" ) } } @@ -267,30 +185,23 @@ CreateCDMIndexAndConstraintScripts <- 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")) { diff --git a/R/backupCDM.r b/R/backupCDM.r index 3c2a857..230455c 100644 --- a/R/backupCDM.r +++ b/R/backupCDM.r @@ -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 @@ -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( diff --git a/R/createPrunedTables.r b/R/createPrunedTables.r index 00ae8a1..bb48af4 100644 --- a/R/createPrunedTables.r +++ b/R/createPrunedTables.r @@ -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 @@ -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"), diff --git a/R/getEventConceptId.r b/R/getEventConceptId.r index 22a7859..279b587 100644 --- a/R/getEventConceptId.r +++ b/R/getEventConceptId.r @@ -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 @@ -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"), diff --git a/R/pruneCDM.r b/R/pruneCDM.r index 31e3937..649febd 100644 --- a/R/pruneCDM.r +++ b/R/pruneCDM.r @@ -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 diff --git a/R/restoreCDMTables.r b/R/restoreCDMTables.r index 0c63535..6816d71 100644 --- a/R/restoreCDMTables.r +++ b/R/restoreCDMTables.r @@ -7,9 +7,9 @@ #' \code{DatabaseConnector} package. #' @param cdmSchema The name of the database schema that contains the CDM #' instance. 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" are supported. +#' @param cdmVersion The version of your CDM. Currently "5.3.1" and "5.4.0" are supported. #'@export @@ -18,10 +18,10 @@ restoreCDMTables <- { 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, "/restore_cdm_tables.sql"),