Packages
hl7v2
2.2.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/type/pta.ex
defmodule HL7v2.Type.PTA do
@moduledoc """
Policy Type and Amount (PTA) -- HL7v2 composite data type.
Specifies a policy type, amount class, and money/percentage value for insurance.
3 components:
1. Policy Type (IS) -- Table 0147: e.g., "ANC" (ancillary), "2ANC" (second ancillary)
2. Amount Class (IS) -- Table 0193: e.g., "LM" (limit), "PC" (percentage), "UP" (unlimited)
3. Money or Percentage Quantity (NM) -- the numeric value
"""
@behaviour HL7v2.Type
alias HL7v2.Type
alias HL7v2.Type.NM
defstruct [
:policy_type,
:amount_class,
:money_or_percentage_quantity
]
@type t :: %__MODULE__{
policy_type: binary() | nil,
amount_class: binary() | nil,
money_or_percentage_quantity: NM.t() | nil
}
@doc """
Parses a PTA from a list of components.
## Examples
iex> HL7v2.Type.PTA.parse(["ANC", "LM", "1000"])
%HL7v2.Type.PTA{policy_type: "ANC", amount_class: "LM", money_or_percentage_quantity: %HL7v2.Type.NM{value: "1000", original: "1000"}}
iex> HL7v2.Type.PTA.parse([])
%HL7v2.Type.PTA{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
policy_type: Type.get_component(components, 0),
amount_class: Type.get_component(components, 1),
money_or_percentage_quantity: components |> Type.get_component(2) |> NM.parse()
}
end
@doc """
Encodes a PTA to a list of component strings.
## Examples
iex> HL7v2.Type.PTA.encode(%HL7v2.Type.PTA{policy_type: "ANC", amount_class: "LM", money_or_percentage_quantity: %HL7v2.Type.NM{value: "1000", original: "1000"}})
["ANC", "LM", "1000"]
iex> HL7v2.Type.PTA.encode(nil)
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = pta) do
[
pta.policy_type || "",
pta.amount_class || "",
NM.encode(pta.money_or_percentage_quantity)
]
|> Type.trim_trailing()
end
end