Skip to content

Commit

Permalink
e
Browse files Browse the repository at this point in the history
  • Loading branch information
gowthamrao committed Oct 23, 2023
1 parent 6444773 commit 3f75a6f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 22 deletions.
14 changes: 8 additions & 6 deletions R/CreateCohortExplorerApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#' replace the personId in the source with a randomly assigned newId.
#' @param featureCohortDatabaseSchema The CohortDatabaseSchema where the feature cohort table exits.
#' @param featureCohortTable The Cohort table where feature cohorts are instantiated.
#' @param featureCohortDefinitionSet The CohortDefinitionSet object corresponding to the cohorts to
#' @param featureCohortDefinitionSet The CohortDefinitionSet object corresponding to the cohorts to
#' be used as features.
#' @returns Returns invisibly the full path of the export folder where the
#' files were created. In this path are the files that are part of the 'shiny'
Expand Down Expand Up @@ -202,7 +202,7 @@ createCohortExplorerApp <- function(connectionDetails = NULL,
access = "x",
add = errorMessage
)

useCohortDomain <- FALSE
if (any(
!is.null(featureCohortDefinitionSet),
Expand Down Expand Up @@ -731,7 +731,7 @@ createCohortExplorerApp <- function(connectionDetails = NULL,
) %>%
dplyr::tibble() %>%
dplyr::mutate(endDate = .data$startDate)

featureCohortData <- NULL
if (useCohortDomain) {
writeLines("Getting feature cohort table.")
Expand Down Expand Up @@ -1174,10 +1174,12 @@ createCohortExplorerApp <- function(connectionDetails = NULL,
data = measurement,
useNewId = assignNewId
)

if (!is.null(featureCohortData)) {
featureCohortData <- replaceId(data = featureCohortData,
useNewId = assignNewId)
featureCohortData <- replaceId(
data = featureCohortData,
useNewId = assignNewId
)
}

results <- list(
Expand Down
4 changes: 2 additions & 2 deletions R/Helper.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ replaceId <- function(data, useNewId = TRUE) {
addDays <- function(x, n) {
# Ensure that x is of class Date
xAsDate <- as.Date(x)

# Add n days to xAsDate
newDate <- xAsDate + as.integer(n)

return(newDate)
}

Expand Down
30 changes: 16 additions & 14 deletions tests/testthat/test-createCohortExplorerApp.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ test_that("do Not Export CohortData", {

test_that("use cohort features", {
skip_if(skipCdmTests, "CDM settings not configured")

library(dplyr)

connection <-
DatabaseConnector::connect(connectionDetails = connectionDetails)
on.exit(DatabaseConnector::disconnect(connection))

# create a cohort with 1000 persons
createCohortTableSql <- "
DROP TABLE IF EXISTS @cohort_database_schema.@cohort_table;
Expand Down Expand Up @@ -374,7 +374,7 @@ test_that("use cohort features", {
2 cohort_definition_id,
cohort_start_date,
cohort_end_date
FROM @cohort_database_schema.@cohort_table
FROM @cohort_database_schema.@cohort_table
WHERE cohort_definition_id = 1;
INSERT INTO @cohort_database_schema.@cohort_table
Expand All @@ -384,10 +384,12 @@ test_that("use cohort features", {
cohort_end_date
FROM @cohort_database_schema.@cohort_table
WHERE cohort_definition_id = 1;"

featureCohortDefinitionSet <- dplyr::tibble(cohortId = 2,
cohortName = "same cohort")


featureCohortDefinitionSet <- dplyr::tibble(
cohortId = 2,
cohortName = "same cohort"
)

DatabaseConnector::renderTranslateExecuteSql(
connection = connection,
sql = createCohortTableSql,
Expand All @@ -396,12 +398,12 @@ test_that("use cohort features", {
reportOverallTime = FALSE,
cohort_database_schema = cohortDatabaseSchema,
cdm_database_schema = cdmDatabaseSchema,
cohort_table = cohortTable,
cohort_table = cohortTable,
tempEmulationSchema = tempEmulationSchema
)

outputDir <- tempfile()

outputPath <- createCohortExplorerApp(
connection = connection,
cdmDatabaseSchema = cdmDatabaseSchema,
Expand All @@ -412,18 +414,18 @@ test_that("use cohort features", {
exportFolder = outputDir,
featureCohortDatabaseSchema = cohortDatabaseSchema,
featureCohortDefinitionSet = featureCohortDefinitionSet,
featureCohortTable = cohortTable,
featureCohortTable = cohortTable,
cohortDefinitionId = 1
)

testthat::expect_true(file.exists(
file.path(
outputPath,
"data",
"CohortExplorer_1_databaseData.rds"
)
))

testthat::expect_error(
createCohortExplorerApp(
connection = connection,
Expand Down

0 comments on commit 3f75a6f

Please sign in to comment.