Commit 8fc87ae7 authored by Pepe Márquez Romero's avatar Pepe Márquez Romero

scripts sql para instancia de omop en PostgreSQL y MySQL

parent 7d631397
`mysql -u omop_root -h IP -pPASS -P PORT omop -e "source $(pwd)/omop_tables.sql"`
`mysql -u omop_root -h IP -pPASS -P PORT omop -e "source $(pwd)/omop_cdm_primary_keys.sql"`
`mysql -u omop_root -h IP -pPASS -P PORT omop -e "source $(pwd)/omop_cdm_constraints.sql"`
No hace falta crear indexes porque MySQL crea indexes cuando se crea una primary key y una foreign key.
`mysql -u omop_root -h IP -pPASS -P PORT omop -e "source $(pwd)/drop_tables.sql"`
This diff is collapsed.
/*sql server OMOP CDM Indices
There are no unique indices created because it is assumed that the primary key constraints have been run prior to
implementing indices
*/
/************************
Standardized clinical data
************************/
CREATE INDEX idx_person_id ON PERSON (person_id ASC);
CREATE INDEX idx_gender ON PERSON (gender_concept_id ASC);
CREATE INDEX idx_observation_period_id_1 ON OBSERVATION_PERIOD (person_id ASC);
CREATE INDEX idx_visit_person_id_1 ON VISIT_OCCURRENCE (person_id ASC);
CREATE INDEX idx_visit_concept_id_1 ON VISIT_OCCURRENCE (visit_concept_id ASC);
CREATE INDEX idx_visit_det_person_id_1 ON VISIT_DETAIL (person_id ASC);
CREATE INDEX idx_visit_det_concept_id_1 ON VISIT_DETAIL (visit_detail_concept_id ASC);
CREATE INDEX idx_condition_person_id_1 ON CONDITION_OCCURRENCE (person_id ASC);
CREATE INDEX idx_condition_concept_id_1 ON CONDITION_OCCURRENCE (condition_concept_id ASC);
CREATE INDEX idx_condition_visit_id_1 ON CONDITION_OCCURRENCE (visit_occurrence_id ASC);
CREATE INDEX idx_drug_person_id_1 ON DRUG_EXPOSURE (person_id ASC);
CREATE INDEX idx_drug_concept_id_1 ON DRUG_EXPOSURE (drug_concept_id ASC);
CREATE INDEX idx_drug_visit_id_1 ON DRUG_EXPOSURE (visit_occurrence_id ASC);
CREATE INDEX idx_procedure_person_id_1 ON PROCEDURE_OCCURRENCE (person_id ASC);
CREATE INDEX idx_procedure_concept_id_1 ON PROCEDURE_OCCURRENCE (procedure_concept_id ASC);
CREATE INDEX idx_procedure_visit_id_1 ON PROCEDURE_OCCURRENCE (visit_occurrence_id ASC);
CREATE INDEX idx_device_person_id_1 ON DEVICE_EXPOSURE (person_id ASC);
CREATE INDEX idx_device_concept_id_1 ON DEVICE_EXPOSURE (device_concept_id ASC);
CREATE INDEX idx_device_visit_id_1 ON DEVICE_EXPOSURE (visit_occurrence_id ASC);
CREATE INDEX idx_measurement_person_id_1 ON MEASUREMENT (person_id ASC);
CREATE INDEX idx_measurement_concept_id_1 ON MEASUREMENT (measurement_concept_id ASC);
CREATE INDEX idx_measurement_visit_id_1 ON MEASUREMENT (visit_occurrence_id ASC);
CREATE INDEX idx_observation_person_id_1 ON OBSERVATION (person_id ASC);
CREATE INDEX idx_observation_concept_id_1 ON OBSERVATION (observation_concept_id ASC);
CREATE INDEX idx_observation_visit_id_1 ON OBSERVATION (visit_occurrence_id ASC);
CREATE INDEX idx_death_person_id_1 ON DEATH (person_id ASC);
CREATE INDEX idx_note_person_id_1 ON NOTE (person_id ASC);
CREATE INDEX idx_note_concept_id_1 ON NOTE (note_type_concept_id ASC);
CREATE INDEX idx_note_visit_id_1 ON NOTE (visit_occurrence_id ASC);
CREATE INDEX idx_note_nlp_note_id_1 ON NOTE_NLP (note_id ASC);
CREATE INDEX idx_note_nlp_concept_id_1 ON NOTE_NLP (note_nlp_concept_id ASC);
CREATE INDEX idx_specimen_person_id_1 ON SPECIMEN (person_id ASC);
CREATE INDEX idx_specimen_concept_id_1 ON SPECIMEN (specimen_concept_id ASC);
CREATE INDEX idx_fact_relationship_id1 ON FACT_RELATIONSHIP (domain_concept_id_1 ASC);
CREATE INDEX idx_fact_relationship_id2 ON FACT_RELATIONSHIP (domain_concept_id_2 ASC);
CREATE INDEX idx_fact_relationship_id3 ON FACT_RELATIONSHIP (relationship_concept_id ASC);
/************************
Standardized health system data
************************/
CREATE INDEX idx_location_id_1 ON LOCATION(location_id ASC);
CREATE INDEX idx_care_site_id_1 ON CARE_SITE(care_site_id ASC);
CREATE INDEX idx_provider_id_1 ON PROVIDER (provider_id ASC);
/************************
Standardized health economics
************************/
CREATE INDEX idx_period_person_id_1 ON PAYER_PLAN_PERIOD (person_id ASC);
CREATE INDEX idx_cost_event_id ON COST (cost_event_id ASC);
/************************
Standardized derived elements
************************/
CREATE INDEX idx_drug_era_person_id_1 ON DRUG_ERA (person_id ASC);
CREATE INDEX idx_drug_era_concept_id_1 ON DRUG_ERA (drug_concept_id ASC);
CREATE INDEX idx_dose_era_person_id_1 ON DOSE_ERA (person_id ASC);
CREATE INDEX idx_dose_era_concept_id_1 ON DOSE_ERA (drug_concept_id ASC);
CREATE INDEX idx_condition_era_person_id_1 ON CONDITION_ERA (person_id ASC);
CREATE INDEX idx_condition_era_concept_id_1 ON CONDITION_ERA (condition_concept_id ASC);
/**************************
Standardized meta-data
***************************/
CREATE INDEX idx_metadata_concept_id_1 ON METADATA (metadata_concept_id ASC);
/**************************
Standardized vocabularies
***************************/
CREATE INDEX idx_concept_concept_id ON CONCEPT (concept_id ASC);
CREATE INDEX idx_concept_code ON CONCEPT (concept_code ASC);
CREATE INDEX idx_concept_vocabluary_id ON CONCEPT (vocabulary_id ASC);
CREATE INDEX idx_concept_domain_id ON CONCEPT (domain_id ASC);
CREATE INDEX idx_vocabulary_vocabulary_id ON VOCABULARY (vocabulary_id ASC);
CREATE INDEX idx_domain_domain_id ON DOMAIN (domain_id ASC);
CREATE INDEX idx_concept_class_class_id ON CONCEPT_CLASS (concept_class_id ASC);
CREATE INDEX idx_concept_relationship_id_1 ON CONCEPT_RELATIONSHIP (concept_id_1 ASC);
CREATE INDEX idx_concept_relationship_id_2 ON CONCEPT_RELATIONSHIP (concept_id_2 ASC);
CREATE INDEX idx_concept_relationship_id_3 ON CONCEPT_RELATIONSHIP (relationship_id ASC);
CREATE INDEX idx_relationship_rel_id ON RELATIONSHIP (relationship_id ASC);
CREATE INDEX idx_concept_synonym_id ON CONCEPT_SYNONYM (concept_id ASC);
CREATE INDEX idx_concept_ancestor_id_1 ON CONCEPT_ANCESTOR (ancestor_concept_id ASC);
CREATE INDEX idx_concept_ancestor_id_2 ON CONCEPT_ANCESTOR (descendant_concept_id ASC);
CREATE INDEX idx_source_to_concept_map_3 ON SOURCE_TO_CONCEPT_MAP (target_concept_id ASC);
CREATE INDEX idx_source_to_concept_map_1 ON SOURCE_TO_CONCEPT_MAP (source_vocabulary_id ASC);
CREATE INDEX idx_source_to_concept_map_2 ON SOURCE_TO_CONCEPT_MAP (target_vocabulary_id ASC);
CREATE INDEX idx_source_to_concept_map_c ON SOURCE_TO_CONCEPT_MAP (source_code ASC);
CREATE INDEX idx_drug_strength_id_1 ON DRUG_STRENGTH (drug_concept_id ASC);
CREATE INDEX idx_drug_strength_id_2 ON DRUG_STRENGTH (ingredient_concept_id ASC);
--Additional v60 indices
--CREATE CLUSTERED INDEX idx_survey_person_id_1 ON SURVEY_CONDUCT (person_id ASC);
--CREATE CLUSTERED INDEX idx_episode_person_id_1 ON EPISODE (person_id ASC);
--CREATE INDEX idx_episode_concept_id_1 ON EPISODE (episode_concept_id ASC);
--CREATE CLUSTERED INDEX idx_episode_event_id_1 ON EPISODE_EVENT (episode_id ASC);
--CREATE INDEX idx_ee_field_concept_id_1 ON EPISODE_EVENT (event_field_concept_id ASC);
--sql server CDM Primary Key Constraints for OMOP Common Data Model 5.4 -- mysql CDM Primary Key Constraints for OMOP Common Data Model 5.4
ALTER TABLE PERSON ADD CONSTRAINT xpk_PERSON PRIMARY KEY (person_id);
ALTER TABLE OBSERVATION_PERIOD ADD CONSTRAINT xpk_OBSERVATION_PERIOD PRIMARY KEY (observation_period_id); ALTER TABLE omop.PERSON ADD CONSTRAINT xpk_PERSON PRIMARY KEY (person_id);
ALTER TABLE VISIT_OCCURRENCE ADD CONSTRAINT xpk_VISIT_OCCURRENCE PRIMARY KEY (visit_occurrence_id);
ALTER TABLE VISIT_DETAIL ADD CONSTRAINT xpk_VISIT_DETAIL PRIMARY KEY (visit_detail_id); ALTER TABLE omop.OBSERVATION_PERIOD ADD CONSTRAINT xpk_OBSERVATION_PERIOD PRIMARY KEY (observation_period_id);
ALTER TABLE CONDITION_OCCURRENCE ADD CONSTRAINT xpk_CONDITION_OCCURRENCE PRIMARY KEY (condition_occurrence_id);
ALTER TABLE DRUG_EXPOSURE ADD CONSTRAINT xpk_DRUG_EXPOSURE PRIMARY KEY (drug_exposure_id); ALTER TABLE omop.VISIT_OCCURRENCE ADD CONSTRAINT xpk_VISIT_OCCURRENCE PRIMARY KEY (visit_occurrence_id);
ALTER TABLE PROCEDURE_OCCURRENCE ADD CONSTRAINT xpk_PROCEDURE_OCCURRENCE PRIMARY KEY (procedure_occurrence_id);
ALTER TABLE DEVICE_EXPOSURE ADD CONSTRAINT xpk_DEVICE_EXPOSURE PRIMARY KEY (device_exposure_id); ALTER TABLE omop.VISIT_DETAIL ADD CONSTRAINT xpk_VISIT_DETAIL PRIMARY KEY (visit_detail_id);
ALTER TABLE MEASUREMENT ADD CONSTRAINT xpk_MEASUREMENT PRIMARY KEY (measurement_id);
ALTER TABLE OBSERVATION ADD CONSTRAINT xpk_OBSERVATION PRIMARY KEY (observation_id); ALTER TABLE omop.CONDITION_OCCURRENCE ADD CONSTRAINT xpk_CONDITION_OCCURRENCE PRIMARY KEY (condition_occurrence_id);
ALTER TABLE NOTE ADD CONSTRAINT xpk_NOTE PRIMARY KEY (note_id);
ALTER TABLE NOTE_NLP ADD CONSTRAINT xpk_NOTE_NLP PRIMARY KEY (note_nlp_id); ALTER TABLE omop.DRUG_EXPOSURE ADD CONSTRAINT xpk_DRUG_EXPOSURE PRIMARY KEY (drug_exposure_id);
ALTER TABLE SPECIMEN ADD CONSTRAINT xpk_SPECIMEN PRIMARY KEY (specimen_id);
ALTER TABLE LOCATION ADD CONSTRAINT xpk_LOCATION PRIMARY KEY (location_id); ALTER TABLE omop.PROCEDURE_OCCURRENCE ADD CONSTRAINT xpk_PROCEDURE_OCCURRENCE PRIMARY KEY (procedure_occurrence_id);
ALTER TABLE CARE_SITE ADD CONSTRAINT xpk_CARE_SITE PRIMARY KEY (care_site_id);
ALTER TABLE PROVIDER ADD CONSTRAINT xpk_PROVIDER PRIMARY KEY (provider_id); ALTER TABLE omop.DEVICE_EXPOSURE ADD CONSTRAINT xpk_DEVICE_EXPOSURE PRIMARY KEY (device_exposure_id);
ALTER TABLE PAYER_PLAN_PERIOD ADD CONSTRAINT xpk_PAYER_PLAN_PERIOD PRIMARY KEY (payer_plan_period_id);
ALTER TABLE COST ADD CONSTRAINT xpk_COST PRIMARY KEY (cost_id); ALTER TABLE omop.MEASUREMENT ADD CONSTRAINT xpk_MEASUREMENT PRIMARY KEY (measurement_id);
ALTER TABLE DRUG_ERA ADD CONSTRAINT xpk_DRUG_ERA PRIMARY KEY (drug_era_id);
ALTER TABLE DOSE_ERA ADD CONSTRAINT xpk_DOSE_ERA PRIMARY KEY (dose_era_id); ALTER TABLE omop.OBSERVATION ADD CONSTRAINT xpk_OBSERVATION PRIMARY KEY (observation_id);
ALTER TABLE CONDITION_ERA ADD CONSTRAINT xpk_CONDITION_ERA PRIMARY KEY (condition_era_id);
ALTER TABLE EPISODE ADD CONSTRAINT xpk_EPISODE PRIMARY KEY (episode_id); ALTER TABLE omop.NOTE ADD CONSTRAINT xpk_NOTE PRIMARY KEY (note_id);
ALTER TABLE METADATA ADD CONSTRAINT xpk_METADATA PRIMARY KEY (metadata_id);
ALTER TABLE CONCEPT ADD CONSTRAINT xpk_CONCEPT PRIMARY KEY (concept_id); ALTER TABLE omop.NOTE_NLP ADD CONSTRAINT xpk_NOTE_NLP PRIMARY KEY (note_nlp_id);
ALTER TABLE VOCABULARY ADD CONSTRAINT xpk_VOCABULARY PRIMARY KEY (vocabulary_id);
ALTER TABLE DOMAIN ADD CONSTRAINT xpk_DOMAIN PRIMARY KEY (domain_id); ALTER TABLE omop.SPECIMEN ADD CONSTRAINT xpk_SPECIMEN PRIMARY KEY (specimen_id);
ALTER TABLE CONCEPT_CLASS ADD CONSTRAINT xpk_CONCEPT_CLASS PRIMARY KEY (concept_class_id);
ALTER TABLE RELATIONSHIP ADD CONSTRAINT xpk_RELATIONSHIP PRIMARY KEY (relationship_id); ALTER TABLE omop.LOCATION ADD CONSTRAINT xpk_LOCATION PRIMARY KEY (location_id);
ALTER TABLE COHORT ADD CONSTRAINT xpk_COHORT PRIMARY KEY (cohort_definition_id);
ALTER TABLE omop.CARE_SITE ADD CONSTRAINT xpk_CARE_SITE PRIMARY KEY (care_site_id);
ALTER TABLE omop.PROVIDER ADD CONSTRAINT xpk_PROVIDER PRIMARY KEY (provider_id);
ALTER TABLE omop.PAYER_PLAN_PERIOD ADD CONSTRAINT xpk_PAYER_PLAN_PERIOD PRIMARY KEY (payer_plan_period_id);
ALTER TABLE omop.COST ADD CONSTRAINT xpk_COST PRIMARY KEY (cost_id);
ALTER TABLE omop.DRUG_ERA ADD CONSTRAINT xpk_DRUG_ERA PRIMARY KEY (drug_era_id);
ALTER TABLE omop.DOSE_ERA ADD CONSTRAINT xpk_DOSE_ERA PRIMARY KEY (dose_era_id);
ALTER TABLE omop.CONDITION_ERA ADD CONSTRAINT xpk_CONDITION_ERA PRIMARY KEY (condition_era_id);
ALTER TABLE omop.EPISODE ADD CONSTRAINT xpk_EPISODE PRIMARY KEY (episode_id);
ALTER TABLE omop.METADATA ADD CONSTRAINT xpk_METADATA PRIMARY KEY (metadata_id);
ALTER TABLE omop.CONCEPT ADD CONSTRAINT xpk_CONCEPT PRIMARY KEY (concept_id);
ALTER TABLE omop.VOCABULARY ADD CONSTRAINT xpk_VOCABULARY PRIMARY KEY (vocabulary_id);
ALTER TABLE omop.DOMAIN ADD CONSTRAINT xpk_DOMAIN PRIMARY KEY (domain_id);
ALTER TABLE omop.CONCEPT_CLASS ADD CONSTRAINT xpk_CONCEPT_CLASS PRIMARY KEY (concept_class_id);
ALTER TABLE omop.RELATIONSHIP ADD CONSTRAINT xpk_RELATIONSHIP PRIMARY KEY (relationship_id);
ALTER TABLE omop.COHORT_DEFINITION ADD CONSTRAINT xpk_COHORT_DEFINITION PRIMARY KEY (cohort_definition_id);
This diff is collapsed.
...@@ -5,3 +5,5 @@ db: ...@@ -5,3 +5,5 @@ db:
-e POSTGRES_PASSWORD=postgres \ -e POSTGRES_PASSWORD=postgres \
postgres:latest postgres:latest
stop:
docker kill postgres
`psql "host=127.0.0.1 port=5432 dbname=omop password=postgres" -c "CREATE SCHEMA omop" -U postgres`
`psql "host=127.0.0.1 port=5432 dbname=omop password=postgres" -c "\i omop_ddl_postgres.sql" -U postgres`
`psql "host=127.0.0.1 port=5432 dbname=omop password=postgres" -c "\i omop_pk_postgres.sql" -U postgres`
`psql "host=127.0.0.1 port=5432 dbname=omop password=postgres" -c "\i omop_constraints_postgres.sql" -U postgres`
`psql "host=127.0.0.1 port=5432 dbname=omop password=postgres" -c "\i omop_indexes_postgres.sql" -U postgres`
`psql "host=127.0.0.1 port=5432 dbname=omop password=postgres" -c "DROP SCHEMA omop CASCADE" -U postgres`
...@@ -350,7 +350,7 @@ ALTER TABLE omop.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_numerator_unit_c ...@@ -350,7 +350,7 @@ ALTER TABLE omop.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_numerator_unit_c
ALTER TABLE omop.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_denominator_unit_concept_id FOREIGN KEY (denominator_unit_concept_id) REFERENCES omop.CONCEPT (CONCEPT_ID); ALTER TABLE omop.DRUG_STRENGTH ADD CONSTRAINT fpk_DRUG_STRENGTH_denominator_unit_concept_id FOREIGN KEY (denominator_unit_concept_id) REFERENCES omop.CONCEPT (CONCEPT_ID);
ALTER TABLE omop.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_cohort_definition_id FOREIGN KEY (cohort_definition_id) REFERENCES omop.COHORT (COHORT_DEFINITION_ID); ALTER TABLE omop.COHORT ADD CONSTRAINT fpk_COHORT_cohort_definition_id FOREIGN KEY (cohort_definition_id) REFERENCES omop.COHORT_DEFINITION (COHORT_DEFINITION_ID);
ALTER TABLE omop.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_definition_type_concept_id FOREIGN KEY (definition_type_concept_id) REFERENCES omop.CONCEPT (CONCEPT_ID); ALTER TABLE omop.COHORT_DEFINITION ADD CONSTRAINT fpk_COHORT_DEFINITION_definition_type_concept_id FOREIGN KEY (definition_type_concept_id) REFERENCES omop.CONCEPT (CONCEPT_ID);
......
...@@ -56,3 +56,4 @@ ALTER TABLE omop.CONCEPT_CLASS ADD CONSTRAINT xpk_CONCEPT_CLASS PRIMARY KEY (con ...@@ -56,3 +56,4 @@ ALTER TABLE omop.CONCEPT_CLASS ADD CONSTRAINT xpk_CONCEPT_CLASS PRIMARY KEY (con
ALTER TABLE omop.RELATIONSHIP ADD CONSTRAINT xpk_RELATIONSHIP PRIMARY KEY (relationship_id); ALTER TABLE omop.RELATIONSHIP ADD CONSTRAINT xpk_RELATIONSHIP PRIMARY KEY (relationship_id);
ALTER TABLE omop.COHORT_DEFINITION ADD CONSTRAINT xpk_COHORT_DEFINITION PRIMARY KEY (cohort_definition_id);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment