Skip to content

Commit

Permalink
removed use of non-cd tables as its too confusing to maintain
Browse files Browse the repository at this point in the history
  • Loading branch information
azimov committed Oct 4, 2023
1 parent 65f1c3a commit d898d56
Showing 1 changed file with 8 additions and 32 deletions.
40 changes: 8 additions & 32 deletions R/cohort-diagnostics-main.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ createCdDatabaseDataSource <- function(
},
cgTable = resultDatabaseSettings$cgTable,
cgTablePrefix = resultDatabaseSettings$cgTablePrefix,
useCgTable = TRUE,
databaseTable = resultDatabaseSettings$databaseTable,
databaseTablePrefix = resultDatabaseSettings$databaseTablePrefix,
useCgTable = FALSE,
databaseTable = "database",
databaseTablePrefix = "cd_",
dataModelSpecifications = modelSpec
)

Expand All @@ -213,14 +213,7 @@ createCdDatabaseDataSource <- function(
shiny::setProgress(value = 0.2, message = "Getting cohorts")


dataSource$useCgTable <- !tableIsEmpty(dataSource = dataSource,
tableName = paste0(dataSource$cgTablePrefix, dataSource$cgTable))

if (dataSource$useCgTable) {
dataSource$cohortTableName <- paste0(dataSource$cgTablePrefix, dataSource$cgTable)
} else {
dataSource$cohortTableName <- paste0(dataSource$cdTablePrefix, "cohort")
}
dataSource$cohortTableName <- paste0(dataSource$cdTablePrefix, "cohort")

dataSource$cohortTable <- getCohortTable(dataSource)

Expand Down Expand Up @@ -311,28 +304,11 @@ getDatabaseTable <- function(dataSource) {

# SO much of the app requires this table in memory - it would be much better to re-write queries to not need it!
getCohortTable <- function(dataSource) {
if (!tableIsEmpty(
dataSource = dataSource,
tableName = paste0(dataSource$cgTablePrefix, dataSource$cgTable)
cohortTable <- dataSource$connectionHandler$queryDb(
"SELECT cohort_id, cohort_name FROM @schema.@cd_table_prefixcohort",
schema = dataSource$schema,
cd_table_prefix = dataSource$cdTablePrefix
)
) {
cohortTable <- dataSource$connectionHandler$queryDb(
"SELECT cohort_definition_id as cohort_id, cohort_name FROM @schema.@table_name",
schema = dataSource$schema,
table_name = paste0(dataSource$cgTablePrefix, dataSource$cgTable)
)
} else {
cohortTable <- dataSource$connectionHandler$queryDb(
"SELECT cohort_id, cohort_name FROM @schema.@cd_table_prefixcohort",
schema = dataSource$schema,
cd_table_prefix = dataSource$cdTablePrefix
)
}

# Old label - is this needed??
if ("cohortDefinitionId" %in% names(cohortTable)) {
cohortTable <- cohortTable %>% dplyr::mutate(cohortId = .data$cohortDefinitionId)
}

cohortTable <- cohortTable %>%
dplyr::arrange(.data$cohortId) %>%
Expand Down

0 comments on commit d898d56

Please sign in to comment.