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

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

Use better names for variables that hold FHIR data
parent e5139ea4
......@@ -19,6 +19,7 @@
-- 2021-01-28: - Reimplementation of "Condition" resource processing to make it compatible with GECCO modeling
-- 2021-01-29: - Achieve backward-compatibility with PostgreSQL 9.4 (old Miracum i2b2 Deployment)
-- - For start_date and end_date, instead of now(), use '-infinity'::timestamptz if no timestamp could be determined
-- - Reimplementation of "Observation" resource processing to make it compatible with GECCO modeling
-- ============= Create Basic Tables =============
......@@ -342,15 +343,15 @@ begin
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.CodeCodingSystem) || ':' || fhir_data.CodeCodingCode, -- concept_cd
i2b2miracum.get_system_abbrv(fhir_data.code_coding_system) || ':' || fhir_data.code_coding_code, -- concept_cd
'FHIR', -- provider_id
case when fhir_data.OnsetDateTime is not null then fhir_data.OnsetDateTime
else '-infinity'::timestamptz
end, -- start_date
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
case when fhir_data.verificationStatus_coding_system is not null
then i2b2miracum.get_system_abbrv(fhir_data.verificationStatus_coding_system) || ':' || fhir_data.verificationStatus_coding_code
when fhir_data.extension_valueCodeableConcept_coding_system is not null
then i2b2miracum.get_system_abbrv(fhir_data.extension_valueCodeableConcept_coding_system) || ':' || fhir_data.extension_valueCodeableConcept_coding_code
else '@'
end, -- modifier_cd
nextval('instance_num_seq'), -- instance_num
......@@ -378,29 +379,29 @@ begin
--jsonb_path_query(fhir2, '$.id')->>0 as ID,
(fhir2->>'id')::text as ID,
OnsetDateTime,
CodeCodingCode,
CodeCodingSystem,
VerificationStatusCodingCode,
VerificationStatusCodingSystem,
ExtensionValueCodeableConceptCodingCode,
ExtensionValueCodeableConceptCodingSystem
code_coding_code,
code_coding_system,
verificationStatus_coding_code,
verificationStatus_coding_system,
extension_valueCodeableConcept_coding_code,
extension_valueCodeableConcept_coding_system
from FhirTempTable
left join (select (fhir2->>'recordedDate')::timestamp as OnsetDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_array_elements(fhir->'code'->'coding')->>'code' as CodeCodingCode,
jsonb_array_elements(fhir->'code'->'coding')->>'system' as CodeCodingSystem
--jsonb_path_query(fhir2, '$.code.coding.code')->>0 as CodeCodingCode,
--jsonb_path_query(fhir2, '$.code.coding.system')->>0 as CodeCodingSystem
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
--jsonb_path_query(fhir2, '$.code.coding.code')->>0 as code_coding_code,
--jsonb_path_query(fhir2, '$.code.coding.system')->>0 as code_coding_system
from FhirTempTable) as sq2 on true
left join (select jsonb_array_elements(fhir->'verificationStatus'->'coding')->>'code' as VerificationStatusCodingCode,
jsonb_array_elements(fhir->'verificationStatus'->'coding')->>'system' as VerificationStatusCodingSystem
--jsonb_path_query(fhir2, '$.verificationStatus.coding.code')->>0 as VerificationStatusCodingCode,
--jsonb_path_query(fhir2, '$.verificationStatus.coding.system')->>0 as VerificationStatusCodingSystem
left join (select jsonb_array_elements(fhir->'verificationStatus'->'coding')->>'code' as verificationStatus_coding_code,
jsonb_array_elements(fhir->'verificationStatus'->'coding')->>'system' as verificationStatus_coding_system
--jsonb_path_query(fhir2, '$.verificationStatus.coding.code')->>0 as verificationStatus_coding_code,
--jsonb_path_query(fhir2, '$.verificationStatus.coding.system')->>0 as verificationStatus_coding_system
from FhirTempTable) as sq3 on true
left join (select jsonb_array_elements(jsonb_array_elements(fhir->'extension')->'valueCodeableConcept'->'coding')->>'code' as ExtensionValueCodeableConceptCodingCode,
jsonb_array_elements(jsonb_array_elements(fhir->'extension')->'valueCodeableConcept'->'coding')->>'system' as ExtensionValueCodeableConceptCodingSystem
--jsonb_path_query(fhir2, '$.extension.valueCodeableConcept.coding.code')->>0 as ExtensionValueCodeableConceptCodingCode,
--jsonb_path_query(fhir2, '$.extension.valueCodeableConcept.coding.system')->>0 as ExtensionValueCodeableConceptCodingSystem
left join (select jsonb_array_elements(jsonb_array_elements(fhir->'extension')->'valueCodeableConcept'->'coding')->>'code' as extension_valueCodeableConcept_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir->'extension')->'valueCodeableConcept'->'coding')->>'system' as extension_valueCodeableConcept_coding_system
--jsonb_path_query(fhir2, '$.extension.valueCodeableConcept.coding.code')->>0 as extension_valueCodeableConcept_coding_code,
--jsonb_path_query(fhir2, '$.extension.valueCodeableConcept.coding.system')->>0 as extension_valueCodeableConcept_coding_system
from FhirTempTable) as sq4 on true
) fhir_data;
end if;
......@@ -416,11 +417,15 @@ begin
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.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
case when fhir_data.performedDateTime is not null then fhir_data.performedDateTime
when fhir_data.effectiveDateTime is not null then fhir_data.effectiveDateTime
else '-infinity'::timestamptz end, -- start_date
'@', -- modifier_cd
case when fhir_data.valueCodeableConcept_coding_system is not null
then i2b2miracum.get_system_abbrv(fhir_data.valueCodeableConcept_coding_system) || ':' || fhir_data.valueCodeableConcept_coding_code
else '@'
end, -- modifier_cd
nextval('instance_num_seq'), -- instance_num
'N', -- valtype_cd
'E', -- tval_char
......@@ -428,7 +433,8 @@ begin
'', -- valueflag_cd
1, -- quantity_num
fhir_data.valueQuantity_unit, -- units_cd
case when fhir_data.effectiveDateTime is not null then fhir_data.effectiveDateTime
case when fhir_data.performedDateTime is not null then fhir_data.performedDateTime
when fhir_data.effectiveDateTime is not null then fhir_data.effectiveDateTime
else '-infinity'::timestamptz end, -- end_date
'', -- location_cd
FHIR_id, -- observation_blob
......@@ -439,15 +445,38 @@ 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->>'effectiveDateTime')::timestamp as effectiveDateTime,
(fhir->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value,
fhir->'valueQuantity'->>'unit'::text as valueQuantity_unit,
fhir->'valueQuantity'->>'system'::text as valueQuantity_system,
fhir->'valueQuantity'->>'code'::text as valueQuantity_code
) fhir_data;
from (
with FhirTempTable(fhir2) AS (select fhir)
select
--jsonb_path_query(fhir2, '$.id')->>0 as ID,
(fhir2->>'id')::text as ID,
performedDateTime,
code_coding_code,
code_coding_system,
valueQuantity_value,
valueQuantity_unit,
valueQuantity_system,
valueQuantity_code,
valueCodeableConcept_coding_code,
valueCodeableConcept_coding_system,
effectiveDateTime
from FhirTempTable
left join (select (fhir2->>'performedDateTime')::timestamp as performedDateTime
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 (fhir->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value,
fhir->'valueQuantity'->>'unit'::text as valueQuantity_unit,
fhir->'valueQuantity'->>'system'::text as valueQuantity_system,
fhir->'valueQuantity'->>'code'::text as valueQuantity_code
from FhirTempTable) as sq3 on true
left join (select jsonb_array_elements(fhir->'valueCodeableConcept'->'coding')->>'code' as valueCodeableConcept_coding_code,
jsonb_array_elements(fhir->'valueCodeableConcept'->'coding')->>'system' as valueCodeableConcept_coding_system
from FhirTempTable) as sq4 on true
left join (select (fhir2->>'effectiveDateTime')::timestamp as effectiveDateTime
from FhirTempTable) as sq5 on true
) fhir_data;
end if;
--
-- *** Handle GECCO FHIR Immunization 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