Commit ec571597 authored by Sebastian Mate's avatar Sebastian Mate
Browse files

Implementation of support for "DiagnosticReport" resource

Update docu
parent f8c73823
......@@ -76,6 +76,20 @@ It does not yet process the fields:
* `category`
* `status`
### DiagnosticReport
Timestamps are derived from:
* `effectiveDateTime`
The following fields are used to generate i2b2 modifiers:
* `conclusionCode.coding.system` and `conclusionCode.coding.code`
It does not yet process the fields:
* `category`
......
......@@ -22,6 +22,8 @@
-- - Reimplementation of "Observation" resource processing to make it compatible with GECCO modeling
-- - Reimplementation of "Procedure" resource processing to make it compatible with GECCO modeling
-- 2021-02-01: - Add support for "bodySite" field in "Procedure" ressource
-- - Implementation of support for "DiagnosticReport" resource
-- ============= Create Basic Tables =============
......@@ -165,7 +167,7 @@ begin
FHIR_resourcetype != 'Medication' and
FHIR_resourcetype != 'MedicationStatement' and
FHIR_resourcetype != 'ServiceRequest' and -- Ignored, not useful for i2b2.
FHIR_resourcetype != 'DiagnosticReport' -- Ignored, not useful for i2b2.
FHIR_resourcetype != 'DiagnosticReport'
then raise exception 'Resource type "%" not supported.', FHIR_resourcetype; end if;
--
perform i2b2miracum.fhir_elt_log('--- Processing new ' || FHIR_resourcetype || ' resource:');
......@@ -623,6 +625,65 @@ begin
) fhir_data;
end if;
--
-- *** Handle FHIR DIAGNOSTICREPORT resource ***
--
if FHIR_resourcetype = 'DiagnosticReport' 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.code_coding_system) || ':' || fhir_data.code_coding_code, -- concept_cd
'FHIR', -- provider_id
case when fhir_data.effectiveDateTime is not null then fhir_data.effectiveDateTime
else '-infinity'::timestamptz end, -- start_date
case when fhir_data.conclusionCode_coding_system is not null
then i2b2miracum.get_system_abbrv(fhir_data.conclusionCode_coding_system) || ':' || fhir_data.conclusionCode_coding_code
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.effectiveDateTime is not null then fhir_data.effectiveDateTime
else '-infinity'::timestamptz end, -- end_date
'', -- location_cd
FHIR_id, -- observation_blob
0, -- confidence_num
now(), -- update_date
now(), -- download_date
now(), -- import_date
FHIR_sourcesystem, -- sourcesystem_cd
1, -- upload_id
nextval('instance_num_seq') -- text_search_index
from (
with FhirTempTable(fhir2) AS (select fhir)
select
--jsonb_path_query(fhir2, '$.id')->>0 as ID,
(fhir2->>'id')::text as ID,
effectiveDateTime,
code_coding_code,
code_coding_system,
conclusionCode_coding_code,
conclusionCode_coding_system
from FhirTempTable
left join (select (fhir2->>'effectiveDateTime')::timestamp as effectiveDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_array_elements(fhir->'code'->'coding')->>'code' as code_coding_code,
jsonb_array_elements(fhir->'code'->'coding')->>'system' as code_coding_system
from FhirTempTable) as sq2 on true
left join (select jsonb_array_elements(jsonb_array_elements(fhir->'conclusionCode')->'coding')->>'code' as conclusionCode_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir->'conclusionCode')->'coding')->>'system' as conclusionCode_coding_system
from FhirTempTable) as sq3 on true
) fhir_data;
end if;
--
-- *** Handle FHIR MEDICATION resource ***
--
if FHIR_resourcetype = 'Medication' 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