Skip to content

Commit

Permalink
Added if exists/select + drop statement for the i2b2concept synonym. …
Browse files Browse the repository at this point in the history
…Added if exists/select + drop statements for the primary key constraints on the measurement, drug exposure, procedure occurrence and condition occurrence tables
  • Loading branch information
anaholzbach committed Jul 14, 2017
1 parent 7959d0c commit d9926af
Showing 1 changed file with 37 additions and 20 deletions.
57 changes: 37 additions & 20 deletions MSSQL/OMOPLoader.sql
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
----------------------------------------------------------------------------------------------------------------------------------------

-- Change to your omop database
use PMI
use i2b2stub;
go

-- drop any existing synonyms
IF EXISTS (SELECT * FROM sys.synonyms WHERE name = N'i2b2concept') DROP SYNONYM i2b2concept
IF EXISTS (SELECT * FROM sys.synonyms WHERE name = N'i2b2fact') DROP SYNONYM i2b2fact
IF EXISTS (SELECT * FROM sys.synonyms WHERE name = N'i2b2patient') DROP SYNONYM i2b2patient
IF EXISTS (SELECT * FROM sys.synonyms WHERE name = N'i2b2visit') DROP SYNONYM i2b2visit
Expand All @@ -41,31 +42,35 @@ GO

-- You will almost certainly need to edit your database name
-- Synonyms for dimension tables
create synonym i2b2visit for PMI..visit_dimension
create synonym i2b2visit for i2b2stub..visit_dimension
GO
create synonym i2b2patient for PMI..patient_dimension
create synonym i2b2patient for i2b2stub..patient_dimension
GO
create synonym i2b2fact for PMI..observation_fact
create synonym i2b2fact for i2b2stub..observation_fact
GO
create synonym i2b2concept for PMI..concept_dimension
create synonym i2b2concept for i2b2stub..concept_dimension
GO

-- You will almost certainly need to edit your database name
-- Synonyms for ontology dimensions and loyalty cohort summary
create synonym pcornet_med for PMI..pcornet_med
GO
create synonym pcornet_lab for PMI..pcornet_lab
GO
create synonym pcornet_diag for PMI..pcornet_diag
GO
create synonym pcornet_demo for PMI..pcornet_demo
GO
create synonym pcornet_proc for PMI..pcornet_proc
GO
create synonym pcornet_vital for PMI..pcornet_vital_30
GO
create synonym pcornet_enc for PMI..pcornet_enc_15
GO
-- The synonyms in comments have identical names to the tables -
-- you will only need to edit and uncomment if your tables have
-- names other than these

--create synonym pcornet_med for i2b2stub..pcornet_med
--GO
--create synonym pcornet_lab for i2b2stub..pcornet_lab
--GO
--create synonym pcornet_diag for i2b2stub..pcornet_diag
--GO
--create synonym pcornet_demo for i2b2stub..pcornet_demo
--GO
create synonym pcornet_proc for i2b2stub..pcornet_proc_nocpt
GO
--create synonym pcornet_vital for i2b2stub..pcornet_vital
--GO
--create synonym pcornet_enc for i2b2stub..pcornet_enc
--GO

-- Create the demographics codelist (no need to modify)
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[omop_codelist]') AND type in (N'U'))
Expand Down Expand Up @@ -156,28 +161,40 @@ GO




IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME = 'xpk_condition_occurrence')
Alter table condition_occurrence DROP constraint xpk_condition_occurrence
Go
Alter Table condition_occurrence Drop Column condition_occurrence_id
Go

Alter Table condition_occurrence
Add condition_occurrence_id Int Identity(1, 1)
Go


IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME = 'xpk_procedure_occurrence')
Alter table procedure_occurrence DROP constraint xpk_procedure_occurrence
Go
Alter Table procedure_occurrence Drop Column procedure_occurrence_id
Go

Alter Table procedure_occurrence
Add procedure_occurrence_id Int Identity(1, 1)
Go

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME = 'xpk_measurement')
Alter table measurement DROP constraint xpk_measurement
Go
Alter Table measurement Drop Column measurement_id
Go

Alter Table measurement
Add measurement_id Int Identity(1, 1)
Go

IF EXISTS (SELECT * FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS WHERE CONSTRAINT_NAME = 'xpk_drug_exposure')
Alter table drug_exposure DROP constraint xpk_drug_exposure
Go
Alter Table drug_exposure Drop Column drug_exposure_id
Go

Expand Down

0 comments on commit d9926af

Please # to comment.