8000 United Kingdom Extensions: Added NHSNumber generator to Person by JohnStabler · Pull Request #483 · bchavez/Bogus · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

United Kingdom Extensions: Added NHSNumber generator to Person #483

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ In the examples above, all three alternative styles of using **Bogus** produce t
* `Bogus.DataSets.Finance.SortCode()` - Banking Sort Code
* `Bogus.DataSets.Finance.Nino()` - National Insurance Number
* `Bogus.DataSets.Address.CountryOfUnitedKingdom()` - Country of the United Kingdom
* `Bogus.Person.NHSNumber()` - UK National Health Service Number
* **`using Bogus.Extensions.UnitedStates;`**
* `Bogus.Person.Ssn()` - Social Security Number
* `Bogus.DataSets.Company.Ein()` - Employer Identification Number
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Bogus.Bson;
using Bogus.DataSets;
using System.Xml.Schema;

namespace Bogus.Extensions.UnitedKingdom
{
Expand All @@ -16,7 +17,7 @@ public static string SortCode(this Finance finance, bool includeSeparator = true
const string withSeparator = "##-##-##";
const string withoutSeparator = "######";

if( includeSeparator )
if (includeSeparator)
{
return finance.Random.ReplaceNumbers(withSeparator);
}
Expand All @@ -29,7 +30,7 @@ public static string SortCode(this Finance finance, bool includeSeparator = true
/// </summary>
public static string Nino(this Finance finance, bool includeSeparator = true)
{
const string valid1stPrefixChars = "ABCEGHJKLMNOPRSTWXYZ";
const string valid1stPrefixChars = "ABCEGHJKLMNOPRSTWXYZ";
//const string valid2ndPrefixChars = "ABCEGHJKLMN PRSTWXYZ";
const string validSuffixChars = "ABCD";

Expand Down Expand Up @@ -68,5 +69,44 @@ public static string CountryOfUnitedKingdom(this Address address)
var countries = Database.Get(nameof(address), "uk_country", "en_GB") as BArray;
return address.Random.ArrayElement(countries);
}

/// <summary>
/// National Health Service Number
/// </summary>
/// <param name="person"></param>
/// <returns></returns>
public static string NHSNumber(this Person person)
{
string generatedDigits;
bool valid;

do
{
generatedDigits = person.Random.ReplaceNumbers("#########");
valid = true;

int sum = 0;
for (int i = 0; i < generatedDigits.Length; i++)
{
int digit = int.Parse(generatedDigits[i].ToString());
sum += digit * (10 - i);
}

int checkDigit = 11 - (sum % 11);

if (checkDigit == 11)
checkDigit = 0;

if (checkDigit == 10) // This NHS number is invalid and cannot exist
valid = false;
else
generatedDigits += checkDigit.ToString();

} while (!valid);

return generatedDigits;

}

}
}
0