Skip to content
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
3 changes: 2 additions & 1 deletion .lintr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ linters: linters_with_defaults(
brace_linter = NULL,
object_length_linter = NULL,
line_length_linter = NULL,
cyclocomp_linter = NULL
cyclocomp_linter = NULL,
pipe_consistency_linter = NULL
) # see vignette("lintr")
encoding: "UTF-8"
41 changes: 13 additions & 28 deletions R/LoadSyntheaTables.r
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ LoadSyntheaTables <-
csvList <- list.files(syntheaFileLoc, pattern = "*.csv")

conn <- DatabaseConnector::connect(connectionDetails)
dateColumns <- c("START", "STOP", "DATE", "START_DATE", "END_DATE", "BIRTHDATE", "DEATHDATE")

for (csv in csvList) {
syntheaTable <-
Expand All @@ -52,33 +53,11 @@ LoadSyntheaTables <-
writeLines(paste0("Loading: ", csv))

# experiencing type conversion errors and need to explicitly case some columns
if ("START" %in% colnames(syntheaTable)) {
syntheaTable$START <-
as.Date(syntheaTable$START, format = "%Y-%m-%d")
}
if ("STOP" %in% colnames(syntheaTable)) {
syntheaTable$STOP <-
as.Date(syntheaTable$STOP, format = "%Y-%m-%d")
}
if ("DATE" %in% colnames(syntheaTable)) {
syntheaTable$DATE <-
as.Date(syntheaTable$DATE, format = "%Y-%m-%d")
}
if ("START_DATE" %in% colnames(syntheaTable)) {
syntheaTable$START_DATE <-
as.Date(syntheaTable$START_DATE, format = "%Y-%m-%d")
}
if ("END_DATE" %in% colnames(syntheaTable)) {
syntheaTable$END_DATE <-
as.Date(syntheaTable$END_DATE, format = "%Y-%m-%d")
}
if ("BIRTHDATE" %in% colnames(syntheaTable)) {
syntheaTable$BIRTHDATE <-
as.Date(syntheaTable$BIRTHDATE, format = "%Y-%m-%d")
}
if ("DEATHDATE" %in% colnames(syntheaTable)) {
syntheaTable$DEATHDATE <-
as.Date(syntheaTable$DEATHDATE, format = "%Y-%m-%d")
tableDateColumns <- intersect(dateColumns, colnames(syntheaTable))
for (dateColumn in tableDateColumns) {
syntheaTable[[dateColumn]] <- as.character(syntheaTable[[dateColumn]])
syntheaTable[[dateColumn]][nchar(syntheaTable[[dateColumn]]) == 0] <- NA_character_
syntheaTable[[dateColumn]] <- substr(syntheaTable[[dateColumn]], 1, 10)
}
if ("CODE" %in% colnames(syntheaTable)) {
syntheaTable$CODE <- as.character(syntheaTable$CODE)
Expand All @@ -96,11 +75,17 @@ LoadSyntheaTables <-
as.numeric(syntheaTable$UTILIZATION)
}

insertData <- as.data.frame(syntheaTable, stringsAsFactors = FALSE)
insertDateColumns <- intersect(dateColumns, colnames(insertData))
for (dateColumn in insertDateColumns) {
insertData[[dateColumn]] <- as.Date(insertData[[dateColumn]], format = "%Y-%m-%d")
}

suppressWarnings({
DatabaseConnector::insertTable(
conn,
tableName = paste0(syntheaSchema, ".", strsplit(csv, "[.]")[[1]][1]),
data = as.data.frame(syntheaTable),
data = insertData,
dropTableIfExists = FALSE,
createTable = FALSE,
bulkLoad = bulkLoad,
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ ETLSyntheaBuilder::CreateCDMTables(connectionDetails = cd, cdmSchema = cdmSchema
ETLSyntheaBuilder::CreateSyntheaTables(connectionDetails = cd, syntheaSchema = syntheaSchema, syntheaVersion = syntheaVersion)

ETLSyntheaBuilder::LoadSyntheaTables(connectionDetails = cd, syntheaSchema = syntheaSchema, syntheaFileLoc = syntheaFileLoc)

ETLSyntheaBuilder::LoadVocabFromCsv(connectionDetails = cd, cdmSchema = cdmSchema, vocabFileLoc = vocabFileLoc)

## Note this step assumes you have built the CDM using the ETLSyntheaBuilder::CreateCDMTables command. If you have executed the DDL using the OHDSI/CommonDataModel package you will encounter constraint errors.
ETLSyntheaBuilder::LoadVocabFromCsv(connectionDetails = cd, cdmSchema = cdmSchema, vocabFileLoc = vocabFileLoc,delimiter='\t')

ETLSyntheaBuilder::CreateMapAndRollupTables(connectionDetails = cd, cdmSchema = cdmSchema, syntheaSchema = syntheaSchema, cdmVersion = cdmVersion, syntheaVersion = syntheaVersion)

Expand Down
3 changes: 2 additions & 1 deletion extras/codeToRun.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ ETLSyntheaBuilder::CreateSyntheaTables(connectionDetails,syntheaSchema, syntheaV
# Populate synthea tables
ETLSyntheaBuilder::LoadSyntheaTables(connectionDetails,syntheaSchema,syntheaFileLoc)
# Populate vocabulary tables
ETLSyntheaBuilder::LoadVocabFromCsv(connectionDetails,cdmDatabaseSchema,vocabFileLoc)
## Note this step assumes you have built the CDM using the ETLSyntheaBuilder::CreateCDMTables command. If you have executed the DDL using the OHDSI/CommonDataModel package you will encounter constraint errors.
ETLSyntheaBuilder::LoadVocabFromCsv(connectionDetails,cdmDatabaseSchema,vocabFileLoc,delimiter='\t')
# Create intermediate vocabulary mapping and visit rollup tables
ETLSyntheaBuilder::CreateMapAndRollupTables(connectionDetails, cdmDatabaseSchema,syntheaSchema,cdmVersion,syntheaVersion)
## Optional Step to create extra indices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ create table @synthea_schema.payer_transitions (
--HINT DISTRIBUTE_ON_RANDOM
create table @synthea_schema.payers (
id varchar(1000),
"name" varchar(1000),
ownership varchar NULL,
"name" varchar(1000),
ownership varchar(1000),
address varchar(1000),
city varchar(1000),
state_headquartered varchar(1000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ create table @synthea_schema.payer_transitions (
--HINT DISTRIBUTE_ON_RANDOM
create table @synthea_schema.payers (
id varchar(1000),
"name" varchar(1000),
ownership varchar NULL,
"name" varchar(1000),
ownership varchar(1000),
address varchar(1000),
city varchar(1000),
state_headquartered varchar(1000),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,8 +294,8 @@ create table @synthea_schema.payer_transitions (
--HINT DISTRIBUTE_ON_RANDOM
create table @synthea_schema.payers (
id varchar(1000),
"name" varchar(1000),
ownership varchar NULL,
"name" varchar(1000),
ownership varchar(1000),
address varchar(1000),
city varchar(1000),
state_headquartered varchar(1000),
Expand Down
Loading