ex_hl7 v0.3.0 HL7.Codec

Functions that decode and encode HL7 fields, repetitions, components and subcomponents.

Each type of item has a canonical representation, that will vary depending on whether the trim option was used when decoding or encoding. If we set trim to true, some trailing optional items and separators will be omitted from the decoded or encoded result, as we can see in the following example:

import HL7.Codec

decode_field("504599^223344&&IIN&^~", separators(), trim: true)

Where the result is:

{"504599", {"223344", "", "IIN"}}

With trim set to false the result would be:

[{"504599", {"223344", "", "IIN", ""}, ""}, ""]

Both representations are correct, given that HL7 allows trailing items that are empty to be omitted. This causes an ambiguity because the same item can be interpreted in several ways when it is the first and only item present.

For example, in the following HL7 segment the item in the third field (504599) might be the same in both cases (i.e. the first component of the second field):

  1. AUT||504599^^||||0000190447|^||
  2. AUT||504599||||0000190447|^||

But for this module it has two different representations:

  1. First component of the second field
  2. Second field

To resolve the ambiguity in the HL7 syntax, the code decoding and encoding HL7 segments using the functions in this module must be aware of this issue and deal with it accordingly when performing lookups or comparisons.

Summary

Functions

Decode a binary holding one or more HL7 components into its canonical representation

Decode a binary holding an HL7 field into its canonical representation

Decode a binary holding one or more HL7 subcomponents into its canonical representation

Escape a string that may contain separators using the HL7 escaping rules

Return the separator corresponding to an item type

Return the default separators used to encode HL7 messages in their compiled format. These are

Convert an escaped string into its original value

Functions

compile_separators(args)
decode_components(components, separators \\ "|^&~", trim \\ true)

Decode a binary holding one or more HL7 components into its canonical representation.

decode_field(field, separators \\ "|^&~", trim \\ true)

Specs

decode_field(binary, separators :: binary, trim :: boolean) :: HL7.Type.field

Decode a binary holding an HL7 field into its canonical representation.

decode_subcomponents(component, separators \\ "|^&~", trim \\ true)

Decode a binary holding one or more HL7 subcomponents into its canonical representation.

decode_value(value, type \\ :string)

Specs

decode_value(HL7.Type.field, type :: atom) ::
  HL7.Type.value |
  :nomatch
encode_components(components, separators \\ "|^&~", trim \\ true)
encode_field(field, separators \\ "|^&~", trim \\ true)
encode_subcomponents(subcomponents, separators \\ "|^&~", trim \\ true)
encode_value(value, type \\ :string)

Specs

encode_value(HL7.Type.value | nil, type :: atom) ::
  binary |
  :nomatch
escape(value, separators \\ "|^&~", escape_char \\ 92)

Escape a string that may contain separators using the HL7 escaping rules.

Arguments

  • value: a string to escape; it may or may not contain separator characters.

  • separators: a binary containing the item separators to be used when generating the message as returned by HL7.Codec.compile_separators/1. Defaults to HL7.Codec.separators.

  • escape_char: character to be used as escape delimiter. Defaults to ?\\. ## Examples iex> “ABCDEF” = HL7.Codec.escape(“ABCDEF”) iex> “ABC\F\DEF\S\GHI” = HL7.Codec.escape(“ABC|DEF^GHI”, separators: HL7.Codec.separators(), escape_char: ?\)
format_date(date)
format_datetime(datetime)
match_separator(char, arg2)
separator(item_type, separators \\ "|^&~")

Specs

separator(HL7.Type.item_type, binary) :: byte

Return the separator corresponding to an item type.

separators()

Return the default separators used to encode HL7 messages in their compiled format. These are:

  • |: field separator
  • ^: component separator
  • &: subcomponent separator
  • ~: repetition separator

To use custom separators in a message use HL7.Codec.compile_separators/1 and pass the returned value as argument to the encoding functions.

unescape(value, separators \\ "|^&~", escape_char \\ 92)

Convert an escaped string into its original value.

Arguments

  • value: a string to unescape; it may or may not contain escaped characters.

  • escape_char: character that was used as escape delimiter. Defaults to ?\\. ## Examples iex> “ABCDEF” = HL7.unescape(“ABCDEF”) iex> “ABC|DEF|GHI” = HL7.Codec.unescape(“ABC\F\DEF\F\GHI”, ?\)