Commit 592627e4 authored by Sebastian Mate's avatar Sebastian Mate
Browse files

GECCO: Update ETL for Condition

parent 1a6636c4
create table i2b2miracum.FhirFields as (
select
''::text ResourceType,
''::text Profile,
''::text SystemPath,
''::text SystemValue,
''::text CodePath,
''::text CodeValue,
''::text DisplayPath,
''::text DisplayValue );
truncate table i2b2miracum.FhirFields;
-- Then paste the contents of FhirFields.tsv into that table.
-- List all resource types:
select distinct resourcetype from i2b2miracum.FhirFields;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Condition' 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;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Consent' 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 = 'Immunization' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Observation' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Procedure' order by systempath asc;
This diff is collapsed.
with FhirTempTable (fhir2) as (select '{
"resourceType": "Condition",
"id": "36acd3086ae51cb61cd000f0faaf709d",
"meta": {
"profile": [ "https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/diagnosis-covid-19" ]
},
"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"
} ],
"clinicalStatus": {
"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)"
} ]
},
"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)"
} ]
},
"subject": {
"reference": "Patient/e7407eae9d4dc4cb8def9a0f96932c02"
},
"recordedDate": "1970-01-01T00:00:00+00:00",
"_recordedDate": {
"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"
} ]
}
} ]
}'::jsonb fhir)
select
(fhir2->>'id')::text as ID,
StartTimes, EndTimes,
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 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
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
from FhirTempTable
union
select 'clinicalStatus' ModifierType, -- GECCO
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
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
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
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
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
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
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) as sq4 on true
;
\ No newline at end of file
......@@ -360,15 +360,13 @@ 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.code_coding_system) || ':' || fhir_data.code_coding_code, -- concept_cd
i2b2miracum.get_system_abbrv(fhir_data.MainSystem) || ':' || fhir_data.MainCode, -- concept_cd
'FHIR', -- provider_id
case when fhir_data.OnsetDateTime is not null then fhir_data.OnsetDateTime
case when fhir_data.StartTimes is not null then fhir_data.StartTimes
else '-infinity'::timestamptz
end, -- start_date
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
case when fhir_data.ModifierSystem is not null
then i2b2miracum.get_system_abbrv(fhir_data.ModifierSystem) || ':' || fhir_data.ModifierCode
else '@'
end, -- modifier_cd
nextval('instance_num_seq'), -- instance_num
......@@ -378,41 +376,76 @@ 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.EndTimes is not null then fhir_data.EndTimes
else '-infinity'::timestamptz
end, -- end_date
'', -- location_cd
FHIR_id, -- observation_blob
ID, -- observation_blob
0, -- confidence_num
now(), -- update_date
now(), -- download_date
now(), -- import_date
FHIR_sourcesystem, -- sourcesystem_cd
'Condition.' || ModifierType 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,
select
(fhir2->>'id')::text as ID,
OnsetDateTime,
code_coding_code,
code_coding_system,
verificationStatus_coding_code,
verificationStatus_coding_system,
extension_valueCodeableConcept_coding_code,
extension_valueCodeableConcept_coding_system
StartTimes, EndTimes,
MainSystem, MainCode,
ModifierType, ModifierSystem, ModifierCode
from FhirTempTable
left join (select (fhir2->>'recordedDate')::timestamp as OnsetDateTime
left join (select (fhir2->>'recordedDate')::timestamp as StartTimes
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
left join (select (fhir2->>'recordedDate')::timestamp as EndTimes
from FhirTempTable) as sq2 on true
left join (select jsonb_array_elements(fhir2->'verificationStatus'->'coding')->>'code' as verificationStatus_coding_code,
jsonb_array_elements(fhir2->'verificationStatus'->'coding')->>'system' as verificationStatus_coding_system
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 jsonb_array_elements(jsonb_array_elements(fhir2->'extension')->'valueCodeableConcept'->'coding')->>'code' as extension_valueCodeableConcept_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir2->'extension')->'valueCodeableConcept'->'coding')->>'system' as extension_valueCodeableConcept_coding_system
left join (select 'bodySite' ModifierType, -- GECCO
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
from FhirTempTable
union
select 'clinicalStatus' ModifierType, -- GECCO
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
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
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
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
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
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
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) 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