import { sectionReadFailure, type SectionReadFailure } from './sectionReadRefusal'; /** * A STATUS THAT WAS REFUSED IS NOT A STATUS THAT FAILED TO LOAD. * * The agreement sections on a patient's view of a practice read one status each and, when that read * threw, discarded the error and rendered one box: *"We couldn't load this right now, so we aren't * showing a status rather than showing one we are unsure of"* with a Try again under it. The instinct in * that sentence is right and is not what changes here - refusing to show a status it is unsure of is * exactly correct, and inventing "no access" because a fetch failed would tell a patient their record is * closed when it may be wide open. * * WHAT IS WRONG IS THAT IT SAYS THE SAME THING TO TWO DIFFERENT EVENTS. Measured on journey D8: the three * calls come back 403. So the server refused on authorization grounds and the interface reported a * transient fetch problem and offered a button that can only produce the same 403 for as long as the * patient keeps pressing it. * * The rule this sits under was re-ruled on 2026-09-06: *"a refusal renders as a denial naming what is * denied, never as a failure or empty data."* A retry prompt over a refusal is the "failure" half of that * sentence. * * SO THE FALLBACK SPLITS IN TWO AND NEITHER HALF EVER NAMES A STATUS. A denial says it was refused and * offers no retry, because there is nothing to retry. Everything else keeps the careful sentence and the * Try again it has always had. */ export type AgreementStatusFailure = SectionReadFailure; /** * Which of the two this was. * * ONLY A PERMANENT DENIAL IS RECLASSIFIED. A 5xx, a timeout and a dropped connection are all genuinely * retryable and keep the retry, which is the control that stops this becoming the same defect pointing * the other way - telling somebody with a bad connection that they are not allowed to see their own * agreement would be worse than what it replaces. */ export const agreementStatusFailure = (error: unknown): AgreementStatusFailure => sectionReadFailure(error); /** * What a refused status says. * * IT NAMES WHAT COULD NOT BE READ, which is the whole of the rule: "this" is not a denial, "the status of * your HIPAA authorization with Great River Health Center" is. And it says the retry is absent on purpose, * because a control that silently disappears reads as a bug to the person who saw it a moment ago. * * IT DOES NOT GUESS AT WHY. The refusal arrives as a bare 403 and this surface cannot tell a practice's * configuration from a gap in the patient's own session, so it says what happened and where to get the * answer instead of inventing a cause. Naming the practice as the one who withheld it would be an * accusation we have no evidence for. */ export const agreementStatusDeniedMessage = (practice: string, documentName: string): string => `We are not allowed to show you the status of your ${documentName} with ${practice}. ` + 'That is a refusal rather than a loading problem, so trying again will not change it. ' + `Ask ${practice} directly, and they can tell you where it stands.`;