Commit 2092aecf authored by Sebastian Mate's avatar Sebastian Mate
Browse files

Initial support for resource type "Consent"

Note: Implementation of "Immunization" and "Consent" useless, as-is. TODO
parent 2cdd1d4a
......@@ -14,6 +14,8 @@
-- - Generation of system identifier abbreviations now handled in function get_system_abbrv()
-- - Initial support for resource type "Immunization"
-- 2021-01-27: - Add support for various ways of patient-referencing for GECCO resources
-- - Initial support for resource type "Consent"
-- - Note: Implementation of "Immunization" and "Consent" useless, as-is. TODO
-- ============= Create Basic Tables =============
......@@ -138,9 +140,9 @@ declare
FHIR_resourcetype text := json_extract_path_text(fhir::json, 'resourceType');
FHIR_sourcesystem text := fhir->'meta'->>'source';
FHIR_patient_identifier text; -- Use the resource ID if patient identifier ist not specified otherwise.
FHIR_subject_reference text; -- Fallback for GECCO (bug in odm2fhir?)
FHIR_patient_reference text; -- Fallback for GECCO Immunization (bug in odm2fhir?)
FHIR_patient_identifier2 text; -- Fallback GECCO Immunization (older odm2fhir?)
FHIR_patient_identifier_GECCO text := fhir->'subject'->>'reference'; -- Fallback GECCO
FHIR_patient_identifier_GECCO_ImmunCons1 text := fhir->'patient'->'identifier'->>'value'; -- Fallback GECCO Immunization/Consent
FHIR_patient_identifier_GECCO_ImmunCons2 text := fhir->'patient'->>'reference'; -- Fallback GECCO Immunization/Consent (variant 2)
FHIR_encounter_identifier text;
i2b2_patient_identifier int; declare i2b2_patient_found int;
i2b2_encounter_identifier int; declare i2b2_encounter_found int;
......@@ -150,7 +152,8 @@ begin
FHIR_resourcetype != 'Encounter' and
FHIR_resourcetype != 'Condition' and
FHIR_resourcetype != 'Observation' and
FHIR_resourcetype != 'Immunization' and
FHIR_resourcetype != 'Immunization' and -- TODO
FHIR_resourcetype != 'Consent' and -- TODO
FHIR_resourcetype != 'Procedure' and
FHIR_resourcetype != 'Medication' and
FHIR_resourcetype != 'MedicationStatement' and
......@@ -174,20 +177,17 @@ begin
end if;
else
FHIR_patient_identifier := fhir->'subject'->'identifier'->>'value';
FHIR_subject_reference := fhir->'subject'->>'reference'; -- Fallback GECCO
FHIR_patient_reference := fhir->'patient'->>'reference'; -- Fallback GECCO Immunization
FHIR_patient_identifier2 := fhir->'patient'->'identifier'->>'value'; -- Fallback GECCO Immunization (older odm2fhir?)
--
if FHIR_patient_identifier is null and FHIR_subject_reference is not null then
FHIR_patient_identifier := FHIR_subject_reference;
if FHIR_patient_identifier is null and FHIR_patient_identifier_GECCO is not null then
FHIR_patient_identifier := FHIR_patient_identifier_GECCO;
end if;
--
if FHIR_patient_identifier is null and FHIR_patient_reference is not null then
FHIR_patient_identifier := FHIR_patient_reference;
if FHIR_patient_identifier is null and FHIR_patient_identifier_GECCO_ImmunCons1 is not null then
FHIR_patient_identifier := FHIR_patient_identifier_GECCO_ImmunCons1;
end if;
--
if FHIR_patient_identifier is null and FHIR_patient_identifier2 is not null then
FHIR_patient_identifier := FHIR_patient_identifier2;
if FHIR_patient_identifier is null and FHIR_patient_identifier_GECCO_ImmunCons2 is not null then
FHIR_patient_identifier := FHIR_patient_identifier_GECCO_ImmunCons2;
end if;
end if;
--
......@@ -414,7 +414,7 @@ begin
) fhir_data;
end if;
--
-- *** Handle FHIR OBSERVATION resource ***
-- *** Handle GECCO FHIR Immunization resource ***
--
if FHIR_resourcetype = 'Immunization' then
-- Delete previous data:
......@@ -459,6 +459,51 @@ begin
) 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.system) || ':' || fhir_data.code, -- concept_cd
'FHIR', -- provider_id
case when fhir_data.effectiveDateTime is not null then fhir_data.effectiveDateTime
else now() end, -- start_date
'@', -- 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.effectiveDateTime is not null then fhir_data.effectiveDateTime
else now() 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
jsonb_array_elements(fhir->'provision'->'code'->'coding')->>'code' as code,
jsonb_array_elements(fhir->'provision'->'code'->'coding')->>'system' as system,
(fhir->>'effectiveDateTime')::timestamp as effectiveDateTime,
(fhir->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value--,
--fhir->'valueQuantity'->>'unit'::text as valueQuantity_unit,
--fhir->'valueQuantity'->>'system'::text as valueQuantity_system,
--fhir->'valueQuantity'->>'code'::text as valueQuantity_code
) fhir_data;
end if;
--
-- *** Handle FHIR PROCEDURE resource ***
--
if FHIR_resourcetype = 'Procedure' then
......@@ -652,8 +697,8 @@ INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{ "resourceType": "Observation", "i
INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{ "resourceType": "Procedure", "id": "Procedure1", "meta": { "source": "Procedure1.json", "profile": [ "https://www.medizininformatik-initiative.de/fhir/core/modul-prozedur/StructureDefinition/Procedure" ] }, "identifier": [ { "use": "official", "system": "https://fhir.diz.uk-erlangen/NamingSystem/kdbSurrogateProcedureId", "value": "123123123123" } ], "status": "completed", "category": { "coding": [ { "system": "http://snomed.info/sct", "code": "103693007", "display": "Diagnostic procedure" } ] }, "code": { "coding": [ { "system": "http://fhir.de/CodeSystem/dimdi/ops", "version": "2020", "code": "1-632.0" } ] }, "subject": { "identifier": { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/patientId", "value": "Patient1" } }, "encounter": { "identifier": { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "VN" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/encounterId", "value": "Encounter1" } }, "performedDateTime": "2020-07-15T06:42:00+00:00" }');
INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{ "resourceType": "Procedure", "id": "Procedure2", "meta": { "source": "Procedure2.json", "profile": [ "https://www.medizininformatik-initiative.de/fhir/core/modul-prozedur/StructureDefinition/Procedure" ] }, "identifier": [ { "use": "official", "system": "https://fhir.diz.uk-erlangen/NamingSystem/kdbSurrogateProcedureId", "value": "3456345643563465" } ], "status": "completed", "category": { "coding": [ { "system": "http://snomed.info/sct", "code": "103693007", "display": "Diagnostic procedure" } ] }, "code": { "coding": [ { "system": "http://fhir.de/CodeSystem/dimdi/ops", "version": "2021", "code": "1-634.0" } ] }, "subject": { "identifier": { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/patientId", "value": "Patient2" } }, "encounter": { "identifier": { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "VN" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/encounterId", "value": "Encounter1" } }, "performedDateTime": "2021-07-15T06:42:00+00:00" }');
-- Test mit fehlenden Daten, muss Fehlereintrag erzeugen:
INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{ "resourceType": "Observation", "id": "Observation1", "meta": { "source": "Labor1.json", "profile": [ "https://www.medizininformatik-initiative.de/fhir/core/modul-labor/StructureDefinition/ObservationLab" ] }, "identifier": [ { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "OBI" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/swisslab/labObservationId", "value": "123123123123-123123123123", "assigner": { "identifier": { "system": "https://www.medizininformatik-initiative.de/fhir/core/NamingSystem/org-identifier", "value": "UKER" } } } ], "status": "final", "category": [ { "coding": [ { "system": "http://loinc.org", "code": "26436-6" }, { "system": "http://terminology.hl7.org/CodeSystem/observation-category", "code": "laboratory" } ] } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "41653-7" } ] }, "subject": { "identifier": { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/patientId" } }, "encounter": { "reference": "Encounter/Encounter1", "identifier": { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "VN" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/encounterId", "value": "Encounter1" } }, "effectiveDateTime": "2014-12-22T16:23:00+00:00", "issued": "2014-12-22T16:23:00+00:00", "valueQuantity": { "value": 134, "unit": "mg/dL", "system": "http://unitsofmeasure.org", "code": "mg/dL" } }');
-- Test mit fehlenden Daten (Subject), muss neuen Patienten "UNKNOWN" anlegen:
INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{ "resourceType": "Observation", "id": "Observation3", "meta": { "source": "Labor3.json", "profile": [ "https://www.medizininformatik-initiative.de/fhir/core/modul-labor/StructureDefinition/ObservationLab" ] }, "identifier": [ { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "OBI" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/swisslab/labObservationId", "value": "123123123123-123123123123", "assigner": { "identifier": { "system": "https://www.medizininformatik-initiative.de/fhir/core/NamingSystem/org-identifier", "value": "UKER" } } } ], "status": "final", "category": [ { "coding": [ { "system": "http://loinc.org", "code": "26436-6" }, { "system": "http://terminology.hl7.org/CodeSystem/observation-category", "code": "laboratory" } ] } ], "code": { "coding": [ { "system": "http://loinc.org", "code": "41653-7" } ] }, "subject": { "identifier": { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/patientId" } }, "encounter": { "reference": "Encounter/Encounter1", "identifier": { "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "VN" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/encounterId", "value": "Encounter1" } }, "effectiveDateTime": "2014-12-22T16:23:00+00:00", "issued": "2014-12-22T16:23:00+00:00", "valueQuantity": { "value": 134, "unit": "mg/dL", "system": "http://unitsofmeasure.org", "code": "mg/dL" } }');
-- Reihenfolge bei Medication muss egal sein:
INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{"id": "Medication1", "code": {"coding": [{"code": "N06AX16", "system": "http://fhir.de/CodeSystem/dimdi/atc", "display": "Venlafaxin"}, {"code": "N06AX17", "system": "http://fhir.de/CodeSystem/dimdi/atc", "display": "Fake Venlafaxin"}]}, "meta": {"profile": ["https://www.medizininformatik-initiative.de/fhir/core/StructureDefinition/Medication"]}, "identifier": [{"value": "Venlafaxin_25.0mg", "system": "https://averbis.com/de.averbis.types.health.Medication"}], "ingredient": [{"itemCodeableConcept": {"coding": [{"system": "http://fhir.de/CodeSystem/dimdi/atc", "display": "Venlafaxin"}]}}], "resourceType": "Medication"}');
......
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