Skip to content

Commit

Permalink
Ensure temp tables are dropped before creating them (#191)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonysena authored Sep 17, 2024
1 parent 231dfa1 commit 3fb33c4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
1 change: 1 addition & 0 deletions R/NegativeControlCohorts.R
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ createNegativeControlOutcomesQuery <- function(connection,
}
selectClause
ncSetQuery <- paste0(
"DROP TABLE IF EXISTS #nc_set;",
"CREATE TABLE #nc_set (",
" cohort_id bigint NOT NULL,",
" outcome_concept_id bigint NOT NULL",
Expand Down
18 changes: 9 additions & 9 deletions inst/sql/sql_server/CreateResultsDataModel.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
CREATE TABLE @database_schema.@table_prefixcg_cohort_definition (
cohort_definition_id BIGINT NOT NULL,
cohort_definition_id BIGINT NOT NULL,
cohort_name VARCHAR,
description VARCHAR,
json TEXT,
Expand All @@ -11,7 +11,7 @@ CREATE TABLE @database_schema.@table_prefixcg_cohort_definition (
);

CREATE TABLE @database_schema.@table_prefixcg_cohort_generation (
cohort_id BIGINT NOT NULL,
cohort_id BIGINT NOT NULL,
cohort_name VARCHAR,
generation_status VARCHAR,
start_time TIMESTAMP,
Expand All @@ -21,15 +21,15 @@ CREATE TABLE @database_schema.@table_prefixcg_cohort_generation (
);

CREATE TABLE @database_schema.@table_prefixcg_cohort_inclusion (
cohort_definition_id BIGINT NOT NULL,
cohort_definition_id BIGINT NOT NULL,
rule_sequence INT NOT NULL,
name VARCHAR NOT NULL,
description VARCHAR,
PRIMARY KEY(cohort_definition_id,rule_sequence,name)
);

CREATE TABLE @database_schema.@table_prefixcg_cohort_inc_result (
database_id VARCHAR NOT NULL,
database_id VARCHAR NOT NULL,
cohort_definition_id BIGINT NOT NULL,
inclusion_rule_mask INT NOT NULL,
person_count BIGINT NOT NULL,
Expand All @@ -38,7 +38,7 @@ CREATE TABLE @database_schema.@table_prefixcg_cohort_inc_result (
);

CREATE TABLE @database_schema.@table_prefixcg_cohort_inc_stats (
database_id VARCHAR NOT NULL,
database_id VARCHAR NOT NULL,
cohort_definition_id BIGINT NOT NULL,
rule_sequence INT NOT NULL,
person_count BIGINT NOT NULL,
Expand All @@ -49,7 +49,7 @@ CREATE TABLE @database_schema.@table_prefixcg_cohort_inc_stats (
);

CREATE TABLE @database_schema.@table_prefixcg_cohort_summary_stats (
database_id VARCHAR NOT NULL,
database_id VARCHAR NOT NULL,
cohort_definition_id BIGINT NOT NULL,
base_count BIGINT NOT NULL,
final_count BIGINT NOT NULL,
Expand All @@ -58,21 +58,21 @@ CREATE TABLE @database_schema.@table_prefixcg_cohort_summary_stats (
);

CREATE TABLE @database_schema.@table_prefixcg_cohort_censor_stats (
cohort_definition_id BIGINT NOT NULL,
cohort_definition_id BIGINT NOT NULL,
lost_count BIGINT NOT NULL,
PRIMARY KEY(cohort_definition_id,lost_count)
);

CREATE TABLE @database_schema.@table_prefixcg_cohort_count (
database_id VARCHAR NOT NULL,
database_id VARCHAR NOT NULL,
cohort_id BIGINT NOT NULL,
cohort_entries BIGINT NOT NULL,
cohort_subjects BIGINT NOT NULL,
PRIMARY KEY(database_id,cohort_id,cohort_entries,cohort_subjects)
);

CREATE TABLE @database_schema.@table_prefixcg_cohort_count_neg_ctrl (
database_id VARCHAR NOT NULL,
database_id VARCHAR NOT NULL,
cohort_id BIGINT NOT NULL,
cohort_entries BIGINT NOT NULL,
cohort_subjects BIGINT NOT NULL,
Expand Down
1 change: 1 addition & 0 deletions inst/sql/sql_server/NegativeControlOutcomes.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
@nc_set_query

DROP TABLE IF EXISTS #Codesets;
CREATE TABLE #Codesets (
cohort_definition_id bigint NOT NULL,
ancestor_concept_id int NOT NULL,
Expand Down

0 comments on commit 3fb33c4

Please sign in to comment.