HL7 (elixir_hl7 v0.9.1) View Source

Functions to manipulate and query HL7 documents -- plus a way to handle HL7 file streams.

Link to this section Summary

Functions

Creates a list of lists in which the specified segment_name is used to get the first segment map of each list. This function helps to do things like grouping OBX segments with their parent OBR segment.

Finds data within an HL7.t() and from within the data that get/2 returns (segments and repetitions) using an HL7.Path sigil.

Labels source data (a segment map or list of segment maps) by using HL7.Path sigils in a labeled output template.

Creates an HL7 struct from HL7 data (accepting text, lists or the deprecated HL7.Message struct).

Opens an HL7 file stream of either :mllp or :line. If the file_type is not specified it will be inferred from the first three characters of the file contents.

The ~p sigil encodes an HL7 path into a struct at compile-time to guarantee correctness and speed. It is designed to work with data returned by HL7.new!/1.

Converts a segment map (or lists of segments maps) or HL7 struct into a raw Elixir list.

Link to this section Types

Specs

file_type_hl7() :: :mllp | :line | nil

Specs

hl7_list_data() :: String.t() | [hl7_list_data()]

Specs

hl7_map_data() :: %{optional(non_neg_integer()) => hl7_map_data() | String.t()}

Specs

parsed_hl7() :: t() | segment() | [segment()] | hl7_map_data()

Specs

parsed_hl7_segments() :: t() | [segment()]

Specs

segment() :: %{
  required(0) => String.t(),
  optional(pos_integer()) => hl7_map_data() | String.t()
}

Specs

t() :: %HL7{segments: [segment()]}

Link to this section Functions

Link to this function

chunk_by_lead_segment(segments, segment_name, options \\ [])

View Source

Specs

chunk_by_lead_segment(t() | [segment()], String.t(), Keyword.t()) :: [
  [segment()]
]

Creates a list of lists in which the specified segment_name is used to get the first segment map of each list. This function helps to do things like grouping OBX segments with their parent OBR segment.

Options:

keep_prefix_segments: true will leave the first set of non-matching segments in the return value.

Link to this function

do_to_list(hl7_map_data)

View Source

Specs

get(parsed_hl7(), %HL7.Path{
  component: term(),
  data: term(),
  field: term(),
  path: term(),
  repetition: term(),
  segment: term(),
  segment_number: term(),
  subcomponent: term(),
  truncate: term()
}) :: hl7_map_data() | String.t() | nil

Finds data within an HL7.t() and from within the data that get/2 returns (segments and repetitions) using an HL7.Path sigil.

Selecting data across multiple segments or repetitions with the wildcard [*] pattern will return a list of results.

Repetition data can be search using a partial path containing ony the component and/or subcomponent with the preceding period, e.g. ~p".2.3".

Examples

iex> import HL7, only: :sigils
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"OBX-5")
"1.80"

iex> import HL7, only: :sigils
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"OBX[*]-5")
["1.80", "79"]

iex> import HL7, only: :sigils
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"OBX[*]-2!")
["N", "NM"]

iex> import HL7, only: :sigils
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"PID-11[*].5")
["35209", "35200"]

iex> import HL7, only: :sigils
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"PID-11[2].1")
"NICKELL’S PICKLES"

iex> import HL7, only: :sigils
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"PID-11[*]")
...> |> HL7.get(~p".1")
["260 GOODWIN CREST DRIVE", "NICKELL’S PICKLES"]
Link to this function

label(segment_or_segments, template_map)

View Source

Specs

label(t() | segment(), map()) :: map()

Labels source data (a segment map or list of segment maps) by using HL7.Path sigils in a labeled output template.

One-arity functions placed as output template values will be called with the source data.

Examples

iex> import HL7, only: :sigils
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.label(%{mrn: ~p"PID-3!", name: ~p"PID-5.2"})
%{mrn: "56782445", name: "BARRY"}

Specs

new(String.t()) :: {:ok, t()} | {:error, HL7.InvalidMessage.t()}

Specs

new!(hl7_list_data() | String.t() | HL7.Message.t() | [segment()]) :: t()

Creates an HL7 struct from HL7 data (accepting text, lists or the deprecated HL7.Message struct).

Link to this function

open_hl7_file_stream(file_path, file_type \\ nil)

View Source

Specs

open_hl7_file_stream(String.t(), file_type_hl7()) :: Enumerable.t()

Opens an HL7 file stream of either :mllp or :line. If the file_type is not specified it will be inferred from the first three characters of the file contents.

Specs

put(parsed_hl7(), HL7.Path.t(), String.t() | nil | hl7_map_data()) ::
  parsed_hl7()
Link to this function

set_segments(hl7, segments)

View Source
Link to this macro

sigil_p(arg, modifiers)

View Source (macro)

The ~p sigil encodes an HL7 path into a struct at compile-time to guarantee correctness and speed. It is designed to work with data returned by HL7.new!/1.

The full path structure in HL7 is expressed as:

~p"SEGMENT_NAME[SEGMENT_NUMBER]-FIELD[REPETITION].COMPONENT.SUBCOMPONENT

SEGMENT_NAME -- 3 character string SEGMENT_NUMBER -- Positive integer in brackets, defaulting to 1. All segments of the name can be accessed with [*] FIELD -- Positive integer REPETITION -- Positive integer in brackets, defaulting to 1. All repetitions of the field can be accessed with [*] COMPONENT -- Positive integer SUBCOMPONENT -- Positive integer

Example paths:

~p"OBX" refers to the 1st OBX segment in its entirety, the same as ~p"OBX[1]". ~p"OBX-5" means the 1st repetition of the 5th field of the 1st OBX segment. ~p"OBX[1]-5[1]" is equivalent, the numbers in brackets specifying the default repetition and segment number values. ~p"OBX[2]-5" thus means 1st repetition of the 5th field of the 2nd OBX segment. ~p"OBX[*]-5" would get the 1st repetition of the 5th field of every OBX segment, returning a list of results.

Note that repetitions are uncommon in HL7 and the default of a 1st repetition is often just assumed. ~p"PID-3" is equivalent to ~p"PID-3[1]" and is the most standard representation.

All repetitions can be found using a repetition wildcard: ~p"PID-11[*]". A list of lists can be produced by selecting multiple segments and multiple repetitions with ~p"PID[*]-11[*]".

Components and subcomponents can also be accessed with the path structures. h"OBX-2.3.1" would return the 1st subcomponent of the 3rd component of the 2nd field of the 1st OBX.

Lastly, if a path might have additional data such that a string might be found at either ~p"OBX-2" or ~p"OBX-2.1" or even ~p"OBX-2.1.1", there is truncation character (the bang symbol) that will return the first element found in the HL7 text at the target specificity. Thus, ~p"OBX[*]-2!" would get the 1st piece of data in the 2nd field of every OBX whether it is a string or nested map.

Examples

iex> import HL7
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"OBX-5")
"1.80"

iex> import HL7
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"OBX[*]-5")
["1.80", "79"]

iex> import HL7
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"OBX[*]-2!")
["N", "NM"]

iex> import HL7
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"PID-11[*].5")
["35209", "35200"]

iex> import HL7
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"PID[*]-11[*].5")
[["35209", "35200"]]

iex> import HL7
iex> HL7.Examples.wikipedia_sample_hl7()
...> |> HL7.new!()
...> |> HL7.get(~p"PID-11[2].1")
"NICKELL’S PICKLES"

Specs

to_list(t() | hl7_map_data()) :: hl7_list_data()

Converts a segment map (or lists of segments maps) or HL7 struct into a raw Elixir list.

Link to this function

update(hl7, path, default, fun)

View Source