Seeking guidance to handle invalid NHS number code

We are TIF Framework partner of NHS and we need to handle this scenario as a part of patient demographic services, i.e. on receipt of an invalid NHS number code, the wrongly identified local record must be de-coupled from PDS.

I would appreciate if anyone could suggest how do we identify the invalid data so that we could decouple those data from syncing?

Identifying an invalid NHS number is just a case of following the algorithm. See the data dictionary.

python example

def is_nhs_number_valid(nhs_number: str) -> bool:
    # Multiply each of the first 9 digits by the relevant factor
    products = [int(nhs_number[i]) * (10 - i) for i in range(9)]
    # add those together
    total = sum(products)
    # divide by 11 and get the remainder
    remainder = total % 11
    # subtract that remainder from 11 to get the check digit
    check = 11 - remainder
    # if check is 10, invalid NHS Number
    if check == 10:
        return False
    # Use 0 where the check is 11
    if check == 11:
        check = 0
    # last number of the 10 digit nhs number should match the check digit
    return check == int(nhsNumber[-1])

Thanks for your prompt response. Let us review it once from our end. I will come up with my concerns If I encounter any issue.

Thanks for your kind patience. I am sorry however, this isn’t what I am referring to, I am seeking for the identifier required to identify the invalid NHS number which was valid earlier for decoupling case.

Ah, apologies for misunderstanding, you want a meta.security.code value of REDACTED.

However, this will never actually be returned, you’ll instead get a 404 response when trying to retrieve an invalid PDS record.
See the schema in the PDS FHIR Documentation

Would you be able to elaborate your use case?

I suspect it is something that I would have typically handled as a HL7 v2 ADT_A40 message if I was working in a NHS Trust.
In HL7 FHIR something like this Patient - FHIR v4.0.1

This page may cover your use case https://profiles.ihe.net/ITI/PIXm/ITI-104.html

@chris.clarke Thanks, It’s helpful…