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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Package: FeatureExtraction
Type: Package
Title: Generating Features for a Cohort
Version: 3.13.0
Date: 2026-02-28
Date: 2026-03-05
Authors@R: c(
person("Martijn", "Schuemie", , "schuemie@ohdsi.org", role = c("aut")),
person("Marc", "Suchard", role = c("aut")),
Expand Down
2 changes: 1 addition & 1 deletion R/Aggregation.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down
2 changes: 1 addition & 1 deletion R/CompareCohorts.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down
2 changes: 1 addition & 1 deletion R/CovariateData.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down
2 changes: 1 addition & 1 deletion R/DefaultCovariateSettings.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down
2 changes: 1 addition & 1 deletion R/DefaultTemporalCovariateSettings.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down
2 changes: 1 addition & 1 deletion R/DefaultTemporalSequenceCovariateSettings.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down
2 changes: 1 addition & 1 deletion R/DetailedCovariateSettings.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down
2 changes: 1 addition & 1 deletion R/FeatureExtraction.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# @file FeatureExtraction.R
#
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down
105 changes: 51 additions & 54 deletions R/GetCovariates.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down Expand Up @@ -71,7 +71,7 @@
#' privileges where temp tables can be created.
#' @param covariateCohortDatabaseSchema The database schema where the cohorts used to define the covariates can be found.
#' @param covariateCohortTable The table where the cohorts used to define the covariates can be found.
#'
#'
#' @param exportToTable Whether to export to a table rather than Andromeda object
#' @param dropTableIfExists If targetDatabaseSchema, drop any existing tables. Otherwise, results are merged
#' into existing table data. Overides createTable.
Expand All @@ -85,10 +85,10 @@
#' @param targetCovariateContinuousTable (Optional) The name of the table where the resulting continuous covariates will
#' 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}.
#' it is a temp table, do not specify \code{targetDatabaseSchema}.
#' @param targetCovariateRefTable (Optional) The name of the table where the covariate reference will be stored. If
#' it is a temp table, do not specify \code{targetDatabaseSchema}.
#'
#'
#' @param targetAnalysisRefTable (Optional) The name of the table where the analysis reference will be stored. If
#' it is a temp table, do not specify \code{targetDatabaseSchema}.
#' @param targetTimeRefTable (Optional) The name of the table for the time reference. If
Expand Down Expand Up @@ -187,22 +187,23 @@ getDbCovariateData <- function(connectionDetails = NULL,
} else {
cohortDatabaseSchemaTable <- paste(cohortDatabaseSchema, cohortTable, sep = ".")
}

# check for temporal features in any of the settings
if(inherits(covariateSettings, 'covariateSettings')){
if (inherits(covariateSettings, "covariateSettings")) {
anyTemporal <- covariateSettings$temporal | covariateSettings$temporalSequence
} else{
} else {
anyTemporal <- sum(unlist(lapply(
X = covariateSettings,
FUN = function(x){
sum(c(x$temporal,x$temporalSequence)) == 1
}))) > 0
X = covariateSettings,
FUN = function(x) {
sum(c(x$temporal, x$temporalSequence)) == 1
}
))) > 0
}

