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

Composite Price (CP) -- HL7v2 composite data type.

Used for price information with optional range and type qualifiers.

6 components:
1. Price (MO) -- sub-components delimited by `&` (quantity & denomination)
2. Price Type (ID) -- Table 0205
3. From Value (NM)
4. To Value (NM)
5. Range Units (CE) -- sub-components delimited by `&`
6. Range Type (ID) -- Table 0298

# `t`

```elixir
@type t() :: %HL7v2.Type.CP{
  from_value: binary() | nil,
  price: HL7v2.Type.MO.t() | nil,
  price_type: binary() | nil,
  range_type: binary() | nil,
  range_units: HL7v2.Type.CE.t() | nil,
  to_value: binary() | nil
}
```

# `encode`

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

Encodes a CP to a list of component strings.

## Examples

    iex> HL7v2.Type.CP.encode(%HL7v2.Type.CP{price: %HL7v2.Type.MO{quantity: "100.00", denomination: "USD"}, price_type: "UP"})
    ["100.00&USD", "UP"]

    iex> HL7v2.Type.CP.encode(%HL7v2.Type.CP{price: %HL7v2.Type.MO{quantity: "50"}})
    ["50"]

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

# `parse`

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

Parses a CP from a list of components.

## Examples

    iex> HL7v2.Type.CP.parse(["100.00&USD", "UP"])
    %HL7v2.Type.CP{price: %HL7v2.Type.MO{quantity: "100.00", denomination: "USD"}, price_type: "UP"}

    iex> HL7v2.Type.CP.parse(["50"])
    %HL7v2.Type.CP{price: %HL7v2.Type.MO{quantity: "50"}}

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

---

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