NHI Number

The National Health Index (NHI) number is the unique person identifier used within the New Zealand health system. It is technically not a number but rather an alphanumeric identifier consisting of 7 characters, with three letters and four numbers. It is often referred to as the NHI, although care must be taken when using this abbreviated term, because the NHI can also refer to the national collection of health care user demographic data (of which the NHI Number is the unique identifier).

The NHI Number, as part of the NHI was established in 1993.[1]

Usage

Primarily the NHI is used to identify individuals uniquely within the New Zealand health system,[1][2] especially in electronic systems. An example of this is its use to alert health care providers using the Medical Warnings System (MWS) of risks associated with medical decision-making for specific patients.

Format

An NHI number has a specific format. It is 7 characters in length and contains a check digit. This format consists of 3 alphabetic characters being in the range of A-Z, excluding I and O, and 4 numeric characters being in the range 0-9. The 4th numeric character is the check digit. The assignment of the first 6 characters is arbitrary and bears no relationship to the individual to whom it is assigned.

The NHI Number is most often represented with the alphabetic characters upper case.

NHI Numbers are often referred to as being valid or invalid. Any NHI Number that does not fit the correct format or that has an incorrect check digit is referred to as invalid. Usually reference to an NHI Number being valid or not does not indicate that it is correctly associated with the right individual. As the identifier is arbitrary there is no way to do this based solely on the identifier itself.

Duplicates

When it has been identified that an individual has been assigned more than one NHI Number, one is deemed to be the primary identifier. This is usually done by ranking all assigned numbers in alpha-numeric order and choosing the first one as the primary.

All other NHI Numbers for the individual within the NHI are then linked to the primary one.

Check Digit

The NHI Number contains a check digit. The algorithm for generating the digit is described below:

Each alpha character is given a numeric representation equivalent to its ordinal position within the alphabet, starting at A through to Z. The letters I and O are omitted making the ordinal range 1 - 24.

Each alpha character's numeric representation is multiplied by the inverse of its ordinal position within the NHI Number. The first value is multiplied by 7, the second by 6 and so on.

The first 3 numeric characters are multiplied by the inverse of their ordinal position also.

The sum of these multiplications modulus 11 subtracted from 11 is taken as the check digit (a result of 10 is translated to 0).

This scheme is similar to the ISBN check digit scheme.

PHP code to calculate NHI validation

