Commit 63cbe8b8 authored by Sebastian Mate's avatar Sebastian Mate
Browse files

Einfaches Errorhandling/-Logging

parent bd2444be
-- Extrahiert Testdaten aus dem FHIR-GW.
(select data from resources where type = 'Patient' limit 100) union
(select data from resources where type = 'Encounter' limit 100) union
(select data from resources where type = 'Condition' limit 100) union
(select data from resources where type = 'Observation' limit 100) union
(select data from resources where type = 'Procedure' limit 100) union
(select data from resources where type = 'MedicationStatement' limit 100) union
(select data from resources where type = 'Medication' limit 100);
......@@ -14,7 +14,7 @@ create index idx_fhir_resourcetype on i2b2miracum.fhir using btree ((fhir->>'res
-- Create the "fhir_failed" table, used to dump failing data (WIP):
drop table if exists i2b2miracum.fhir_failed;
create table i2b2miracum.fhir_failed (fhir jsonb null);
create table i2b2miracum.fhir_failed (ts timestamptz null, message text null, fhir jsonb null);
-- Create the "fhir_elt_log" table, which log messages:
drop table if exists i2b2miracum.fhir_elt_log;
......@@ -64,23 +64,34 @@ declare FHIR_encounter_identifier text;
declare i2b2_patient_identifier int; declare i2b2_patient_found int;
declare i2b2_encounter_identifier int; declare i2b2_encounter_found int;
begin
if FHIR_resourcetype != 'Patient' and
FHIR_resourcetype != 'Encounter' and
FHIR_resourcetype != 'Condition' and
FHIR_resourcetype != 'Observation' and
FHIR_resourcetype != 'Procedure' and
FHIR_resourcetype != 'ServiceRequest' and -- Ignored, not useful for i2b2.
FHIR_resourcetype != 'DiagnosticReport' -- Ignored, not useful for i2b2.
then raise exception 'Resource type not supported.'; end if;
--
perform i2b2miracum.fhir_elt_log('--- Processing new ' || FHIR_resourcetype || ' resource:');
--
-- Extract FHIR_patient_identifier and FHIR_encounter_identifier from FHIR resource:
if FHIR_resourcetype = 'Patient' then
FHIR_patient_identifier := jsonb_array_elements(new.fhir->'identifier')->>'value';
if FHIR_patient_identifier is null then raise exception 'FHIR_patient_identifier is empty!'; end if;
else
FHIR_patient_identifier := new.fhir->'subject'->'identifier'->>'value';
end if;
--
if FHIR_resourcetype = 'Encounter' then
FHIR_encounter_identifier := jsonb_array_elements(new.fhir->'identifier')->>'value';
if FHIR_encounter_identifier is null then raise exception 'FHIR_encounter_identifier is empty!'; end if;
else
FHIR_encounter_identifier := new.fhir->'encounter'->'identifier'->>'value';
end if;
--
if FHIR_patient_identifier is null then FHIR_patient_identifier := 'NONE'; end if;
if FHIR_encounter_identifier is null then FHIR_encounter_identifier := 'NONE'; end if;
--if FHIR_patient_identifier is null then FHIR_patient_identifier := 'NONE'; end if;
--if FHIR_encounter_identifier is null then FHIR_encounter_identifier := 'NONE'; end if;
perform i2b2miracum.fhir_elt_log('FHIR_patient_identifier = ' || FHIR_patient_identifier);
perform i2b2miracum.fhir_elt_log('FHIR_encounter_identifier = ' || FHIR_encounter_identifier);
--
......@@ -320,11 +331,13 @@ begin
(new.fhir->>'performedDateTime')::timestamp as performedDateTime
) fhir_data;
end if;
return null;
--exception
--when others then
--perform i2b2miracum.fhir_elt_log('Exception cought.');
--insert into i2b2miracum.fhir_failed(fhir) values (new->fhir);
--
return null;
exception
when others then
perform i2b2miracum.fhir_elt_log('Exception cought.');
insert into i2b2miracum.fhir_failed(ts, message, fhir) values (now(), sqlerrm, new.fhir);
return null;
end;
$$;
......@@ -334,6 +347,7 @@ create trigger fhir_inserted before insert on i2b2miracum.fhir for each row exec
-- ============= Some Test Data =============
/*
INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{ "resourceType": "Patient", "id": "Patient1", "meta": { "source": "Patient1.json", "profile": [ "https://fhir.miracum.org/core/StructureDefinition/PatientIn" ] }, "identifier": [ { "use": "official", "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/patientId", "value": "Patient1" } ], "gender": "male", "birthDate": "1977-04-27", "deceasedDateTime": "2000-12-12T12:12:12+00:00", "address": [ { "type": "both", "city": "Entenhausen", "postalCode": "123456", "country": "DE" } ] }');
INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{ "resourceType": "Patient", "id": "Patient2", "meta": { "source": "Patient2.json", "profile": [ "https://fhir.miracum.org/core/StructureDefinition/PatientIn" ] }, "identifier": [ { "use": "official", "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/patientId", "value": "Patient2" } ], "gender": "female", "birthDate": "1978-04-27", "deceasedDateTime": "2001-12-12T12:12:12+00:00", "address": [ { "type": "both", "city": "Entenhausen", "postalCode": "123457", "country": "DE" } ] }');
INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{ "resourceType": "Patient", "id": "Patient1", "meta": { "source": "Patient3.json", "profile": [ "https://fhir.miracum.org/core/StructureDefinition/PatientIn" ] }, "identifier": [ { "use": "official", "type": { "coding": [ { "system": "http://terminology.hl7.org/CodeSystem/v2-0203", "code": "MR" } ] }, "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/patientId", "value": "Patient3" } ], "gender": "male", "birthDate": "1977-04-11", "address": [ { "type": "both", "city": "Entenhausen", "postalCode": "123456", "country": "DE" } ] }');
......@@ -352,3 +366,6 @@ 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:
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" } }');
*/
\ No newline at end of file
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