# Create export tables
# figure out tables
if (exportToTable) {
if(is.null(targetDatabaseSchema)){
if (is.null(targetDatabaseSchema)) {
# turn off create table since the tables are temp
tempOutputTables <- TRUE
# covariate tables
Expand Down Expand Up @@ -235,7 +236,6 @@ getDbCovariateData <- function(connectionDetails = NULL,
} else {
targetTimeRefTable <- paste0("#", targetTimeRefTable)
}

} else {
tempOutputTables <- FALSE
targetCovariateTable <- paste(targetDatabaseSchema, targetCovariateTable, sep = ".")
Expand All @@ -244,13 +244,13 @@ getDbCovariateData <- function(connectionDetails = NULL,
targetAnalysisRefTable <- paste(targetDatabaseSchema, targetAnalysisRefTable, sep = ".")
targetTimeRefTable <- paste(targetDatabaseSchema, targetTimeRefTable, sep = ".")
}

# drop table if required
if(dropTableIfExists){
message('Dropping export tables')
if (dropTableIfExists) {
message("Dropping export tables")
sql <- SqlRender::loadRenderTranslateSql(
sqlFilename = 'DropExportTables.sql',
packageName = 'FeatureExtraction',
sqlFilename = "DropExportTables.sql",
packageName = "FeatureExtraction",
dbms = attr(connection, "dbms"),
tempEmulationSchema = tempEmulationSchema,
temp_tables = tempOutputTables,
Expand All @@ -260,45 +260,42 @@ getDbCovariateData <- function(connectionDetails = NULL,
analysis_ref_table = targetAnalysisRefTable,
time_ref_table = targetTimeRefTable
)

DatabaseConnector::executeSql(
connection = connection,
connection = connection,
sql = sql
)
}
if(dropTableIfExists & !createTable){
stop('Seem to be exporting to tables but create table is FALSE and dropTable is TRUE')

if (dropTableIfExists & !createTable) {
stop("Seem to be exporting to tables but create table is FALSE and dropTable is TRUE")
}

# create the cohort tables if required
if(createTable){
message('Creating export tables')
if (createTable) {
message("Creating export tables")
sql <- SqlRender::loadRenderTranslateSql(
sqlFilename = 'CreateExportTables.sql',
packageName = 'FeatureExtraction',
sqlFilename = "CreateExportTables.sql",
packageName = "FeatureExtraction",
dbms = attr(connection, "dbms"),
tempEmulationSchema = tempEmulationSchema,

aggregated = aggregated,
temporal = anyTemporal,
row_id_field = 'row_id',

row_id_field = "row_id",
covariate_table = targetCovariateTable,
covariate_continuous_table = targetCovariateContinuousTable,
covariate_ref_table = targetCovariateRefTable,
analysis_ref_table = targetAnalysisRefTable,
time_ref_table = targetTimeRefTable
)

DatabaseConnector::executeSql(
connection = connection,
connection = connection,
sql = sql
)
}

}

sql <- "SELECT cohort_definition_id, COUNT_BIG(*) AS population_size FROM @cohort_database_schema_table {@cohort_ids != -1} ? {WHERE cohort_definition_id IN (@cohort_ids)} GROUP BY cohort_definition_id;"
sql <- SqlRender::render(
sql = sql,
Expand Down Expand Up @@ -336,7 +333,7 @@ getDbCovariateData <- function(connectionDetails = NULL,
covariateCohortTable
)
}

for (i in 1:length(covariateSettings)) {
fun <- attr(covariateSettings[[i]], "fun")
args <- list(
Expand Down Expand Up @@ -374,33 +371,33 @@ getDbCovariateData <- function(connectionDetails = NULL,
} else if (hasData(tempCovariateData$covariatesContinuous)) {
covariateData$covariatesContinuous <- tempCovariateData$covariatesContinuous
}
if(hasData(tempCovariateData$covariateRef)){

if (hasData(tempCovariateData$covariateRef)) {
Andromeda::appendToTable(covariateData$covariateRef, tempCovariateData$covariateRef)
}
if(hasData(tempCovariateData$analysisRef)){
if (hasData(tempCovariateData$analysisRef)) {
Andromeda::appendToTable(covariateData$analysisRef, tempCovariateData$analysisRef)
}

if(!exportToTable){
for (name in names(attr(tempCovariateData, "metaData"))) {
if (is.null(attr(covariateData, "metaData")[[name]])) {
attr(covariateData, "metaData")[[name]] <- attr(tempCovariateData, "metaData")[[name]]
} else {
attr(covariateData, "metaData")[[name]] <- list(
c(
unlist(attr(covariateData, "metaData")[[name]]),
attr(tempCovariateData, "metaData")[[name]]

if (!exportToTable) {
for (name in names(attr(tempCovariateData, "metaData"))) {
if (is.null(attr(covariateData, "metaData")[[name]])) {
attr(covariateData, "metaData")[[name]] <- attr(tempCovariateData, "metaData")[[name]]
} else {
attr(covariateData, "metaData")[[name]] <- list(
c(
unlist(attr(covariateData, "metaData")[[name]]),
attr(tempCovariateData, "metaData")[[name]]
)
)
)
}
}
}
} # if not exporting
}
}
}
if(!is.null(covariateData)){

if (!is.null(covariateData)) {
attr(covariateData, "metaData")$populationSize <- populationSize
attr(covariateData, "metaData")$cohortIds <- cohortIds
}
Expand Down
2 changes: 1 addition & 1 deletion R/GetCovariatesFromCohortAttributes.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down
8 changes: 3 additions & 5 deletions R/GetCovariatesFromOtherCohorts.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2025 Observational Health Data Sciences and Informatics
# Copyright 2026 Observational Health Data Sciences and Informatics
#
# This file is part of FeatureExtraction
#
Expand Down Expand Up @@ -28,10 +28,10 @@
#' 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
Expand Down Expand Up @@ -171,13 +171,11 @@ getDbCohortBasedCovariatesData <- function(connection,
cdmVersion = cdmVersion,
rowIdField = rowIdField,
covariateSettings = detailledSettings,

targetCovariateTable = targetCovariateTable,
targetCovariateContinuousTable = targetCovariateContinuousTable,
targetCovariateRefTable = targetCovariateRefTable,
targetAnalysisRefTable = targetAnalysisRefTable,
targetTimeRefTable = targetTimeRefTable,

aggregated = aggregated,
minCharacterizationMean = minCharacterizationMean
)
Expand Down
Loading
Loading