Skip to content

Commit

Permalink
Update for lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
burrowse committed Jan 2, 2024
1 parent d2cf2d0 commit 939d59f
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 135 deletions.
58 changes: 29 additions & 29 deletions R/CreateCDMTables.r
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,41 @@ CreateCDMTables <-
cdmSchema,
cdmVersion,
outputFolder = NULL,
createIndices = FALSE,
createIndices = FALSE,
sqlOnly = FALSE)
{
if (!sqlOnly) {

print("Creating CDM Tables....")

CommonDataModel::executeDdl(
connectionDetails = connectionDetails,
cdmVersion = cdmVersion,
cdmDatabaseSchema = cdmSchema,
executeDdl = TRUE,
executePrimaryKey = TRUE,
executeForeignKey = FALSE
) # False for now due to bug: https://github.com/OHDSI/CommonDataModel/issues/452
print("Creating CDM Tables....")

print("CDM Tables Created.")

if (createIndices) {

print("Creating Indices on CDM Tables....")
CommonDataModel::executeDdl(
connectionDetails = connectionDetails,
cdmVersion = cdmVersion,
cdmDatabaseSchema = cdmSchema,
executeDdl = TRUE,
executePrimaryKey = TRUE,
executeForeignKey = FALSE
) # False for now due to bug: https://github.com/OHDSI/CommonDataModel/issues/452

print("CDM Tables Created.")

if (createIndices) {
print("Creating Indices on CDM Tables....")

indexSQLFile <- CommonDataModel::writeIndex(
targetDialect = connectionDetails$dbms,
cdmVersion = cdmVersion,
cdmDatabaseSchema = cdmSchema,
outputfolder = tempdir())
indexSQLFile <- CommonDataModel::writeIndex(
targetDialect = connectionDetails$dbms,
cdmVersion = cdmVersion,
cdmDatabaseSchema = cdmSchema,
outputfolder = tempdir()
)

indexDDL <-
SqlRender::readSql(paste0(tempdir(), "/", indexSQLFile))
conn <- DatabaseConnector::connect(connectionDetails)
DatabaseConnector::executeSql(conn, indexDDL)
DatabaseConnector::disconnect(conn)
print("Index Creation Complete.")
}

indexDDL <- SqlRender::readSql(paste0(tempdir(),"/",indexSQLFile))
conn <- DatabaseConnector::connect(connectionDetails)
DatabaseConnector::executeSql(conn,indexDDL)
DatabaseConnector::disconnect(conn)
print("Index Creation Complete.")
}

} else {
if (is.null(outputFolder)) {
stop("Must specify an outputFolder location when using sqlOnly = TRUE")
Expand Down
36 changes: 16 additions & 20 deletions R/CreateMapAndRollupTables.r
Original file line number Diff line number Diff line change
Expand Up @@ -30,30 +30,28 @@


CreateMapAndRollupTables <- function(connectionDetails,
cdmSchema,
syntheaSchema,
cdmVersion,
syntheaVersion = "2.7.0",
cdmSourceName = "Synthea synthetic health database",
cdmSourceAbbreviation = "Synthea",
cdmHolder = "OHDSI",
cdmSourceDescription = "SyntheaTM is a Synthetic Patient Population Simulator. The goal is to output synthetic, realistic (but not real), patient data and associated health records in a variety of formats.",
sqlOnly = FALSE)
cdmSchema,
syntheaSchema,
cdmVersion,
syntheaVersion = "2.7.0",
cdmSourceName = "Synthea synthetic health database",
cdmSourceAbbreviation = "Synthea",
cdmHolder = "OHDSI",
cdmSourceDescription = "SyntheaTM is a Synthetic Patient Population Simulator. The goal is to output synthetic, realistic (but not real), patient data and associated health records in a variety of formats.",
sqlOnly = FALSE)
{
# Determine which sql scripts to run based on the given version.
# The path is relative to inst/sql/sql_server.
if (cdmVersion == "5.3") {
sqlFilePath <- "cdm_version/v531"
} else if (cdmVersion == "5.4") {
sqlFilePath <- "cdm_version/v540"
} else {
supportedCDMVersions <- c("5.3", "5.4")

if (!(cdmVersion %in% supportedCDMVersions)) {
stop("Unsupported CDM specified. Supported CDM versions are \"5.3\" and \"5.4\".")
}

supportedSyntheaVersions <- c("2.7.0", "3.0.0","3.1.0","3.2.0")
supportedSyntheaVersions <- c("2.7.0", "3.0.0", "3.1.0", "3.2.0")

if (!(syntheaVersion %in% supportedSyntheaVersions))
stop("Invalid Synthea version specified. Currently \"2.7.0\", \"3.0.0\",\"3.1.0\", and \"3.2.0\" are supported.")
stop(
"Invalid Synthea version specified. Currently \"2.7.0\", \"3.0.0\",\"3.1.0\", and \"3.2.0\" are supported."
)

# Create Vocabulary mapping tables
CreateVocabMapTables(connectionDetails, cdmSchema, cdmVersion, sqlOnly)
Expand All @@ -66,5 +64,3 @@ CreateMapAndRollupTables <- function(connectionDetails,
sqlOnly)

}


13 changes: 8 additions & 5 deletions R/CreateSyntheaTables.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@


CreateSyntheaTables <-
function (connectionDetails,
syntheaSchema,
syntheaVersion = "2.7.0")
function(connectionDetails,
syntheaSchema,
syntheaVersion = "2.7.0")
{
if (syntheaVersion == "2.7.0")
sqlFilePath <- "synthea_version/v270"
Expand All @@ -30,9 +30,12 @@ CreateSyntheaTables <-
else if (syntheaVersion == "3.2.0")
sqlFilePath <- "synthea_version/v320"
else
stop("Invalid synthea version specified. Currently \"2.7.0\", \"3.0.0\", \"3.1.0\" and \"3.2.0\" are supported.")
stop(
"Invalid synthea version specified. Currently \"2.7.0\", \"3.0.0\", \"3.1.0\" and \"3.2.0\" are supported."
)

sqlFilename <- paste0(sqlFilePath, "/", "create_synthea_tables.sql")
sqlFilename <-
paste0(sqlFilePath, "/", "create_synthea_tables.sql")

translatedSql <- SqlRender::loadRenderTranslateSql(
sqlFilename = sqlFilename,
Expand Down
37 changes: 19 additions & 18 deletions R/DropSyntheaTables.r
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ DropSyntheaTables <- function(connectionDetails, syntheaSchema)
syntheaTables <- c(
"ALLERGIES",
"CAREPLANS",
"CLAIMS",
"CLAIMS_TRANSACTIONS",
"CLAIMS",
"CLAIMS_TRANSACTIONS",
"CONDITIONS",
"DEVICES",
"ENCOUNTERS",
Expand All @@ -30,32 +30,33 @@ DropSyntheaTables <- function(connectionDetails, syntheaSchema)
"OBSERVATIONS",
"ORGANIZATIONS",
"PATIENTS",
"PAYERS",
"PAYER_TRANSITIONS",
"PAYERS",
"PAYER_TRANSITIONS",
"PROCEDURES",
"PROVIDERS",
"SUPPLIES"
"SUPPLIES"
)

conn <- DatabaseConnector::connect(connectionDetails)
allTables <- DatabaseConnector::getTableNames(conn, syntheaSchema)
tablesToDrop <- allTables[which(allTables %in% syntheaTables)]

if (length(tablesToDrop) > 0) {
writeLines("Dropping Synthea tables...")
sql <-
paste(
"drop table @synthea_schema.",
tablesToDrop,
";",
collapse = "\n",
sep = ""
)
sql <- SqlRender::render(sql, synthea_schema = syntheaSchema)
sql <- SqlRender::translate(sql, targetDialect = connectionDetails$dbms)
DatabaseConnector::executeSql(conn, sql)
writeLines("Dropping Synthea tables...")
sql <-
paste(
"drop table @synthea_schema.",
tablesToDrop,
";",
collapse = "\n",
sep = ""
)
sql <- SqlRender::render(sql, synthea_schema = syntheaSchema)
sql <-
SqlRender::translate(sql, targetDialect = connectionDetails$dbms)
DatabaseConnector::executeSql(conn, sql)
} else {
print(sprintf("No synthea tables to drop in schema %s",syntheaSchema))
print(sprintf("No synthea tables to drop in schema %s", syntheaSchema))
}

on.exit(DatabaseConnector::disconnect(conn))
Expand Down
57 changes: 30 additions & 27 deletions R/LoadEventTables.r
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ LoadEventTables <- function(connectionDetails,
cdmHolder = "OHDSI",
cdmSourceDescription = "SyntheaTM is a Synthetic Patient Population Simulator. The goal is to output synthetic, realistic (but not real), patient data and associated health records in a variety of formats.",
createIndices = FALSE,
sqlOnly = FALSE)
sqlOnly = FALSE)
{
# Determine which sql scripts to run based on the given version.
# The path is relative to inst/sql/sql_server.
Expand All @@ -51,25 +51,28 @@ LoadEventTables <- function(connectionDetails,
stop("Unsupported CDM specified. Supported CDM versions are \"5.3\" and \"5.4\".")
}

supportedSyntheaVersions <- c("2.7.0", "3.0.0","3.1.0","3.2.0")
supportedSyntheaVersions <- c("2.7.0", "3.0.0", "3.1.0", "3.2.0")

if (!(syntheaVersion %in% supportedSyntheaVersions))
stop("Invalid Synthea version specified. Currently \"2.7.0\", \"3.0.0\",\"3.1.0\", and \"3.2.0\" are supported.")
stop(
"Invalid Synthea version specified. Currently \"2.7.0\", \"3.0.0\",\"3.1.0\", and \"3.2.0\" are supported."
)

if (createIndices) {
print("Creating Indices on CDM Tables....")
print("Creating Indices on CDM Tables....")

indexSQLFile <- CommonDataModel::writeIndex(
targetDialect = connectionDetails$dbms,
cdmVersion = cdmVersion,
cdmDatabaseSchema = cdmSchema,
outputfolder = tempdir())
indexSQLFile <- CommonDataModel::writeIndex(
targetDialect = connectionDetails$dbms,
cdmVersion = cdmVersion,
cdmDatabaseSchema = cdmSchema,
outputfolder = tempdir()
)

indexDDL <- SqlRender::readSql(paste0(tempdir(),"/",indexSQLFile))
conn <- DatabaseConnector::connect(connectionDetails)
DatabaseConnector::executeSql(conn,indexDDL)
DatabaseConnector::disconnect(conn)
print("Index Creation Complete.")
indexDDL <- SqlRender::readSql(paste0(tempdir(), "/", indexSQLFile))
conn <- DatabaseConnector::connect(connectionDetails)
DatabaseConnector::executeSql(conn, indexDDL)
DatabaseConnector::disconnect(conn)
print("Index Creation Complete.")
}

if (!sqlOnly) {
Expand Down Expand Up @@ -233,7 +236,7 @@ LoadEventTables <- function(connectionDetails,
cdm_source_name = cdmSourceName,
cdm_source_abbreviation = cdmSourceAbbreviation,
cdm_holder = cdmHolder,
source_description = paste("Synthea version: ",syntheaVersion," ",cdmSourceDescription)
source_description = paste("Synthea version: ", syntheaVersion, " ", cdmSourceDescription)
)
runStep(sql, fileQuery)

Expand Down Expand Up @@ -267,24 +270,24 @@ LoadEventTables <- function(connectionDetails,
dbms = connectionDetails$dbms,
cdm_schema = cdmSchema,
synthea_schema = syntheaSchema,
synthea_version = syntheaVersion
synthea_version = syntheaVersion
)
runStep(sql, fileQuery)

# cost
if (syntheaVersion == "2.7.0")
fileQuery <- "insert_cost_v270.sql"
else if (syntheaVersion %in% c("3.0.0","3.1.0","3.2.0"))
fileQuery <- "insert_cost_v300.sql"
fileQuery <- "insert_cost_v270.sql"
else if (syntheaVersion %in% c("3.0.0", "3.1.0", "3.2.0"))
fileQuery <- "insert_cost_v300.sql"

sql <- SqlRender::loadRenderTranslateSql(
sqlFilename = file.path(sqlFilePath, fileQuery),
packageName = "ETLSyntheaBuilder",
dbms = connectionDetails$dbms,
cdm_schema = cdmSchema,
synthea_schema = syntheaSchema
)
runStep(sql, fileQuery)
sql <- SqlRender::loadRenderTranslateSql(
sqlFilename = file.path(sqlFilePath, fileQuery),
packageName = "ETLSyntheaBuilder",
dbms = connectionDetails$dbms,
cdm_schema = cdmSchema,
synthea_schema = syntheaSchema
)
runStep(sql, fileQuery)

if (!sqlOnly) {
DatabaseConnector::disconnect(conn)
Expand Down
Loading

0 comments on commit 939d59f

Please sign in to comment.