nhs-number
>>> import nhs_number
# Validation
>>> nhs_number.is_valid('469 819 4180')
True
# Generation (for testing purposes)
>>> nhs_number.generate(quantity=5, for_region=nhs_number.REGION_ENGLAND)
['6239431915', '7634140872', '4069990771', '4453051670', '4843474045']
# Normalisation
>>> nhs_number.normalise_number("406-999-0771")
'4069990771'
A Python package to provide utilities for NHS Numbers, including validity checks, normalisation, and generation.
While validating an NHS Number is straightforward to achieve in code, it seems wasteful for developers to implement their own solutions. Further, many developers are likely unaware of the various rules and nuances of NHS/CHI/H&C Numbers across the UK Nations.
This package aims to provide a single, well-maintained, well-documented solution for all developers.
nhs-number
is a collaboration between several individuals, groups and teams, each separately maintaining an NHS Number Python package. See Contributors for more information.
Features
- Validation of NHS Numbers using the check-digit algorithm.
- Generation of valid and invalid NHS Numbers for testing purposes, for any selected
Region
. - Normalisation of NHS Numbers from various string formats to a standard 10-digit string format.
- Additional details and information on an NHS number, such as the region for which it's valid, and the reason for invalidity, if invalid.
IMPORTANT: You should never need to generate an NHS Number for a live system
Live NHS, CHI, H&C and IHI numbers are always generated by some kind of central authority or registry, such as the NHS Spine in England, and they are assigned to patients, often at or near birth or at the point of becoming a user of that health system.
Unless you represent a central health authority, you should not need to generate an NHS Number for a live system. If you are a patient, you should never need to generate an NHS Number for yourself.
This package is intended for use in testing and development environments where you need to generate NHS Numbers for testing, research purposes, or synthetic data generation.
Scottish CHI Number validation
At present, this library does not reliably validate Scottish CHI Numbers. This is because the first 6 digits of a Scottish CHI Number must be a valid DDMMYY Date of Birth, and this library does not currently check for this. At the moment, only the correct number range is checked for.
Roadmap
- Additional validation for Scottish CHI numbers to ensure the first 6 digits are a valid
DDMMYY
Date of Birth. - Generation of valid Scottish CHI numbers along the same rules.
- Validation and generation of IHI Numbers for the Republic of Ireland, subject to contributors wanting to collaborate on this, and there being a demand for implementation.