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

Code weiterentwickelt

parent 5e2ad6e1
......@@ -8,3 +8,4 @@
(select data from resources where type = 'MedicationStatement' limit 100) union
(select data from resources where type = 'Medication' limit 100);
......@@ -47,18 +47,26 @@ do $$
end;
$$;
--CREATE INDEX observation_fact_observation_blob_idx ON i2b2miracum.observation_fact (observation_blob);
--CREATE INDEX observation_fact_fhir_reference_idx ON i2b2miracum.observation_fact (fhir_reference);
-- Create OBSERVATION_FACT_TEMP, which will be used to store temporary data:
drop table if exists i2b2miracum.observation_fact_temp;
create table i2b2miracum.observation_fact_temp as (select * from i2b2miracum.observation_fact);
-- Create and Initialize PATIENT_NUM up-counter:
drop sequence patient_num_seq;
drop sequence if exists patient_num_seq;
create sequence patient_num_seq;
select setval('patient_num_seq', (select max(patient_num) from i2b2miracum.patient_mapping), true);
-- Create and Initialize ENCOUNTER_NUM up-counter:
drop sequence encounter_num_seq;
drop sequence if exists encounter_num_seq;
create sequence encounter_num_seq;
select setval('encounter_num_seq', (select max(encounter_num) from i2b2miracum.encounter_mapping), true);
-- Create and Initialize INSTANCE_NUM up-counter:
drop sequence instance_num_seq;
drop sequence if exists instance_num_seq;
create sequence instance_num_seq;
select setval('instance_num_seq', (select max(instance_num) from i2b2miracum.observation_fact), true);
......@@ -373,8 +381,41 @@ begin
jsonb_array_elements(new.fhir->'code'->'coding')->>'display' as display
) fhir_data;
-- Update old MedicationStatement data in OBSERVATION_FACT
perform i2b2miracum.fhir_elt_log('Updating OBSERVATION_FACT.');
-- Move the old OBSERVATION_FACT entry (MedicationStatement data) to OBSERVATION_FACT_TEMP:
insert into i2b2miracum.observation_fact_temp (select * from i2b2miracum.observation_fact where fhir_reference = 'Medication/' || FHIR_id);
delete from i2b2miracum.observation_fact where fhir_reference = 'Medication/' || FHIR_id;
insert into i2b2miracum.observation_fact (
select oft.encounter_num,
oft.patient_num,
case when fm.system = 'http://fhir.de/CodeSystem/dimdi/atc' then 'ATC'
else 'UNKNOWN'
end || ':' || fm.code, -- concept_cd
oft.provider_id,
oft.start_date,
oft.modifier_cd,
oft.instance_num,
oft.valtype_cd,
oft.tval_char,
oft.nval_num,
oft.valueflag_cd,
oft.quantity_num,
oft.units_cd,
oft.end_date,
oft.location_cd,
oft.observation_blob,
oft.confidence_num,
oft.update_date,
oft.download_date,
oft.import_date,
oft.sourcesystem_cd,
oft.upload_id,
nextval('instance_num_seq') as text_search_index,
oft.fhir_reference
from i2b2miracum.observation_fact_temp oft, i2b2miracum.fhir_medication fm
where oft.fhir_reference = 'Medication/' || FHIR_id
and oft.fhir_reference = 'Medication/' || fm.id
);
truncate table i2b2miracum.observation_fact_temp;
--
end if;
--
......@@ -458,12 +499,13 @@ 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:
-- 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" } }');
*/
-- 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"}');
INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{"id": "MedicationStatement1", "meta": {"profile": ["https://www.medizininformatik-initiative.de/fhir/core/StructureDefinition/MedicationStatement"], "security": [{"code": "PSEUDED", "system": "http://terminology.hl7.org/CodeSystem/v3-ObservationValue", "display": "part of the resource is pseudonymized"}]}, "dosage": [{"text": "Cisplatin (50 mg/m²", "doseAndRate": [{"doseQuantity": {"unit": "mg/m²", "value": 50.0}}]}], "status": "unknown", "context": {"type": "Encounter", "reference": "Encounter/XXXXXXXXXXXXX", "identifier": {"type": {"text": "Visit number", "coding": [{"code": "VN", "system": "http://terminology.hl7.org/CodeSystem/v2-0203"}]}, "value": "Encounter4", "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/encounterId"}}, "subject": {"type": "Patient", "reference": "Patient/XXXXXXXXXXXXXXX", "identifier": {"type": {"text": "Medical record number", "coding": [{"code": "MR", "system": "http://terminology.hl7.org/CodeSystem/v2-0203"}]}, "value": "Patient4", "system": "https://fhir.diz.uk-erlangen.de/NamingSystem/patientId"}}, "identifier": [{"value": "Cisplatin_50.0mg/m²_208004", "system": "https://averbis.com/de.averbis.types.health.Medication"}], "dateAsserted": "2008-07-29T17:44:00+00:00", "resourceType": "MedicationStatement", "effectiveDateTime": "2008-07-29T17:44:00+00:00", "medicationReference": {"type": "Medication", "reference": "Medication/Medication1", "identifier": {"value": "Cisplatin_50.0mg/m²", "system": "https://averbis.com/de.averbis.types.health.Medication"}}}');
INSERT INTO i2b2miracum.fhir (fhir) VALUES ('{"id": "Medication1", "code": {"coding": [{"code": "N06AX16", "system": "http://fhir.de/CodeSystem/dimdi/atc", "display": "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