Commit 89b1ec2e authored by Sebastian Mate's avatar Sebastian Mate
Browse files

Complete re-implementation with full GECCO support for NUM CODEX

Also integrate MedicationStatement into generic code block
Add missing coding systems
parent dc54712e
......@@ -24,10 +24,11 @@ select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Con
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Procedure' 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 = 'Consent' 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 = 'Immunization' 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 = 'MedicationStatement' order by systempath asc;
......
......@@ -29,7 +29,8 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
valueQuantity_system2::text as valueQuantity_system,
valueQuantity_code2::text as valueQuantity_code
from FhirDataAsTable
left join (select (fhir2->>'performedDateTime')::timestamp as StartTimes2
left join (-- ======== Below code fetches start and end times (columns start_date and end_date) ========
select (fhir2->>'performedDateTime')::timestamp as StartTimes2
from FhirDataAsTable
union
select (fhir2->>'recordedDate')::timestamp as StartTimes2
......@@ -41,7 +42,7 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
select (fhir2->'occurrenceDateTime' || 'T00:00:00+00:00')::timestamp as StartTimes2
from FhirDataAsTable
) as sq1 on true and StartTimes2 is not null
left join (select (fhir2->>'performedDateTime')::timestamp as EndTimes2
left join (select (fhir2->>'performedDateTime')::timestamp as EndTimes2
from FhirDataAsTable
union
select (fhir2->>'recordedDate')::timestamp as EndTimes2
......@@ -53,7 +54,8 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
select (fhir2->>'occurrenceDateTime' || 'T00:00:00+00:00')::timestamp as EndTimes2
from FhirDataAsTable
) as sq2 on true and EndTimes2 is not null
left join (select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as MainCode2,
left join (-- ======== Below code fetches the values that go into the i2b2 concept code (column concept_cd) ========
select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' != 'Consent' and fhir2->>'resourceType' != 'Immunization'
union
......@@ -64,8 +66,13 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
select jsonb_array_elements(fhir2->'vaccineCode'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'vaccineCode'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' = 'Immunization'
union
select jsonb_array_elements(fhir2->'medicationCodeableConcept'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'medicationCodeableConcept'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' = 'MedicationStatement'
) as sq3 on true
left join (select 'bodySite' ModifierType2, -- GECCO Condition, Procedure
left join (-- ======== Below code fetches the values that go into the i2b2 modifier codes (column modifier_cd) ========
select 'bodySite' ModifierType2, -- GECCO Condition, Procedure
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
......@@ -155,12 +162,18 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
jsonb_array_elements(jsonb_array_elements(jsonb_array_elements(fhir2->'protocolApplied')->'targetDisease')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'conclusionCode' ModifierType2, -- GECCO Diagnostic Report
select 'conclusionCode' ModifierType2, -- GECCO DiagnosticReport
jsonb_array_elements(jsonb_array_elements(fhir2->'conclusionCode')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'conclusionCode')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'reasonCode' ModifierType2, -- GECCO MedicationStatement
jsonb_array_elements(jsonb_array_elements(fhir2->'reasonCode')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'reasonCode')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
) as sq4 on true
left join (select (fhir2->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value2, -- GECCO Observation
left join (-- ======== Below code fetches data for other columns ========
select (fhir2->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value2, -- Numeric values for GECCO Observation
fhir2->'valueQuantity'->>'unit'::text as valueQuantity_unit2,
fhir2->'valueQuantity'->>'system'::text as valueQuantity_system2,
fhir2->'valueQuantity'->>'code'::text as valueQuantity_code2
......@@ -169,48 +182,34 @@ end $$ language plpgsql;
select * from i2b2miracum.select_fhir_fields('{
"resourceType": "DiagnosticReport",
"id": "c68b4e1e9fcacebe354709a6b49e2c96",
"resourceType": "MedicationStatement",
"id": "257548c0734113c99bd51b76ae8c76d6",
"meta": {
"profile": [ "https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/diagnostic-report-radiology" ]
"profile": [ "https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/pharmacological-therapy-anticoagulants" ]
},
"identifier": [ {
"system": "https://mein.krankenhaus.de/fhir/NamingSystem/diagnosticreportId",
"value": "Option01-GECCOVISIT.null-Form.bildgebung.1-bildgebung.befund_bildgebender_verfahren_ct.1-befund_bildgebender_verfahren_ct"
"system": "https://mein.krankenhaus.de/fhir/NamingSystem/medicationstatementId",
"value": "Option01-GECCOVISIT.null-Form.medikation.1-medikation.antikoagulation_unfraktioniertes_heparin.1-antikoagulation_unfraktioniertes_heparin"
} ],
"status": "final",
"category": [ {
"status": "active",
"medicationCodeableConcept": {
"coding": [ {
"system": "http://loinc.org",
"code": "18726-0",
"display": "Radiology studies (set)"
"system": "http://snomed.info/sct",
"code": "81839001"
}, {
"system": "http://terminology.hl7.org/CodeSystem/v2-0074",
"code": "RAD",
"display": "Radiology"
} ]
} ],
"code": {
"coding": [ {
"system": "http://loinc.org",
"code": "18748-4",
"display": "Diagnostic imaging study"
"system": "http://fhir.de/CodeSystem/dimdi/atc",
"code": "B01AB01"
} ]
},
"subject": {
"reference": "Patient/969ba73aa2f35a27d698cbbf6f3785fe"
},
"effectiveDateTime": "1970-01-01T00:00:00+00:00",
"_effectiveDateTime": {
"extension": [ {
"url": "http://hl7.org/fhir/StructureDefinition/data-absent-reason",
"valueCode": "unknown"
} ]
},
"conclusionCode": [ {
"effectiveDateTime": "2000-01-01T00:00:00+00:00",
"reasonCode": [ {
"coding": [ {
"system": "http://snomed.info/sct",
"code": "118247008:363713009=373068000"
"code": "373808002",
"display": "Curative - procedure intent (qualifier value)"
} ]
} ]
}'::jsonb);
......
......@@ -27,6 +27,7 @@
-- - Update implementation for "Consent" resource
-- - Update implementation for "MedicationStatement" resource
-- - FIRST RELEASE FOR NUM CODEX
-- 2021-03-10: - Complete re-implementation with full GECCO support for NUM CODEX
-- ============= Create Basic Tables =============
......@@ -117,7 +118,9 @@ begin
when systemlink = 'urn:iso:std:iso:3166' then return 'ISO3166';
when systemlink = 'urn:oid:1.2.276.0.76.5.409' then return 'ICD10';
when systemlink = 'urn:oid:2.16.840.1.113883.6.238' then return 'RaceAndEthnicityCDC';
when systemlink = 'http://terminology.hl7.org/CodeSystem/consentcategorycodes' then return 'CCC';
when systemlink = 'http://terminology.hl7.org/CodeSystem/consentcategorycodes' then return 'FDASIS';
when systemlink = 'http://fdasis.nlm.nih.gov' then return 'CCC';
when systemlink = 'urn:oid:2.16.840.1.113883.6.18.2.6' then return 'ISBT128';
else
perform i2b2miracum.fhir_elt_log('ERROR: Coding system unknown: ' || systemlink);
return 'UNKNOWN';
......@@ -366,7 +369,8 @@ begin
FHIR_resourcetype = 'Observation' or
FHIR_resourcetype = 'Consent' or
FHIR_resourcetype = 'Immunization' or
FHIR_resourcetype = 'DiagnosticReport' then
FHIR_resourcetype = 'DiagnosticReport' or
FHIR_resourcetype = 'MedicationStatement' then
-- Delete previous data:
perform i2b2miracum.fhir_elt_log('Deleting previous entries in OBSERVATION_FACT.');
delete from i2b2miracum.observation_fact where observation_blob = FHIR_id;
......@@ -558,7 +562,8 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
valueQuantity_system2::text as valueQuantity_system,
valueQuantity_code2::text as valueQuantity_code
from FhirDataAsTable
left join (select (fhir2->>'performedDateTime')::timestamp as StartTimes2
left join (-- ======== Below code fetches start and end times (columns start_date and end_date) ========
select (fhir2->>'performedDateTime')::timestamp as StartTimes2
from FhirDataAsTable
union
select (fhir2->>'recordedDate')::timestamp as StartTimes2
......@@ -570,7 +575,7 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
select (fhir2->'occurrenceDateTime' || 'T00:00:00+00:00')::timestamp as StartTimes2
from FhirDataAsTable
) as sq1 on true and StartTimes2 is not null
left join (select (fhir2->>'performedDateTime')::timestamp as EndTimes2
left join (select (fhir2->>'performedDateTime')::timestamp as EndTimes2
from FhirDataAsTable
union
select (fhir2->>'recordedDate')::timestamp as EndTimes2
......@@ -582,7 +587,8 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
select (fhir2->>'occurrenceDateTime' || 'T00:00:00+00:00')::timestamp as EndTimes2
from FhirDataAsTable
) as sq2 on true and EndTimes2 is not null
left join (select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as MainCode2,
left join (-- ======== Below code fetches the values that go into the i2b2 concept code (column concept_cd) ========
select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' != 'Consent' and fhir2->>'resourceType' != 'Immunization'
union
......@@ -593,8 +599,13 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
select jsonb_array_elements(fhir2->'vaccineCode'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'vaccineCode'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' = 'Immunization'
union
select jsonb_array_elements(fhir2->'medicationCodeableConcept'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'medicationCodeableConcept'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' = 'MedicationStatement'
) as sq3 on true
left join (select 'bodySite' ModifierType2, -- GECCO Condition, Procedure
left join (-- ======== Below code fetches the values that go into the i2b2 modifier codes (column modifier_cd) ========
select 'bodySite' ModifierType2, -- GECCO Condition, Procedure
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
......@@ -684,12 +695,18 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
jsonb_array_elements(jsonb_array_elements(jsonb_array_elements(fhir2->'protocolApplied')->'targetDisease')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'conclusionCode' ModifierType2, -- GECCO Diagnostic Report
select 'conclusionCode' ModifierType2, -- GECCO DiagnosticReport
jsonb_array_elements(jsonb_array_elements(fhir2->'conclusionCode')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'conclusionCode')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'reasonCode' ModifierType2, -- GECCO MedicationStatement
jsonb_array_elements(jsonb_array_elements(fhir2->'reasonCode')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'reasonCode')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
) as sq4 on true
left join (select (fhir2->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value2, -- GECCO Observation
left join (-- ======== Below code fetches data for other columns ========
select (fhir2->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value2, -- Numeric values for GECCO Observation
fhir2->'valueQuantity'->>'unit'::text as valueQuantity_unit2,
fhir2->'valueQuantity'->>'system'::text as valueQuantity_system2,
fhir2->'valueQuantity'->>'code'::text as valueQuantity_code2
......
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