From 7caa0956a959bc0955a4142fbedad182d426c0a3 Mon Sep 17 00:00:00 2001 From: Jamie Gilbert Date: Wed, 29 Mar 2023 15:14:58 -0700 Subject: [PATCH] Casting of time series results for Andromeda work --- DESCRIPTION | 2 +- R/TimeSeries.R | 5 +++-- inst/sql/sql_server/ComputeTimeSeries1.sql | 2 +- inst/sql/sql_server/ComputeTimeSeries2.sql | 2 +- inst/sql/sql_server/ComputeTimeSeries3.sql | 2 +- 5 files changed, 7 insertions(+), 6 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index bed23311a..98800272f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -63,7 +63,7 @@ License: Apache License VignetteBuilder: knitr URL: https://ohdsi.github.io/CohortDiagnostics, https://github.com/OHDSI/CohortDiagnostics BugReports: https://github.com/OHDSI/CohortDiagnostics/issues -RoxygenNote: 7.2.1 +RoxygenNote: 7.2.3 Encoding: UTF-8 Language: en-US StagedInstall: no diff --git a/R/TimeSeries.R b/R/TimeSeries.R index 555539748..d4f84c5d0 100644 --- a/R/TimeSeries.R +++ b/R/TimeSeries.R @@ -103,7 +103,6 @@ runCohortTimeSeriesDiagnostics <- function(connectionDetails = NULL, return(NULL) } } - ## Calendar period---- ParallelLogger::logTrace(" - Preparing calendar table for time series computation.") # note calendar span is created based on all dates in observation period table, @@ -529,7 +528,7 @@ executeTimeSeriesDiagnostics <- function(connection, if (runCohortTimeSeries & nrow(cohortDefinitionSet) > 0) { subset <- subsetToRequiredCohorts( cohorts = cohortDefinitionSet %>% - dplyr::filter(cohortId %in% instantiatedCohorts), + dplyr::filter(.data$cohortId %in% instantiatedCohorts), task = "runCohortTimeSeries", incremental = incremental, recordKeepingFile = recordKeepingFile @@ -587,6 +586,7 @@ executeTimeSeriesDiagnostics <- function(connection, ) } ) + data <- makeDataExportable( x = data, tableName = "time_series", @@ -648,6 +648,7 @@ executeTimeSeriesDiagnostics <- function(connection, ) } ) + data <- makeDataExportable( x = data, tableName = "time_series", diff --git a/inst/sql/sql_server/ComputeTimeSeries1.sql b/inst/sql/sql_server/ComputeTimeSeries1.sql index 07701e6fc..f3a0c68f1 100644 --- a/inst/sql/sql_server/ComputeTimeSeries1.sql +++ b/inst/sql/sql_server/ComputeTimeSeries1.sql @@ -7,7 +7,7 @@ SELECT cohort_definition_id cohort_id, time_id, - {@stratify_by_gender} ? {gender,} : {CAST(NULL AS VARCHAR) gender, } + {@stratify_by_gender} ? { CASE WHEN gender IS NULL THEN 'NULL' ELSE gender END} : {'NULL'} gender, {@stratify_by_age_group} ? {FLOOR((YEAR(period_begin) - year_of_birth) / 10) age_group,} : {CAST(NULL AS INT) age_group, } COUNT_BIG(DISTINCT CONCAT(cast(subject_id AS VARCHAR(30)), '_', cast(cohort_start_date AS VARCHAR(30)))) records, -- records in calendar period diff --git a/inst/sql/sql_server/ComputeTimeSeries2.sql b/inst/sql/sql_server/ComputeTimeSeries2.sql index ac06840cd..470d05d79 100644 --- a/inst/sql/sql_server/ComputeTimeSeries2.sql +++ b/inst/sql/sql_server/ComputeTimeSeries2.sql @@ -8,7 +8,7 @@ SELECT cohort_definition_id cohort_id, time_id, - {@stratify_by_gender} ? {gender,} : {CAST(NULL AS VARCHAR) gender, } + {@stratify_by_gender} ? {CASE WHEN gender IS NULL THEN 'NULL' ELSE gender END} : {'NULL'} gender, {@stratify_by_age_group} ? {FLOOR((YEAR(period_begin) - year_of_birth) / 10) AS age_group,} : {CAST(NULL AS INT) age_group, } COUNT_BIG(DISTINCT CONCAT(cast(subject_id AS VARCHAR(30)), '_', cast(observation_period_start_date AS VARCHAR(30)))) records, -- records in calendar month COUNT_BIG(DISTINCT subject_id) subjects, -- unique subjects diff --git a/inst/sql/sql_server/ComputeTimeSeries3.sql b/inst/sql/sql_server/ComputeTimeSeries3.sql index abf33b33e..d054e0ba9 100644 --- a/inst/sql/sql_server/ComputeTimeSeries3.sql +++ b/inst/sql/sql_server/ComputeTimeSeries3.sql @@ -7,7 +7,7 @@ SELECT -44819062 cohort_id, time_id, - {@stratify_by_gender} ? {p.gender,} : {CAST(NULL AS VARCHAR) gender, } + {@stratify_by_gender} ? { CASE WHEN p.gender IS NULL THEN 'NULL' ELSE p.gender END} : {'NULL'} gender, {@stratify_by_age_group} ? {FLOOR((YEAR(period_begin) - year_of_birth) / 10) AS age_group,} : {CAST(NULL AS INT) age_group, } COUNT_BIG(DISTINCT CONCAT(cast(o.person_id AS VARCHAR(30)), '_', cast(observation_period_start_date AS VARCHAR(30)))) records, -- records in calendar month COUNT_BIG(DISTINCT o.person_id) subjects, -- unique subjects