Skip to content

Commit

Permalink
Use of cohort table unified
Browse files Browse the repository at this point in the history
  • Loading branch information
azimov committed Oct 4, 2023
1 parent 5e34dd6 commit 65f1c3a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 20 deletions.
18 changes: 3 additions & 15 deletions R/cohort-diagnostics-compareCharacterization.R
Original file line number Diff line number Diff line change
Expand Up @@ -480,20 +480,6 @@ compareCohortCharacterizationView <- function(id, title = "Compare cohort charac
)
}

# Returns data from cohort table of Cohort Diagnostics results data model
getResultsCohort <- function(dataSource, cohortIds = NULL) {
data <- dataSource$connectionHandler$queryDb(
sql = "SELECT * FROM @schema.@table_name
{@cohort_id != \"\"} ? { WHERE cohort_id IN (@cohort_id)};",
schema = dataSource$schema,
cohort_id = cohortIds,
table_name = paste0(dataSource$cgTablePrefix,dataSource$cgTable),
snakeCaseToCamelCase = TRUE
)
return(data)
}


# Returns cohort as feature characterization
getCohortRelationshipCharacterizationResults <-
function(dataSource,
Expand All @@ -505,7 +491,8 @@ getCohortRelationshipCharacterizationResults <-
cohortIds = cohortIds,
databaseIds = databaseIds
)
cohort <- getResultsCohort(dataSource = dataSource)
cohort <- getCdCohortRows(dataSource = dataSource,
cohortIds = cohortIds)

cohortRelationships <-
getResultsCohortRelationships(
Expand Down Expand Up @@ -577,6 +564,7 @@ getCohortRelationshipCharacterizationResults <-
dplyr::distinct(),
by = c("analysisId")
)

covariateRef <- tidyr::crossing(
cohort,
analysisRef %>%
Expand Down
8 changes: 4 additions & 4 deletions R/cohort-diagnostics-definition.R
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ getConceptSetDetailsFromCohortDefinition <-
}


getCohortJsonSql <- function(dataSource, cohortIds) {
sql <- "SELECT * FROM @schema.@cohort_table
getCdCohortRows <- function(dataSource, cohortIds) {
sql <- "SELECT {@use_cg_table} ? {cohort_definition_id as cohort_id,} * FROM @schema.@cohort_table
WHERE {@use_cg_table} ? {cohort_definition_id} : {cohort_id} IN (@cohort_ids)"
dataSource$connectionHandler$queryDb(
sql = sql,
Expand Down Expand Up @@ -574,7 +574,7 @@ cohortDefinitionsModule <- function(
return(NULL)
}
row <- subset[idx[1],]
return(getCohortJsonSql(dataSource, row$cohortId))
return(getCdCohortRows(dataSource, row$cohortId))
}
})

Expand Down Expand Up @@ -1095,7 +1095,7 @@ cohortDefinitionsModule <- function(
shiny::withProgress(
message = "Export is in progress",
{
definitions <- getCohortJsonSql(dataSource, cohortTable$cohortId)
definitions <- getCdCohortRows(dataSource, cohortTable$cohortId)
exportCohortDefinitionsZip(definitions, zipFile = file)
},
detail = "Please Wait"
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-cohort-diagnostics-definition.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ shiny::testServer(cohortDefinitionsModule, args = list(
), {
getCohortDefinitionResolvedConceptsReactive()
checkmate::expect_data_frame(cohortDefinitionTableData())
defs <- getCohortJsonSql(dataSourceCd, dataSourceCd$cohortTable$cohortId)
defs <- getCdCohortRows(dataSourceCd, dataSourceCd$cohortTable$cohortId)
def <- defs$json[1] %>% RJSONIO::fromJSON(digits = 23)
checkmate::expect_list(getCirceRenderedExpression(def))

Expand Down

0 comments on commit 65f1c3a

Please sign in to comment.