<html>
 <head>
  <title>NHI check</title>
 </head>
 <body style="font-family:verdana" size>
 <p style="font-size:12px">
  <?php
  // Dirty coding to quickly prove NHI number validation ;)
  // Example NHI numbers from Ministry of Health, see http://goo.gl/zqI5Ba 
  $str = "DAB8233"; // wrong
  $str = "CGC2720"; // correct
  $str = "EPT6335"; // correct
  // Start scripting
  print "NHI number: ".$str."<br><br>";
  // Check 3 letters and four numbers
  print "Step 1 and Step 2: \n";
  // Regular expression for 3 letters and 4 numbers
  $pattern = "/^([a-zA-Z]){3}([0-9]){4}?$/";
  if(preg_match($pattern,$str)){
    // Step 1 + Step 2 - Check RegEx
    print "Passed<br>\n";
    // Split string in array 
    $chars = preg_split('//', $str, -1, PREG_SPLIT_NO_EMPTY);
    // Step 3 - Assign first letter its corresponding value from the Alphabet Conversion Table and multiply value by 7
    print "Step 3: ";
    $chars[0] = strtolower($chars[0]);
    $ascii1 = ord($chars[0]);
    // I and O are removed from the Alphabet for readability, dirty hack to accoutn for that
    if ($ascii1 > 105){
  	  if ($ascii1 > 111){
  		  $ascii1 = $ascii1-2;
  	  }else{
  		  $ascii1 = $ascii1-1;
  	  }
    }
    $alphanr1 = $ascii1 - 96;
    $calc1 = $alphanr1*7;
    print "Char: ".$chars[0]." Ascii: ".$ascii1." Alphabet nr: ".$alphanr1." Calculated nr: ".$calc1." <br>\n";
    // Step 4 - Assign second letter its corresponding value from the Alphabet Conversion Table and multiply value by 6.
    print "Step 4: ";
    $chars[1] = strtolower($chars[1]);
    $ascii2 = ord($chars[1]);
    if ($ascii2 > 105){
  	  if ($ascii2 > 111){
  		  $ascii2 = $ascii2-2;
  	  }else{
  		  $ascii2 = $ascii2-1;
  	  }
    }
    $alphanr2 = $ascii2 - 96;
    $calc2 = $alphanr2*6;
    print "Char: ".$chars[1]." Ascii: ".$ascii2." Alphabet nr: ".$alphanr2." Calculated nr: ".$calc2." <br>\n";
    // Step 5 - Assign third letter its corresponding value from the Alphabet Conversion Table and multiply value by 5.
    print "Step 5: ";
    $chars[2] = strtolower($chars[2]);
    $ascii3 = ord($chars[2]);
    if ($ascii3 > 105){
  	  if ($ascii3 > 111){
  		  $ascii3 = $ascii3-2;
  	  }else{
  		  $ascii3 = $ascii3-1;
  	  }
    }
    $alphanr3 = $ascii3 - 96;
    $calc3 = $alphanr3*5;
    print "Char: ".$chars[2]." Ascii: ".$ascii3." Alphabet nr: ".$alphanr3." Calculated nr: ".$calc3." <br>\n";
    // Step 6 - Multiply first number by 4
    print "Step 6: ";
    $calc4 = $chars[3]*4;
    print "Char: ".$chars[3]." Calculated nr: ".$calc4." <br>\n";  
    // Step 7 - Multiply second number by 3
    print "Step 7: ";
    $calc5 = $chars[4]*3;
    print "Char: ".$chars[4]." Calculated nr: ".$calc5." <br>\n";  
    // Step 8 - Multiply third number by 2
    print "Step 8: ";
    $calc6 = $chars[5]*2;
    print "Char: ".$chars[5]." Calculated nr: ".$calc6." <br>\n";
    // Step 9 - Total the result of steps 3 to 8
    $sum = $calc1 + $calc2 + $calc3 + $calc4 + $calc5 + $calc6;
    print "Step 9: ";  
    print "Sum: ".$calc1." + ".$calc2." + ".$calc3." + ".$calc4." + ".$calc5." + ".$calc6." = ".$sum." <br>\n";
    // Step 10 - Apply modulus 11 to create a checksum. 
    $divisor = 11;
    $rest = fmod($sum,$divisor);
    $outcome = $sum / $divisor;
    print "Step 10: Sum: ".$sum." divided by ".$divisor." = ".$outcome." Checksum: ".$rest."<br>";
    // Step 11 - If checksum is zero then the NHI number is incorrect
    if ($rest == 0){
  	  $nhi_correct= false;
      print "Step 11: Failed<br>\n";	  
    }else{
      // Step 12 - Subtract checksum from 11 to create check digit
  	  $check_digit = $divisor-$rest;
  	  print "Step 12: Divisor: ".$divisor." - ".$rest." = ".$check_digit."<br>";
  	  // Step 13 - If check digit equals 10 convert to zero
  	  if ($check_digit == 10){
  		  print "Step 13: Checksum is 10 therefore convert to 0<br>";
  		  $check_digit = 0;
  	  }
  	  // Step 14 - Fourth number must be equal to check digit
  	  if ($chars[6]==$check_digit){
  		  print "Step 14: Parity bit: ".$chars[6]." is equal to check digit ".$check_digit."<br>";
  		  $nhi_correct= true;
  	  }else{
  		  $nhi_correct= false;
  	  }
    }
  }else{
      $nhi_correct= false;
  }
  // Step 15 - NHI number passes all the validations then true otherwise false
  if ($nhi_correct){
    print "<br><font color=\"green\"><b>NHI correct</b></font><br>";
  }else{
    print "<br><font color=\"red\"><b>NHI incorrect</b></font><br>";
  }  
  ?>
  </p>
  </font>
  </body>
</html>

References

External links

This article is issued from Wikipedia - version of the Friday, April 15, 2016. The text is available under the Creative Commons Attribution/Share Alike but additional terms may apply for the media files.