Commit 41ba994c authored by Sebastian Mate's avatar Sebastian Mate
Browse files

Implementation of support for "Immunization" resource

Fix variables (fhir => fhir2)
Update docu
parent ebe32195
i2b2-FHIR-Trigger - Load incoming FHIR data into i2b2 schema via database triggers
# i2b2 FHIR Trigger - Load incoming FHIR data into i2b2 schema via database triggers
When executing this SQL code on an i2b2 database schema a "FHIR" table is created, which can be used to import FHIR data. Simply write the FHIR JSON to the "FHIR" table.
When executing this SQL code on an i2b2 database schema, a "FHIR" table is created which can be used to import FHIR data. Simply write the FHIR JSON to the "FHIR" table.
## Implementation Status
......@@ -25,18 +25,18 @@ In general, `code.coding.code` and `code.coding.system` are used to generate the
### Patient
Currently, the following fields are processed into the PATIENT_DIMENSION table:
Currently, the following fields are processed into the PATIENT.DIMENSION table:
* `birthDate` as birthdate
* `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
Currently, only the encounter IDs are collected and processed into the ENCOUNTER_MAPPING table. To 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 processed.
### Condition
......@@ -104,6 +104,25 @@ It does not yet process the fields:
* `category`
### Immunization
Timestamps are derived from:
* `performedDateTime`
The following fields are used to generate i2b2 modifiers:
* `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.
The following fields are used to generate i2b2 modifiers:
* `vaccineCode.coding.system` and `vaccineCode.coding.code`
It does not yet process the fields:
* `category`
......
......@@ -23,6 +23,7 @@
-- - Reimplementation of "Procedure" resource processing to make it compatible with GECCO modeling
-- 2021-02-01: - Add support for "bodySite" field in "Procedure" ressource
-- - Implementation of support for "DiagnosticReport" resource
-- - Implementation of support for "Immunization" resource
-- ============= Create Basic Tables =============
......@@ -274,7 +275,7 @@ begin
null, -- race_cd
null, -- marital_status_cd
null, -- religion_cd
postalCode, -- zip_cd
address_postalCode, -- zip_cd
null, -- statecityzip_path
null, -- income_cd
null, -- patient_blob
......@@ -290,7 +291,7 @@ begin
(fhir->>'deceasedDateTime')::timestamp as deceasedDateTime,
(fhir->>'birthDate')::timestamp as birthDate,
(fhir->>'gender')::text as gender,
jsonb_array_elements(fhir->'address')->>'postalCode' as postalCode -- zip_cd
jsonb_array_elements(fhir->'address')->>'postalCode' as address_postalCode -- zip_cd
) fhir_data;
end if;
end if;
......@@ -391,14 +392,14 @@ begin
from FhirTempTable
left join (select (fhir2->>'recordedDate')::timestamp as OnsetDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_array_elements(fhir->'code'->'coding')->>'code' as code_coding_code,
jsonb_array_elements(fhir->'code'->'coding')->>'system' as code_coding_system
left join (select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as code_coding_code,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as code_coding_system
from FhirTempTable) as sq2 on true
left join (select jsonb_array_elements(fhir->'verificationStatus'->'coding')->>'code' as verificationStatus_coding_code,
jsonb_array_elements(fhir->'verificationStatus'->'coding')->>'system' as verificationStatus_coding_system
left join (select jsonb_array_elements(fhir2->'verificationStatus'->'coding')->>'code' as verificationStatus_coding_code,
jsonb_array_elements(fhir2->'verificationStatus'->'coding')->>'system' as verificationStatus_coding_system
from FhirTempTable) as sq3 on true
left join (select jsonb_array_elements(jsonb_array_elements(fhir->'extension')->'valueCodeableConcept'->'coding')->>'code' as extension_valueCodeableConcept_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir->'extension')->'valueCodeableConcept'->'coding')->>'system' as extension_valueCodeableConcept_coding_system
left join (select jsonb_array_elements(jsonb_array_elements(fhir2->'extension')->'valueCodeableConcept'->'coding')->>'code' as extension_valueCodeableConcept_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir2->'extension')->'valueCodeableConcept'->'coding')->>'system' as extension_valueCodeableConcept_coding_system
from FhirTempTable) as sq4 on true
) fhir_data;
end if;
......@@ -460,16 +461,16 @@ begin
from FhirTempTable
left join (select (fhir2->>'performedDateTime')::timestamp as performedDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_array_elements(fhir->'code'->'coding')->>'code' as code_coding_code,
jsonb_array_elements(fhir->'code'->'coding')->>'system' as code_coding_system
left join (select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as code_coding_code,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as code_coding_system
from FhirTempTable) as sq2 on true
left join (select (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
left join (select (fhir2->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value,
fhir2->'valueQuantity'->>'unit'::text as valueQuantity_unit,
fhir2->'valueQuantity'->>'system'::text as valueQuantity_system,
fhir2->'valueQuantity'->>'code'::text as valueQuantity_code
from FhirTempTable) as sq3 on true
left join (select jsonb_array_elements(fhir->'valueCodeableConcept'->'coding')->>'code' as valueCodeableConcept_coding_code,
jsonb_array_elements(fhir->'valueCodeableConcept'->'coding')->>'system' as valueCodeableConcept_coding_system
left join (select jsonb_array_elements(fhir2->'valueCodeableConcept'->'coding')->>'code' as valueCodeableConcept_coding_code,
jsonb_array_elements(fhir2->'valueCodeableConcept'->'coding')->>'system' as valueCodeableConcept_coding_system
from FhirTempTable) as sq4 on true
left join (select (fhir2->>'effectiveDateTime')::timestamp as effectiveDateTime
from FhirTempTable) as sq5 on true
......@@ -487,11 +488,14 @@ 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)
select i2b2_encounter_identifier, -- encounter_num
i2b2_patient_identifier, -- patient_num
i2b2miracum.get_system_abbrv(fhir_data.system) || ':' || fhir_data.code, -- concept_cd
/*'VACC:' || */i2b2miracum.get_system_abbrv(fhir_data.protocolApplied_targetDisease_coding_system) || ':' || fhir_data.protocolApplied_targetDisease_coding_code, -- concept_cd
'FHIR', -- provider_id
case when fhir_data.effectiveDateTime is not null then fhir_data.effectiveDateTime
case when fhir_data.performedDateTime is not null then fhir_data.performedDateTime
else '-infinity'::timestamptz end, -- start_date
'@', -- modifier_cd
case when fhir_data.vaccineCode_coding_system is not null
then i2b2miracum.get_system_abbrv(fhir_data.vaccineCode_coding_system) || ':' || fhir_data.vaccineCode_coding_code
else '@'
end, -- modifier_cd
nextval('instance_num_seq'), -- instance_num
'N', -- valtype_cd
'E', -- tval_char
......@@ -499,7 +503,7 @@ begin
'', -- valueflag_cd
1, -- quantity_num
null, -- units_cd
case when fhir_data.effectiveDateTime is not null then fhir_data.effectiveDateTime
case when fhir_data.performedDateTime is not null then fhir_data.performedDateTime
else '-infinity'::timestamptz end, -- end_date
'', -- location_cd
FHIR_id, -- observation_blob
......@@ -510,15 +514,26 @@ begin
FHIR_sourcesystem, -- sourcesystem_cd
1, -- upload_id
nextval('instance_num_seq') -- text_search_index
from (SELECT
jsonb_array_elements(fhir->'vaccineCode'->'coding')->>'code' as code,
jsonb_array_elements(fhir->'vaccineCode'->'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;
from (
with FhirTempTable(fhir2) AS (select fhir)
select
--jsonb_path_query(fhir2, '$.id')->>0 as ID,
(fhir2->>'id')::text as ID,
performedDateTime,
vaccineCode_coding_code,
vaccineCode_coding_system,
protocolApplied_targetDisease_coding_code,
protocolApplied_targetDisease_coding_system
from FhirTempTable
left join (select (fhir2->>'performedDateTime')::timestamp as performedDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_array_elements(fhir2->'vaccineCode'->'coding')->>'code' as vaccineCode_coding_code,
jsonb_array_elements(fhir2->'vaccineCode'->'coding')->>'system' as vaccineCode_coding_system
from FhirTempTable) as sq2 on true
left join (select jsonb_array_elements(jsonb_array_elements(jsonb_array_elements(fhir2->'protocolApplied')->'targetDisease')->'coding')->>'code' as protocolApplied_targetDisease_coding_code,
jsonb_array_elements(jsonb_array_elements(jsonb_array_elements(fhir2->'protocolApplied')->'targetDisease')->'coding')->>'system' as protocolApplied_targetDisease_coding_system
from FhirTempTable) as sq3 on true
) fhir_data;
end if;
--
-- *** Handle GECCO FHIR Consent resource ***
......@@ -616,11 +631,11 @@ begin
from FhirTempTable
left join (select (fhir2->>'performedDateTime')::timestamp as performedDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_array_elements(fhir->'code'->'coding')->>'code' as code_coding_code,
jsonb_array_elements(fhir->'code'->'coding')->>'system' as code_coding_system
left join (select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as code_coding_code,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as code_coding_system
from FhirTempTable) as sq2 on true
left join (select jsonb_array_elements(jsonb_array_elements(fhir->'bodySite')->'coding')->>'code' as bodySite_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir->'bodySite')->'coding')->>'system' as bodySite_coding_system
left join (select jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'code' as bodySite_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'system' as bodySite_coding_system
from FhirTempTable) as sq3 on true
) fhir_data;
end if;
......@@ -675,11 +690,11 @@ begin
from FhirTempTable
left join (select (fhir2->>'effectiveDateTime')::timestamp as effectiveDateTime
from FhirTempTable) as sq1 on true
left join (select jsonb_array_elements(fhir->'code'->'coding')->>'code' as code_coding_code,
jsonb_array_elements(fhir->'code'->'coding')->>'system' as code_coding_system
left join (select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as code_coding_code,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as code_coding_system
from FhirTempTable) as sq2 on true
left join (select jsonb_array_elements(jsonb_array_elements(fhir->'conclusionCode')->'coding')->>'code' as conclusionCode_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir->'conclusionCode')->'coding')->>'system' as conclusionCode_coding_system
left join (select jsonb_array_elements(jsonb_array_elements(fhir2->'conclusionCode')->'coding')->>'code' as conclusionCode_coding_code,
jsonb_array_elements(jsonb_array_elements(fhir2->'conclusionCode')->'coding')->>'system' as conclusionCode_coding_system
from FhirTempTable) as sq3 on true
) fhir_data;
end if;
......
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