Packages
hl7v2
3.4.0
3.10.1
3.9.0
3.8.0
3.7.0
3.6.0
3.5.0
3.4.0
3.3.6
3.3.5
3.3.4
3.3.3
3.3.2
3.3.1
3.3.0
3.2.0
3.1.1
3.1.0
3.0.2
3.0.1
3.0.0
2.11.0
2.10.0
2.9.1
2.9.0
2.8.2
2.8.1
2.8.0
2.7.1
2.7.0
2.6.0
2.5.0
2.4.0
2.3.0
2.2.0
2.1.3
2.1.2
2.1.1
2.1.0
1.4.6
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.0
1.2.0
1.1.0
1.0.0
0.6.0
0.5.6
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.1.0
Pure Elixir HL7 v2.x toolkit — schema-driven parsing, typed segments, message builder, MLLP transport
Current section
Files
Jump to
Current section
Files
lib/hl7v2/segment/obx.ex
defmodule HL7v2.Segment.OBX do
@moduledoc """
Observation/Result (OBX) segment -- HL7v2 v2.5.1.
Carries a single observation value. OBX-5 type varies based on OBX-2 (Value Type).
19 fields per HL7 v2.5.1 specification.
After base parsing, OBX-5 (observation_value) is re-parsed through
`HL7v2.Segment.OBXValue` using the data type declared in OBX-2 (value_type).
Unsupported value types are preserved as raw values. See `HL7v2.Segment.OBXValue`
for the full list of supported OBX-2 codes.
"""
use HL7v2.Segment,
id: "OBX",
fields: [
{1, :set_id, HL7v2.Type.SI, :o, 1},
{2, :value_type, HL7v2.Type.ID, :c, 1},
{3, :observation_identifier, HL7v2.Type.CE, :r, 1},
{4, :observation_sub_id, HL7v2.Type.ST, :c, 1},
{5, :observation_value, :raw, :c, :unbounded},
{6, :units, HL7v2.Type.CE, :o, 1},
{7, :references_range, HL7v2.Type.ST, :o, 1},
{8, :abnormal_flags, HL7v2.Type.IS, :o, :unbounded},
{9, :probability, HL7v2.Type.NM, :o, 1},
{10, :nature_of_abnormal_test, HL7v2.Type.ID, :o, :unbounded},
{11, :observation_result_status, HL7v2.Type.ID, :r, 1},
{12, :effective_date_of_reference_range, HL7v2.Type.TS, :o, 1},
{13, :user_defined_access_checks, HL7v2.Type.ST, :o, 1},
{14, :date_time_of_the_observation, HL7v2.Type.TS, :o, 1},
{15, :producers_id, HL7v2.Type.CE, :o, 1},
{16, :responsible_observer, HL7v2.Type.XCN, :o, :unbounded},
{17, :observation_method, HL7v2.Type.CE, :o, :unbounded},
{18, :equipment_instance_identifier, HL7v2.Type.EI, :o, :unbounded},
{19, :date_time_of_the_analysis, HL7v2.Type.TS, :o, 1}
]
alias HL7v2.Segment.OBXValue
@impl HL7v2.Segment
@spec parse(list(), HL7v2.Separator.t()) :: t()
def parse(raw_fields, separators \\ HL7v2.Separator.default()) do
obx = HL7v2.Segment.do_parse(__MODULE__, @segment_fields, raw_fields, separators)
case obx.value_type do
nil ->
obx
vt ->
parsed = OBXValue.parse(obx.observation_value, vt)
%{obx | observation_value: parsed}
end
end
@impl HL7v2.Segment
@spec encode(t()) :: list()
def encode(%__MODULE__{} = obx) do
# Convert typed observation_value back to raw before base encode
raw_obx =
case obx.value_type do
nil ->
obx
vt ->
raw_value = OBXValue.encode(obx.observation_value, vt)
%{obx | observation_value: raw_value}
end
HL7v2.Segment.do_encode(raw_obx, @segment_fields)
end
end