///|
pub struct NormalizationResult {
  accepted : Array[String]
  rejected : Array[String]
} derive(Debug, Eq, ToJson)

///|
pub fn normalize_codes(inputs : Array[String]) -> NormalizationResult {
  let accepted = []
  let rejected = []
  for input in inputs {
    try parse_icd10(input) catch {
      _ => rejected.push(input)
    } noraise {
      code => accepted.push(code.canonical())
    }
  }
  { accepted, rejected }
}

///|
pub fn canonicalize_lines(text : String) -> NormalizationResult {
  let lines = []
  let mut current = ""
  for c in text {
    if c == '\n' {
      lines.push(current)
      current = ""
    } else if c != '\r' {
      current = current + c.to_string()
    }
  }
  if !current.is_empty() {
    lines.push(current)
  }
  normalize_codes(lines)
}