Question
· Nov 29, 2023

NHS Number verification

Hi Community, 

Can I please check if any one is aware of any functionality in HealthShare to verify NHS Number check digit.

We are trying to implement the NHS Number check digit validation using Modulus 11 Algorithm ( described here : NHS NUMBER (datadictionary.nhs.uk) ) 

I wanted to check if there is any built in option available or if anyone has implemented something similar using Object Script. 

 

Thank you for your help.  

Mary

Product version: IRIS 2021.1
$ZV: IRIS for Windows (x86-64) 2021.1 (Build 215U) Wed Jun 9 2021 09:39:22 EDT [HealthConnect:3.3.0] [HealthConnect:3.3.0]
Discussion (3)2
Log in or sign up to continue

Hi Mary, this may work for you. It could do with a tidy up but should put you on the correct path. You can use this for testing - https://wiki.discoverydataservice.org/index.php?title=Dummy_NHS_numbers ClassMethod ValidNHS(pNHS As %String = "", Output pFailReason) As %Boolean { IF pNHS'?10N { set pFailReason = "Num" Quit 0 } set nCheckdigit = $Extract(pNHS,10,10) set nChi9Digits = $Extract(pNHS,1,9) set nMultFact = 2 set nCalcCheckdigit = 0 for i = 9 : -1 : 1 { set nThisDigit = $Extract(nChi9Digits,i,i) set nCalcCheckdigit = nCalcCheckdigit + (nThisDigit * nMultFact) set nMultFact = nMultFact + 1 } set nCalcCheckdigit = (nCalcCheckdigit # 11) set nCalcCheckdigit = 11 - nCalcCheckdigit if (nCalcCheckdigit = 10) { set pFailReason = "ChkDig" Quit 0 } if (nCalcCheckdigit = 11) { set nCalcCheckdigit = 0 } if (nCheckdigit = nCalcCheckdigit) { set pFailReason = "" Quit 1 } Else { set pFailReason = "ChkDig match" Quit 0 } }

Hi Ian, I guess in the copy/paste something went wrong 😉
Same code with different formatting:

ClassMethod ValidNHS(pNHS As %String = "", Output pFailReason) As %Boolean
{
    IF pNHS'?10N {
        set pFailReason = "Num"
        Quit 0
    }
    set nCheckdigit = $Extract(pNHS,10,10)
    set nChi9Digits = $Extract(pNHS,1,9)
    set nMultFact = 2
    set nCalcCheckdigit = 0
    for i = 9 : -1 : 1 {
        set nThisDigit = $Extract(nChi9Digits,i,i)
        set nCalcCheckdigit = nCalcCheckdigit + (nThisDigit * nMultFact)
        set nMultFact = nMultFact + 1
    }
    set nCalcCheckdigit = (nCalcCheckdigit # 11)
    set nCalcCheckdigit = 11 - nCalcCheckdigit
    if (nCalcCheckdigit = 10) {
        set pFailReason = "ChkDig"
        Quit 0
    }
    if (nCalcCheckdigit = 11) {
        set nCalcCheckdigit = 0
    }
    if (nCheckdigit = nCalcCheckdigit) {
        set pFailReason = ""
        Quit 1
    } Else {
        set pFailReason = "ChkDig match"
        Quit 0
    }
}