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

Update docu

parent 9088329f
create table i2b2miracum.FhirFields as (
select
''::text ResourceType,
''::text Profile,
''::text SystemPath,
''::text SystemValue,
''::text CodePath,
''::text CodeValue,
''::text DisplayPath,
''::text DisplayValue );
truncate table i2b2miracum.FhirFields;
-- Then paste the contents of FhirFields.tsv into that table.
-- List all resource types:
select distinct resourcetype from i2b2miracum.FhirFields;
select distinct systempath from i2b2miracum.FhirFields;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Condition' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Procedure' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Observation' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Consent' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'Immunization' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'DiagnosticReport' order by systempath asc;
select distinct systempath from i2b2miracum.FhirFields where resourcetype = 'MedicationStatement' order by systempath asc;
This diff is collapsed.
# 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.
## Implementation Status
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
* Encounter
* Condition
* Observation
* Immunization
* Consent
* Procedure
* Medication
* MedicationStatement
* DiagnosticReport
* ServiceRequest: Is ignored, as it's not contributing useful data to be queried by i2b2.
## Implementation Details
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 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.
### Encounter
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
Timestamps are derived from:
* `performedDateTime`
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 (this list may not be complete):
* `clinicalStatus`
* `category`
* `stage`
### Observation
Timestamps are derived from:
* `performedDateTime`
* `effectiveDateTime`
Numeric values are derived from:
* `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 (this list may not be complete):
* `category`
### Procedure
Timestamps are derived from:
* `performedDateTime`
The following fields are used to generate i2b2 modifiers:
* `bodySite.coding.system` and `bodySite.coding.code`
It does not yet process the fields (this list may not be complete):
* `category`
* `status`
### DiagnosticReport
Timestamps are derived from:
* `effectiveDateTime`
The following fields are used to generate i2b2 modifiers:
* `conclusionCode.coding.system` and `conclusionCode.coding.code`
It does not yet process the fields (this list may not be complete):
* `category`
### Immunization
Timestamps are derived from:
* `performedDateTime`
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.
The following fields are used to generate i2b2 modifiers:
* `vaccineCode.coding.system` and `vaccineCode.coding.code`
It does not yet process the fields (this list may not be complete):
* `category`
### Consent
Timestamps are derived from:
* `effectiveDateTime`
The following fields are used to generate i2b2 concept codes:
* `category.coding.system` and `category.coding.code`
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`
# 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.
## Implementation Status
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
* Encounter
* Condition
* Observation
* Immunization
* Consent
* Procedure
* Medication
* MedicationStatement
* DiagnosticReport
* ServiceRequest: Is ignored, as it's not contributing useful data to be queried by i2b2.
The code has been implemented with the GECCO dataset in mind (to process FHIR data generated with the odm2fhir program), but it may work with generic MII profiles.
## Implementation Details
### General:
* In most cases (depending on the FHIR profile) `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).
### Theory of Operation
* Function "fhir_inserted" is triggered whenever a FHIR resource is inserted into the "FHIR" table. If the resource is of type "Bundle", it is split into the distinct FHIR resources. The function then passes the FHIR data the function "process_fhir_resource" (see next).
* The Function "process_fhir_resource" contains the core logic that distributes the FHIR data to the i2b2 database tables. The first section of the function tries to determine which Patient and which Encounter are referenced and if both already exist in the i2b2 database. It then restores or creates new i2b2-internal patient and encounter mappings. In general, this first part populates the i2b2 table "PATIENT_MAPPING", "PATIENT_DIMENSION", "ENCOUNTER_MAPPING", and "VISIT_DIMENSION". The second part in general only populates "OBSERVATION_FACT" with the actual medical data, that is extracted from the FHIR data via the "select_fhir_fields" function (see next).
* The function "select_fhir_fields" is used to extract medical data from the FHIR resources. As noted above, in most cases (depending on the FHIR profile), the JSON paths `code.coding.code` and `code.coding.system` are used to generate the i2b2 concept code in column "CONCEPT_CD" of the table "OBSERVATION_FACT". However, there are also other JSON paths that provide additional information, which should create a so called "i2b2 Modifier" that is to be put into the "MODIFIER_CD" column. As this information may be located in different JSON paths (depending on the FHIR profile), the function "select_fhir_fields" aims to handle this in a generic way. Also timestamps may be located in different positions in the JSON, as are numeric values and others. The function "select_fhir_fields" extracts these data and returns a table that is then used by the function "process_fhir_resource" as described above. Note that the the table, in general, contains the cross product (i.e., all combinations) of the i2b2 concept codes and the i2b2 modifiers. This ensures that any combination can be found later in the i2b2 query user interface.
drop function i2b2miracum.select_fhir_fields(fhir jsonb);
create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
returns table (ID text,
StartTimes timestamp,
EndTimes timestamp,
MainSystem text,
MainCode text,
ModifierType text,
ModifierSystem text,
ModifierCode text,
valueQuantity_value numeric(18, 5),
valueQuantity_unit text,
valueQuantity_system text,
valueQuantity_code text)
as $$ begin return query
with FhirDataAsTable(fhir2) as (select fhir)
select
(fhir2->>'id')::text as ID,
StartTimes2::timestamp as StartTimes,
EndTimes2::timestamp as EndTimes,
MainSystem2::text as MainSystem,
MainCode2::text as MainCode,
ModifierType2::text as ModifierType,
ModifierSystem2::text as ModifierSystem,
ModifierCode2::text as ModifierCode,
valueQuantity_value2::numeric(18, 5) as valueQuantity_valuenumeric,
valueQuantity_unit2::text as valueQuantity_unit,
valueQuantity_system2::text as valueQuantity_system,
valueQuantity_code2::text as valueQuantity_code
from FhirDataAsTable
left join (-- ======== Below code fetches start and end times (columns start_date and end_date) ========
select (fhir2->>'performedDateTime')::timestamp as StartTimes2
from FhirDataAsTable
union
select (fhir2->>'recordedDate')::timestamp as StartTimes2
from FhirDataAsTable
union
select (fhir2->>'effectiveDateTime')::timestamp as StartTimes2
from FhirDataAsTable
union
select (fhir2->'occurrenceDateTime' || 'T00:00:00+00:00')::timestamp as StartTimes2
from FhirDataAsTable
) as sq1 on true and StartTimes2 is not null
left join (select (fhir2->>'performedDateTime')::timestamp as EndTimes2
from FhirDataAsTable
union
select (fhir2->>'recordedDate')::timestamp as EndTimes2
from FhirDataAsTable
union
select (fhir2->>'effectiveDateTime')::timestamp as EndTimes2
from FhirDataAsTable
union
select (fhir2->>'occurrenceDateTime' || 'T00:00:00+00:00')::timestamp as EndTimes2
from FhirDataAsTable
) as sq2 on true and EndTimes2 is not null
left join (-- ======== Below code fetches the values that go into the i2b2 concept code (column concept_cd) ========
select jsonb_array_elements(fhir2->'code'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'code'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' != 'Consent' and fhir2->>'resourceType' != 'Immunization'
union
select jsonb_array_elements(fhir2->'scope'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'scope'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' = 'Consent'
union
select jsonb_array_elements(fhir2->'vaccineCode'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'vaccineCode'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' = 'Immunization'
union
select jsonb_array_elements(fhir2->'medicationCodeableConcept'->'coding')->>'code' as MainCode2,
jsonb_array_elements(fhir2->'medicationCodeableConcept'->'coding')->>'system' as MainSystem2
from FhirDataAsTable where fhir2->>'resourceType' = 'MedicationStatement'
) as sq3 on true
left join (-- ======== Below code fetches the values that go into the i2b2 modifier codes (column modifier_cd) ========
select 'bodySite' ModifierType2, -- GECCO Condition, Procedure
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'bodySite')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'category' ModifierType2, -- GECCO Condition, Observation
jsonb_array_elements(jsonb_array_elements(fhir2->'category')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'category')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable where jsonb_typeof(fhir2->'category') = 'array'
union
select 'category' ModifierType2, -- GECCO Procedure
jsonb_array_elements(fhir2->'category'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(fhir2->'category'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable where jsonb_typeof(fhir2->'category') != 'array'
union
select 'clinicalStatus' ModifierType2, -- GECCO Condition
jsonb_array_elements(fhir2->'clinicalStatus'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(fhir2->'clinicalStatus'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'modifierExtension.valueCodeableConcept' ModifierType2, -- GECCO Condition
jsonb_array_elements(jsonb_array_elements(fhir2->'modifierExtension')->'valueCodeableConcept'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'modifierExtension')->'valueCodeableConcept'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'severity' ModifierType2, -- GECCO Condition
jsonb_array_elements(fhir2->'severity'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(fhir2->'severity'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'stage.summary' ModifierType2, -- GECCO Condition
jsonb_array_elements(jsonb_array_elements(fhir2->'stage')->'summary'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'stage')->'summary'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'stage.type' ModifierType2, -- GECCO Condition
jsonb_array_elements(jsonb_array_elements(fhir2->'stage')->'type'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'stage')->'type'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'verificationStatus' ModifierType2, -- GECCO Condition
jsonb_array_elements(fhir2->'verificationStatus'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(fhir2->'verificationStatus'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'extension.valueCodeableConcept' ModifierType2, -- Nicht-GECCO Condition
jsonb_array_elements(jsonb_array_elements(fhir2->'extension')->'valueCodeableConcept'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'extension')->'valueCodeableConcept'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'usedCode' ModifierType2, -- GECCO Procedure
jsonb_array_elements(jsonb_array_elements(fhir2->'usedCode')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'usedCode')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'component.code' ModifierType2, -- GECCO Observation
jsonb_array_elements(jsonb_array_elements(fhir2->'component')->'code'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'component')->'code'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'component.valueCodeableConcept' ModifierType2, -- GECCO Observation
jsonb_array_elements(jsonb_array_elements(fhir2->'component')->'valueCodeableConcept'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'component')->'valueCodeableConcept'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'dataAbsentReason' ModifierType2, -- GECCO Observation
jsonb_array_elements(fhir2->'dataAbsentReason'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(fhir2->'dataAbsentReason'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'method' ModifierType2, -- GECCO Observation
jsonb_array_elements(fhir2->'method'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(fhir2->'method'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'valueCodeableConcept' ModifierType2, -- GECCO Observation
jsonb_array_elements(fhir2->'valueCodeableConcept'->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(fhir2->'valueCodeableConcept'->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'provision.code' ModifierType2, -- GECCO Consent
jsonb_array_elements(jsonb_array_elements(fhir2->'provision'->'code')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'provision'->'code')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'protocolApplied.targetDisease' ModifierType2, -- GECCO Immunization
jsonb_array_elements(jsonb_array_elements(jsonb_array_elements(fhir2->'protocolApplied')->'targetDisease')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(jsonb_array_elements(fhir2->'protocolApplied')->'targetDisease')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'conclusionCode' ModifierType2, -- GECCO DiagnosticReport
jsonb_array_elements(jsonb_array_elements(fhir2->'conclusionCode')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'conclusionCode')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
union
select 'reasonCode' ModifierType2, -- GECCO MedicationStatement
jsonb_array_elements(jsonb_array_elements(fhir2->'reasonCode')->'coding')->>'code' as ModifierCode2,
jsonb_array_elements(jsonb_array_elements(fhir2->'reasonCode')->'coding')->>'system' as ModifierSystem2
from FhirDataAsTable
) as sq4 on true
left join (-- ======== Below code fetches data for other columns ========
select (fhir2->'valueQuantity'->>'value')::numeric(18,5) as valueQuantity_value2, -- Numeric values for GECCO Observation
fhir2->'valueQuantity'->>'unit'::text as valueQuantity_unit2,
fhir2->'valueQuantity'->>'system'::text as valueQuantity_system2,
fhir2->'valueQuantity'->>'code'::text as valueQuantity_code2
from FhirDataAsTable) as sq5 on true;
end $$ language plpgsql;
select * from i2b2miracum.select_fhir_fields('{
"resourceType": "MedicationStatement",
"id": "257548c0734113c99bd51b76ae8c76d6",
"meta": {
"profile": [ "https://www.netzwerk-universitaetsmedizin.de/fhir/StructureDefinition/pharmacological-therapy-anticoagulants" ]
},
"identifier": [ {
"system": "https://mein.krankenhaus.de/fhir/NamingSystem/medicationstatementId",
"value": "Option01-GECCOVISIT.null-Form.medikation.1-medikation.antikoagulation_unfraktioniertes_heparin.1-antikoagulation_unfraktioniertes_heparin"
} ],
"status": "active",
"medicationCodeableConcept": {
"coding": [ {
"system": "http://snomed.info/sct",
"code": "81839001"
}, {
"system": "http://fhir.de/CodeSystem/dimdi/atc",
"code": "B01AB01"
} ]
},
"subject": {
"reference": "Patient/969ba73aa2f35a27d698cbbf6f3785fe"
},
"effectiveDateTime": "2000-01-01T00:00:00+00:00",
"reasonCode": [ {
"coding": [ {
"system": "http://snomed.info/sct",
"code": "373808002",
"display": "Curative - procedure intent (qualifier value)"
} ]
} ]
}'::jsonb);
-- 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);
......@@ -67,8 +67,8 @@ truncate table i2b2miracum.fhir_elt_log;
do $$
begin
alter table i2b2miracum.observation_fact add fhir_reference varchar(100) null;
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 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);
exception
when others then raise notice 'Index or column already exists';
end;
......@@ -98,29 +98,29 @@ create or replace function i2b2miracum.get_system_abbrv(systemlink text) returns
$$
begin
case when systemlink = 'http://dicom.nema.org/resources/ontology/DCM' then return 'DCM';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/atc' then return 'ATC';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/icd-10-gm' then return 'ICD10';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/ops' then return 'OPS';
when systemlink = 'http://fhir.de/CodeSystem/gender-amtlich-de' then return 'GenderAmtlichDE';
when systemlink = 'http://hl7.org/fhir/administrative-gender' then return 'AdminGender';
when systemlink = 'http://hl7.org/fhir/uv/ips/CodeSystem/absent-unknown-uv-ips' then return 'ABSENT';
when systemlink = 'http://loinc.org' then return 'LOINC';
when systemlink = 'http://snomed.info/sct' then return 'SNOMED-CT';
when systemlink = 'http://terminology.hl7.org/CodeSystem/condition-clinical' then return 'CC';
when systemlink = 'http://terminology.hl7.org/CodeSystem/condition-ver-status' then return 'CVS';
when systemlink = 'http://terminology.hl7.org/CodeSystem/consentscope' then return 'CS';
when systemlink = 'http://terminology.hl7.org/CodeSystem/data-absent-reason' then return 'DAR';
when systemlink = 'http://terminology.hl7.org/CodeSystem/observation-category' then return 'OC';
when systemlink = 'http://terminology.hl7.org/CodeSystem/v2-0074' then return 'DiagnosticServiceSectionId';
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/ecrf-parameter-codes' then return 'ECRF';
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/frailty-score' then return 'FRAILTY';
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/sofa-score' then return 'SOFA';
when systemlink = 'urn:iso:std:iso:3166' then return 'ISO3166';
when systemlink = 'urn:oid:1.2.276.0.76.5.409' then return 'ICD10';
when systemlink = 'urn:oid:2.16.840.1.113883.6.238' then return 'RaceAndEthnicityCDC';
when systemlink = 'http://terminology.hl7.org/CodeSystem/consentcategorycodes' then return 'FDASIS';
when systemlink = 'http://fdasis.nlm.nih.gov' then return 'CCC';
when systemlink = 'urn:oid:2.16.840.1.113883.6.18.2.6' then return 'ISBT128';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/atc' then return 'ATC';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/icd-10-gm' then return 'ICD10';
when systemlink = 'http://fhir.de/CodeSystem/dimdi/ops' then return 'OPS';
when systemlink = 'http://fhir.de/CodeSystem/gender-amtlich-de' then return 'GenderAmtlichDE';
when systemlink = 'http://hl7.org/fhir/administrative-gender' then return 'AdminGender';
when systemlink = 'http://hl7.org/fhir/uv/ips/CodeSystem/absent-unknown-uv-ips' then return 'ABSENT';
when systemlink = 'http://loinc.org' then return 'LOINC';
when systemlink = 'http://snomed.info/sct' then return 'SNOMED-CT';
when systemlink = 'http://terminology.hl7.org/CodeSystem/condition-clinical' then return 'CC';
when systemlink = 'http://terminology.hl7.org/CodeSystem/condition-ver-status' then return 'CVS';
when systemlink = 'http://terminology.hl7.org/CodeSystem/consentscope' then return 'CS';
when systemlink = 'http://terminology.hl7.org/CodeSystem/data-absent-reason' then return 'DAR';
when systemlink = 'http://terminology.hl7.org/CodeSystem/observation-category' then return 'OC';
when systemlink = 'http://terminology.hl7.org/CodeSystem/v2-0074' then return 'DiagnosticServiceSectionId';
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/ecrf-parameter-codes' then return 'ECRF';
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/frailty-score' then return 'FRAILTY';
when systemlink = 'https://www.netzwerk-universitaetsmedizin.de/fhir/CodeSystem/sofa-score' then return 'SOFA';
when systemlink = 'urn:iso:std:iso:3166' then return 'ISO3166';
when systemlink = 'urn:oid:1.2.276.0.76.5.409' then return 'ICD10';
when systemlink = 'urn:oid:2.16.840.1.113883.6.238' then return 'RaceAndEthnicityCDC';
when systemlink = 'http://terminology.hl7.org/CodeSystem/consentcategorycodes' then return 'FDASIS';
when systemlink = 'http://fdasis.nlm.nih.gov' then return 'CCC';
when systemlink = 'urn:oid:2.16.840.1.113883.6.18.2.6' then return 'ISBT128';
else
perform i2b2miracum.fhir_elt_log('ERROR: Coding system unknown: ' || systemlink);
return 'UNKNOWN';
......@@ -534,7 +534,7 @@ end;
$$;
create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
returns table (ID text,
returns table (ID text,
StartTimes timestamp,
EndTimes timestamp,
MainSystem text,
......@@ -546,9 +546,9 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
valueQuantity_unit text,
valueQuantity_system text,
valueQuantity_code text)
as $$ begin return query
with FhirDataAsTable(fhir2) as (select fhir)
select
as $$ begin return query
with FhirDataAsTable(fhir2) as (select fhir)
select
(fhir2->>'id')::text as ID,
StartTimes2::timestamp as StartTimes,
EndTimes2::timestamp as EndTimes,
......@@ -566,25 +566,25 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
select (fhir2->>'performedDateTime')::timestamp as StartTimes2
from FhirDataAsTable
union
select (fhir2->>'recordedDate')::timestamp as StartTimes2
select (fhir2->>'recordedDate')::timestamp as StartTimes2
from FhirDataAsTable
union
select (fhir2->>'effectiveDateTime')::timestamp as StartTimes2
select (fhir2->>'effectiveDateTime')::timestamp as StartTimes2
from FhirDataAsTable
union
select (fhir2->'occurrenceDateTime' || 'T00:00:00+00:00')::timestamp as StartTimes2
select (fhir2->'occurrenceDateTime' || 'T00:00:00+00:00')::timestamp as StartTimes2
from FhirDataAsTable
) as sq1 on true and StartTimes2 is not null
left join (select (fhir2->>'performedDateTime')::timestamp as EndTimes2
from FhirDataAsTable
union
select (fhir2->>'recordedDate')::timestamp as EndTimes2
select (fhir2->>'recordedDate')::timestamp as EndTimes2
from FhirDataAsTable
union
select (fhir2->>'effectiveDateTime')::timestamp as EndTimes2
select (fhir2->>'effectiveDateTime')::timestamp as EndTimes2
from FhirDataAsTable
union
select (fhir2->>'occurrenceDateTime' || 'T00:00:00+00:00')::timestamp as EndTimes2
select (fhir2->>'occurrenceDateTime' || 'T00:00:00+00:00')::timestamp as EndTimes2
from FhirDataAsTable
) as sq2 on true and EndTimes2 is not null
left join (-- ======== Below code fetches the values that go into the i2b2 concept code (column concept_cd) ========
......@@ -606,17 +606,17 @@ create or replace function i2b2miracum.select_fhir_fields(fhir jsonb)
) as sq3 on true
left join (-- ======== Below code fetches the values that go into the i2b2 modifier codes (column modifier_cd) ========
select 'bodySite' ModifierType2, -- GECCO Condition, Procedure