Packages
hl7v2
2.1.2
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/spd.ex
defmodule HL7v2.Type.SPD do
@moduledoc """
Specialty Description (SPD) -- HL7v2 composite data type.
Describes a practitioner's specialty or board certification.
4 components:
1. Specialty Name (ST)
2. Governing Board (ST)
3. Eligible or Certified (ID) -- C (certified), E (eligible)
4. Date of Certification (DT)
"""
@behaviour HL7v2.Type
alias HL7v2.Type
alias HL7v2.Type.DT
defstruct [:specialty_name, :governing_board, :eligible_or_certified, :date_of_certification]
@type t :: %__MODULE__{
specialty_name: binary() | nil,
governing_board: binary() | nil,
eligible_or_certified: binary() | nil,
date_of_certification: Date.t() | DT.t() | nil
}
@doc """
Parses an SPD from a list of components.
## Examples
iex> HL7v2.Type.SPD.parse(["Cardiology", "ABIM", "C", "20200601"])
%HL7v2.Type.SPD{specialty_name: "Cardiology", governing_board: "ABIM", eligible_or_certified: "C", date_of_certification: ~D[2020-06-01]}
iex> HL7v2.Type.SPD.parse(["Internal Medicine"])
%HL7v2.Type.SPD{specialty_name: "Internal Medicine"}
iex> HL7v2.Type.SPD.parse([])
%HL7v2.Type.SPD{}
"""
@spec parse(list()) :: t()
def parse(components) when is_list(components) do
%__MODULE__{
specialty_name: Type.get_component(components, 0),
governing_board: Type.get_component(components, 1),
eligible_or_certified: Type.get_component(components, 2),
date_of_certification: components |> Type.get_component(3) |> DT.parse()
}
end
@doc """
Encodes an SPD to a list of component strings.
## Examples
iex> HL7v2.Type.SPD.encode(%HL7v2.Type.SPD{specialty_name: "Cardiology", governing_board: "ABIM", eligible_or_certified: "C", date_of_certification: ~D[2020-06-01]})
["Cardiology", "ABIM", "C", "20200601"]
iex> HL7v2.Type.SPD.encode(nil)
[]
"""
@spec encode(t() | nil) :: list()
def encode(nil), do: []
def encode(%__MODULE__{} = spd) do
[
spd.specialty_name || "",
spd.governing_board || "",
spd.eligible_or_certified || "",
DT.encode(spd.date_of_certification)
]
|> Type.trim_trailing()
end
end