
<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaScript &#8211; Mark&#039;s Website</title>
	<atom:link href="https://kram.nz/tag/javascript/feed/" rel="self" type="application/rss+xml" />
	<link>https://kram.nz</link>
	<description>Solution Architect - Healthcare IT</description>
	<lastBuildDate>Tue, 06 Jun 2023 09:42:17 +0000</lastBuildDate>
	<language>en-GB</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.2.2</generator>

<image>
	<url>https://kram.nz/wp-content/uploads/2016/04/cropped-M-32x32.png</url>
	<title>JavaScript &#8211; Mark&#039;s Website</title>
	<link>https://kram.nz</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>NHI Validation</title>
		<link>https://kram.nz/2019/02/nhi-validation/</link>
					<comments>https://kram.nz/2019/02/nhi-validation/#respond</comments>
		
		<dc:creator><![CDATA[M]]></dc:creator>
		<pubDate>Wed, 20 Feb 2019 11:01:10 +0000</pubDate>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Healthcare]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[NHI]]></category>
		<category><![CDATA[NHI Generator]]></category>
		<category><![CDATA[NHI Validator]]></category>
		<guid isPermaLink="false">https://kram.nz/?p=433</guid>

					<description><![CDATA[Here is a National Health Index (NHI) validator and generator that I created. NHIs are healthcare identifiers used in New Zealand[1][2][3]. NHI Validator NHI: Generate NHIs Generate random NHIs Generate The current Id. structure only allows for around 13.8 million NHI's. With a population of around 5 million in 2019 and the possibility of a [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>Here is a National Health Index (NHI) validator and generator that I created. NHIs are healthcare identifiers used in New Zealand<a class="reflink" href="#ref-nhi-wiki">[1]</a><a class="reflink" href="#ref-nhi-gov">[2]</a><a class="reflink" href="#ref-nhi-midcentral">[3]</a>.</p>



<form id="nhi-validator"> <fieldset> <legend>NHI Validator</legend> <div><label for="nhinumberfield">NHI:</label> <input id="nhinumberfield" type="text" maxlength="7" placeholder="ABC1234" pattern="[A-HJ-NP-Z]{3}\d{4}" onload="validateNhi(this)" onkeydown="validateNhi(this)" title="Three letters (without I or O) and 4 numbers" required="" autofocus=""> </div><div id="validation-result"></div> </fieldset></form><form id="nhi-generator"> <fieldset> <legend>Generate NHIs</legend> <p>Generate random NHIs</p> <button name="generate-nhi-button" type="button" onclick="generateNhis(this)">Generate</button> <ul id="generated-nhis"></ul> </fieldset></form><script>function generateNhis(){for(var e=document.getElementById("generated-nhis");e.hasChildNodes();){e.removeChild(e.lastChild)}for(var t=0;t<20;t+=1){var n=document.createElement("li"),a=document.createTextNode(generateRandomNhi());n.appendChild(a),e.appendChild(n)}}function generateRandomNhi(){for(var e="",t=0;t<6;t+=1){e+=t<3?randomNhiCharacter():getRandomInteger(0,10)}return e+=generateChecksum(e)}function getRandomInteger(e,t){return e=Math.ceil(e),t=Math.floor(t),Math.floor(Math.random()*(t-e))+e}function randomNhiCharacter(){var e=["A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"];return e[getRandomInteger(0,e.length)]}function validateNhi(e){setTimeout(function(){e.value=cleanNHI(e.value),7==e.value.length&#038;&#038;validateChecksum(e.value)?(e.setCustomValidity(""),document.getElementById("validation-result").innerHTML="This is a valid NHI!"):(e.setCustomValidity("Invalid NHI"),proposePossibleNhis(e.value))},1)}function proposePossibleNhis(invalidNhi){var ul=document.createElement("ul");if(invalidNhi.length==7){for(var index=0;index<7;index+=1){var alternativeNhi=findValidNhiAt(invalidNhi,index);if(alternativeNhi){var n=document.createElement("li");var a=document.createTextNode(alternativeNhi);n.appendChild(a);ul.appendChild(n)}}}var resultNode=document.getElementById("validation-result");for(;resultNode.hasChildNodes();){resultNode.removeChild(resultNode.lastChild)}var message=document.createElement("p");message.appendChild(document.createTextNode("Could it be one of the following?"));resultNode.appendChild(message);resultNode.appendChild(ul)}function findValidNhiAt(invalidNhi,index){if(index<3){var alphabet=["A","B","C","D","E","F","G","H","J","K","L","M","N","P","Q","R","S","T","U","V","W","X","Y","Z"];for(var i=0;i<alphabet.length;i+=1){var proposedNhi=invalidNhi.substr(0,index)+alphabet[i]+invalidNhi.substr(index+1);if(validateChecksum(proposedNhi)){return proposedNhi}}}for(var i=0;i<10;i+=1){var proposedNhi=invalidNhi.substr(0,index)+i+invalidNhi.substr(index+1);if(validateChecksum(proposedNhi)){return proposedNhi}}return null}function cleanNHI(e){return e.toUpperCase().replace("I","").replace("O","").substring(0,7)}function validateChecksum(e){return generateChecksum(e)==valueOf(e.charCodeAt(6))}function generateChecksum(e){for(sum=0,i=0;i<6;i+=1){sum+=valueOf(e.charCodeAt(i))*(7-i)}if(sum%11==0){return "Invalid"}return(11-sum%11)%10}function valueOf(e){return 47<e&#038;&#038;e<58?e-48:64<e&#038;&#038;e<73?e-64:73<e&#038;&#038;e<79?e-65:79<e&#038;&#038;e<91?e-66:void 0}</script><style>#generated-nhis,#validation-result ul{column-count:2;-webkit-column-count:2;-moz-column-count:2;font-family:monospace}#nhinumberfield:focus:required:invalid{background-color:pink;color:white}#nhinumberfield:required:valid{background-color:white;color:black}#nhinumberfield:invalid{border-color:red}#nhinumberfield,#nhinumberfield:valid{border-color:green}</style>



<ul>
<li>NHI's uses the letters A-Z without I or O.</li>



<li>NHI's start with three letters and end with four numbers.</li>



<li>The last digit is a checksum.</li>



<li>NHI's are assigned randomly. I believe hospitals have distinct sets ready to be assigned.</li>



<li>Its possible for somebody to have multiple NHIs (first alphabetically is the primary).</li>
</ul>



<p>The current Id. structure only allows for around 13.8 million NHI's. With a population of around 5 million in 2019 and the possibility of a single person being associated to multiple Id.s, I suspect NHIs in their current form wont be around very long.</p>



<h2 class="wp-block-heading">References</h2>



<p>(last checked 2023-06-06)</p>



<ol><li><a href="https://en.wikipedia.org/wiki/NHI_Number" target="_blank" rel="noopener noreferrer" id="ref-nhi-wiki">https://en.wikipedia.org/wiki/NHI_Number</a></li><li><del><a href="https://www.health.govt.nz/our-work/health-identity/national-nhi-gov" target="_blank" rel="noopener noreferrer" id="ref-nhi-gov">https://www.health.govt.nz/our-work/health-identity/national-health-index</a></del></li><li><a href="http://www.midcentraldhb.govt.nz/PatientsandVisitors/GeneralInformation/Pages/NHI.aspx" target="_blank" rel="noopener noreferrer" id="ref-nhi-midcentral">http://www.midcentraldhb.govt.nz/PatientsandVisitors/GeneralInformation/Pages/NHI.aspx</a></li></ol>



<p>[EDIT]: Thanks to Chris W for pointing out a bug in my previous implementation. If the checksum is a '0' before being subtracted from 11, the NHI number is deemed to be invalid. This is now fixed in the generator.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://kram.nz/2019/02/nhi-validation/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
