use super::funejson::Value; use super::validation_nhs_number::validate_nhs_number; /// 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. /// /// # Panics /// Panics when the number is not a valid NHS number. pub fn format_nhs_number(value: &str) -> String { let result = validate_nhs_number(value); match (result.valid, result.formatted) { (true, Some(formatted)) => formatted, _ => panic!("not a valid NHS number ({})", result.reason.unwrap_or_default()), } } pub fn fune_vector(args: &[Value]) -> Value { // A non-string arrives as an empty string, which validation.nhs-number // reports as empty: the answer TypeScript and Python give too. Value::str(&format_nhs_number(args[0].as_str())) }