Skip to content

Commit

Permalink
Merge pull request #1659 from SimonUzL/main
Browse files Browse the repository at this point in the history
Fix constraint.sql for mimic-iv-ed PostgreSQL
  • Loading branch information
alistairewj authored Nov 16, 2023
2 parents d1367d7 + 3e82775 commit 930533b
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 additions & 28 deletions mimic-iv-ed/buildmimic/postgres/constraint.sql
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
SET search_path TO mimic_ed;
SET search_path TO mimiciv_ed;
---------------------------
---------------------------
-- Creating Primary Keys --
---------------------------
---------------------------

ALTER TABLE mimic_ed.edstays DROP CONSTRAINT IF EXISTS edstays_pk CASCADE;
ALTER TABLE mimic_ed.edstays
ALTER TABLE mimiciv_ed.edstays DROP CONSTRAINT IF EXISTS edstays_pk CASCADE;
ALTER TABLE mimiciv_ed.edstays
ADD CONSTRAINT edstays_pk
PRIMARY KEY (stay_id);

ALTER TABLE mimic_ed.diagnosis DROP CONSTRAINT IF EXISTS diagnosis_pk CASCADE;
ALTER TABLE mimic_ed.diagnosis
ALTER TABLE mimiciv_ed.diagnosis DROP CONSTRAINT IF EXISTS diagnosis_pk CASCADE;
ALTER TABLE mimiciv_ed.diagnosis
ADD CONSTRAINT diagnosis_pk
PRIMARY KEY (stay_id, seq_num);

--ALTER TABLE mimic_ed.medrecon DROP CONSTRAINT IF EXISTS medrecon_pk CASCADE;
--ALTER TABLE mimic_ed.medrecon
--ALTER TABLE mimiciv_ed.medrecon DROP CONSTRAINT IF EXISTS medrecon_pk CASCADE;
--ALTER TABLE mimiciv_ed.medrecon
--ADD CONSTRAINT medrecon_pk
-- PRIMARY KEY (stay_id, charttime, name);

--ALTER TABLE mimic_ed.pyxis DROP CONSTRAINT IF EXISTS pyxis_pk CASCADE;
--ALTER TABLE mimic_ed.pyxis
--ALTER TABLE mimiciv_ed.pyxis DROP CONSTRAINT IF EXISTS pyxis_pk CASCADE;
--ALTER TABLE mimiciv_ed.pyxis
--ADD CONSTRAINT pyxis_pk
-- PRIMARY KEY (stay_id, charttime, name);

ALTER TABLE mimic_ed.triage DROP CONSTRAINT IF EXISTS triage_pk CASCADE;
ALTER TABLE mimic_ed.triage
ALTER TABLE mimiciv_ed.triage DROP CONSTRAINT IF EXISTS triage_pk CASCADE;
ALTER TABLE mimiciv_ed.triage
ADD CONSTRAINT triage_pk
PRIMARY KEY (stay_id);

ALTER TABLE mimic_ed.vitalsign DROP CONSTRAINT IF EXISTS vitalsign_pk CASCADE;
ALTER TABLE mimic_ed.vitalsign
ALTER TABLE mimiciv_ed.vitalsign DROP CONSTRAINT IF EXISTS vitalsign_pk CASCADE;
ALTER TABLE mimiciv_ed.vitalsign
ADD CONSTRAINT vitalsign_pk
PRIMARY KEY (stay_id, charttime);

Expand All @@ -41,32 +41,32 @@ ADD CONSTRAINT vitalsign_pk
---------------------------
---------------------------

ALTER TABLE mimic_ed.diagnosis DROP CONSTRAINT IF EXISTS diagnosis_edstays_fk CASCADE;
ALTER TABLE mimic_ed.diagnosis
ALTER TABLE mimiciv_ed.diagnosis DROP CONSTRAINT IF EXISTS diagnosis_edstays_fk CASCADE;
ALTER TABLE mimiciv_ed.diagnosis
ADD CONSTRAINT diagnosis_edstays_fk
FOREIGN KEY (stay_id)
REFERENCES mimic_ed.edstays (stay_id);
REFERENCES mimiciv_ed.edstays (stay_id);

ALTER TABLE mimic_ed.medrecon DROP CONSTRAINT IF EXISTS medrecon_edstays_fk CASCADE;
ALTER TABLE mimic_ed.medrecon
ALTER TABLE mimiciv_ed.medrecon DROP CONSTRAINT IF EXISTS medrecon_edstays_fk CASCADE;
ALTER TABLE mimiciv_ed.medrecon
ADD CONSTRAINT medrecon_edstays_fk
FOREIGN KEY (stay_id)
REFERENCES mimic_ed.edstays (stay_id);
REFERENCES mimiciv_ed.edstays (stay_id);

ALTER TABLE mimic_ed.pyxis DROP CONSTRAINT IF EXISTS pyxis_edstays_fk CASCADE;
ALTER TABLE mimic_ed.pyxis
ALTER TABLE mimiciv_ed.pyxis DROP CONSTRAINT IF EXISTS pyxis_edstays_fk CASCADE;
ALTER TABLE mimiciv_ed.pyxis
ADD CONSTRAINT pyxis_edstays_fk
FOREIGN KEY (stay_id)
REFERENCES mimic_ed.edstays (stay_id);
REFERENCES mimiciv_ed.edstays (stay_id);

ALTER TABLE mimic_ed.triage DROP CONSTRAINT IF EXISTS triage_edstays_fk CASCADE;
ALTER TABLE mimic_ed.triage
ALTER TABLE mimiciv_ed.triage DROP CONSTRAINT IF EXISTS triage_edstays_fk CASCADE;
ALTER TABLE mimiciv_ed.triage
ADD CONSTRAINT triage_edstays_fk
FOREIGN KEY (stay_id)
REFERENCES mimic_ed.edstays (stay_id);
REFERENCES mimiciv_ed.edstays (stay_id);

ALTER TABLE mimic_ed.vitalsign DROP CONSTRAINT IF EXISTS vitalsign_edstays_fk CASCADE;
ALTER TABLE mimic_ed.vitalsign
ALTER TABLE mimiciv_ed.vitalsign DROP CONSTRAINT IF EXISTS vitalsign_edstays_fk CASCADE;
ALTER TABLE mimiciv_ed.vitalsign
ADD CONSTRAINT vitalsign_edstays_fk
FOREIGN KEY (stay_id)
REFERENCES mimic_ed.edstays (stay_id);
REFERENCES mimiciv_ed.edstays (stay_id);

0 comments on commit 930533b

Please sign in to comment.