from .validation_nhs_number import validate_nhs_number def format_nhs_number(value: str) -> str: """The NHS number in the 3-3-4 display format NHS systems use, after a full check with validation.nhs-number. An invalid number is an error, not a formatted string: a well-spaced wrong number looks more trustworthy than a badly spaced right one. The error names the reason but never echoes the number, which is a patient identifier and has no place in a log.""" result = validate_nhs_number(value) if not result.valid or result.formatted is None: raise ValueError("not a valid NHS number (%s)" % (result.reason,)) return result.formatted