Download the PHP package fredbradley/php-nhs-number without Composer
On this page you can find all versions of the php package fredbradley/php-nhs-number. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download fredbradley/php-nhs-number
More information about fredbradley/php-nhs-number
Files in fredbradley/php-nhs-number
Package php-nhs-number
Short Description Utility class to validate, format and generate NHS numbers.
License MIT
Homepage https://github.com/imliam/php-nhs-number
Informations about the package php-nhs-number
NHS Numbers
Utility class to validate, format and generate NHS numbers.
- NHS Numbers
- 🤔 F.A.Q.
- What is an NHS number?
- How do you validate an NHS number?
- 💾 Installation
- 📝 Usage
- ✅ Testing
- 🔖 Changelog
- ⬆️ Upgrading
- 🎉 Contributing
- 🔒 Security
- 👷 Credits
- ♻️ License
- 🤔 F.A.Q.
🤔 F.A.Q.
What is an NHS number?
An "NHS number" is a unique identifier that every individual patient registered with Great Britain's National Health Service (NHS) has.
You can find out more about NHS numbers on the nhs.uk website.
How do you validate an NHS number?
Not every number is a valid NHS number - they must conform to a simple algorithm to be considered valid. Before the algorithm is run, there are a few things to note about NHS numbers:
- An NHS number must be numeric
- An NHS number must be 10 digits long
- An NHS number can begin with a
0
, so it should be handled as a string, not an integer - The last digit of the NHS number is used as the "check digit" for the algorithm
The algorithm to validate an NHS number using its "check digit" is as follows:
- Multiple each of the first nine digits by a defined weight, shown below:
Original digit | Multiplied by |
---|---|
1 | 10 |
2 | 9 |
3 | 8 |
4 | 7 |
5 | 6 |
6 | 5 |
7 | 4 |
8 | 3 |
9 | 2 |
- Calculate the sum of all 9 multiplications
- Divide this sum by 11 and get the remainder
- Subtract 11 from the remainder to get the total
- If the total is 11 then the identifier, otherwise the identifier is the total
- If the identifier is 10, then the NHS number is wrong
- If the identifier is the same as the check digit, then the NHS number is correct
💾 Installation
You can install the package with Composer using the following command:
📝 Usage
You can new up the NhsNumber
object by passing through an NHS number.
The NHS recommend that when displaying an NHS number to a human, it should be spaced out in a 3-3-4 format, which helps it to be easier to read. To do this, call the ->format()
method or cast the object to a string.
To get a boolean representation of whether or not the current number is valid, call the ->isValid()
method on the object.
If you need more information on why a given NHS number may be invalid, you can call the ->validate()
method directly. This will throw an InvalidNhsNumberException
exception whose message will explain why the number is not valid.
To generate a single or multiple random valid NHS numbers for testing purposes, call the ::getRandomNumber()
or ::getRandomNumbers($count)
static methods respectively.
✅ Testing
🔖 Changelog
Please see the changelog file for more information on what has changed recently.
⬆️ Upgrading
Please see the upgrading file for details on upgrading from previous versions.
🎉 Contributing
Please see the code of conduct for details on contributing to the project.
🔒 Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
👷 Credits
- Liam Hammett
- Peter Fisher for the original class
- All Contributors
♻️ License
The MIT License (MIT). Please see the license file for more information.