tests/testthat/setup.R

library(Eunomia)
connectionDetails <- getEunomiaConnectionDetails()

if (grepl("testthat", getwd())) {
  cohortPath <- "cohorts"
} else {
  cohortPath <- file.path("tests", "testthat", "cohorts")
}

creationFile <- file.path(cohortPath, "CohortsToCreate.csv")
cohortDefinitionSet <- CohortGenerator::getCohortDefinitionSet(
  settingsFileName = creationFile,
  sqlFolder = cohortPath,
  jsonFolder = cohortPath,
  cohortFileNameValue = c("cohortId")
)

cohortTableNames <- CohortGenerator::getCohortTableNames(cohortTable = "cohort")

CohortGenerator::createCohortTables(
  connectionDetails = connectionDetails,
  cohortTableNames = cohortTableNames,
  cohortDatabaseSchema = "main",
  incremental = FALSE
)


CohortGenerator::generateCohortSet(
  connectionDetails = connectionDetails,
  cdmDatabaseSchema = "main",
  cohortDatabaseSchema = "main",
  cohortTableNames = cohortTableNames,
  cohortDefinitionSet = cohortDefinitionSet,
  incremental = FALSE
)

withr::defer(
  {
    unlink(connectionDetails$server())
  },
  testthat::teardown_env()
)
OHDSI/PheValuator documentation built on Jan. 28, 2024, 4:05 a.m.