Commit 43c4bdfe authored by Sebastian Mate's avatar Sebastian Mate
Browse files

FIRST RELEASE FOR NUM CODEX

Update implementation for "MedicationStatement" resource
Update docu
parent a7bb8fbb
......@@ -7,16 +7,16 @@ When executing this SQL code on an i2b2 database schema, a "FHIR" table is creat
The SQL Trigger is aware of or processes the following FHIR resource types and assumes that these follow the MII (German Medical Informatic Initiative) modeling:
* Bundle: Is split into the other resource types below.
* Patient OK
* Encounter OK
* Condition OK
* Observation OK
* Immunization OK
* Consent OK
* Procedure OK
* Patient
* Encounter
* Condition
* Observation
* Immunization
* Consent
* Procedure
* Medication
* MedicationStatement
* DiagnosticReport OK
* DiagnosticReport
* ServiceRequest: Is ignored, as it's not contributing useful data to be queried by i2b2.
## Implementation Details
......@@ -25,21 +25,29 @@ General:
* `code.coding.code` and `code.coding.system` are used to generate the i2b2 concept code.
* If no timestamp can be found in the data, the PostgreSQL function call `'-infinity'::timestamptz` is used to generate a dummy date, which is "292269055-12-03 00:00:00".
* The code is configured to process GECCO FHIR ressourced generated by "odm2fhir". As such, it uses the FHIR ID to reference patients. If instead you wish to reference patients via `identifier.value`, uncomment the code line after "Disable next line for GECCO:".
Error handling:
* Error are logged in the table FHIR_ETL_LOG and can be viewed easily via "SELECT * FROM FHIR_ETL_LOG WHERE message LIKE 'ERROR%'.
* Failed ressources are stored in table FHIR_FAILED.
* Note that errors of the type "ERROR: Exception cought: null value in column "concept_cd" violates not-null constraint" occur whenever no information in the FHIR resource is available to create a proper i2b2 concept code. This may happen when the coding is missing (e.g., `code.coding.code` and `code.coding.system`). The error can therefore be ignored (or better, the FHIR resource should be completed).
### Patient
Currently, the following fields are processed into the PATIENT.DIMENSION table:
* `birthDate` as birthdate
* `birthDate` as birth date
* `gender` as gender
* `deceasedDateTime` as death date
* `address.postalCode` as ZIP code
Note that no entries in OBSERVATION.FACT are currently being generated based on these data.
Note that no entries in OBSERVATION_FACT are currently being generated based on these data.
### Patient
### Encounter
Currently, only the encounter IDs are collected and processed into the ENCOUNTER.MAPPING table. No patient transfer data (aka "Verlegungskette") is currently being processed.
Currently, only the encounter IDs are collected and processed into the ENCOUNTER_MAPPING table. No patient transfer data (aka "Verlegungskette") is currently being handled.
### Condition
......@@ -52,7 +60,7 @@ The following fields are used to generate i2b2 modifiers:
* `verificationStatus.coding.system` and `verificationStatus.coding.code`
* `extension.valueCodeableConcept.coding.system` and `extension.valueCodeableConcept.coding.code`
It does not process the fields:
It does not process the fields (this list may not be complete):
* `clinicalStatus`
* `category`
......@@ -67,14 +75,14 @@ Timestamps are derived from:
Numeric values are derived from:
* `valueQuantity.value`
* `valueQuantity.value` or
* `valueQuantity.unit`
The following fields are used to generate i2b2 modifiers:
* `valueCodeableConcept.coding.system` and `valueCodeableConcept.coding.code`
It does not yet process the fields:
It does not yet process the fields (this list may not be complete):
* `category`
......@@ -88,7 +96,7 @@ The following fields are used to generate i2b2 modifiers:
* `bodySite.coding.system` and `bodySite.coding.code`
It does not yet process the fields:
It does not yet process the fields (this list may not be complete):
* `category`
* `status`
......@@ -103,7 +111,7 @@ The following fields are used to generate i2b2 modifiers:
* `conclusionCode.coding.system` and `conclusionCode.coding.code`
It does not yet process the fields:
It does not yet process the fields (this list may not be complete):
* `category`
......@@ -117,13 +125,13 @@ The following fields are used to generate i2b2 concept codes:
* `protocolApplied.targetDisease.coding.system` and `protocolApplied.targetDisease.coding.code`
***IMPORTANT:***: This generates concept codes such as "SNOMED-CT:6142004", where "6142004" is referring to "Influenza (disorder)". The concept code itself does not specify that it is about a patient's vaccination and not about a patient's disease. This needs to be addressed in a future update.
***IMPORTANT:*** This generates concept codes such as "SNOMED-CT:6142004", where "6142004" is referring to "Influenza (disorder)". The concept code itself does not specify that it is about a patient's vaccination and not about a patient's disease. This needs to be addressed in a future update.
The following fields are used to generate i2b2 modifiers:
* `vaccineCode.coding.system` and `vaccineCode.coding.code`
It does not yet process the fields:
It does not yet process the fields (this list may not be complete):
* `category`
......@@ -141,6 +149,29 @@ The following fields are used to generate i2b2 modifiers:
* `provision.code.coding.system` and `provision.code.coding.code`
### Medication
The "Medication" resource does not contribute patient-related data, instead it provides additional information about a medication that may be referenced in a "MedicationStatement" resource. This information is storen in the table FHIR_MEDICATION.
### MedicationStatement
Timestamps are derived from:
* `effectiveDateTime`
The following fields are used to generate i2b2 concept codes:
* `medicationCodeableConcept_coding_system` and `medicationCodeableConcept_coding_code` (as in the GECCO resources)
* The codes from table FHIR_MEDICATION, if a "Medication" resource is referenced
* Simply "Medication", if none of the above is available. It may be updated lated when a "Medication" resource becomes available.
The following fields are used to generate i2b2 modifiers:
* `provision.code.coding.system` and `provision.code.coding.code`
It does not yet process the fields (this list may not be complete):
* `status`
......@@ -25,7 +25,8 @@
-- - Implementation of support for "DiagnosticReport" resource
-- - Implementation of support for "Immunization" resource
-- - Update implementation for "Consent" resource
-- - Update implementation for "MedicationStatement" resource
-- - FIRST RELEASE FOR NUM CODEX
-- ============= Create Basic Tables =============
......@@ -598,11 +599,11 @@ begin
from FhirTempTable
left join (select (fhir2->>'effectiveDateTime')::timestamp as effectiveDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_array_elements(jsonb_array_elements(fhir->'category')->'coding')->>'code' as category_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir->'category')->'coding')->>'system' as category_coding_system
left join (select jsonb_array_elements(jsonb_array_elements(fhir2->'category')->'coding')->>'code' as category_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir2->'category')->'coding')->>'system' as category_coding_system
from FhirTempTable) as sq2 on true
left join (select jsonb_array_elements(jsonb_array_elements(fhir->'provision'->'code')->'coding')->>'code' as provision_code_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir->'provision'->'code')->'coding')->>'system' as provision_code_coding_system
left join (select jsonb_array_elements(jsonb_array_elements(fhir2->'provision'->'code')->'coding')->>'code' as provision_code_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir2->'provision'->'code')->'coding')->>'system' as provision_code_coding_system
from FhirTempTable) as sq3 on true
) fhir_data;
end if;
......@@ -751,7 +752,7 @@ begin
insert into i2b2miracum.observation_fact (
select oft.encounter_num,
oft.patient_num,
i2b2miracum.get_system_abbrv(fhir_data.system) || ':' || fhir_data.code, -- concept_cd
i2b2miracum.get_system_abbrv(fm.system) || ':' || fm.code, -- concept_cd
oft.provider_id,
oft.start_date,
oft.modifier_cd,
......@@ -792,8 +793,8 @@ begin
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, fhir_reference)
select i2b2_encounter_identifier, -- encounter_num
i2b2_patient_identifier, -- patient_num
case when fhir_data.code is not null then
i2b2miracum.get_system_abbrv(fhir_data.system) || ':' || fhir_data.code
case when fhir_data.medicationCodeableConcept_coding_code is not null then
i2b2miracum.get_system_abbrv(fhir_data.medicationCodeableConcept_coding_system) || ':' || fhir_data.medicationCodeableConcept_coding_code
when fhir_data.medication_code is not null then
i2b2miracum.get_system_abbrv(fhir_data.medication_system) || ':' || fhir_data.medication_code
else
......@@ -822,7 +823,27 @@ begin
1, -- upload_id
nextval('instance_num_seq'), -- text_search_index
medication_reference -- fhir_reference
from (select (new_as_table.fhir->>'effectiveDateTime')::timestamp as effectiveDateTime,
from (
with FhirTempTable(fhir2) AS (select fhir)
select
--jsonb_path_query(fhir2, '$.id')->>0 as ID,
(fhir2->>'id')::text as ID,
effectiveDateTime,
fhir_medication.code as medication_code,
fhir_medication.system as medication_system,
FhirTempTable.fhir2->'medicationReference'->>'reference' as medication_reference,
medicationCodeableConcept_coding_code,
medicationCodeableConcept_coding_system
from FhirTempTable
left join i2b2miracum.fhir_medication
on FhirTempTable.fhir2->'medicationReference'->>'reference' = 'Medication/' || fhir_medication.id
left join (select (fhir2->>'effectiveDateTime')::timestamp as effectiveDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_array_elements(fhir2->'medicationCodeableConcept'->'coding')->>'code' as medicationCodeableConcept_coding_code,
jsonb_array_elements(fhir2->'medicationCodeableConcept'->'coding')->>'system' as medicationCodeableConcept_coding_system
from FhirTempTable) as sq2 on true
) fhir_data;
/*from (select (new_as_table.fhir->>'effectiveDateTime')::timestamp as effectiveDateTime,
fhir_medication.code as medication_code,
fhir_medication.system as medication_system,
new_as_table.fhir->'medicationReference'->>'reference' as medication_reference, -- from i2b2 table "fhir_medication"
......@@ -831,7 +852,7 @@ begin
from (select fhir) new_as_table
left join i2b2miracum.fhir_medication
on new_as_table.fhir->'medicationReference'->>'reference' = 'Medication/' || fhir_medication.id
) fhir_data;
) fhir_data;*/
end if;
--
--return null; -- Return nothing. This prevents that the FHIR data is actually written into the "FHIR" table.
......
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