It's been a long time since I've posted here...So I hope you don't mind a
request for help.
Does anyone know of or have an NPI check digit calculator? I believe it's
based on the Luhn formula for computing the modulus 10 "double-add-double"
check digit...
I found a website to do this, but would like to have our system (we use MSM
and Cache in MSM mode) validate at entry time itself. Here's the website we
are using in the mean time:
http://www.barrydebruin.com/php/npi/
I basically need MUMPS code to do this...
We do have check digit calcs in our system, but none seem to be for a number
of this size. NPIs are 10 digits total (nine + 1 check digit)..."Tweaking"
those doesn't seem to be working. I'm sure it's something I'm doing wrong.
Thx in advance for any assistance, JJ
I've found the "what" to do, just wondered if there was some code already
out there...Thx! I appreciate your response, JJ
I wrote the NPI calulator you mentioned below.
I have the same calculations in javscript and C# if that would help. I
wrote mine in php.
Barry
I don't know mumps, but
> Does anyone know of or have an NPI check digit calculator? I believe it's
> based on the Luhn formula for computing the modulus 10 "double-add-double"
> check digit...
I had one for credit card numbers.
Added the stuff for NPI and converted it to standard Mumps.
HTH
Herman
hsNPIM
; Calculate and check a check digit according to Luhn's algorithm
; ISO 7812
; standard MUMPS version
Calculate(InputNumber, NPI, Debug)
; In NPI mode number can be:
; - 9 digits
; - idem plus one dash or space
; - 14 digits (first five fixed 80840)
; - idem plus one dash or space
New Number,Total,Count,Length,Error,i,Digit,CheckDigit
If $Get(Debug) Write "Calculate for : ",InputNumber,!
Set Number=$Translate(InputNumber,"- ","")
; optional additional checks on the number of spaces or dashes
Set Error=""
If $Get(NPI) Do
. If $Length(Number)=9 Set Number="80840"_Number
. If $Length(Number)'=14 Set Error="Error: not a valid NPI number"
. If $Extract(Number,1,5)'="80840" Set Error="Error: not a valid NPI
number"
If $Length(Error) Quit Error
Set Total="",Length=$Length(Number)
For i=Length:-1:1 Do
. If (Length+1-i)#2 Set Digit=($Extract(Number,i)*2)
. Else Set Digit=$Extract(Number,i)
. Set Total=Digit_Total
Set Count=0
For i=1:1:$Length(Total) Set Count=Count+$Extract(Total,i)
Set CheckDigit=10-Count#10
If $Get(Debug) Write "Check Digit: ",CheckDigit,!
Quit CheckDigit
Check(InputNumber,NPI,Debug)
New Number,InputCheck,CheckDigit
If $Get(Debug) Write "Check number: ",InputNumber,!
Set Number=$Translate(InputNumber," -","")
Set InputCheck=$Extract(Number,$Length(Number))
Set Number=$Extract(Number,1,$Length(Number)-1)
Set CheckDigit=$$Calculate(Number,.NPI)
If CheckDigit=InputCheck Quit "OK"
Quit "Invalid number: "_InputCheck_" should be "_CheckDigit
Test
Kill
Set NPI=1
Set Debug=1
; NPI numbers
For Number=123456789,"12345-6789","12 3456789" {
For Prefix="","80840" {
Set CheckNumber=$$Calculate(Prefix_Number,NPI,Debug)
Set TestNumber=Prefix_Number_CheckNumber
Set Check=$$Check(TestNumber,NPI,Debug)
If Check'="OK" Write Check,!
}
}
; Other numbers, such as credit cards
Set NPI=0
For Number="5413 3027 3931 020","4563 5302 2224 656" {
Set Check=$$Calculate(Number,NPI,Debug)
Set TestNumber=Number_Check
Set Check=$$Check(TestNumber,NPI,Debug)
If Check'="OK" Write Check,!
}