# `HL7v2.Type.HD`
[🔗](https://github.com/Balneario-de-Cofrentes/hl7v2/blob/v3.10.1/lib/hl7v2/type/hd.ex#L1)

Hierarchic Designator (HD) -- HL7v2 composite data type.

Used to identify sending/receiving applications, facilities, and assigning
authorities. Appears as a top-level component and as a sub-component inside
CX, EI, PL, and XON.

3 components:
1. Namespace ID (IS)
2. Universal ID (ST)
3. Universal ID Type (ID) -- DNS, GUID, ISO, UUID, etc.

When HD appears inside another composite (e.g., CX.4), its internal parts
are encoded as sub-components using `&`.

# `t`

```elixir
@type t() :: %HL7v2.Type.HD{
  namespace_id: binary() | nil,
  universal_id: binary() | nil,
  universal_id_type: binary() | nil
}
```

# `encode`

```elixir
@spec encode(t() | nil) :: list()
```

Encodes an HD to a list of component/sub-component strings.

## Examples

    iex> HL7v2.Type.HD.encode(%HL7v2.Type.HD{namespace_id: "HOSP", universal_id: "2.16.840.1.113883.19.4.6", universal_id_type: "ISO"})
    ["HOSP", "2.16.840.1.113883.19.4.6", "ISO"]

    iex> HL7v2.Type.HD.encode(%HL7v2.Type.HD{namespace_id: "MRN"})
    ["MRN"]

    iex> HL7v2.Type.HD.encode(nil)
    []

# `parse`

```elixir
@spec parse(list()) :: t()
```

Parses an HD from a list of components (or sub-components).

## Examples

    iex> HL7v2.Type.HD.parse(["HOSP", "2.16.840.1.113883.19.4.6", "ISO"])
    %HL7v2.Type.HD{namespace_id: "HOSP", universal_id: "2.16.840.1.113883.19.4.6", universal_id_type: "ISO"}

    iex> HL7v2.Type.HD.parse(["MRN"])
    %HL7v2.Type.HD{namespace_id: "MRN"}

    iex> HL7v2.Type.HD.parse([])
    %HL7v2.Type.HD{}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
