Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions R/GetCovariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ getDbCovariateData <- function(connectionDetails = NULL,
cohortIds = c(-1),
rowIdField = "subject_id",
covariateSettings,

exportToTable = FALSE,
createTable = exportToTable,
dropTableIfExists = exportToTable,
Expand All @@ -146,7 +145,6 @@ getDbCovariateData <- function(connectionDetails = NULL,
targetCovariateRefTable = NULL,
targetAnalysisRefTable = NULL,
targetTimeRefTable = NULL,

aggregated = FALSE,
minCharacterizationMean = 0,
tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"),
Expand Down Expand Up @@ -350,15 +348,11 @@ getDbCovariateData <- function(connectionDetails = NULL,
cdmVersion = cdmVersion,
rowIdField = rowIdField,
covariateSettings = covariateSettings[[i]],

targetCovariateTable = targetCovariateTable,
targetCovariateContinuousTable = targetCovariateContinuousTable,
targetCovariateRefTable = targetCovariateRefTable,
targetAnalysisRefTable = targetAnalysisRefTable,
targetTimeRefTable = targetTimeRefTable,
dropTableIfExists = FALSE, # can remove this input
createTable = FALSE, # can remove this input

aggregated = aggregated,
minCharacterizationMean = minCharacterizationMean
)
Expand Down
2 changes: 2 additions & 0 deletions R/GetCovariatesFromOtherCohorts.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#' a permanent table in the \code{targetDatabaseSchema} or a temp table. If
#' it is a temp table, do not specify \code{targetDatabaseSchema}.
#'
#' @param targetCovariateContinuousTable (Optional) The name of the table where the resulting continuous covariates should be stored.
#' @param targetCovariateRefTable (Optional) The name of the table where the covariate reference will be stored.
#'
#' @param targetAnalysisRefTable (Optional) The name of the table where the analysis reference will be stored.
Expand All @@ -48,6 +49,7 @@ getDbCohortBasedCovariatesData <- function(connection,
cdmVersion = "5",
rowIdField = "subject_id",
covariateSettings,
targetDatabaseSchema = NULL,
targetCovariateTable = NULL,
targetCovariateContinuousTable = NULL,
targetCovariateRefTable = NULL,
Expand Down
27 changes: 14 additions & 13 deletions R/GetDefaultCovariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,14 @@
#' be stored. If not provided, results will be fetched to R. The table can be
#' a permanent table in the \code{targetDatabaseSchema} or a temp table. If
#' it is a temp table, do not specify \code{targetDatabaseSchema}.
#'
#' @param targetCovariateContinuousTable (Optional) The name of the table where the resulting continuous covariates should be stored.
#' @param targetCovariateRefTable (Optional) The name of the table where the covariate reference will be stored.
#'
#' @param targetAnalysisRefTable (Optional) The name of the table where the analysis reference will be stored.
#' @param targetTimeRefTable (Optional) The name of the table for the time reference
#' @param minCharacterizationMean The minimum mean value for binary characterization output. Values below this will be cut off from output. This
#' will help reduce the file size of the characterization output, but will remove information
#' on covariates that have very low values. The default is 0.
#'
#'
#' @param dropTableIfExists If targetDatabaseSchema, drop any existing tables. Otherwise, results are merged
#' into existing table data. Overides createTable.
#' @param createTable Run sql to create table? Code does not check if table exists.
#' @template GetCovarParams
#'
#' @examples
Expand All @@ -59,9 +54,7 @@
#' connection = connection,
#' cdmDatabaseSchema = "main",
#' cohortTable = "cohort",
#' covariateSettings = createDefaultCovariateSettings(),
#' targetDatabaseSchema = "main",
#' targetCovariateTable = "ut_cov"
#' covariateSettings = createDefaultCovariateSettings()
#' )
#' }
#' @export
Expand All @@ -74,15 +67,12 @@ getDbDefaultCovariateData <- function(connection,
cdmVersion = "5",
rowIdField = "subject_id",
covariateSettings,

targetDatabaseSchema = NULL,
targetCovariateTable = NULL,
targetCovariateContinuousTable = NULL,
targetCovariateRefTable = NULL,
targetAnalysisRefTable = NULL,
targetTimeRefTable = NULL,

dropTableIfExists = FALSE,
createTable = TRUE,
aggregated = FALSE,
minCharacterizationMean = 0,
tempEmulationSchema = getOption("sqlRenderTempEmulationSchema")) {
Expand Down Expand Up @@ -298,6 +288,17 @@ getDbDefaultCovariateData <- function(connection,
andromedaTableName = "covariateRef",
snakeCaseToCamelCase = TRUE
)

collisions <- covariateData$covariateRef %>%
dplyr::filter(collisions > 0) %>%
dplyr::collect()

if (nrow(collisions) > 0) {
warning(sprintf(
"Collisions in covariate IDs detected for post-coordinated concepts with covariate IDs %s",
paste(collisions$covariateId, paste = ", ")
))
}
} else{
sql <- "
INSERT INTO @target_covariate_ref_table(
Expand Down
4 changes: 3 additions & 1 deletion R/UnitTestHelperFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
#' @param minCharacterizationMean The minimum mean value for binary characterization output. Values below this will be cut off from output. This
#' will help reduce the file size of the characterization output, but will remove information
#' on covariates that have very low values. The default is 0.
#' @param ... Additional arguments, not used.
#' @return
#' Returns an object of type \code{covariateData}, containing information on the covariates.
#'
Expand All @@ -71,7 +72,8 @@
rowIdField = "subject_id",
covariateSettings,
aggregated = FALSE,
minCharacterizationMean = 0) {
minCharacterizationMean = 0,
...) {
writeLines("Constructing length of observation covariates")
if (covariateSettings$useLengthOfObs == FALSE) {
return(NULL)
Expand Down
5 changes: 4 additions & 1 deletion man/dot-getDbLooCovariateData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions man/getDbCohortBasedCovariatesData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 7 additions & 13 deletions man/getDbDefaultCovariateData.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion tests/testthat/setup.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@ library(testthat)
library(FeatureExtraction)
library(dplyr)

# AGS: This rJava code block was used to add the Java dependencies to the classpath for testing. It is needed to run the tests on all platforms, but it is not needed when running individual test files in RStudio, which is why it is not included in the helper functions file. If we want to run individual test files, we can use the loadRenderTranslateUnitTestSql function defined below, which also adds the Java dependencies to the classpath if they are not already there.
# library(rJava)
# .jinit()
# jar_dirs <- c(
# system.file("java", package = "DatabaseConnector"),
# system.file("java", package = "SqlRender"),
# system.file("java", package = "FeatureExtraction")
# )
# jar_files <- unlist(
# lapply(jar_dirs, list.files, pattern = "\\.jar$", full.names = TRUE)
# )
# .jaddClassPath(jar_files)

dbms <- getOption("dbms", default = "sqlite")
message("************* Testing on ", dbms, " *************\n")

Expand Down Expand Up @@ -98,7 +111,7 @@ checkRemoteFileAvailable <- function(remoteFile) {
}
# Then stop if status > 400
if (httr::http_error(resp)) {
message_for_status(resp)
httr::message_for_status(resp)
return(NULL)
}
return("success")
Expand Down
Loading