Commit 70956f24 authored by Sebastian Mate's avatar Sebastian Mate
Browse files

Also integrate Observation into this code block

parent 2410d642
......@@ -348,10 +348,11 @@ begin
end if;
end if;
--
-- *** Handle FHIR CONDITION, PROCEDURE resource ***
-- *** Handle various types of resources ***
--
if FHIR_resourcetype = 'Condition' or
FHIR_resourcetype = 'Procedure' then
FHIR_resourcetype = 'Procedure' or
FHIR_resourcetype = 'Observation' then
-- Delete previous data:
perform i2b2miracum.fhir_elt_log('Deleting previous entries in OBSERVATION_FACT.');
delete from i2b2miracum.observation_fact where observation_blob = FHIR_id;
......@@ -370,12 +371,24 @@ begin
else '@'
end, -- modifier_cd
nextval('instance_num_seq'), -- instance_num
'@', -- valtype_cd
null, -- tval_char
null, -- nval_num
null, -- valueflag_cd
null, -- quantity_num
null, -- units_cd
case when FHIR_resourcetype = 'Observation' then 'N'
else '@'
end, -- valtype_cd
case when FHIR_resourcetype = 'Observation' then 'E'
else null
end, -- tval_char
case when FHIR_resourcetype = 'Observation' then fhir_data.valueQuantity_value
else null
end, -- nval_num
case when FHIR_resourcetype = 'Observation' then ''
else null
end, -- valueflag_cd
case when FHIR_resourcetype = 'Observation' then 1
else null
end, -- quantity_num
case when FHIR_resourcetype = 'Observation' then fhir_data.valueQuantity_unit
else null
end, -- units_cd
case when fhir_data.EndTimes is not null then fhir_data.EndTimes
else '-infinity'::timestamptz
end, -- end_date
......@@ -392,48 +405,6 @@ begin
end if;
/*
--
-- *** Handle FHIR OBSERVATION resource ***
--
if FHIR_resourcetype = 'Observation' then
-- Delete previous data:
perform i2b2miracum.fhir_elt_log('Deleting previous entries in OBSERVATION_FACT.');
delete from i2b2miracum.observation_fact where observation_blob = FHIR_id;
-- Insert new data:
perform i2b2miracum.fhir_elt_log('Inserting into OBSERVATION_FACT.');
insert into i2b2miracum.observation_fact (encounter_num, patient_num, concept_cd, provider_id, start_date, modifier_cd, instance_num, valtype_cd, tval_char, nval_num, valueflag_cd, quantity_num, units_cd, end_date, location_cd, observation_blob, confidence_num, update_date, download_date, import_date, sourcesystem_cd, upload_id, text_search_index)
select i2b2_encounter_identifier, -- encounter_num
i2b2_patient_identifier, -- patient_num
i2b2miracum.get_system_abbrv(fhir_data.MainSystem) || ':' || fhir_data.MainCode, -- concept_cd
'FHIR', -- provider_id
case when fhir_data.StartTimes is not null then fhir_data.StartTimes
else '-infinity'::timestamptz
end, -- start_date
case when fhir_data.ModifierSystem is not null
then i2b2miracum.get_system_abbrv(fhir_data.ModifierSystem) || ':' || fhir_data.ModifierCode
else '@'
end, -- modifier_cd
nextval('instance_num_seq'), -- instance_num
'N', -- valtype_cd
'E', -- tval_char
fhir_data.valueQuantity_value, -- nval_num
'', -- valueflag_cd
1, -- quantity_num
fhir_data.valueQuantity_unit, -- units_cd
case when fhir_data.EndTimes is not null then fhir_data.EndTimes
else '-infinity'::timestamptz
end, -- end_date
'', -- location_cd
ID, -- observation_blob
0, -- confidence_num
now(), -- update_date
now(), -- download_date
now(), -- import_date
'Observation.' || ModifierType FHIR_sourcesystem, -- sourcesystem_cd
1, -- upload_id
nextval('instance_num_seq') -- text_search_index
from (select * from select_fhir_fields(fhir)) as fhir_data;
end if;
--
-- *** Handle GECCO FHIR Immunization resource ***
--
if FHIR_resourcetype = 'Immunization' then // TODO !!!
......@@ -517,48 +488,6 @@ begin
from (select * from select_fhir_fields(fhir)) as fhir_data;
end if;
--
-- *** Handle FHIR PROCEDURE resource ***
--
if FHIR_resourcetype = 'Procedure' then
-- Delete previous data:
perform i2b2miracum.fhir_elt_log('Deleting previous entries in OBSERVATION_FACT.');
delete from i2b2miracum.observation_fact where observation_blob = FHIR_id;
-- Insert new data:
perform i2b2miracum.fhir_elt_log('Inserting into OBSERVATION_FACT.');
insert into i2b2miracum.observation_fact (encounter_num, patient_num, concept_cd, provider_id, start_date, modifier_cd, instance_num, valtype_cd, tval_char, nval_num, valueflag_cd, quantity_num, units_cd, end_date, location_cd, observation_blob, confidence_num, update_date, download_date, import_date, sourcesystem_cd, upload_id, text_search_index)
select i2b2_encounter_identifier, -- encounter_num
i2b2_patient_identifier, -- patient_num
i2b2miracum.get_system_abbrv(fhir_data.MainSystem) || ':' || fhir_data.MainCode, -- concept_cd
'FHIR', -- provider_id
case when fhir_data.StartTimes is not null then fhir_data.StartTimes
else '-infinity'::timestamptz
end, -- start_date
case when fhir_data.ModifierSystem is not null
then i2b2miracum.get_system_abbrv(fhir_data.ModifierSystem) || ':' || fhir_data.ModifierCode
else '@'
end, -- modifier_cd
nextval('instance_num_seq'), -- instance_num
'@', -- valtype_cd
null, -- tval_char
null, -- nval_num
null, -- valueflag_cd
null, -- quantity_num
null, -- units_cd
case when fhir_data.EndTimes is not null then fhir_data.EndTimes
else '-infinity'::timestamptz
end, -- end_date
'', -- location_cd
ID, -- observation_blob
0, -- confidence_num
now(), -- update_date
now(), -- download_date
now(), -- import_date
'Procedure.' || ModifierType FHIR_sourcesystem, -- sourcesystem_cd
1, -- upload_id
nextval('instance_num_seq') -- text_search_index
from (select * from select_fhir_fields(fhir)) as fhir_data;
end if;
--
-- *** Handle FHIR DIAGNOSTICREPORT resource ***
--
if FHIR_resourcetype = 'DiagnosticReport' then
......
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