Functional Weave
Code in TypeScript

health.nhs-number-format@1.0.1

impl/python.py

681 bytes · the Python implementation · view raw

Imports name this capability’s declared dependencies, which fune builds next to it in your project; each one links to its page.

from .validation_nhs_number import validate_nhs_number  ← from validation.nhs-number ^2.0.0 · built alongside by fune


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