Commit 3d3ebe0f authored by Sebastian Mate's avatar Sebastian Mate
Browse files

GECCO: Update ETL for Procedure

parent 592627e4
......@@ -17,7 +17,13 @@ truncate table i2b2miracum.FhirFields;
-- List all resource types:
select distinct resourcetype from i2b2miracum.FhirFields;
select distinct systempath from i2b2miracum.FhirFields;
order by systempath asc;;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Condition' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Procedure' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'MedicationStatement' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'DiagnosticReport' order by systempath asc;
......
with FhirTempTable (fhir2) as (select '{
"resourceType": "Condition",
"id": "36acd3086ae51cb61cd000f0faaf709d",
"resourceType": "Procedure",
"id": "21d1509d40a698daddad8723861bf665",
"meta": {
"profile": [ "https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/diagnosis-covid-19" ]
"profile": [ "https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/respiratory-therapies" ]
},
"identifier": [ {
"system": "https://mein.krankenhaus.de/fhir/NamingSystem/conditionId",
"value": "2-GECCOVISIT.null-Form.krankheitsbeginn_aufnahme.1-krankheitsbeginn_aufnahme.erkrankungsphase_zum_zeitpunkt_der_diagnose_code.1-erkrankungsphase_zum_zeitpunkt_der_diagnose_code"
"system": "https://mein.krankenhaus.de/fhir/NamingSystem/procedureId",
"value": "2-GECCOVISIT.null-Form.therapie.1-therapie.beatmungstherapie_code.1-beatmungstherapie"
} ],
"clinicalStatus": {
"status": "in-progress",
"category": {
"coding": [ {
"system": "http://terminology.hl7.org/CodeSystem/condition-clinical",
"code": "active",
"display": "Active"
} ]
},
"verificationStatus": {
"coding": [ {
"system": "http://terminology.hl7.org/CodeSystem/condition-ver-status",
"code": "confirmed",
"display": "Confirmed"
}, {
"system": "http://snomed.info/sct",
"code": "410605003",
"display": "Confirmed present (qualifier value)"
"code": "277132007",
"display": "Therapeutic procedure (procedure)"
} ]
},
"category": [ {
"coding": [ {
"system": "http://snomed.info/sct",
"code": "394807007",
"display": "Infectious diseases (specialty) (qualifier value)"
} ]
} ],
"code": {
"coding": [ {
"system": "http://snomed.info/sct",
"code": "840539006",
"display": "Disease caused by Severe acute respiratory syndrome coronavirus 2 (disorder)"
"code": "40617009:425391005=129121000"
} ]
},
"subject": {
"reference": "Patient/e7407eae9d4dc4cb8def9a0f96932c02"
},
"recordedDate": "1970-01-01T00:00:00+00:00",
"_recordedDate": {
"performedDateTime": "1970-01-01T00:00:00+00:00",
"_performedDateTime": {
"extension": [ {
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
"valueCode": "unknown"
} ]
},
"stage": [ {
"summary": {
"coding": [ {
"system": "http://snomed.info/sct",
"code": "255604002"
}, {
"system": "http://snomed.info/sct",
"code": "371923003"
} ]
},
"type": {
"coding": [ {
"system": "http://loinc.org",
"code": "88859-4"
}, {
"system": "http://snomed.info/sct",
"code": "385349001"
} ]
}
"usedCode": [ {
"coding": [ {
"system": "http://snomed.info/sct",
"code": "129121000"
} ]
} ]
}'::jsonb fhir)
select
......@@ -77,56 +45,73 @@ with FhirTempTable (fhir2) as (select '{
MainSystem, MainCode,
ModifierType, ModifierSystem, ModifierCode
from FhirTempTable
left join (select (fhir2->>'recordedDate')::timestamp as StartTimes
from FhirTempTable) as sq1 on true
left join (select (fhir2->>'recordedDate')::timestamp as EndTimes
from FhirTempTable) as sq2 on true
left join (select (fhir2->>'performedDateTime')::timestamp as StartTimes
from FhirTempTable
union
select (fhir2->>'recordedDate')::timestamp as StartTimes
from FhirTempTable
) as sq1 on true and StartTimes is not null
left join (select (fhir2->>'performedDateTime')::timestamp as EndTimes
from FhirTempTable
union
select (fhir2->>'recordedDate')::timestamp as EndTimes
from FhirTempTable) as sq2 on true and EndTimes is not null
left join (select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as MainCode,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as MainSystem
from FhirTempTable) as sq3 on true
left join (select 'bodySite' ModifierType, -- GECCO
left join (select 'bodySite' ModifierType, -- GECCO Condition, Procedure
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'code' as ModifierCode,
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'category' ModifierType, -- GECCO
jsonb_array_elements(jsonb_array_elements(fhir2->'category')->'coding')->>'code' as ModifierCode,
jsonb_array_elements(jsonb_array_elements(fhir2->'category')->'coding')->>'system' as ModifierSystem
--select 'category' ModifierType, -- GECCO Condition
-- jsonb_array_elements(jsonb_array_elements(fhir2->'category')->'coding')->>'code' as ModifierCode,
-- jsonb_array_elements(jsonb_array_elements(fhir2->'category')->'coding')->>'system' as ModifierSystem
-- from FhirTempTable
--union
select 'category' ModifierType, -- GECCO Procedure
jsonb_array_elements(fhir2->'category'->'coding')->>'code' as ModifierCode,
jsonb_array_elements(fhir2->'category'->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'clinicalStatus' ModifierType, -- GECCO
union
select 'clinicalStatus' ModifierType, -- GECCO Condition
jsonb_array_elements(fhir2->'clinicalStatus'->'coding')->>'code' as ModifierCode,
jsonb_array_elements(fhir2->'clinicalStatus'->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'modifierExtension.valueCodeableConcept' ModifierType, -- GECCO
select 'modifierExtension.valueCodeableConcept' ModifierType, -- GECCO Condition
jsonb_array_elements(jsonb_array_elements(fhir2->'modifierExtension')->'valueCodeableConcept'->'coding')->>'code' as ModifierCode,
jsonb_array_elements(jsonb_array_elements(fhir2->'modifierExtension')->'valueCodeableConcept'->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'severity' ModifierType, -- GECCO
select 'severity' ModifierType, -- GECCO Condition
jsonb_array_elements(fhir2->'severity'->'coding')->>'code' as ModifierCode,
jsonb_array_elements(fhir2->'severity'->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'stage.summary' ModifierType, -- GECCO
select 'stage.summary' ModifierType, -- GECCO Condition
jsonb_array_elements(jsonb_array_elements(fhir2->'stage')->'summary'->'coding')->>'code' as ModifierCode,
jsonb_array_elements(jsonb_array_elements(fhir2->'stage')->'summary'->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'stage.type' ModifierType, -- GECCO
select 'stage.type' ModifierType, -- GECCO Condition
jsonb_array_elements(jsonb_array_elements(fhir2->'stage')->'type'->'coding')->>'code' as ModifierCode,
jsonb_array_elements(jsonb_array_elements(fhir2->'stage')->'type'->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'verificationStatus' ModifierType, -- GECCO
select 'verificationStatus' ModifierType, -- GECCO Condition
jsonb_array_elements(fhir2->'verificationStatus'->'coding')->>'code' as ModifierCode,
jsonb_array_elements(fhir2->'verificationStatus'->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'extension.valueCodeableConcept' ModifierType, -- Nicht GECCO
union
select 'extension.valueCodeableConcept' ModifierType, -- Nicht-GECCO Condition
jsonb_array_elements(jsonb_array_elements(fhir2->'extension')->'valueCodeableConcept'->'coding')->>'code' as ModifierCode,
jsonb_array_elements(jsonb_array_elements(fhir2->'extension')->'valueCodeableConcept'->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'usedCode' ModifierType, -- GECCO Procedure
jsonb_array_elements(jsonb_array_elements(fhir2->'usedCode')->'coding')->>'code' as ModifierCode,
jsonb_array_elements(jsonb_array_elements(fhir2->'usedCode')->'coding')->>'system' as ModifierSystem
from FhirTempTable) as sq4 on true
;
\ No newline at end of file
......@@ -66,14 +66,13 @@ truncate table i2b2miracum.fhir_elt_log;
do $$
begin
alter table i2b2miracum.observation_fact add fhir_reference varchar(100) null;
create index observation_fact_observation_blob_idx on i2b2miracum.observation_fact (observation_blob);
create index observation_fact_fhir_reference_idx on i2b2miracum.observation_fact (fhir_reference);
exception
when duplicate_column then raise notice 'Column already exists.';
when others then raise notice 'Index or column already exists';
end;
$$;
--CREATE INDEX observation_fact_observation_blob_idx ON i2b2miracum.observation_fact (observation_blob);
--CREATE INDEX observation_fact_fhir_reference_idx ON i2b2miracum.observation_fact (fhir_reference);
-- Create OBSERVATION_FACT_TEMP, which will be used to store temporary data:
drop table if exists i2b2miracum.observation_fact_temp;
create table i2b2miracum.observation_fact_temp as (select * from i2b2miracum.observation_fact);
......@@ -357,7 +356,7 @@ 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.MainSystem) || ':' || fhir_data.MainCode, -- concept_cd
......@@ -388,9 +387,8 @@ begin
'Condition.' || ModifierType FHIR_sourcesystem, -- sourcesystem_cd
1, -- upload_id
nextval('instance_num_seq') -- text_search_index
from (
with FhirTempTable(fhir2) AS (select fhir)
select
from (with FhirTempTable(fhir2) AS (select fhir)
select
(fhir2->>'id')::text as ID,
StartTimes, EndTimes,
MainSystem, MainCode,
......@@ -680,23 +678,40 @@ begin
nextval('instance_num_seq') -- text_search_index
from (
with FhirTempTable(fhir2) AS (select fhir)
select
--jsonb_path_query(fhir2, '$.id')->>0 as ID,
select
(fhir2->>'id')::text as ID,
performedDateTime,
code_coding_code,
code_coding_system,
bodySite_coding_code,
bodySite_coding_system
StartTimes, EndTimes,
MainSystem, MainCode,
ModifierType, ModifierSystem, ModifierCode
from FhirTempTable
left join (select (fhir2->>'performedDateTime')::timestamp as performedDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as code_coding_code,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as code_coding_system
from FhirTempTable) as sq2 on true
left join (select jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'code' as bodySite_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'system' as bodySite_coding_system
left join (select (fhir2->>'performedDateTime')::timestamp as StartTimes
from FhirTempTable
union
select (fhir2->>'recordedDate')::timestamp as StartTimes
from FhirTempTable
) as sq1 on true and StartTimes is not null
left join (select (fhir2->>'performedDateTime')::timestamp as EndTimes
from FhirTempTable
union
select (fhir2->>'recordedDate')::timestamp as EndTimes
from FhirTempTable) as sq2 on true and EndTimes is not null
left join (select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as MainCode,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as MainSystem
from FhirTempTable) as sq3 on true
left join (select 'bodySite' ModifierType, -- GECCO Condition, Procedure
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'code' as ModifierCode,
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'category' ModifierType, -- GECCO Procedure
jsonb_array_elements(fhir2->'category'->'coding')->>'code' as ModifierCode,
jsonb_array_elements(fhir2->'category'->'coding')->>'system' as ModifierSystem
from FhirTempTable
union
select 'usedCode' ModifierType, -- GECCO Procedure
jsonb_array_elements(jsonb_array_elements(fhir2->'usedCode')->'coding')->>'code' as ModifierCode,
jsonb_array_elements(jsonb_array_elements(fhir2->'usedCode')->'coding')->>'system' as ModifierSystem
from FhirTempTable) as sq4 on true
) fhir_data;
end if;
--
......
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