Skip to content

Commit 3f3869b

Browse files
committed
fix conflicts
2 parents be6a6c5 + 6eb850a commit 3f3869b

12 files changed

+760
-718
lines changed

R/runTimeSeries.R

+97-148
Large diffs are not rendered by default.

R/runVisitContext.R

+43-12
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ getVisitContext <- function(connection = NULL,
5757

5858
if (!is.null(conceptIdTable)) {
5959

60-
createTablesql <- "IF OBJECT_ID('@unique_concept_id_table', 'U') IS NULL CREATE TABLE @unique_concept_id_table (concept_id BIGINT);"
61-
62-
DatabaseConnector::renderTranslateExecuteSql(
63-
connection = connection,
64-
sql = createTablesql,
65-
tempEmulationSchema = tempEmulationSchema,
66-
unique_concept_id_table = conceptIdTable,
67-
progressBar = FALSE,
68-
reportOverallTime = FALSE
69-
)
60+
# add concepts to #concept_ids if they don't already exist
61+
if (!tempTableExists(connection, "concept_ids")) {
62+
DatabaseConnector::renderTranslateExecuteSql(
63+
connection = connection,
64+
sql = "CREATE TABLE #concept_ids (concept_id BIGINT);",
65+
tempEmulationSchema = tempEmulationSchema,
66+
progressBar = FALSE,
67+
reportOverallTime = FALSE
68+
)
69+
}
7070

7171
sql <- "INSERT INTO @unique_concept_id_table (concept_id)
7272
SELECT DISTINCT visit_concept_id
@@ -106,6 +106,33 @@ getVisitContext <- function(connection = NULL,
106106
return(visitContext)
107107
}
108108

109+
110+
111+
#' runVisitContext
112+
#'
113+
#' @description
114+
#' Generates the `visit_context.csv` which contains the counts for the subjects by `cohort_id`,
115+
#' `visit_concept_id` and `visit_context`. The `visit_context` categorizes visit occurrences of
116+
#' subjects based on how each the start and end date of each visit related to the cohort start date
117+
#' to which each subject belongs. No output will be generated for cohorts with no subjects.If there
118+
#' is no cohort with subjects execution will halt and `visit_context.csv` will not be generated.
119+
#'
120+
#' @template Connection
121+
#' @template cohortDefinitionSet
122+
#' @template ExportFolder
123+
#' @param databaseId A short string for identifying the database (e.g. 'Synpuf').
124+
#' @template CohortDatabaseSchema
125+
#' @template CdmDatabaseSchema
126+
#' @template TempEmulationSchema
127+
#' @template CohortTable
128+
#' @template cdmVersion
129+
#' @template MinCellCount
130+
#' @template Incremental
131+
#' @param incrementalFolder If \code{incremental = TRUE}, specify a folder where records are kept
132+
#' of which cohort diagnostics has been executed. If not specified, a file named `incremental` will be created inside the
133+
#' \code{export_folder} directory.
134+
#'
135+
#' @export
109136
runVisitContext <- function(connection,
110137
cohortDefinitionSet,
111138
exportFolder,
@@ -118,7 +145,12 @@ runVisitContext <- function(connection,
118145
minCellCount,
119146
incremental,
120147
incrementalFolder = file.path(exportFolder, "incremental")){
121-
148+
149+
# Create export file if it doesn't exist
150+
if (!file.exists(gsub("/$", "", exportFolder))) {
151+
dir.create(exportFolder, recursive = TRUE)
152+
ParallelLogger::logInfo("Created export folder", exportFolder)
153+
}
122154

123155
if (incremental && !file.exists(incrementalFolder)) {
124156
# Create the file if it doesn't exist
@@ -186,7 +218,6 @@ runVisitContext <- function(connection,
186218
conceptIdTable = "#concept_ids"
187219
)
188220
} else {
189-
getResultsDataModelSpecifications("visit_context")
190221
data <- dplyr::tibble(
191222
cohortId = integer(),
192223
visitConceptId = integer(),

R/utils.R

+3-4
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,8 @@ tempTableExists <- function(connection, tempTableName) {
324324
DatabaseConnector::renderTranslateQuerySql(
325325
connection = connection,
326326
sql = "select top 1 * from #@tempTableName;",
327-
tempTableName = tempTableName)
328-
),
327+
tempTableName = tempTableName)
328+
),
329329
error = function(e) {
330330
if (methods::is(connection, "DatabaseConnectorJdbcConnection") &&
331331
DatabaseConnector::dbms(connection) %in% c("postgresql", "redshift")) {
@@ -344,7 +344,7 @@ exportDataToCsv <- function(data, tableName, fileName, minCellCount = 5, databas
344344
minCellCount = minCellCount,
345345
databaseId = databaseId
346346
)
347-
347+
348348
if (!is.null(enforceMinCellValueFunc) && nrow(data) > 0) {
349349
data <- enforceMinCellValueFunc
350350
}
@@ -358,7 +358,6 @@ exportDataToCsv <- function(data, tableName, fileName, minCellCount = 5, databas
358358
return(data)
359359
}
360360

361-
362361
assertCohortDefinitionSetContainsAllParents <- function(cohortDefinitionSet) {
363362
stopifnot(CohortGenerator::isCohortDefinitionSet(cohortDefinitionSet))
364363
if ("subsetParent" %in% names(cohortDefinitionSet)) {

inst/sql/sql_server/ComputeTimeSeries4.sql

-76
This file was deleted.

inst/sql/sql_server/ComputeTimeSeries5.sql

-55
This file was deleted.

inst/sql/sql_server/ComputeTimeSeries6.sql

-49
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
DROP TABLE IF EXISTS #ts_cohort;
2+
DROP TABLE IF EXISTS #ts_cohort_first;
3+
DROP TABLE IF EXISTS #ts_output;
4+
5+
--HINT DISTRIBUTE_ON_KEY(subject_id)
6+
SELECT *
7+
INTO #ts_cohort
8+
FROM @cohort_database_schema.@cohort_table {@cohort_ids != '' } ? {
9+
WHERE cohort_definition_id IN (@cohort_ids) };
10+
11+
--HINT DISTRIBUTE_ON_KEY(subject_id)
12+
SELECT cohort_definition_id,
13+
subject_id,
14+
min(cohort_start_date) cohort_start_date,
15+
min(cohort_end_date) cohort_end_date
16+
INTO #ts_cohort_first
17+
FROM #ts_cohort
18+
GROUP BY cohort_definition_id,
19+
subject_id;
20+
21+
22+
SELECT c.*,
23+
CASE
24+
WHEN c.cohort_start_date = cf.cohort_start_date
25+
THEN 'Y'
26+
ELSE 'N'
27+
END first_occurrence {@stratify_by_gender} ? {,
28+
concept.concept_name gender} {@stratify_by_age_group} ? {,
29+
p.year_of_birth}
30+
INTO #cohort_ts
31+
FROM #ts_cohort c
32+
INNER JOIN #ts_cohort_first cf
33+
ON c.cohort_definition_id = cf.cohort_definition_id
34+
AND c.subject_id = cf.subject_id {@stratify_by_gender | @stratify_by_age_group} ? {
35+
INNER JOIN @cdm_database_schema.person p
36+
ON c.subject_id = p.person_id} {@stratify_by_gender} ? {
37+
INNER JOIN @cdm_database_schema.concept
38+
ON p.gender_concept_id = concept.concept_id};
39+
40+
DROP TABLE IF EXISTS #ts_cohort;
41+
DROP TABLE IF EXISTS #ts_cohort_first;

man-roxygen/DatabaseIds.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#' of the results data model.
44
#' @param databaseId The databaseId to retrieve the results for. This is a
55
#' character field values from the `databaseId` field of the `database` table
6-
#' of the results data model.
6+
#' of the results data model.

man/runTimeSeries.Rd

+13-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/setup.R

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ library(CohortDiagnostics)
22
library(testthat)
33

44
dbmsToTest <- c(
5-
"sqlite",
6-
"duckdb",
7-
"postgresql",
8-
"redshift",
9-
"sql server"
5+
"sqlite"#,
6+
# "duckdb",
7+
# "postgresql",
8+
# "redshift",
9+
# "sql server"
1010
)
1111

1212
useAllCovariates <- FALSE

0 commit comments

Comments
 (0)