Skip to content

Commit

Permalink
Adding correct null handling for bp vital signs observations in fhir_…
Browse files Browse the repository at this point in the history
…observation_vitalsigns.sql to conform with http://hl7.org/fhir/StructureDefinition/bp|4.0. Always producing the required bp components, with not values if not available.

Fixing:

kind-lab#105

Observation.component: minimum required = 2, but only found 0 (from http://hl7.org/fhir/StructureDefinition/bp|4.0.1)

Slice 'Observation.component:DiastolicBP': a matching slice is required, but not found (from http://hl7.org/fhir/StructureDefinition/bp|4.0.1). Note that other slices are allowed in addition to this required slice

Slice 'Observation.component:SystolicBP': a matching slice is required, but not found (from http://hl7.org/fhir/StructureDefinition/bp|4.0.1). Note that other slices are allowed in addition to this required slice
  • Loading branch information
piotrszul committed Jun 27, 2024
1 parent ba8387d commit 6e9306a
Showing 1 changed file with 77 additions and 27 deletions.
104 changes: 77 additions & 27 deletions sql/fhir_observation_vitalsigns.sql
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ SELECT
ELSE NULL -- blood pressure stored in components
END
, 'component', CASE
WHEN vs_VALUE IS NULL THEN NULL
WHEN vs_KEY = 'dbp' THEN
jsonb_build_array(
jsonb_build_object(
Expand All @@ -155,12 +154,25 @@ SELECT
, 'display', 'Systolic blood pressure'
))
)
, 'valueQuantity', jsonb_build_object(
'value', vs_SBP
, 'unit', 'mm[Hg]'
, 'system', 'http://unitsofmeasure.org'
, 'code', 'mm[Hg]'
)
, 'valueQuantity',
CASE WHEN vs_SBP IS NOT NULL THEN
jsonb_build_object(
'value', vs_SBP
, 'unit', 'mm[Hg]'
, 'system', 'http://unitsofmeasure.org'
, 'code', 'mm[Hg]'
)
END
, 'dataAbsentReason',
CASE WHEN vs_SBP IS NULL THEN
jsonb_build_object(
'coding', jsonb_build_array(jsonb_build_object(
'system', 'http://terminology.hl7.org/CodeSystem/data-absent-reason'
, 'code', 'unknown'
, 'display', 'Unknown'
))
)
END
)
, jsonb_build_object(
'code', jsonb_build_object(
Expand All @@ -170,12 +182,25 @@ SELECT
, 'display', 'Diastolic blood pressure'
))
)
, 'valueQuantity', jsonb_build_object(
'value', vs_VALUE
, 'unit', 'mm[Hg]'
, 'system', 'http://unitsofmeasure.org'
, 'code', 'mm[Hg]'
)
, 'valueQuantity',
CASE WHEN vs_VALUE IS NOT NULL THEN
jsonb_build_object(
'value', vs_VALUE
, 'unit', 'mm[Hg]'
, 'system', 'http://unitsofmeasure.org'
, 'code', 'mm[Hg]'
)
END
, 'dataAbsentReason',
CASE WHEN vs_VALUE IS NULL THEN
jsonb_build_object(
'coding', jsonb_build_array(jsonb_build_object(
'system', 'http://terminology.hl7.org/CodeSystem/data-absent-reason'
, 'code', 'unknown'
, 'display', 'Unknown'
))
)
END
)
)
ELSE NULL END
Expand Down Expand Up @@ -327,7 +352,6 @@ SELECT
ELSE NULL -- blood pressure stored in components
END
, 'component', CASE
WHEN vs_VALUE IS NULL THEN NULL
WHEN vs_KEY = 'dbp' THEN
jsonb_build_array(
jsonb_build_object(
Expand All @@ -338,12 +362,25 @@ SELECT
, 'display', 'Systolic blood pressure'
))
)
, 'valueQuantity', jsonb_build_object(
'value', vs_SBP
, 'unit', 'mm[Hg]'
, 'system', 'http://unitsofmeasure.org'
, 'code', 'mm[Hg]'
)
, 'valueQuantity',
CASE WHEN vs_SBP IS NOT NULL THEN
jsonb_build_object(
'value', vs_SBP
, 'unit', 'mm[Hg]'
, 'system', 'http://unitsofmeasure.org'
, 'code', 'mm[Hg]'
)
END
, 'dataAbsentReason',
CASE WHEN vs_SBP IS NULL THEN
jsonb_build_object(
'coding', jsonb_build_array(jsonb_build_object(
'system', 'http://terminology.hl7.org/CodeSystem/data-absent-reason'
, 'code', 'unknown'
, 'display', 'Unknown'
))
)
END
),
jsonb_build_object(
'code', jsonb_build_object(
Expand All @@ -353,13 +390,26 @@ SELECT
, 'display', 'Diastolic blood pressure'
))
)
, 'valueQuantity', jsonb_build_object(
'value', vs_VALUE
, 'unit', 'mm[Hg]'
, 'system', 'http://unitsofmeasure.org'
, 'code', 'mm[Hg]'
)
)
, 'valueQuantity',
CASE WHEN vs_VALUE IS NOT NULL THEN
jsonb_build_object(
'value', vs_VALUE
, 'unit', 'mm[Hg]'
, 'system', 'http://unitsofmeasure.org'
, 'code', 'mm[Hg]'
)
END
, 'dataAbsentReason',
CASE WHEN vs_VALUE IS NULL THEN
jsonb_build_object(
'coding', jsonb_build_array(jsonb_build_object(
'system', 'http://terminology.hl7.org/CodeSystem/data-absent-reason'
, 'code', 'unknown'
, 'display', 'Unknown'
))
)
END
)
)
ELSE NULL END
)) AS fhir
Expand Down

0 comments on commit 6e9306a

Please sign in to comment.