Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update uom for measurements #20

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
15 changes: 10 additions & 5 deletions MSSQL/preparePCORnetOntology.sql
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
-- Modify the PCORnet ontology to be compatible with the new version of the OMOP transform, i2o 2020
-- Run this from your i2b2 database that has the mapped PCORnet ontology!
-- Jeff Klann PhD, April 2020
--------------------------------------------------------------------------------------------------------
-- Description: Prep the local PCORnet ontology for use in the OMOP transformation
-- Run this from your i2b2 database that has the mapped PCORnet ontology!
-- Authored By: Jeff Klann PhD, April 2020
-- Updated on: 2020-12-07 by Kevin Embree
-- To include i_unit column to maintain compatibility with PHS specific logic
--------------------------------------------------------------------------------------------------------

-- Set up the extra columns i_stdcode, i_stddomain for labs
-- Set up the extra columns i_stdcode, i_stddomain, i_unit for labs
ALTER TABLE [dbo].[pcornet_lab]
ADD [i_stdcode] varchar(50) NULL,
[i_stddomain] varchar(25) NULL
[i_stddomain] varchar(25) NULL,
[i_unit] varchar(25) NULL
GO
CREATE NONCLUSTERED INDEX [pcornetlab_stdcode]
ON [dbo].[pcornet_lab]([i_stdcode])
Expand Down
75 changes: 75 additions & 0 deletions MSSQL/preparePHSOntology.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
---------------------------------------------------------------------------------------------
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This script almost could be used generally, not just at PHS. You don't need to make those changes, but please describe what it's doing in the documentation and it is adaptable to any site using low/high/units in metadata XML.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I would rename it something like extractUnitsFromOntology

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed the script to be not PHS specific.

-- Mass General Brigham specific modifications
-- Description: i2o_transform works off the PCORNET ARCH ontologies, following script
-- --Modifies the transformation to use i2b2 ontoloies in certain circumstances
-- --Adds manual mappings specific to Mass General Brigham
-- Authored by: Jeff Klann
-- Updated by: Kevin Embree on 2020-12-07 to use units specified in the MGB i2b2 XML
-- Added manual mappings for unit conversion
--------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------
-- When to run....
-- After the initial install of the pcornet Ontology or updates to the preparePCORnetOntology.sql
-- Run the new preparePCORnetOntology.sql
-- Subsequent to preparePCORnetOntology.sql For Mass General Brigham users, after delivery of a new i2b2 datamart or updates to the PrepNewOMOPLoader_PHS.sql
-- Run this script, PrepNewOMOPLoader_PHS.sql
--------------------------------------------------------------------------------------------

-- Set up the extra columns i_stdcode, i_stddomain
ALTER TABLE [dbo].[i2b2metadata]
ADD [i_stdcode] varchar(100) NULL,
[i_stddomain] varchar(100) NULL,
[i_unit] varchar(100) NULL
GO
CREATE NONCLUSTERED INDEX [i2b2meta_stdcode]
ON [dbo].[i2b2metadata]([i_stdcode])
GO

-- Chris' approach, use a view
drop view vw_labtests_reconstructed
GO
create view vw_LabTests_Reconstructed
as
with t as (
select l.c_name,
l.c_basecode,
f.ENCOUNTER_NUM,
f.PATIENT_NUM,
f.VALTYPE_CD,
f.NVAL_NUM,
f.TVAL_CHAR,
f.VALUEFLAG_CD,
try_cast(l.c_metadataxml as xml) valuexml
from i2b2metadata l
inner join observation_fact f on l.C_BASECODE = f.CONCEPT_CD
where l.c_fullname like '\I2B2MetaData\LabTests\%')
select c_name LabName,
C_BASECODE Concept_Cd,
ENCOUNTER_NUM Encounter_Num,
PATIENT_NUM Patient_Num,
VALTYPE_CD ValueType,
NVAL_NUM NumericValue,
TVAL_CHAR TextValue,
VALUEFLAG_CD ValueFlag,
valuexml,
valuexml.value('(/ValueMetadata/Loinc)[1]','VARCHAR(100)') Loinc,
valuexml.value('(/ValueMetadata/LowofLowValue)[1]','VARCHAR(100)') RefLowofLow,
valuexml.value('(/ValueMetadata/HighofLowValue)[1]','VARCHAR(100)') RefHighofLow,
valuexml.value('(/ValueMetadata/LowofHighValue)[1]','VARCHAR(100)') RefLowofHigh,
valuexml.value('(/ValueMetadata/HighofHighValue)[1]','VARCHAR(100)') RefHighofHigh,
valuexml.value('(/ValueMetadata/UnitValues/NormalUnits)[1]','VARCHAR(100)') Units
from t
GO

-- Update to set i_stddomain, i_stdcode and i_unit all at once from XML no need for vw_LabTests_Reconstructed
update m set i_stddomain='LOINC',i_stdcode=try_cast(m.c_metadataxml as xml).value('(/ValueMetadata/Loinc)[1]','VARCHAR(50)'), i_unit = try_cast(m.c_metadataxml as xml).value('(/ValueMetadata/UnitValues/NormalUnits)[1]','VARCHAR(25)') from i2b2metadata m
where m.C_FULLNAME like '%\I2B2MetaData\LabTests\%'
GO
-- Create the new views - change COVID_Mart to your DB name
IF EXISTS (SELECT * FROM sys.views WHERE name = N'i2o_ontology_lab') DROP VIEW i2o_ontology_lab
IF EXISTS (SELECT * FROM sys.views WHERE name = N'i2o_ontology_drug') DROP VIEW i2o_ontology_drug
GO
create view i2o_ontology_lab as (select * from AllOfUs_Mart..i2b2metadata where i_stddomain='LOINC')
GO
create view i2o_ontology_drug as (select * from AllOfUs_Mart..pcornet_med where i_stddomain='RxNorm' or i_stddomain='NDC')
GO