README.md

# NHI

[![Repository](https://img.shields.io/badge/jamesansley%2Fnhi-102335?logo=codeberg&labelColor=07121A)](https://codeberg.org/jamesansley/nhi)
[![License](https://img.shields.io/badge/Apache--2.0-002d00?label=license)](https://codeberg.org/jamesansley/nhi/src/branch/main/LICENSE)
[![Hex](https://img.shields.io/hexpm/v/nhi)](https://hex.pm/packages/nhi)

A function to check strings against the New Zealand Ministry of Health NHI
Validation Routine.
Supports the old and new NHI number formats specified in
[HISO 10046:2024](https://www.tewhatuora.govt.nz/publications/hiso-100462024-consumer-health-identity-standard/).

## Install

```elixir
def deps do
  [
    {:nhi, "~> 0.0.1"}
  ]
end
```

For the other versions of this library, see:

- [nhi on PyPi](https://pypi.org/project/python-nhi/)
- [nhi on JSR](https://jsr.io/@ansley/nhi)
- [nhi on Crates](https://crates.io/crates/nhi)
- [nhi with Pkl](https://codeberg.org/jamesansley/nhi/src/branch/main/pkl)

## Usage

New format NHI values:

```elixir
iex> Nhi.valid?("ABC12DS")
true
iex> Nhi.valid?("AAA11AU")
true
```

Old format NHI values:

```elixir
iex> Nhi.valid?("AAA1116")
true
iex> Nhi.valid?("BBB2221")
true
```

By default, test NHI values (starting with 'Z') are rejected:

```elixir
iex> Nhi.valid?("ZZZ00AC")
false
```

Test values can be allowed with the `allow_test_values` flag:

```elixir
iex> Nhi.valid?("ZZZ00AC", allow_test_values: true)
true
```

## See Also

- https://www.tewhatuora.govt.nz/publications/hiso-100462024-consumer-health-identity-standard/