Skip to content

Commit 6eb850a

Browse files
authored
Merge pull request #84 from darwin-eu-dev/issue72
time series
2 parents 2c603a3 + d77a6a2 commit 6eb850a

9 files changed

+490
-469
lines changed

R/runTimeSeries.R

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

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.

0 commit comments

Comments
 (0)