uk-fci / nhs-number

Python package to provide utilities for NHS Numbers, including validity checks, normalisation, and generation.
https://nhs-number.uk-fci.tech/
MIT License
4 stars 6 forks source link

Handing ints to normalise()/standardise_format()will fail on some CHI numbers #19

Closed andylaw closed 1 year ago

andylaw commented 1 year ago

Calling code that reads NHS numbers as integers and calls normalise()/standardise_format() will fail if the number has a leading zero. The zero will be stripped and thus the function will only see a 9 digit number. That will fail the pattern match.

Two options:

  1. require the calling code to provide a string and fail if it doesn't (passing the buck). This is consistent with our current definition of the input number as str
  2. check for int argument and convert to 10-digit, zero-padded string as a separate case
pacharanero commented 1 year ago

This appears to be fixed by #20

I have added a test which explicitly looks for this case of a valid CHI number with a leading zero (eg "0607230002"), represented as a 9-digit integer value without leading zero (eg 607230002) due to the fact you cannot have a leading zero in an integer in Python as it is a syntax error.

Test is added in commit 97ee37cb0622a4d6701f8d43a2a0048e834a2cba