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

Reimplementation of "Condition" resource processing to make it compatible with GECCO modeling

parent 2092aecf
......@@ -16,6 +16,8 @@
-- 2021-01-27: - Add support for various ways of patient-referencing for GECCO resources
-- - Initial support for resource type "Consent"
-- - Note: Implementation of "Immunization" and "Consent" useless, as-is. TODO
-- 2021-01-28: - Reimplementation of "Condition" resource processing to make it compatible with GECCO modeling
-- ============= Create Basic Tables =============
......@@ -95,6 +97,7 @@ begin
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/ecrf-parameter-codes' then return 'ECRF';
when systemlink = 'http://fdasis.nlm.nih.gov' then return 'FDASIS';
when systemlink = 'http://dicom.nema.org/resources/ontology/DCM' then return 'DCM';
when systemlink = 'http://terminology.hl7.org/CodeSystem/condition-ver-status' then return 'CVS';
else
perform i2b2miracum.fhir_elt_log('ERROR: Coding system unknown: ' || systemlink);
return 'UNKNOWN';
......@@ -334,15 +337,20 @@ begin
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)
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.system) || ':' || fhir_data.code, -- concept_cd
i2b2miracum.get_system_abbrv(fhir_data.CodeCodingSystem) || ':' || fhir_data.CodeCodingCode, -- concept_cd
'FHIR', -- provider_id
case when fhir_data.onsetDateTime is not null then fhir_data.onsetDateTime
case when fhir_data.OnsetDateTime is not null then fhir_data.OnsetDateTime
else now()
end, -- start_date
'@', -- modifier_cd
case when fhir_data.VerificationStatusCodingSystem is not null
then i2b2miracum.get_system_abbrv(fhir_data.VerificationStatusCodingSystem) || ':' || fhir_data.VerificationStatusCodingCode
when fhir_data.ExtensionValueCodeableConceptCodingSystem is not null
then i2b2miracum.get_system_abbrv(fhir_data.ExtensionValueCodeableConceptCodingSystem) || ':' || fhir_data.ExtensionValueCodeableConceptCodingCode
else '@'
end, -- modifier_cd
nextval('instance_num_seq'), -- instance_num
'@', -- valtype_cd
null, -- tval_char
......@@ -350,7 +358,7 @@ begin
null, -- valueflag_cd
null, -- quantity_num
null, -- units_cd
case when fhir_data.onsetDateTime is not null then fhir_data.onsetDateTime
case when fhir_data.OnsetDateTime is not null then fhir_data.OnsetDateTime
else now()
end, -- end_date
'', -- location_cd
......@@ -362,11 +370,30 @@ begin
FHIR_sourcesystem, -- sourcesystem_cd
1, -- upload_id
nextval('instance_num_seq') -- text_search_index
from (SELECT
jsonb_array_elements(fhir->'code'->'coding')->>'code' as code,
jsonb_array_elements(fhir->'code'->'coding')->>'system' as system,
(fhir->>'onsetDateTime')::timestamp as onsetDateTime
) fhir_data;
from (
with FhirTempTable(fhir2) AS (select fhir)
select
jsonb_path_query(fhir2, '$.id')->>0 as ID,
OnsetDateTime,
CodeCodingCode,
CodeCodingSystem,
VerificationStatusCodingCode,
VerificationStatusCodingSystem,
ExtensionValueCodeableConceptCodingCode,
ExtensionValueCodeableConceptCodingSystem
from FhirTempTable
left join (select (fhir2->>'onsetDateTime')::timestamp as OnsetDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_path_query(fhir2, '$.code.coding.code')->>0 as CodeCodingCode,
jsonb_path_query(fhir2, '$.code.coding.system')->>0 as CodeCodingSystem
from FhirTempTable) as sq2 on true
left join (select jsonb_path_query(fhir2, '$.verificationStatus.coding.code')->>0 as VerificationStatusCodingCode,
jsonb_path_query(fhir2, '$.verificationStatus.coding.system')->>0 as VerificationStatusCodingSystem
from FhirTempTable) as sq3 on true
left join (select jsonb_path_query(fhir2, '$.extension.valueCodeableConcept.coding.code')->>0 as ExtensionValueCodeableConceptCodingCode,
jsonb_path_query(fhir2, '$.extension.valueCodeableConcept.coding.system')->>0 as ExtensionValueCodeableConceptCodingSystem
from FhirTempTable) as sq4 on true
) fhir_data;
end if;
--
-- *** Handle FHIR OBSERVATION resource ***
......
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