diff --git a/R/NegativeControlCohorts.R b/R/NegativeControlCohorts.R index a031078..afd816a 100644 --- a/R/NegativeControlCohorts.R +++ b/R/NegativeControlCohorts.R @@ -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", diff --git a/inst/sql/sql_server/CreateResultsDataModel.sql b/inst/sql/sql_server/CreateResultsDataModel.sql index 9440b46..ed94a5a 100644 --- a/inst/sql/sql_server/CreateResultsDataModel.sql +++ b/inst/sql/sql_server/CreateResultsDataModel.sql @@ -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, @@ -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, @@ -21,7 +21,7 @@ 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, @@ -29,7 +29,7 @@ CREATE TABLE @database_schema.@table_prefixcg_cohort_inclusion ( ); 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, @@ -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, @@ -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, @@ -58,13 +58,13 @@ 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, @@ -72,7 +72,7 @@ CREATE TABLE @database_schema.@table_prefixcg_cohort_count ( ); 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, diff --git a/inst/sql/sql_server/NegativeControlOutcomes.sql b/inst/sql/sql_server/NegativeControlOutcomes.sql index 2957a19..9c5f4b5 100644 --- a/inst/sql/sql_server/NegativeControlOutcomes.sql +++ b/inst/sql/sql_server/NegativeControlOutcomes.sql @@ -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,