The Community Health Index (CHI) is a register of all patients in
NHS Scotland. A CHI number is a unique, ten-digit identifier assigned to
each patient on the index.
The first six digits of a CHI number are a patient's date of birth in
DD/MM/YY format.
The ninth digit of a CHI number identifies a patient's sex: odd for male,
even for female. The tenth digit is a check digit, denoted checksum
.
While a CHI number is made up exclusively of numeric digits, it cannot be
stored with numeric
class in R. This is because leading zeros in
numeric values are silently dropped, a practice not exclusive to R. For this
reason, chi_check
accepts input values of character
class
only. A leading zero can be added to a nine-digit CHI number using
chi_pad()
.
chi_check
assesses whether an entered CHI number is valid by checking
whether the answer to each of the following criteria is Yes
:
Does it contain no non-numeric characters?
Is it ten digits in length?
Do the first six digits denote a valid date?
Is the checksum digit correct?