From 8d7d0199af2f93d49ffac227efb49abd119cb6d1 Mon Sep 17 00:00:00 2001 From: Clair Blacketer Date: Wed, 22 Sep 2021 15:50:21 -0400 Subject: [PATCH] Regenerate DDLs for CDM 5.4 --- .gitignore | 1 + R/buildRelease.R | 2 +- .../OMOPCDM_bigquery_5.4_constraints.sql | 24 ++++++++++++++-- .../5.4/bigquery/OMOPCDM_bigquery_5.4_ddl.sql | 14 +++++----- .../impala/OMOPCDM_impala_5.4_constraints.sql | 24 ++++++++++++++-- .../ddl/5.4/impala/OMOPCDM_impala_5.4_ddl.sql | 22 +++++++-------- .../OMOPCDM_netezza_5.4_constraints.sql | 24 ++++++++++++++-- .../5.4/netezza/OMOPCDM_netezza_5.4_ddl.sql | 28 +++++++++---------- .../oracle/OMOPCDM_oracle_5.4_constraints.sql | 24 ++++++++++++++-- .../ddl/5.4/oracle/OMOPCDM_oracle_5.4_ddl.sql | 28 +++++++++---------- .../5.4/pdw/OMOPCDM_pdw_5.4_constraints.sql | 24 ++++++++++++++-- inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_ddl.sql | 28 +++++++++---------- .../OMOPCDM_postgresql_5.4_constraints.sql | 24 ++++++++++++++-- .../postgresql/OMOPCDM_postgresql_5.4_ddl.sql | 28 +++++++++---------- .../OMOPCDM_redshift_5.4_constraints.sql | 24 ++++++++++++++-- .../5.4/redshift/OMOPCDM_redshift_5.4_ddl.sql | 28 +++++++++---------- .../OMOPCDM_sql_server_5.4_constraints.sql | 24 ++++++++++++++-- .../sql_server/OMOPCDM_sql_server_5.4_ddl.sql | 28 +++++++++---------- 18 files changed, 280 insertions(+), 119 deletions(-) diff --git a/.gitignore b/.gitignore index 9282ef1..c634810 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ extras/CodeToRun.R ehthumbs.db Thumbs.db extras/codeToRun.R +output/ diff --git a/R/buildRelease.R b/R/buildRelease.R index 15dae6b..4c3dbd1 100644 --- a/R/buildRelease.R +++ b/R/buildRelease.R @@ -73,7 +73,7 @@ buildRelease <- function(cdmVersions = listSupportedVersions(), #' buildReleaseZip <- function(cdmVersion, targetDialect = listSupportedDialects(), - outputfolder = file.path(getwd(), "inst", "ddl")){ + outputfolder = file.path(getwd(), "output")){ # argument checks stopifnot(is.character(cdmVersion), length(cdmVersion) == 1, cdmVersion %in% listSupportedVersions()) diff --git a/inst/ddl/5.4/bigquery/OMOPCDM_bigquery_5.4_constraints.sql b/inst/ddl/5.4/bigquery/OMOPCDM_bigquery_5.4_constraints.sql index 654387d..96ef0b9 100644 --- a/inst/ddl/5.4/bigquery/OMOPCDM_bigquery_5.4_constraints.sql +++ b/inst/ddl/5.4/bigquery/OMOPCDM_bigquery_5.4_constraints.sql @@ -102,6 +102,14 @@ alter table @cdmDatabaseSchema.procedure_occurrence add constraint fpk_procedure alter table @cdmDatabaseSchema.procedure_occurrence add constraint fpk_procedure_occurrence_modifier_concept_id foreign key (modifier_concept_id) references @cdmDatabaseSchema.concept (concept_id); +alter table @cdmDatabaseSchema.procedure_occurrence add constraint fpk_procedure_occurrence_provider_id foreign key (provider_id) references @cdmDatabaseSchema.provider (provider_id); + +alter table @cdmDatabaseSchema.procedure_occurrence add constraint fpk_procedure_occurrence_visit_occurrence_id foreign key (visit_occurrence_id) references @cdmDatabaseSchema.visit_occurrence (visit_occurrence_id); + +alter table @cdmDatabaseSchema.procedure_occurrence add constraint fpk_procedure_occurrence_visit_detail_id foreign key (visit_detail_id) references @cdmDatabaseSchema.visit_detail (visit_detail_id); + +alter table @cdmDatabaseSchema.procedure_occurrence add constraint fpk_procedure_occurrence_procedure_source_concept_id foreign key (procedure_source_concept_id) references @cdmDatabaseSchema.concept (concept_id); + alter table @cdmDatabaseSchema.device_exposure add constraint fpk_device_exposure_person_id foreign key (person_id) references @cdmDatabaseSchema.person (person_id); alter table @cdmDatabaseSchema.device_exposure add constraint fpk_device_exposure_device_concept_id foreign key (device_concept_id) references @cdmDatabaseSchema.concept (concept_id); @@ -116,6 +124,10 @@ alter table @cdmDatabaseSchema.device_exposure add constraint fpk_device_exposur alter table @cdmDatabaseSchema.device_exposure add constraint fpk_device_exposure_device_source_concept_id foreign key (device_source_concept_id) references @cdmDatabaseSchema.concept (concept_id); +alter table @cdmDatabaseSchema.device_exposure add constraint fpk_device_exposure_unit_concept_id foreign key (unit_concept_id) references @cdmDatabaseSchema.concept (concept_id); + +alter table @cdmDatabaseSchema.device_exposure add constraint fpk_device_exposure_unit_source_concept_id foreign key (unit_source_concept_id) references @cdmDatabaseSchema.concept (concept_id); + alter table @cdmDatabaseSchema.measurement add constraint fpk_measurement_person_id foreign key (person_id) references @cdmDatabaseSchema.person (person_id); alter table @cdmDatabaseSchema.measurement add constraint fpk_measurement_measurement_concept_id foreign key (measurement_concept_id) references @cdmDatabaseSchema.concept (concept_id); @@ -172,8 +184,6 @@ alter table @cdmDatabaseSchema.death add constraint fpk_death_cause_source_conce alter table @cdmDatabaseSchema.note add constraint fpk_note_person_id foreign key (person_id) references @cdmDatabaseSchema.person (person_id); -alter table @cdmDatabaseSchema.note add constraint fpk_note_note_event_field_concept_id foreign key (note_event_field_concept_id) references @cdmDatabaseSchema.concept (concept_id); - alter table @cdmDatabaseSchema.note add constraint fpk_note_note_type_concept_id foreign key (note_type_concept_id) references @cdmDatabaseSchema.concept (concept_id); alter table @cdmDatabaseSchema.note add constraint fpk_note_note_class_concept_id foreign key (note_class_concept_id) references @cdmDatabaseSchema.concept (concept_id); @@ -188,6 +198,8 @@ alter table @cdmDatabaseSchema.note add constraint fpk_note_visit_occurrence_id alter table @cdmDatabaseSchema.note add constraint fpk_note_visit_detail_id foreign key (visit_detail_id) references @cdmDatabaseSchema.visit_detail (visit_detail_id); +alter table @cdmDatabaseSchema.note add constraint fpk_note_note_event_field_concept_id foreign key (note_event_field_concept_id) references @cdmDatabaseSchema.concept (concept_id); + alter table @cdmDatabaseSchema.note_nlp add constraint fpk_note_nlp_section_concept_id foreign key (section_concept_id) references @cdmDatabaseSchema.concept (concept_id); alter table @cdmDatabaseSchema.note_nlp add constraint fpk_note_nlp_note_nlp_concept_id foreign key (note_nlp_concept_id) references @cdmDatabaseSchema.concept (concept_id); @@ -212,6 +224,8 @@ alter table @cdmDatabaseSchema.fact_relationship add constraint fpk_fact_relatio alter table @cdmDatabaseSchema.fact_relationship add constraint fpk_fact_relationship_relationship_concept_id foreign key (relationship_concept_id) references @cdmDatabaseSchema.concept (concept_id); +alter table @cdmDatabaseSchema.location add constraint fpk_location_country_concept_id foreign key (country_concept_id) references @cdmDatabaseSchema.concept (concept_id); + alter table @cdmDatabaseSchema.care_site add constraint fpk_care_site_place_of_service_concept_id foreign key (place_of_service_concept_id) references @cdmDatabaseSchema.concept (concept_id); alter table @cdmDatabaseSchema.care_site add constraint fpk_care_site_location_id foreign key (location_id) references @cdmDatabaseSchema.location (location_id); @@ -266,6 +280,8 @@ alter table @cdmDatabaseSchema.dose_era add constraint fpk_dose_era_drug_concept alter table @cdmDatabaseSchema.dose_era add constraint fpk_dose_era_unit_concept_id foreign key (unit_concept_id) references @cdmDatabaseSchema.concept (concept_id); +alter table @cdmDatabaseSchema.condition_era add constraint fpk_condition_era_person_id foreign key (person_id) references @cdmDatabaseSchema.person (person_id); + alter table @cdmDatabaseSchema.condition_era add constraint fpk_condition_era_condition_concept_id foreign key (condition_concept_id) references @cdmDatabaseSchema.concept (concept_id); alter table @cdmDatabaseSchema.episode add constraint fpk_episode_person_id foreign key (person_id) references @cdmDatabaseSchema.person (person_id); @@ -288,6 +304,8 @@ alter table @cdmDatabaseSchema.metadata add constraint fpk_metadata_metadata_typ alter table @cdmDatabaseSchema.metadata add constraint fpk_metadata_value_as_concept_id foreign key (value_as_concept_id) references @cdmDatabaseSchema.concept (concept_id); +alter table @cdmDatabaseSchema.cdm_source add constraint fpk_cdm_source_cdm_version_concept_id foreign key (cdm_version_concept_id) references @cdmDatabaseSchema.concept (concept_id); + alter table @cdmDatabaseSchema.concept add constraint fpk_concept_domain_id foreign key (domain_id) references @cdmDatabaseSchema.domain (domain_id); alter table @cdmDatabaseSchema.concept add constraint fpk_concept_vocabulary_id foreign key (vocabulary_id) references @cdmDatabaseSchema.vocabulary (vocabulary_id); @@ -332,6 +350,8 @@ alter table @cdmDatabaseSchema.drug_strength add constraint fpk_drug_strength_nu alter table @cdmDatabaseSchema.drug_strength add constraint fpk_drug_strength_denominator_unit_concept_id foreign key (denominator_unit_concept_id) references @cdmDatabaseSchema.concept (concept_id); +alter table @cdmDatabaseSchema.cohort_definition add constraint fpk_cohort_definition_cohort_definition_id foreign key (cohort_definition_id) references @cdmDatabaseSchema.cohort (cohort_definition_id); + alter table @cdmDatabaseSchema.cohort_definition add constraint fpk_cohort_definition_definition_type_concept_id foreign key (definition_type_concept_id) references @cdmDatabaseSchema.concept (concept_id); alter table @cdmDatabaseSchema.cohort_definition add constraint fpk_cohort_definition_subject_concept_id foreign key (subject_concept_id) references @cdmDatabaseSchema.concept (concept_id); diff --git a/inst/ddl/5.4/bigquery/OMOPCDM_bigquery_5.4_ddl.sql b/inst/ddl/5.4/bigquery/OMOPCDM_bigquery_5.4_ddl.sql index e81ca85..3e8deae 100644 --- a/inst/ddl/5.4/bigquery/OMOPCDM_bigquery_5.4_ddl.sql +++ b/inst/ddl/5.4/bigquery/OMOPCDM_bigquery_5.4_ddl.sql @@ -123,6 +123,8 @@ create table @cdmDatabaseSchema.procedure_occurrence ( procedure_concept_id INT64 not null, procedure_date date not null, procedure_datetime datetime null, + procedure_end_date date null, + procedure_end_datetime datetime null, procedure_type_concept_id INT64 not null, modifier_concept_id INT64, quantity INT64, @@ -131,9 +133,7 @@ create table @cdmDatabaseSchema.procedure_occurrence ( visit_detail_id INT64, procedure_source_value STRING, procedure_source_concept_id INT64, - modifier_source_value STRING, - procedure_status_source_value STRING, - procedure_status_concept_id INT64 not null ); + modifier_source_value STRING ); --HINT DISTRIBUTE ON KEY (person_id) create table @cdmDatabaseSchema.device_exposure ( @@ -221,8 +221,6 @@ create table @cdmDatabaseSchema.death ( create table @cdmDatabaseSchema.note ( note_id INT64 not null, person_id INT64 not null, - note_event_id INT64, - note_event_field_concept_id INT64, note_date date not null, note_datetime datetime null, note_type_concept_id INT64 not null, @@ -234,7 +232,9 @@ create table @cdmDatabaseSchema.note ( provider_id INT64, visit_occurrence_id INT64, visit_detail_id INT64, - note_source_value STRING ); + note_source_value STRING, + note_event_id INT64, + note_event_field_concept_id INT64 ); --HINT DISTRIBUTE ON RANDOM create table @cdmDatabaseSchema.note_nlp ( @@ -458,7 +458,7 @@ create table @cdmDatabaseSchema.concept ( create table @cdmDatabaseSchema.vocabulary ( vocabulary_id STRING not null, vocabulary_name STRING not null, - vocabulary_reference STRING not null, + vocabulary_reference STRING, vocabulary_version STRING, vocabulary_concept_id INT64 not null ); diff --git a/inst/ddl/5.4/impala/OMOPCDM_impala_5.4_constraints.sql b/inst/ddl/5.4/impala/OMOPCDM_impala_5.4_constraints.sql index 141c2cd..28c1204 100644 --- a/inst/ddl/5.4/impala/OMOPCDM_impala_5.4_constraints.sql +++ b/inst/ddl/5.4/impala/OMOPCDM_impala_5.4_constraints.sql @@ -102,6 +102,14 @@ ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_modifier_concept_id FOREIGN KEY (modifier_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_provider_id FOREIGN KEY (provider_id) REFERENCES @cdmDatabaseSchema.PROVIDER (PROVIDER_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_occurrence_id FOREIGN KEY (visit_occurrence_id) REFERENCES @cdmDatabaseSchema.VISIT_OCCURRENCE (VISIT_OCCURRENCE_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_procedure_source_concept_id FOREIGN KEY (procedure_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_concept_id FOREIGN KEY (device_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -116,6 +124,10 @@ ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSUR ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_source_concept_id FOREIGN KEY (device_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_source_concept_id FOREIGN KEY (unit_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_measurement_concept_id FOREIGN KEY (measurement_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -172,8 +184,6 @@ ALTER TABLE @cdmDatabaseSchema.DEATH ADD CONSTRAINT fpk_DEATH_cause_source_conce ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); -ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); - ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_type_concept_id FOREIGN KEY (note_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_class_concept_id FOREIGN KEY (note_class_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -188,6 +198,8 @@ ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_occurrence_id ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); +ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_section_concept_id FOREIGN KEY (section_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_note_nlp_concept_id FOREIGN KEY (note_nlp_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -212,6 +224,8 @@ ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIO ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIONSHIP_relationship_concept_id FOREIGN KEY (relationship_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.`location` ADD CONSTRAINT fpk_LOCATION_country_concept_id FOREIGN KEY (country_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_place_of_service_concept_id FOREIGN KEY (place_of_service_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_location_id FOREIGN KEY (location_id) REFERENCES @cdmDatabaseSchema.`location` (LOCATION_ID); @@ -266,6 +280,8 @@ ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_drug_concept ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); + ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_condition_concept_id FOREIGN KEY (condition_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.EPISODE ADD CONSTRAINT fpk_EPISODE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); @@ -288,6 +304,8 @@ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_metadata_typ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_value_as_concept_id FOREIGN KEY (value_as_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CDM_SOURCE ADD CONSTRAINT fpk_CDM_SOURCE_cdm_version_concept_id FOREIGN KEY (cdm_version_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_domain_id FOREIGN KEY (domain_id) REFERENCES @cdmDatabaseSchema.DOMAIN (DOMAIN_ID); ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_vocabulary_id FOREIGN KEY (vocabulary_id) REFERENCES @cdmDatabaseSchema.VOCABULARY (VOCABULARY_ID); @@ -332,6 +350,8 @@ ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_nu ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_denominator_unit_concept_id FOREIGN KEY (denominator_unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_cohort_definition_id FOREIGN KEY (cohort_definition_id) REFERENCES @cdmDatabaseSchema.COHORT (COHORT_DEFINITION_ID); + ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_definition_type_concept_id FOREIGN KEY (definition_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_subject_concept_id FOREIGN KEY (subject_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); diff --git a/inst/ddl/5.4/impala/OMOPCDM_impala_5.4_ddl.sql b/inst/ddl/5.4/impala/OMOPCDM_impala_5.4_ddl.sql index 47a6ffc..e8b4ca1 100644 --- a/inst/ddl/5.4/impala/OMOPCDM_impala_5.4_ddl.sql +++ b/inst/ddl/5.4/impala/OMOPCDM_impala_5.4_ddl.sql @@ -123,6 +123,8 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ( procedure_concept_id INT, procedure_date TIMESTAMP, procedure_datetime TIMESTAMP, + procedure_end_date TIMESTAMP, + procedure_end_datetime TIMESTAMP, procedure_type_concept_id INT, modifier_concept_id integer NULL, quantity integer NULL, @@ -131,9 +133,7 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ( visit_detail_id integer NULL, procedure_source_value VARCHAR(50), procedure_source_concept_id integer NULL, - modifier_source_value VARCHAR(50), - procedure_status_source_value VARCHAR(50), - procedure_status_concept_id INT ); + modifier_source_value VARCHAR(50) ); --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ( @@ -221,8 +221,6 @@ CREATE TABLE @cdmDatabaseSchema.DEATH ( CREATE TABLE @cdmDatabaseSchema.NOTE ( note_id INT, person_id INT, - note_event_id BIGINT, - note_event_field_concept_id integer NULL, note_date TIMESTAMP, note_datetime TIMESTAMP, note_type_concept_id INT, @@ -234,7 +232,9 @@ CREATE TABLE @cdmDatabaseSchema.NOTE ( provider_id integer NULL, visit_occurrence_id integer NULL, visit_detail_id integer NULL, - note_source_value VARCHAR(50) ); + note_source_value VARCHAR(50), + note_event_id BIGINT, + note_event_field_concept_id integer NULL ); --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.NOTE_NLP ( @@ -395,14 +395,14 @@ CREATE TABLE @cdmDatabaseSchema.CONDITION_ERA ( --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.EPISODE ( - episode_id INT, - person_id INT, + episode_id BIGINT, + person_id BIGINT, episode_concept_id INT, episode_start_date TIMESTAMP, episode_start_datetime TIMESTAMP, episode_end_date TIMESTAMP, episode_end_datetime TIMESTAMP, - episode_parent_id integer NULL, + episode_parent_id BIGINT, episode_number integer NULL, episode_object_concept_id INT, episode_type_concept_id INT, @@ -411,8 +411,8 @@ CREATE TABLE @cdmDatabaseSchema.EPISODE ( --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.EPISODE_EVENT ( - episode_id INT, - event_id INT, + episode_id BIGINT, + event_id BIGINT, episode_event_field_concept_id INT ); --HINT DISTRIBUTE ON RANDOM diff --git a/inst/ddl/5.4/netezza/OMOPCDM_netezza_5.4_constraints.sql b/inst/ddl/5.4/netezza/OMOPCDM_netezza_5.4_constraints.sql index dc66e00..ae85da7 100644 --- a/inst/ddl/5.4/netezza/OMOPCDM_netezza_5.4_constraints.sql +++ b/inst/ddl/5.4/netezza/OMOPCDM_netezza_5.4_constraints.sql @@ -102,6 +102,14 @@ ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_modifier_concept_id FOREIGN KEY (modifier_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_provider_id FOREIGN KEY (provider_id) REFERENCES @cdmDatabaseSchema.PROVIDER (PROVIDER_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_occurrence_id FOREIGN KEY (visit_occurrence_id) REFERENCES @cdmDatabaseSchema.VISIT_OCCURRENCE (VISIT_OCCURRENCE_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_procedure_source_concept_id FOREIGN KEY (procedure_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_concept_id FOREIGN KEY (device_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -116,6 +124,10 @@ ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSUR ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_source_concept_id FOREIGN KEY (device_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_source_concept_id FOREIGN KEY (unit_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_measurement_concept_id FOREIGN KEY (measurement_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -172,8 +184,6 @@ ALTER TABLE @cdmDatabaseSchema.DEATH ADD CONSTRAINT fpk_DEATH_cause_source_conce ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); -ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); - ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_type_concept_id FOREIGN KEY (note_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_class_concept_id FOREIGN KEY (note_class_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -188,6 +198,8 @@ ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_occurrence_id ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); +ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_section_concept_id FOREIGN KEY (section_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_note_nlp_concept_id FOREIGN KEY (note_nlp_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -212,6 +224,8 @@ ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIO ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIONSHIP_relationship_concept_id FOREIGN KEY (relationship_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.LOCATION ADD CONSTRAINT fpk_LOCATION_country_concept_id FOREIGN KEY (country_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_place_of_service_concept_id FOREIGN KEY (place_of_service_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_location_id FOREIGN KEY (location_id) REFERENCES @cdmDatabaseSchema.LOCATION (LOCATION_ID); @@ -266,6 +280,8 @@ ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_drug_concept ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); + ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_condition_concept_id FOREIGN KEY (condition_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.EPISODE ADD CONSTRAINT fpk_EPISODE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); @@ -288,6 +304,8 @@ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_metadata_typ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_value_as_concept_id FOREIGN KEY (value_as_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CDM_SOURCE ADD CONSTRAINT fpk_CDM_SOURCE_cdm_version_concept_id FOREIGN KEY (cdm_version_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_domain_id FOREIGN KEY (domain_id) REFERENCES @cdmDatabaseSchema.DOMAIN (DOMAIN_ID); ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_vocabulary_id FOREIGN KEY (vocabulary_id) REFERENCES @cdmDatabaseSchema.VOCABULARY (VOCABULARY_ID); @@ -332,6 +350,8 @@ ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_nu ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_denominator_unit_concept_id FOREIGN KEY (denominator_unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_cohort_definition_id FOREIGN KEY (cohort_definition_id) REFERENCES @cdmDatabaseSchema.COHORT (COHORT_DEFINITION_ID); + ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_definition_type_concept_id FOREIGN KEY (definition_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_subject_concept_id FOREIGN KEY (subject_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); diff --git a/inst/ddl/5.4/netezza/OMOPCDM_netezza_5.4_ddl.sql b/inst/ddl/5.4/netezza/OMOPCDM_netezza_5.4_ddl.sql index fb146df..ed0ef42 100644 --- a/inst/ddl/5.4/netezza/OMOPCDM_netezza_5.4_ddl.sql +++ b/inst/ddl/5.4/netezza/OMOPCDM_netezza_5.4_ddl.sql @@ -64,8 +64,8 @@ CREATE TABLE @cdmDatabaseSchema.VISIT_DETAIL ( visit_detail_source_value varchar(50) NULL, visit_detail_source_concept_id Integer NULL, admitted_from_concept_id Integer NULL, - admitted_from_source_value Varchar(50) NULL, - discharged_to_source_value Varchar(50) NULL, + admitted_from_source_value varchar(50) NULL, + discharged_to_source_value varchar(50) NULL, discharged_to_concept_id integer NULL, preceding_visit_detail_id integer NULL, parent_visit_detail_id integer NULL, @@ -123,6 +123,8 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ( procedure_concept_id integer NOT NULL, procedure_date date NOT NULL, procedure_datetime TIMESTAMP NULL, + procedure_end_date date NULL, + procedure_end_datetime TIMESTAMP NULL, procedure_type_concept_id integer NOT NULL, modifier_concept_id integer NULL, quantity integer NULL, @@ -131,9 +133,7 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ( visit_detail_id integer NULL, procedure_source_value varchar(50) NULL, procedure_source_concept_id integer NULL, - modifier_source_value varchar(50) NULL, - procedure_status_source_value varchar(50) NULL, - procedure_status_concept_id integer NOT NULL ); + modifier_source_value varchar(50) NULL ); --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ( @@ -221,8 +221,6 @@ CREATE TABLE @cdmDatabaseSchema.DEATH ( CREATE TABLE @cdmDatabaseSchema.NOTE ( note_id integer NOT NULL, person_id integer NOT NULL, - note_event_id bigint NULL, - note_event_field_concept_id integer NULL, note_date date NOT NULL, note_datetime TIMESTAMP NULL, note_type_concept_id integer NOT NULL, @@ -234,7 +232,9 @@ CREATE TABLE @cdmDatabaseSchema.NOTE ( provider_id integer NULL, visit_occurrence_id integer NULL, visit_detail_id integer NULL, - note_source_value varchar(50) NULL ); + note_source_value varchar(50) NULL, + note_event_id bigint NULL, + note_event_field_concept_id integer NULL ); --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.NOTE_NLP ( @@ -395,14 +395,14 @@ CREATE TABLE @cdmDatabaseSchema.CONDITION_ERA ( --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.EPISODE ( - episode_id integer NOT NULL, - person_id integer NOT NULL, + episode_id bigint NOT NULL, + person_id bigint NOT NULL, episode_concept_id integer NOT NULL, episode_start_date date NOT NULL, episode_start_datetime TIMESTAMP NULL, episode_end_date date NULL, episode_end_datetime TIMESTAMP NULL, - episode_parent_id integer NULL, + episode_parent_id bigint NULL, episode_number integer NULL, episode_object_concept_id integer NOT NULL, episode_type_concept_id integer NOT NULL, @@ -411,8 +411,8 @@ CREATE TABLE @cdmDatabaseSchema.EPISODE ( --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.EPISODE_EVENT ( - episode_id integer NOT NULL, - event_id integer NOT NULL, + episode_id bigint NOT NULL, + event_id bigint NOT NULL, episode_event_field_concept_id integer NOT NULL ); --HINT DISTRIBUTE ON RANDOM @@ -458,7 +458,7 @@ CREATE TABLE @cdmDatabaseSchema.CONCEPT ( CREATE TABLE @cdmDatabaseSchema.VOCABULARY ( vocabulary_id varchar(20) NOT NULL, vocabulary_name varchar(255) NOT NULL, - vocabulary_reference varchar(255) NOT NULL, + vocabulary_reference varchar(255) NULL, vocabulary_version varchar(255) NULL, vocabulary_concept_id integer NOT NULL ); diff --git a/inst/ddl/5.4/oracle/OMOPCDM_oracle_5.4_constraints.sql b/inst/ddl/5.4/oracle/OMOPCDM_oracle_5.4_constraints.sql index 3570a25..f35297c 100644 --- a/inst/ddl/5.4/oracle/OMOPCDM_oracle_5.4_constraints.sql +++ b/inst/ddl/5.4/oracle/OMOPCDM_oracle_5.4_constraints.sql @@ -102,6 +102,14 @@ ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_modifier_concept_id FOREIGN KEY (modifier_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_provider_id FOREIGN KEY (provider_id) REFERENCES @cdmDatabaseSchema.PROVIDER (PROVIDER_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_occurrence_id FOREIGN KEY (visit_occurrence_id) REFERENCES @cdmDatabaseSchema.VISIT_OCCURRENCE (VISIT_OCCURRENCE_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_procedure_source_concept_id FOREIGN KEY (procedure_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_concept_id FOREIGN KEY (device_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -116,6 +124,10 @@ ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSUR ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_source_concept_id FOREIGN KEY (device_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_source_concept_id FOREIGN KEY (unit_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_measurement_concept_id FOREIGN KEY (measurement_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -172,8 +184,6 @@ ALTER TABLE @cdmDatabaseSchema.DEATH ADD CONSTRAINT fpk_DEATH_cause_source_conce ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); -ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); - ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_type_concept_id FOREIGN KEY (note_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_class_concept_id FOREIGN KEY (note_class_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -188,6 +198,8 @@ ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_occurrence_id ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); +ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_section_concept_id FOREIGN KEY (section_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_note_nlp_concept_id FOREIGN KEY (note_nlp_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -212,6 +224,8 @@ ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIO ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIONSHIP_relationship_concept_id FOREIGN KEY (relationship_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.LOCATION ADD CONSTRAINT fpk_LOCATION_country_concept_id FOREIGN KEY (country_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_place_of_service_concept_id FOREIGN KEY (place_of_service_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_location_id FOREIGN KEY (location_id) REFERENCES @cdmDatabaseSchema.LOCATION (LOCATION_ID); @@ -266,6 +280,8 @@ ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_drug_concept ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); + ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_condition_concept_id FOREIGN KEY (condition_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.EPISODE ADD CONSTRAINT fpk_EPISODE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); @@ -288,6 +304,8 @@ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_metadata_typ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_value_as_concept_id FOREIGN KEY (value_as_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CDM_SOURCE ADD CONSTRAINT fpk_CDM_SOURCE_cdm_version_concept_id FOREIGN KEY (cdm_version_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_domain_id FOREIGN KEY (domain_id) REFERENCES @cdmDatabaseSchema.DOMAIN (DOMAIN_ID); ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_vocabulary_id FOREIGN KEY (vocabulary_id) REFERENCES @cdmDatabaseSchema.VOCABULARY (VOCABULARY_ID); @@ -332,6 +350,8 @@ ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_nu ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_denominator_unit_concept_id FOREIGN KEY (denominator_unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_cohort_definition_id FOREIGN KEY (cohort_definition_id) REFERENCES @cdmDatabaseSchema.COHORT (COHORT_DEFINITION_ID); + ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_definition_type_concept_id FOREIGN KEY (definition_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_subject_concept_id FOREIGN KEY (subject_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); diff --git a/inst/ddl/5.4/oracle/OMOPCDM_oracle_5.4_ddl.sql b/inst/ddl/5.4/oracle/OMOPCDM_oracle_5.4_ddl.sql index 4923ccf..c80b1c3 100644 --- a/inst/ddl/5.4/oracle/OMOPCDM_oracle_5.4_ddl.sql +++ b/inst/ddl/5.4/oracle/OMOPCDM_oracle_5.4_ddl.sql @@ -64,8 +64,8 @@ CREATE TABLE @cdmDatabaseSchema.VISIT_DETAIL ( visit_detail_source_value varchar(50) NULL, visit_detail_source_concept_id Integer NULL, admitted_from_concept_id Integer NULL, - admitted_from_source_value Varchar(50) NULL, - discharged_to_source_value Varchar(50) NULL, + admitted_from_source_value varchar(50) NULL, + discharged_to_source_value varchar(50) NULL, discharged_to_concept_id integer NULL, preceding_visit_detail_id integer NULL, parent_visit_detail_id integer NULL, @@ -123,6 +123,8 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ( procedure_concept_id integer NOT NULL, procedure_date date NOT NULL, procedure_datetime TIMESTAMP NULL, + procedure_end_date date NULL, + procedure_end_datetime TIMESTAMP NULL, procedure_type_concept_id integer NOT NULL, modifier_concept_id integer NULL, quantity integer NULL, @@ -131,9 +133,7 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ( visit_detail_id integer NULL, procedure_source_value varchar(50) NULL, procedure_source_concept_id integer NULL, - modifier_source_value varchar(50) NULL, - procedure_status_source_value varchar(50) NULL, - procedure_status_concept_id integer NOT NULL ); + modifier_source_value varchar(50) NULL ); --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ( @@ -221,8 +221,6 @@ CREATE TABLE @cdmDatabaseSchema.DEATH ( CREATE TABLE @cdmDatabaseSchema.NOTE ( note_id integer NOT NULL, person_id integer NOT NULL, - note_event_id NUMBER(19) NULL, - note_event_field_concept_id integer NULL, note_date date NOT NULL, note_datetime TIMESTAMP NULL, note_type_concept_id integer NOT NULL, @@ -234,7 +232,9 @@ CREATE TABLE @cdmDatabaseSchema.NOTE ( provider_id integer NULL, visit_occurrence_id integer NULL, visit_detail_id integer NULL, - note_source_value varchar(50) NULL ); + note_source_value varchar(50) NULL, + note_event_id NUMBER(19) NULL, + note_event_field_concept_id integer NULL ); --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.NOTE_NLP ( @@ -395,14 +395,14 @@ CREATE TABLE @cdmDatabaseSchema.CONDITION_ERA ( --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.EPISODE ( - episode_id integer NOT NULL, - person_id integer NOT NULL, + episode_id NUMBER(19) NOT NULL, + person_id NUMBER(19) NOT NULL, episode_concept_id integer NOT NULL, episode_start_date date NOT NULL, episode_start_datetime TIMESTAMP NULL, episode_end_date date NULL, episode_end_datetime TIMESTAMP NULL, - episode_parent_id integer NULL, + episode_parent_id NUMBER(19) NULL, episode_number integer NULL, episode_object_concept_id integer NOT NULL, episode_type_concept_id integer NOT NULL, @@ -411,8 +411,8 @@ CREATE TABLE @cdmDatabaseSchema.EPISODE ( --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.EPISODE_EVENT ( - episode_id integer NOT NULL, - event_id integer NOT NULL, + episode_id NUMBER(19) NOT NULL, + event_id NUMBER(19) NOT NULL, episode_event_field_concept_id integer NOT NULL ); --HINT DISTRIBUTE ON RANDOM @@ -458,7 +458,7 @@ CREATE TABLE @cdmDatabaseSchema.CONCEPT ( CREATE TABLE @cdmDatabaseSchema.VOCABULARY ( vocabulary_id varchar(20) NOT NULL, vocabulary_name varchar(255) NOT NULL, - vocabulary_reference varchar(255) NOT NULL, + vocabulary_reference varchar(255) NULL, vocabulary_version varchar(255) NULL, vocabulary_concept_id integer NOT NULL ); diff --git a/inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_constraints.sql b/inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_constraints.sql index 1e5807c..be22f0f 100644 --- a/inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_constraints.sql +++ b/inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_constraints.sql @@ -102,6 +102,14 @@ ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_modifier_concept_id FOREIGN KEY (modifier_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_provider_id FOREIGN KEY (provider_id) REFERENCES @cdmDatabaseSchema.PROVIDER (PROVIDER_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_occurrence_id FOREIGN KEY (visit_occurrence_id) REFERENCES @cdmDatabaseSchema.VISIT_OCCURRENCE (VISIT_OCCURRENCE_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_procedure_source_concept_id FOREIGN KEY (procedure_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_concept_id FOREIGN KEY (device_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -116,6 +124,10 @@ ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSUR ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_source_concept_id FOREIGN KEY (device_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_source_concept_id FOREIGN KEY (unit_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_measurement_concept_id FOREIGN KEY (measurement_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -172,8 +184,6 @@ ALTER TABLE @cdmDatabaseSchema.DEATH ADD CONSTRAINT fpk_DEATH_cause_source_conce ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); -ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); - ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_type_concept_id FOREIGN KEY (note_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_class_concept_id FOREIGN KEY (note_class_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -188,6 +198,8 @@ ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_occurrence_id ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); +ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_section_concept_id FOREIGN KEY (section_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_note_nlp_concept_id FOREIGN KEY (note_nlp_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -212,6 +224,8 @@ ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIO ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIONSHIP_relationship_concept_id FOREIGN KEY (relationship_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.LOCATION ADD CONSTRAINT fpk_LOCATION_country_concept_id FOREIGN KEY (country_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_place_of_service_concept_id FOREIGN KEY (place_of_service_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_location_id FOREIGN KEY (location_id) REFERENCES @cdmDatabaseSchema.LOCATION (LOCATION_ID); @@ -266,6 +280,8 @@ ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_drug_concept ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); + ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_condition_concept_id FOREIGN KEY (condition_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.EPISODE ADD CONSTRAINT fpk_EPISODE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); @@ -288,6 +304,8 @@ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_metadata_typ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_value_as_concept_id FOREIGN KEY (value_as_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CDM_SOURCE ADD CONSTRAINT fpk_CDM_SOURCE_cdm_version_concept_id FOREIGN KEY (cdm_version_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_domain_id FOREIGN KEY (domain_id) REFERENCES @cdmDatabaseSchema.DOMAIN (DOMAIN_ID); ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_vocabulary_id FOREIGN KEY (vocabulary_id) REFERENCES @cdmDatabaseSchema.VOCABULARY (VOCABULARY_ID); @@ -332,6 +350,8 @@ ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_nu ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_denominator_unit_concept_id FOREIGN KEY (denominator_unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_cohort_definition_id FOREIGN KEY (cohort_definition_id) REFERENCES @cdmDatabaseSchema.COHORT (COHORT_DEFINITION_ID); + ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_definition_type_concept_id FOREIGN KEY (definition_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_subject_concept_id FOREIGN KEY (subject_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); diff --git a/inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_ddl.sql b/inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_ddl.sql index 7c9ab27..dcdff2b 100644 --- a/inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_ddl.sql +++ b/inst/ddl/5.4/pdw/OMOPCDM_pdw_5.4_ddl.sql @@ -63,8 +63,8 @@ IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.VISIT_DETAIL (visi visit_detail_source_value varchar(50) NULL, visit_detail_source_concept_id Integer NULL, admitted_from_concept_id Integer NULL, - admitted_from_source_value Varchar(50) NULL, - discharged_to_source_value Varchar(50) NULL, + admitted_from_source_value varchar(50) NULL, + discharged_to_source_value varchar(50) NULL, discharged_to_concept_id integer NULL, preceding_visit_detail_id integer NULL, parent_visit_detail_id integer NULL, @@ -122,6 +122,8 @@ IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENC procedure_concept_id integer NOT NULL, procedure_date date NOT NULL, procedure_datetime datetime NULL, + procedure_end_date date NULL, + procedure_end_datetime datetime NULL, procedure_type_concept_id integer NOT NULL, modifier_concept_id integer NULL, quantity integer NULL, @@ -130,9 +132,7 @@ IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENC visit_detail_id integer NULL, procedure_source_value varchar(50) NULL, procedure_source_concept_id integer NULL, - modifier_source_value varchar(50) NULL, - procedure_status_source_value varchar(50) NULL, - procedure_status_concept_id integer NOT NULL ) + modifier_source_value varchar(50) NULL ) WITH (DISTRIBUTION = HASH(person_id)); --HINT DISTRIBUTE ON KEY (person_id) @@ -220,8 +220,6 @@ WITH (DISTRIBUTION = HASH(person_id)); --HINT DISTRIBUTE ON KEY (person_id) IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.NOTE (note_id integer NOT NULL, person_id integer NOT NULL, - note_event_id bigint NULL, - note_event_field_concept_id integer NULL, note_date date NOT NULL, note_datetime datetime NULL, note_type_concept_id integer NOT NULL, @@ -233,7 +231,9 @@ IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.NOTE (note_id inte provider_id integer NULL, visit_occurrence_id integer NULL, visit_detail_id integer NULL, - note_source_value varchar(50) NULL ) + note_source_value varchar(50) NULL, + note_event_id bigint NULL, + note_event_field_concept_id integer NULL ) WITH (DISTRIBUTION = HASH(person_id)); --HINT DISTRIBUTE ON RANDOM @@ -394,14 +394,14 @@ IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.CONDITION_ERA (con WITH (DISTRIBUTION = HASH(person_id)); --HINT DISTRIBUTE ON KEY (person_id) -IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.EPISODE (episode_id integer NOT NULL, - person_id integer NOT NULL, +IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.EPISODE (episode_id bigint NOT NULL, + person_id bigint NOT NULL, episode_concept_id integer NOT NULL, episode_start_date date NOT NULL, episode_start_datetime datetime NULL, episode_end_date date NULL, episode_end_datetime datetime NULL, - episode_parent_id integer NULL, + episode_parent_id bigint NULL, episode_number integer NULL, episode_object_concept_id integer NOT NULL, episode_type_concept_id integer NOT NULL, @@ -410,8 +410,8 @@ IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.EPISODE (episode_i WITH (DISTRIBUTION = HASH(person_id)); --HINT DISTRIBUTE ON RANDOM -IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.EPISODE_EVENT (episode_id integer NOT NULL, - event_id integer NOT NULL, +IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.EPISODE_EVENT (episode_id bigint NOT NULL, + event_id bigint NOT NULL, episode_event_field_concept_id integer NOT NULL ) WITH (DISTRIBUTION = REPLICATE); @@ -457,7 +457,7 @@ WITH (DISTRIBUTION = REPLICATE); --HINT DISTRIBUTE ON RANDOM IF XACT_STATE() = 1 COMMIT; CREATE TABLE @cdmDatabaseSchema.VOCABULARY (vocabulary_id varchar(20) NOT NULL, vocabulary_name varchar(255) NOT NULL, - vocabulary_reference varchar(255) NOT NULL, + vocabulary_reference varchar(255) NULL, vocabulary_version varchar(255) NULL, vocabulary_concept_id integer NOT NULL ) WITH (DISTRIBUTION = REPLICATE); diff --git a/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_constraints.sql b/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_constraints.sql index 00e8c17..004ee9c 100644 --- a/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_constraints.sql +++ b/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_constraints.sql @@ -102,6 +102,14 @@ ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_modifier_concept_id FOREIGN KEY (modifier_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_provider_id FOREIGN KEY (provider_id) REFERENCES @cdmDatabaseSchema.PROVIDER (PROVIDER_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_occurrence_id FOREIGN KEY (visit_occurrence_id) REFERENCES @cdmDatabaseSchema.VISIT_OCCURRENCE (VISIT_OCCURRENCE_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_procedure_source_concept_id FOREIGN KEY (procedure_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_concept_id FOREIGN KEY (device_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -116,6 +124,10 @@ ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSUR ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_source_concept_id FOREIGN KEY (device_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_source_concept_id FOREIGN KEY (unit_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_measurement_concept_id FOREIGN KEY (measurement_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -172,8 +184,6 @@ ALTER TABLE @cdmDatabaseSchema.DEATH ADD CONSTRAINT fpk_DEATH_cause_source_conce ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); -ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); - ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_type_concept_id FOREIGN KEY (note_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_class_concept_id FOREIGN KEY (note_class_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -188,6 +198,8 @@ ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_occurrence_id ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); +ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_section_concept_id FOREIGN KEY (section_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_note_nlp_concept_id FOREIGN KEY (note_nlp_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -212,6 +224,8 @@ ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIO ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIONSHIP_relationship_concept_id FOREIGN KEY (relationship_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.LOCATION ADD CONSTRAINT fpk_LOCATION_country_concept_id FOREIGN KEY (country_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_place_of_service_concept_id FOREIGN KEY (place_of_service_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_location_id FOREIGN KEY (location_id) REFERENCES @cdmDatabaseSchema.LOCATION (LOCATION_ID); @@ -266,6 +280,8 @@ ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_drug_concept ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); + ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_condition_concept_id FOREIGN KEY (condition_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.EPISODE ADD CONSTRAINT fpk_EPISODE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); @@ -288,6 +304,8 @@ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_metadata_typ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_value_as_concept_id FOREIGN KEY (value_as_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CDM_SOURCE ADD CONSTRAINT fpk_CDM_SOURCE_cdm_version_concept_id FOREIGN KEY (cdm_version_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_domain_id FOREIGN KEY (domain_id) REFERENCES @cdmDatabaseSchema.DOMAIN (DOMAIN_ID); ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_vocabulary_id FOREIGN KEY (vocabulary_id) REFERENCES @cdmDatabaseSchema.VOCABULARY (VOCABULARY_ID); @@ -332,6 +350,8 @@ ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_nu ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_denominator_unit_concept_id FOREIGN KEY (denominator_unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_cohort_definition_id FOREIGN KEY (cohort_definition_id) REFERENCES @cdmDatabaseSchema.COHORT (COHORT_DEFINITION_ID); + ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_definition_type_concept_id FOREIGN KEY (definition_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_subject_concept_id FOREIGN KEY (subject_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); diff --git a/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_ddl.sql b/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_ddl.sql index b80dcbc..0e23afd 100644 --- a/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_ddl.sql +++ b/inst/ddl/5.4/postgresql/OMOPCDM_postgresql_5.4_ddl.sql @@ -64,8 +64,8 @@ CREATE TABLE @cdmDatabaseSchema.VISIT_DETAIL ( visit_detail_source_value varchar(50) NULL, visit_detail_source_concept_id Integer NULL, admitted_from_concept_id Integer NULL, - admitted_from_source_value Varchar(50) NULL, - discharged_to_source_value Varchar(50) NULL, + admitted_from_source_value varchar(50) NULL, + discharged_to_source_value varchar(50) NULL, discharged_to_concept_id integer NULL, preceding_visit_detail_id integer NULL, parent_visit_detail_id integer NULL, @@ -123,6 +123,8 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ( procedure_concept_id integer NOT NULL, procedure_date date NOT NULL, procedure_datetime TIMESTAMP NULL, + procedure_end_date date NULL, + procedure_end_datetime TIMESTAMP NULL, procedure_type_concept_id integer NOT NULL, modifier_concept_id integer NULL, quantity integer NULL, @@ -131,9 +133,7 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ( visit_detail_id integer NULL, procedure_source_value varchar(50) NULL, procedure_source_concept_id integer NULL, - modifier_source_value varchar(50) NULL, - procedure_status_source_value varchar(50) NULL, - procedure_status_concept_id integer NOT NULL ); + modifier_source_value varchar(50) NULL ); --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ( @@ -221,8 +221,6 @@ CREATE TABLE @cdmDatabaseSchema.DEATH ( CREATE TABLE @cdmDatabaseSchema.NOTE ( note_id integer NOT NULL, person_id integer NOT NULL, - note_event_id bigint NULL, - note_event_field_concept_id integer NULL, note_date date NOT NULL, note_datetime TIMESTAMP NULL, note_type_concept_id integer NOT NULL, @@ -234,7 +232,9 @@ CREATE TABLE @cdmDatabaseSchema.NOTE ( provider_id integer NULL, visit_occurrence_id integer NULL, visit_detail_id integer NULL, - note_source_value varchar(50) NULL ); + note_source_value varchar(50) NULL, + note_event_id bigint NULL, + note_event_field_concept_id integer NULL ); --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.NOTE_NLP ( @@ -395,14 +395,14 @@ CREATE TABLE @cdmDatabaseSchema.CONDITION_ERA ( --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.EPISODE ( - episode_id integer NOT NULL, - person_id integer NOT NULL, + episode_id bigint NOT NULL, + person_id bigint NOT NULL, episode_concept_id integer NOT NULL, episode_start_date date NOT NULL, episode_start_datetime TIMESTAMP NULL, episode_end_date date NULL, episode_end_datetime TIMESTAMP NULL, - episode_parent_id integer NULL, + episode_parent_id bigint NULL, episode_number integer NULL, episode_object_concept_id integer NOT NULL, episode_type_concept_id integer NOT NULL, @@ -411,8 +411,8 @@ CREATE TABLE @cdmDatabaseSchema.EPISODE ( --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.EPISODE_EVENT ( - episode_id integer NOT NULL, - event_id integer NOT NULL, + episode_id bigint NOT NULL, + event_id bigint NOT NULL, episode_event_field_concept_id integer NOT NULL ); --HINT DISTRIBUTE ON RANDOM @@ -458,7 +458,7 @@ CREATE TABLE @cdmDatabaseSchema.CONCEPT ( CREATE TABLE @cdmDatabaseSchema.VOCABULARY ( vocabulary_id varchar(20) NOT NULL, vocabulary_name varchar(255) NOT NULL, - vocabulary_reference varchar(255) NOT NULL, + vocabulary_reference varchar(255) NULL, vocabulary_version varchar(255) NULL, vocabulary_concept_id integer NOT NULL ); diff --git a/inst/ddl/5.4/redshift/OMOPCDM_redshift_5.4_constraints.sql b/inst/ddl/5.4/redshift/OMOPCDM_redshift_5.4_constraints.sql index 38b09d3..cd53626 100644 --- a/inst/ddl/5.4/redshift/OMOPCDM_redshift_5.4_constraints.sql +++ b/inst/ddl/5.4/redshift/OMOPCDM_redshift_5.4_constraints.sql @@ -102,6 +102,14 @@ ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_modifier_concept_id FOREIGN KEY (modifier_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_provider_id FOREIGN KEY (provider_id) REFERENCES @cdmDatabaseSchema.PROVIDER (PROVIDER_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_occurrence_id FOREIGN KEY (visit_occurrence_id) REFERENCES @cdmDatabaseSchema.VISIT_OCCURRENCE (VISIT_OCCURRENCE_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_procedure_source_concept_id FOREIGN KEY (procedure_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_concept_id FOREIGN KEY (device_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -116,6 +124,10 @@ ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSUR ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_source_concept_id FOREIGN KEY (device_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_source_concept_id FOREIGN KEY (unit_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_measurement_concept_id FOREIGN KEY (measurement_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -172,8 +184,6 @@ ALTER TABLE @cdmDatabaseSchema.DEATH ADD CONSTRAINT fpk_DEATH_cause_source_conce ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); -ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); - ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_type_concept_id FOREIGN KEY (note_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_class_concept_id FOREIGN KEY (note_class_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -188,6 +198,8 @@ ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_occurrence_id ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); +ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_section_concept_id FOREIGN KEY (section_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_note_nlp_concept_id FOREIGN KEY (note_nlp_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -212,6 +224,8 @@ ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIO ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIONSHIP_relationship_concept_id FOREIGN KEY (relationship_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.LOCATION ADD CONSTRAINT fpk_LOCATION_country_concept_id FOREIGN KEY (country_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_place_of_service_concept_id FOREIGN KEY (place_of_service_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_location_id FOREIGN KEY (location_id) REFERENCES @cdmDatabaseSchema.LOCATION (LOCATION_ID); @@ -266,6 +280,8 @@ ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_drug_concept ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); + ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_condition_concept_id FOREIGN KEY (condition_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.EPISODE ADD CONSTRAINT fpk_EPISODE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); @@ -288,6 +304,8 @@ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_metadata_typ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_value_as_concept_id FOREIGN KEY (value_as_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CDM_SOURCE ADD CONSTRAINT fpk_CDM_SOURCE_cdm_version_concept_id FOREIGN KEY (cdm_version_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_domain_id FOREIGN KEY (domain_id) REFERENCES @cdmDatabaseSchema.DOMAIN (DOMAIN_ID); ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_vocabulary_id FOREIGN KEY (vocabulary_id) REFERENCES @cdmDatabaseSchema.VOCABULARY (VOCABULARY_ID); @@ -332,6 +350,8 @@ ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_nu ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_denominator_unit_concept_id FOREIGN KEY (denominator_unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_cohort_definition_id FOREIGN KEY (cohort_definition_id) REFERENCES @cdmDatabaseSchema.COHORT (COHORT_DEFINITION_ID); + ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_definition_type_concept_id FOREIGN KEY (definition_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_subject_concept_id FOREIGN KEY (subject_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); diff --git a/inst/ddl/5.4/redshift/OMOPCDM_redshift_5.4_ddl.sql b/inst/ddl/5.4/redshift/OMOPCDM_redshift_5.4_ddl.sql index 83d2293..a327a79 100644 --- a/inst/ddl/5.4/redshift/OMOPCDM_redshift_5.4_ddl.sql +++ b/inst/ddl/5.4/redshift/OMOPCDM_redshift_5.4_ddl.sql @@ -63,8 +63,8 @@ CREATE TABLE @cdmDatabaseSchema.VISIT_DETAIL (visit_detail_id integer NOT NULL, visit_detail_source_value varchar(50) NULL, visit_detail_source_concept_id Integer NULL, admitted_from_concept_id Integer NULL, - admitted_from_source_value Varchar(50) NULL, - discharged_to_source_value Varchar(50) NULL, + admitted_from_source_value varchar(50) NULL, + discharged_to_source_value varchar(50) NULL, discharged_to_concept_id integer NULL, preceding_visit_detail_id integer NULL, parent_visit_detail_id integer NULL, @@ -122,6 +122,8 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE (procedure_occurrence_id i procedure_concept_id integer NOT NULL, procedure_date date NOT NULL, procedure_datetime TIMESTAMP NULL, + procedure_end_date date NULL, + procedure_end_datetime TIMESTAMP NULL, procedure_type_concept_id integer NOT NULL, modifier_concept_id integer NULL, quantity integer NULL, @@ -130,9 +132,7 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE (procedure_occurrence_id i visit_detail_id integer NULL, procedure_source_value varchar(50) NULL, procedure_source_concept_id integer NULL, - modifier_source_value varchar(50) NULL, - procedure_status_source_value varchar(50) NULL, - procedure_status_concept_id integer NOT NULL ) + modifier_source_value varchar(50) NULL ) DISTKEY(person_id); --HINT DISTRIBUTE ON KEY (person_id) @@ -220,8 +220,6 @@ DISTKEY(person_id); --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.NOTE (note_id integer NOT NULL, person_id integer NOT NULL, - note_event_id bigint NULL, - note_event_field_concept_id integer NULL, note_date date NOT NULL, note_datetime TIMESTAMP NULL, note_type_concept_id integer NOT NULL, @@ -233,7 +231,9 @@ CREATE TABLE @cdmDatabaseSchema.NOTE (note_id integer NOT NULL, provider_id integer NULL, visit_occurrence_id integer NULL, visit_detail_id integer NULL, - note_source_value varchar(50) NULL ) + note_source_value varchar(50) NULL, + note_event_id bigint NULL, + note_event_field_concept_id integer NULL ) DISTKEY(person_id); --HINT DISTRIBUTE ON RANDOM @@ -394,14 +394,14 @@ CREATE TABLE @cdmDatabaseSchema.CONDITION_ERA (condition_era_id integer NOT NUL DISTKEY(person_id); --HINT DISTRIBUTE ON KEY (person_id) -CREATE TABLE @cdmDatabaseSchema.EPISODE (episode_id integer NOT NULL, - person_id integer NOT NULL, +CREATE TABLE @cdmDatabaseSchema.EPISODE (episode_id bigint NOT NULL, + person_id bigint NOT NULL, episode_concept_id integer NOT NULL, episode_start_date date NOT NULL, episode_start_datetime TIMESTAMP NULL, episode_end_date date NULL, episode_end_datetime TIMESTAMP NULL, - episode_parent_id integer NULL, + episode_parent_id bigint NULL, episode_number integer NULL, episode_object_concept_id integer NOT NULL, episode_type_concept_id integer NOT NULL, @@ -410,8 +410,8 @@ CREATE TABLE @cdmDatabaseSchema.EPISODE (episode_id integer NOT NULL, DISTKEY(person_id); --HINT DISTRIBUTE ON RANDOM -CREATE TABLE @cdmDatabaseSchema.EPISODE_EVENT (episode_id integer NOT NULL, - event_id integer NOT NULL, +CREATE TABLE @cdmDatabaseSchema.EPISODE_EVENT (episode_id bigint NOT NULL, + event_id bigint NOT NULL, episode_event_field_concept_id integer NOT NULL ) DISTSTYLE ALL; @@ -457,7 +457,7 @@ DISTSTYLE ALL; --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.VOCABULARY (vocabulary_id varchar(20) NOT NULL, vocabulary_name varchar(255) NOT NULL, - vocabulary_reference varchar(255) NOT NULL, + vocabulary_reference varchar(255) NULL, vocabulary_version varchar(255) NULL, vocabulary_concept_id integer NOT NULL ) DISTSTYLE ALL; diff --git a/inst/ddl/5.4/sql_server/OMOPCDM_sql_server_5.4_constraints.sql b/inst/ddl/5.4/sql_server/OMOPCDM_sql_server_5.4_constraints.sql index 26f9cf3..58560dd 100644 --- a/inst/ddl/5.4/sql_server/OMOPCDM_sql_server_5.4_constraints.sql +++ b/inst/ddl/5.4/sql_server/OMOPCDM_sql_server_5.4_constraints.sql @@ -102,6 +102,14 @@ ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_modifier_concept_id FOREIGN KEY (modifier_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_provider_id FOREIGN KEY (provider_id) REFERENCES @cdmDatabaseSchema.PROVIDER (PROVIDER_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_occurrence_id FOREIGN KEY (visit_occurrence_id) REFERENCES @cdmDatabaseSchema.VISIT_OCCURRENCE (VISIT_OCCURRENCE_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); + +ALTER TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ADD CONSTRAINT fpk_PROCEDURE_OCCURRENCE_procedure_source_concept_id FOREIGN KEY (procedure_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_concept_id FOREIGN KEY (device_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -116,6 +124,10 @@ ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSUR ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_device_source_concept_id FOREIGN KEY (device_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + +ALTER TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ADD CONSTRAINT fpk_DEVICE_EXPOSURE_unit_source_concept_id FOREIGN KEY (unit_source_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); ALTER TABLE @cdmDatabaseSchema.MEASUREMENT ADD CONSTRAINT fpk_MEASUREMENT_measurement_concept_id FOREIGN KEY (measurement_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -172,8 +184,6 @@ ALTER TABLE @cdmDatabaseSchema.DEATH ADD CONSTRAINT fpk_DEATH_cause_source_conce ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); -ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); - ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_type_concept_id FOREIGN KEY (note_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_class_concept_id FOREIGN KEY (note_class_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -188,6 +198,8 @@ ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_occurrence_id ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_visit_detail_id FOREIGN KEY (visit_detail_id) REFERENCES @cdmDatabaseSchema.VISIT_DETAIL (VISIT_DETAIL_ID); +ALTER TABLE @cdmDatabaseSchema.NOTE ADD CONSTRAINT fpk_NOTE_note_event_field_concept_id FOREIGN KEY (note_event_field_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_section_concept_id FOREIGN KEY (section_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.NOTE_NLP ADD CONSTRAINT fpk_NOTE_NLP_note_nlp_concept_id FOREIGN KEY (note_nlp_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); @@ -212,6 +224,8 @@ ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIO ALTER TABLE @cdmDatabaseSchema.FACT_RELATIONSHIP ADD CONSTRAINT fpk_FACT_RELATIONSHIP_relationship_concept_id FOREIGN KEY (relationship_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.LOCATION ADD CONSTRAINT fpk_LOCATION_country_concept_id FOREIGN KEY (country_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_place_of_service_concept_id FOREIGN KEY (place_of_service_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.CARE_SITE ADD CONSTRAINT fpk_CARE_SITE_location_id FOREIGN KEY (location_id) REFERENCES @cdmDatabaseSchema.LOCATION (LOCATION_ID); @@ -266,6 +280,8 @@ ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_drug_concept ALTER TABLE @cdmDatabaseSchema.DOSE_ERA ADD CONSTRAINT fpk_DOSE_ERA_unit_concept_id FOREIGN KEY (unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); + ALTER TABLE @cdmDatabaseSchema.CONDITION_ERA ADD CONSTRAINT fpk_CONDITION_ERA_condition_concept_id FOREIGN KEY (condition_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.EPISODE ADD CONSTRAINT fpk_EPISODE_person_id FOREIGN KEY (person_id) REFERENCES @cdmDatabaseSchema.PERSON (PERSON_ID); @@ -288,6 +304,8 @@ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_metadata_typ ALTER TABLE @cdmDatabaseSchema.METADATA ADD CONSTRAINT fpk_METADATA_value_as_concept_id FOREIGN KEY (value_as_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.CDM_SOURCE ADD CONSTRAINT fpk_CDM_SOURCE_cdm_version_concept_id FOREIGN KEY (cdm_version_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); + ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_domain_id FOREIGN KEY (domain_id) REFERENCES @cdmDatabaseSchema.DOMAIN (DOMAIN_ID); ALTER TABLE @cdmDatabaseSchema.CONCEPT ADD CONSTRAINT fpk_CONCEPT_vocabulary_id FOREIGN KEY (vocabulary_id) REFERENCES @cdmDatabaseSchema.VOCABULARY (VOCABULARY_ID); @@ -332,6 +350,8 @@ ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_nu ALTER TABLE @cdmDatabaseSchema.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_denominator_unit_concept_id FOREIGN KEY (denominator_unit_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); +ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_cohort_definition_id FOREIGN KEY (cohort_definition_id) REFERENCES @cdmDatabaseSchema.COHORT (COHORT_DEFINITION_ID); + ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_definition_type_concept_id FOREIGN KEY (definition_type_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); ALTER TABLE @cdmDatabaseSchema.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_subject_concept_id FOREIGN KEY (subject_concept_id) REFERENCES @cdmDatabaseSchema.CONCEPT (CONCEPT_ID); diff --git a/inst/ddl/5.4/sql_server/OMOPCDM_sql_server_5.4_ddl.sql b/inst/ddl/5.4/sql_server/OMOPCDM_sql_server_5.4_ddl.sql index b71b9ae..749cb8d 100644 --- a/inst/ddl/5.4/sql_server/OMOPCDM_sql_server_5.4_ddl.sql +++ b/inst/ddl/5.4/sql_server/OMOPCDM_sql_server_5.4_ddl.sql @@ -64,8 +64,8 @@ CREATE TABLE @cdmDatabaseSchema.VISIT_DETAIL ( visit_detail_source_value varchar(50) NULL, visit_detail_source_concept_id Integer NULL, admitted_from_concept_id Integer NULL, - admitted_from_source_value Varchar(50) NULL, - discharged_to_source_value Varchar(50) NULL, + admitted_from_source_value varchar(50) NULL, + discharged_to_source_value varchar(50) NULL, discharged_to_concept_id integer NULL, preceding_visit_detail_id integer NULL, parent_visit_detail_id integer NULL, @@ -123,6 +123,8 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ( procedure_concept_id integer NOT NULL, procedure_date date NOT NULL, procedure_datetime datetime NULL, + procedure_end_date date NULL, + procedure_end_datetime datetime NULL, procedure_type_concept_id integer NOT NULL, modifier_concept_id integer NULL, quantity integer NULL, @@ -131,9 +133,7 @@ CREATE TABLE @cdmDatabaseSchema.PROCEDURE_OCCURRENCE ( visit_detail_id integer NULL, procedure_source_value varchar(50) NULL, procedure_source_concept_id integer NULL, - modifier_source_value varchar(50) NULL, - procedure_status_source_value varchar(50) NULL, - procedure_status_concept_id integer NOT NULL ); + modifier_source_value varchar(50) NULL ); --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.DEVICE_EXPOSURE ( @@ -221,8 +221,6 @@ CREATE TABLE @cdmDatabaseSchema.DEATH ( CREATE TABLE @cdmDatabaseSchema.NOTE ( note_id integer NOT NULL, person_id integer NOT NULL, - note_event_id bigint NULL, - note_event_field_concept_id integer NULL, note_date date NOT NULL, note_datetime datetime NULL, note_type_concept_id integer NOT NULL, @@ -234,7 +232,9 @@ CREATE TABLE @cdmDatabaseSchema.NOTE ( provider_id integer NULL, visit_occurrence_id integer NULL, visit_detail_id integer NULL, - note_source_value varchar(50) NULL ); + note_source_value varchar(50) NULL, + note_event_id bigint NULL, + note_event_field_concept_id integer NULL ); --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.NOTE_NLP ( @@ -395,14 +395,14 @@ CREATE TABLE @cdmDatabaseSchema.CONDITION_ERA ( --HINT DISTRIBUTE ON KEY (person_id) CREATE TABLE @cdmDatabaseSchema.EPISODE ( - episode_id integer NOT NULL, - person_id integer NOT NULL, + episode_id bigint NOT NULL, + person_id bigint NOT NULL, episode_concept_id integer NOT NULL, episode_start_date date NOT NULL, episode_start_datetime datetime NULL, episode_end_date date NULL, episode_end_datetime datetime NULL, - episode_parent_id integer NULL, + episode_parent_id bigint NULL, episode_number integer NULL, episode_object_concept_id integer NOT NULL, episode_type_concept_id integer NOT NULL, @@ -411,8 +411,8 @@ CREATE TABLE @cdmDatabaseSchema.EPISODE ( --HINT DISTRIBUTE ON RANDOM CREATE TABLE @cdmDatabaseSchema.EPISODE_EVENT ( - episode_id integer NOT NULL, - event_id integer NOT NULL, + episode_id bigint NOT NULL, + event_id bigint NOT NULL, episode_event_field_concept_id integer NOT NULL ); --HINT DISTRIBUTE ON RANDOM @@ -458,7 +458,7 @@ CREATE TABLE @cdmDatabaseSchema.CONCEPT ( CREATE TABLE @cdmDatabaseSchema.VOCABULARY ( vocabulary_id varchar(20) NOT NULL, vocabulary_name varchar(255) NOT NULL, - vocabulary_reference varchar(255) NOT NULL, + vocabulary_reference varchar(255) NULL, vocabulary_version varchar(255) NULL, vocabulary_concept_id integer NOT NULL );