Use the vendored library in third_party/Portal.Formatting to format the phone number in the patient profile response. Read its README for how to reference and call it.
