#numbers #health #validation #string #routine #zealand #ministry

nhi

A function to check strings against the New Zealand Ministry of Health NHI Validation Routine

4 releases

0.1.1 Sep 3, 2023
0.1.0 Sep 3, 2023
0.0.2 Aug 30, 2023
0.0.1 Aug 30, 2023

#1 in #routine

42 downloads per month

MIT license

14KB
193 lines

NHI

Checks strings against the New Zealand Ministry of Health NHI Validation Routine. Supports the old and new NHI number formats specified in HISO 10046:2023.

Docs

Example

NHI values can be validated with the is_nhi function, or parsed to NHI structs:

use nhi::{is_nhi, NHI};

fn main() {
    let nhi_str = "zac5361";

    assert_eq!(is_nhi(nhi_str), true);
    
    let nhi: NHI = nhi_str.parse().unwrap();
    assert_eq!(nhi.as_str(), nhi_str.to_uppercase());
}

More examples are available in the docs.

See Also


lib.rs:

Checks strings against the New Zealand Ministry of Health NHI Validation Routine. Supports the old and new NHI number formats specified in HISO 10046:2023.

Usage

A simple [is_nhi] function can check whether a string is valid:

use nhi::is_nhi;

assert_eq!(is_nhi("ZAC5361"),  true);
assert_eq!(is_nhi("ZBN77VL"),  true);
assert_eq!(is_nhi("ZZZ0044"),  false);
assert_eq!(is_nhi("ZZZ00AA"),  false);

Alternatively, strings can be parsed to [NHI] values:

use nhi::NHI;

let nhi: NHI = "zbn77vl".parse().unwrap();
assert_eq!(nhi.as_str(), "ZBN77VL");

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 using [is_nhi], you will need to manually check for a Z prefix:

use nhi::is_nhi;

let value = "zvb97xq";

assert_eq!(is_nhi(value),  true);
assert_eq!(!value.to_uppercase().starts_with('Z') && is_nhi(value),  false);

Alternatively, parsed [NHI] values provide NHI::is_test and NHI::is_not_test methods:

use nhi::NHI;

let reserved: NHI = "ZAA0105".parse().unwrap();
let unreserved: NHI = "JBX3656".parse().unwrap();

assert!(reserved.is_test());
assert!(unreserved.is_not_test());

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

Dependencies

~2.2–3.5MB
~58K SLoC