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

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

parent e34b9678
......@@ -20,7 +20,7 @@
-- 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
-- - Reimplementation of "Procedure" resource processing to make it compatible with GECCO modeling
-- ============= Create Basic Tables =============
......@@ -390,18 +390,12 @@ begin
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
--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 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 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;
......@@ -580,7 +574,7 @@ 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.performedDateTime is not null then fhir_data.performedDateTime
else '-infinity'::timestamptz end, -- start_date
......@@ -603,11 +597,21 @@ 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->>'performedDateTime')::timestamp as performedDateTime
) 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
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
) fhir_data;
end if;
--
-- *** Handle FHIR MEDICATION 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