fredbradley/php-nhs-number
Composer 安装命令:
composer require fredbradley/php-nhs-number
包简介
Utility class to validate, format and generate NHS numbers.
关键字:
README 文档
README
Utility class to validate, format and generate NHS numbers.
🤔 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:
composer require imliam/php-nhs-number:^1.1
📝 Usage
You can new up the NhsNumber object by passing through an NHS number.
$nhsNumber = new \ImLiam\NhsNumber\NhsNumber('9077844449');
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.
echo $nhsNumber->format(); // '907 784 4449' echo (string) $nhsNumber; // '907 784 4449'
To get a boolean representation of whether or not the current number is valid, call the ->isValid() method on the object.
$nhsNumber->isValid(); // true
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.
try { $nhsNumber = new \ImLiam\NhsNumber\NhsNumber('9077844446'); $nhsNumber->validate(); } catch (\ImLiam\NhsNumber\InvalidNhsNumberException $e) { echo $e->getMessage(); // "The NHS number's check digit does not match." }
To generate a single or multiple random valid NHS numbers for testing purposes, call the ::getRandomNumber() or ::getRandomNumbers($count) static methods respectively.
echo \ImLiam\NhsNumber\NhsNumber::getRandomNumber(); // '9278462608' echo \ImLiam\NhsNumber\NhsNumber::getRandomNumbers(5); // ['7448556886', '0372104223', '8416367035']
✅ Testing
composer test
🔖 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 contributing file and code of conduct for details on contributing to the project.
🔒 Security
If you discover any security related issues, please email liam@liamhammett.com 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.
fredbradley/php-nhs-number 适用场景与选型建议
fredbradley/php-nhs-number 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.2k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 09 月 30 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「imliam」 「php-nhs-number」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 fredbradley/php-nhs-number 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fredbradley/php-nhs-number 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 fredbradley/php-nhs-number 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
An easier way to define custom Blade directives.
Utility class to validate, format and generate NHS numbers.
Ensure that a Gmail address is unique
Set a .env file variable from the command line
Present names for English-language applications.
Gracefully handle an unwanted exit statement.
统计信息
- 总下载量: 5.2k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-09-30