Expand description
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
Structs
- Represents a valid NHI number that satisfies the HISO 10046:2023 standard.
- Empty struct to indicate an invalid NHI string
Functions
- Checks a string against the New Zealand Ministry of Health NHI specification defined by the HISO 10046:2023 standard