Skip to content

Commit

Permalink
Update uploadToDatabase.R
Browse files Browse the repository at this point in the history
- fixing result upload issue when there is a ' in a cohort's name
  • Loading branch information
jreps committed Sep 21, 2023
1 parent bf871cc commit 820e05e
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions R/uploadToDatabase.R
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ addCohort <- function(
targetDialect = targetDialect,
tableName = 'cohort_definition',
columnNames = c('cohort_name'),
values = c(paste0("'",cohortDefinition$cohortName,"'")),
values = c(paste0("'",gsub('\'', '', cohortDefinition$cohortName),"'")),
tempEmulationSchema = tempEmulationSchema
)

Expand All @@ -1157,12 +1157,12 @@ addCohort <- function(

if(addNew){
cohortDefinitionId <- result$cohortDefinitionId[result$json %in% json]
ParallelLogger::logInfo(paste0('Cohort ',cohortDefinition$cohortName,' exists in cohort_definition with cohort id', result$cohortDefinitionId[result$json %in% json]))
ParallelLogger::logInfo(paste0('Cohort ',gsub('\'', '', cohortDefinition$cohortName),' exists in cohort_definition with cohort id', result$cohortDefinitionId[result$json %in% json]))
} else{
ParallelLogger::logInfo(paste0('Adding cohort ',cohortDefinition$cohortName))
ParallelLogger::logInfo(paste0('Adding cohort ',gsub('\'', '', cohortDefinition$cohortName)))

data <- data.frame(
cohortName = cohortDefinition$cohortName,
cohortName = gsub('\'', '', cohortDefinition$cohortName),
cohortDefinitionId = cohortDefinition$cohortId,
json = json
)
Expand All @@ -1187,7 +1187,7 @@ addCohort <- function(
targetDialect = targetDialect,
tableName = 'cohort_definition',
columnNames = c('cohort_name', 'cohort_definition_id'),
values = c(paste0("'",cohortDefinition$cohortName,"'"), cohortDefinition$cohortId),
values = c(paste0("'",gsub('\'', '', cohortDefinition$cohortName),"'"), cohortDefinition$cohortId),
tempEmulationSchema = tempEmulationSchema
)

Expand All @@ -1202,18 +1202,18 @@ addCohort <- function(
targetDialect = targetDialect,
tableName = 'cohorts',
columnNames = c('cohort_definition_id','cohort_name'),
values = c(cohortDefinitionId, paste0("'",cohortDefinition$cohortName,"'")),
values = c(cohortDefinitionId, paste0("'",gsub('\'', '', cohortDefinition$cohortName),"'")),
tempEmulationSchema = tempEmulationSchema
)

if(nrow(result)>0){
ParallelLogger::logInfo(paste0('Cohort ',cohortDefinition$cohortName,' exists in cohorts with cohort id', result$cohortId))
ParallelLogger::logInfo(paste0('Cohort ',gsub('\'', '', cohortDefinition$cohortName),' exists in cohorts with cohort id', result$cohortId))
} else{
ParallelLogger::logInfo(paste0('Adding cohort ',cohortDefinition$cohortName))
ParallelLogger::logInfo(paste0('Adding cohort ',gsub('\'', '', cohortDefinition$cohortName)))

data <- data.frame(
cohortDefinitionId = cohortDefinitionId,
cohortName = cohortDefinition$cohortName
cohortName = gsub('\'', '', cohortDefinition$cohortName)
)
DatabaseConnector::insertTable(
connection = conn,
Expand All @@ -1235,7 +1235,7 @@ addCohort <- function(
targetDialect = targetDialect,
tableName = 'cohorts',
columnNames = c('cohort_definition_id','cohort_name'),
values = c(cohortDefinitionId, paste0("'",cohortDefinition$cohortName,"'")),
values = c(cohortDefinitionId, paste0("'",gsub('\'', '', cohortDefinition$cohortName),"'")),
tempEmulationSchema = tempEmulationSchema
)
}
Expand Down

0 comments on commit 820e05e

Please sign in to comment.