eddieantonio / rust-nhi

Checks strings against the New Zealand Ministry of Health NHI Validation Routine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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:2023.

Install

cargo add nhi

Usage

use nhi::is_nhi;

fn main() {
    println!("{}", is_nhi("ZAC5361"));  // true
    println!("{}", is_nhi("ZBN77VL"));  // true
    println!("{}", is_nhi("ZZZ0044"));  // false
    println!("{}", is_nhi("ZZZ00AA"));  // false
}

Checks are case-insensitive.

Note: This does not check that the NHI number has been assigned to a person, it merely checks the NHI is consistent with the HISO 10046:2023 standard.

Excluding Testcases

NHI numbers that begin with Z are reserved for testing. If you wish to exclude these values, you will need to manually check for a Z prefix:

use nhi::is_nhi;

fn main() {
    let value = "zvb97xq";

    println!("{}", is_nhi(value));  // true
    println!("{}", !value.to_uppercase().starts_with('Z') && is_nhi(value));  // false
}

Note: This check does not mean that the NHI number has been assigned to a person, it just means that the NHI value is not reserved for testing.

See Also

About

Checks strings against the New Zealand Ministry of Health NHI Validation Routine

License:MIT License


Languages

Language:Rust 100.0%