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

Integrate Consent, Immunization, DiagnosticReport

Update abbreviations of coding systems
parent 70956f24
......@@ -23,11 +23,10 @@ select distinct systempath from i2b2miracum.FhirFields;
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 = '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 = '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;
......
drop function select_fhir_fields(fhir jsonb);
drop function i2b2miracum.select_fhir_fields(fhir jsonb);
create or replace function select_fhir_fields(fhir jsonb)
create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
returns table (ID text,
StartTimes timestamp,
EndTimes timestamp,
......@@ -37,7 +37,10 @@ create or replace function select_fhir_fields(fhir jsonb)
union
select (fhir2->>'effectiveDateTime')::timestamp as StartTimes2
from FhirDataAsTable
) as sq1 on true and StartTimes is not null
union
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
from FhirDataAsTable
union
......@@ -45,10 +48,23 @@ create or replace function select_fhir_fields(fhir jsonb)
from FhirDataAsTable
union
select (fhir2->>'effectiveDateTime')::timestamp as EndTimes2
from FhirDataAsTable) as sq2 on true and EndTimes is not null
from FhirDataAsTable
union
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,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as MainSystem2
from FhirDataAsTable) as sq3 on true
from FhirDataAsTable where fhir2->>'resourceType' != 'Consent' and fhir2->>'resourceType' != 'Immunization'
union
select jsonb_array_elements(fhir2->'scope'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'scope'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' = 'Consent'
union
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'
) as sq3 on true
left join (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
......@@ -128,14 +144,74 @@ create or replace function select_fhir_fields(fhir jsonb)
jsonb_array_elements(fhir2->'valueCodeableConcept'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(fhir2->'valueCodeableConcept'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'provision.code' ModifierType2, -- GECCO Consent
jsonb_array_elements(jsonb_array_elements(fhir2->'provision'->'code')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'provision'->'code')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'protocolApplied.targetDisease' ModifierType2, -- GECCO Immunization
jsonb_array_elements(jsonb_array_elements(jsonb_array_elements(fhir2->'protocolApplied')->'targetDisease')->'coding')->>'code' as ModifierCode2,
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
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
) as sq4 on true
left join (select (fhir2->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value2, -- GECCO Observation
fhir2->'valueQuantity'->>'unit'::text as valueQuantity_unit2,
fhir2->'valueQuantity'->>'system'::text as valueQuantity_system2,
fhir2->'valueQuantity'->>'code'::text as valueQuantity_code2
from FhirDataAsTable) as sq5 on true;
end $$ language plpgsql
end $$ language plpgsql;
select * from select_fhir_fields('{"resourceType":"DiagnosticReport","id":"e0d61687b8caad84ac548a72e80410e2","meta":{"profile":["https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/diagnostic-report-radiology"]},"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_us"}],"status":"final","category":[{"coding":[{"system":"http://loinc.org","code":"18726-0","display":"Radiology studies (set)"},{"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"}]},"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":[{"coding":[{"system":"http://snomed.info/sct","code":"118247008:363713009=373068000"}]}]}'::jsonb);
select * from i2b2miracum.select_fhir_fields('{
"resourceType": "DiagnosticReport",
"id": "c68b4e1e9fcacebe354709a6b49e2c96",
"meta": {
"profile": [ "https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/diagnostic-report-radiology" ]
},
"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"
} ],
"status": "final",
"category": [ {
"coding": [ {
"system": "http://loinc.org",
"code": "18726-0",
"display": "Radiology studies (set)"
}, {
"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"
} ]
},
"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": [ {
"coding": [ {
"system": "http://snomed.info/sct",
"code": "118247008:363713009=373068000"
} ]
} ]
}'::jsonb);
......@@ -96,17 +96,28 @@ select setval('instance_num_seq', (select max(instance_num) from i2b2miracum.obs
create or replace function i2b2miracum.get_system_abbrv(systemlink text) returns text language plpgsql as
$$
begin
case when systemlink = 'http://fhir.de/CodeSystem/dimdi/icd-10-gm' then return 'ICD10';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/ops' then return 'OPS';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/atc' then return 'ATC';
when systemlink = 'http://snomed.info/sct' then return 'SNOMED-CT';
when systemlink = 'http://loinc.org' then return 'LOINC';
when systemlink = 'urn:oid:2.16.840.1.113883.6.18.2.6' then return 'PRODUCT-TYPE';
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/ecrf-parameter-codes' then return 'ECRF';
when systemlink = 'http://fdasis.nlm.nih.gov' then return 'FDASIS';
when systemlink = 'http://dicom.nema.org/resources/ontology/DCM' then return 'DCM';
when systemlink = 'http://terminology.hl7.org/CodeSystem/condition-ver-status' then return 'CVS';
when systemlink = 'http://terminology.hl7.org/CodeSystem/consentcategorycodes' then return 'CCC';
case when systemlink = 'http://dicom.nema.org/resources/ontology/DCM' then return 'DCM';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/atc' then return 'ATC';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/icd-10-gm' then return 'ICD10';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/ops' then return 'OPS';
when systemlink = 'http://fhir.de/CodeSystem/gender-amtlich-de' then return 'GenderAmtlichDE';
when systemlink = 'http://hl7.org/fhir/administrative-gender' then return 'AdminGender';
when systemlink = 'http://hl7.org/fhir/uv/ips/CodeSystem/absent-unknown-uv-ips' then return 'ABSENT';
when systemlink = 'http://loinc.org' then return 'LOINC';
when systemlink = 'http://snomed.info/sct' then return 'SNOMED-CT';
when systemlink = 'http://terminology.hl7.org/CodeSystem/condition-clinical' then return 'CC';
when systemlink = 'http://terminology.hl7.org/CodeSystem/condition-ver-status' then return 'CVS';
when systemlink = 'http://terminology.hl7.org/CodeSystem/consentscope' then return 'CS';
when systemlink = 'http://terminology.hl7.org/CodeSystem/data-absent-reason' then return 'DAR';
when systemlink = 'http://terminology.hl7.org/CodeSystem/observation-category' then return 'OC';
when systemlink = 'http://terminology.hl7.org/CodeSystem/v2-0074' then return 'DiagnosticServiceSectionId';
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/ecrf-parameter-codes' then return 'ECRF';
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/frailty-score' then return 'FRAILTY';
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/sofa-score' then return 'SOFA';
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';
else
perform i2b2miracum.fhir_elt_log('ERROR: Coding system unknown: ' || systemlink);
return 'UNKNOWN';
......@@ -352,7 +363,10 @@ begin
--
if FHIR_resourcetype = 'Condition' or
FHIR_resourcetype = 'Procedure' or
FHIR_resourcetype = 'Observation' then
FHIR_resourcetype = 'Observation' or
FHIR_resourcetype = 'Consent' or
FHIR_resourcetype = 'Immunization' or
FHIR_resourcetype = 'DiagnosticReport' 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;
......@@ -401,133 +415,10 @@ begin
FHIR_resourcetype || '.' || ModifierType FHIR_sourcesystem, -- sourcesystem_cd
1, -- upload_id
nextval('instance_num_seq') -- text_search_index
from (select * from select_fhir_fields(fhir)) as fhir_data;
from (select * from i2b2miracum.select_fhir_fields(fhir)) as fhir_data;
end if;
/*
--
-- *** Handle GECCO FHIR Immunization resource ***
--
if FHIR_resourcetype = 'Immunization' then // TODO !!!
-- Delete previous data:
perform i2b2miracum.fhir_elt_log('Deleting previous entries in OBSERVATION_FACT.');
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)
select i2b2_encounter_identifier, -- encounter_num
i2b2_patient_identifier, -- patient_num
/*'VACC:' || */i2b2miracum.get_system_abbrv(fhir_data.MainSystem) || ':' || fhir_data.MainCode, -- concept_cd
'FHIR', -- provider_id
case when fhir_data.StartTimes is not null then fhir_data.StartTimes
else '-infinity'::timestamptz
end, -- start_date
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
'N', -- valtype_cd
'E', -- tval_char
null, -- nval_num
'', -- valueflag_cd
1, -- quantity_num
null, -- units_cd
case when fhir_data.EndTimes is not null then fhir_data.EndTimes
else '-infinity'::timestamptz
end, -- end_date
'', -- location_cd
FHIR_id, -- observation_blob
0, -- confidence_num
now(), -- update_date
now(), -- download_date
now(), -- import_date
FHIR_sourcesystem, -- sourcesystem_cd
1, -- upload_id
nextval('instance_num_seq') -- text_search_index
from (select * from select_fhir_fields(fhir)) as fhir_data;
end if;
--
-- *** Handle GECCO FHIR Consent resource ***
--
if FHIR_resourcetype = 'Consent' 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;
-- 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)
select i2b2_encounter_identifier, -- encounter_num
i2b2_patient_identifier, -- patient_num
i2b2miracum.get_system_abbrv(fhir_data.MainSystem) || ':' || fhir_data.MainCode, -- concept_cd
'FHIR', -- provider_id
case when fhir_data.StartTimes is not null then fhir_data.StartTimes
else '-infinity'::timestamptz
end, -- start_date
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
'N', -- valtype_cd
'E', -- tval_char
null, -- nval_num
'', -- valueflag_cd
1, -- quantity_num
null, -- units_cd
case when fhir_data.EndTimes is not null then fhir_data.EndTimes
else '-infinity'::timestamptz end, -- end_date
'', -- location_cd
FHIR_id, -- observation_blob
0, -- confidence_num
now(), -- update_date
now(), -- download_date
now(), -- import_date
FHIR_sourcesystem, -- sourcesystem_cd
1, -- upload_id
nextval('instance_num_seq') -- text_search_index
from (select * from select_fhir_fields(fhir)) as fhir_data;
end if;
--
-- *** Handle FHIR DIAGNOSTICREPORT resource ***
--
if FHIR_resourcetype = 'DiagnosticReport' 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;
-- 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)
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
'FHIR', -- provider_id
case when fhir_data.effectiveDateTime is not null then fhir_data.effectiveDateTime
else '-infinity'::timestamptz end, -- start_date
case when fhir_data.conclusionCode_coding_system is not null
then i2b2miracum.get_system_abbrv(fhir_data.conclusionCode_coding_system) || ':' || fhir_data.conclusionCode_coding_code
else '@'
end, -- modifier_cd
nextval('instance_num_seq'), -- instance_num
'@', -- valtype_cd
null, -- tval_char
null, -- nval_num
null, -- valueflag_cd
null, -- quantity_num
null, -- units_cd
case when fhir_data.effectiveDateTime is not null then fhir_data.effectiveDateTime
else '-infinity'::timestamptz end, -- end_date
'', -- location_cd
FHIR_id, -- observation_blob
0, -- confidence_num
now(), -- update_date
now(), -- download_date
now(), -- import_date
FHIR_sourcesystem, -- sourcesystem_cd
1, -- upload_id
nextval('instance_num_seq') -- text_search_index
from (select * from select_fhir_fields(fhir)) as fhir_data;
end if;
--
-- *** Handle FHIR MEDICATION resource ***
--
if FHIR_resourcetype = 'Medication' then
......@@ -625,7 +516,7 @@ begin
1, -- upload_id
nextval('instance_num_seq'), -- text_search_index
medication_reference -- fhir_reference
from (select * from select_fhir_fields(fhir)) as fhir_data;
from (select * from i2b2miracum.select_fhir_fields(fhir)) as fhir_data;
end if;
*/
--
......@@ -638,8 +529,7 @@ exception
end;
$$;
create or replace function select_fhir_fields(fhir jsonb)
create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
returns table (ID text,
StartTimes timestamp,
EndTimes timestamp,
......@@ -676,7 +566,10 @@ create or replace function select_fhir_fields(fhir jsonb)
union
select (fhir2->>'effectiveDateTime')::timestamp as StartTimes2
from FhirDataAsTable
) as sq1 on true and StartTimes is not null
union
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
from FhirDataAsTable
union
......@@ -684,10 +577,23 @@ create or replace function select_fhir_fields(fhir jsonb)
from FhirDataAsTable
union
select (fhir2->>'effectiveDateTime')::timestamp as EndTimes2
from FhirDataAsTable) as sq2 on true and EndTimes is not null
from FhirDataAsTable
union
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,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as MainSystem2
from FhirDataAsTable) as sq3 on true
from FhirDataAsTable where fhir2->>'resourceType' != 'Consent' and fhir2->>'resourceType' != 'Immunization'
union
select jsonb_array_elements(fhir2->'scope'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'scope'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' = 'Consent'
union
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'
) as sq3 on true
left join (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
......@@ -767,6 +673,21 @@ create or replace function select_fhir_fields(fhir jsonb)
jsonb_array_elements(fhir2->'valueCodeableConcept'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(fhir2->'valueCodeableConcept'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'provision.code' ModifierType2, -- GECCO Consent
jsonb_array_elements(jsonb_array_elements(fhir2->'provision'->'code')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'provision'->'code')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'protocolApplied.targetDisease' ModifierType2, -- GECCO Immunization
jsonb_array_elements(jsonb_array_elements(jsonb_array_elements(fhir2->'protocolApplied')->'targetDisease')->'coding')->>'code' as ModifierCode2,
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
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
) as sq4 on true
left join (select (fhir2->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value2, -- GECCO Observation
fhir2->'valueQuantity'->>'unit'::text as valueQuantity_unit2,
......
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