Liking cljdoc? Tell your friends :D

com.eldrix.nhsnumber

Utility functions for validating, formatting, normalising and generating UK NHS numbers.

Utility functions for validating, formatting, normalising and generating
UK NHS numbers.
raw docstring

format-nnnclj/s

(format-nnn nnn)
(format-nnn nnn sep)

Formats an NHS number for display purposes into 3,3,4 format (as per standard ISB 0149 Amd 136/2010) with 'sep' used as separator (default, a blank space). e.g.,

(format-nnn "1112223304")
=> "111 222 3304"
Formats an NHS number for display purposes into 3,3,4 format (as per standard
ISB 0149 Amd 136/2010) with 'sep' used as separator (default, a blank space).
e.g.,
```
(format-nnn "1112223304")
=> "111 222 3304"
```
sourceraw docstring

normaliseclj/s

(normalise s)
(normalise s mode)

Normalise an NHS number, removing non-digit characters such as whitespace and punctuation. Returns 'nil' if the resulting string is not 10 digits long. e.g.,

(normalise "111 222 3304")
=> "1112223304"

There are two modes :lenient and :strict

  • :lenient :removes spaces and punctuation from anywhere in string
  • :strict :only a single space or punctuation permitted between 3,3,4 groups.
Normalise an NHS number, removing non-digit characters such as whitespace and
punctuation. Returns 'nil' if the resulting string is not 10 digits long.
e.g.,
```
(normalise "111 222 3304")
=> "1112223304"
```
There are two modes :lenient and :strict
- :lenient :removes spaces and punctuation from anywhere in string
- :strict  :only a single space or punctuation permitted between 3,3,4 groups.
sourceraw docstring

ordered-sequenceclj/s

(ordered-sequence)
(ordered-sequence prefix)

Return a lazy sequence of ordered, valid NHS numbers. Given the results will be ordered, they are guaranteed to be unique within the same sequence.

Return a lazy sequence of ordered, valid NHS numbers. Given the results will
be ordered, they are guaranteed to be unique within the same sequence.
sourceraw docstring

randomclj/s

(random)
(random prefix)

Generate a random valid NHS number with the given prefix. There are no guarantees that duplicate NHS numbers will not be generated on successive calls. As such, if a sequence of unique NHS numbers are required, use:

(take 50 (distinct (random-sequence "999")))

Alternatively, store previously used generated NHS numbers and retry if a duplicate is generated.

Generate a random valid NHS number with the given prefix. There are no
guarantees that duplicate NHS numbers will not be generated on successive
calls. As such, if a sequence of unique NHS numbers are required, use:
```
(take 50 (distinct (random-sequence "999")))
```
Alternatively, store previously used generated NHS numbers and retry if a
duplicate is generated.
sourceraw docstring

random-sequenceclj/s

(random-sequence)
(random-sequence prefix)

Returns a lazy sequence of randomly generated valid NHS numbers. This may generate duplicate NHS numbers within the sequence. If only distinct NHS numbers are required, use:

(take 50 (distinct (random-sequence 999)))

This example generates 50 unique NHS numbers with the prefix '999'.

Returns a lazy sequence of randomly generated valid NHS numbers. This may
generate duplicate NHS numbers within the sequence. If only distinct NHS
numbers are required, use:
```
(take 50 (distinct (random-sequence 999)))
```
This example generates 50 unique NHS numbers with the prefix '999'.
sourceraw docstring

valid*?clj/s

(valid*? s)
source

valid?clj/s

(valid? nnn)

Validate an NHS number using the modulus 11 algorithm. An NHS number should be 10 numeric digits with the tenth digit a check digit. The validation occurs as follows:

  1. Multiply each of the first nine digits by a weighting factor (digit 1:10, 2:9, 3:8, 4:7, 5:6, 6:5, 7:4, 8:3, 9:2)
  2. Add the results of each multiplication together
  3. Divide total by 11, establish the remainder
  4. Subtract the remainder from 11 to give the check digit
  5. If result is 11, the check digit is 0
  6. If result is 10, NHS number is invalid
  7. Check remainder matches the check digit, if it does not NHS number is invalid
Validate an NHS number using the modulus 11 algorithm.
An NHS number should be 10 numeric digits with the tenth digit a check digit.
The validation occurs as follows:
1. Multiply each of the first nine digits by a weighting factor (digit 1:10, 2:9, 3:8, 4:7, 5:6, 6:5, 7:4, 8:3, 9:2)
2. Add the results of each multiplication together
3. Divide total by 11, establish the remainder
4. Subtract the remainder from 11 to give the check digit
5. If result is 11, the check digit is 0
6. If result is 10, NHS number is invalid
7. Check remainder matches the check digit, if it does not NHS number is invalid
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close