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

Extended Composite ID with Check Digit (CX) -- HL7v2 composite data type.

Used for MRN, patient IDs, visit numbers, and other identifiers.

10 components:
1. ID Number (ST)
2. Check Digit (ST)
3. Check Digit Scheme (ID) -- Table 0061
4. Assigning Authority (HD) -- sub-components delimited by `&`
5. Identifier Type Code (ID) -- Table 0203: MR, PI, VN, AN, SS, etc.
6. Assigning Facility (HD) -- sub-components delimited by `&`
7. Effective Date (DT)
8. Expiration Date (DT)
9. Assigning Jurisdiction (CWE) -- sub-components delimited by `&`
10. Assigning Agency or Department (CWE) -- sub-components delimited by `&`

# `t`

```elixir
@type t() :: %HL7v2.Type.CX{
  assigning_agency: HL7v2.Type.CWE.t() | nil,
  assigning_authority: HL7v2.Type.HD.t() | nil,
  assigning_facility: HL7v2.Type.HD.t() | nil,
  assigning_jurisdiction: HL7v2.Type.CWE.t() | nil,
  check_digit: binary() | nil,
  check_digit_scheme: binary() | nil,
  effective_date: Date.t() | HL7v2.Type.DT.t() | nil,
  expiration_date: Date.t() | HL7v2.Type.DT.t() | nil,
  id: binary() | nil,
  identifier_type_code: binary() | nil
}
```

# `encode`

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

Encodes a CX to a list of component strings.

## Examples

    iex> HL7v2.Type.CX.encode(%HL7v2.Type.CX{id: "12345", assigning_authority: %HL7v2.Type.HD{namespace_id: "MRN"}, identifier_type_code: "MR"})
    ["12345", "", "", "MRN", "MR"]

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

# `parse`

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

Parses a CX from a list of components.

Components containing sub-components (HD, CWE) are split by `&` and
parsed into their respective structs.

## Examples

    iex> HL7v2.Type.CX.parse(["12345", "", "", "MRN", "MR"])
    %HL7v2.Type.CX{id: "12345", assigning_authority: %HL7v2.Type.HD{namespace_id: "MRN"}, identifier_type_code: "MR"}

    iex> HL7v2.Type.CX.parse(["12345", "", "", "MRN&1.2.3&ISO", "MR"])
    %HL7v2.Type.CX{
      id: "12345",
      assigning_authority: %HL7v2.Type.HD{namespace_id: "MRN", universal_id: "1.2.3", universal_id_type: "ISO"},
      identifier_type_code: "MR"
    }

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

---

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