import type { OrgAuthorizationStatusValue } from '../../../services/OrgAuthorizationService.tsx'; /** * / auth-consent Slice A - what to TELL a practitioner when Start encounter fails. * * WHY THIS CANNOT BE AN `err.status === 403` CHECK. The authorizer `throw`s, API Gateway generates * the 403 itself, and that generated response carries NO CORS headers - so the browser rejects with an * opaque `TypeError: Failed to fetch` (). There is no status code and * no body left to branch on by the time the error reaches us. The caller therefore ASKS the * authorization service what the patient's status is, and this function turns that answer into copy. * * The bug being fixed: a patient whose org authorization is still `proposed` can never start a visit, * yet the practitioner was told "Please try again" - advice guaranteed to fail no matter how many times * it is followed. See akashic-docs/hipaa-authorization-consent-chain.md for why the gate is correct and * must NOT be widened to make this go away. */ export const GENERIC_START_FAILURE_MESSAGE = 'Could not start the encounter. Please try again.'; // Both remedies are named on purpose. The portal covers patients who use it; the front desk covers the // ones who never will, which is the majority of the in-office population this product serves. export const AUTHORIZATION_REQUIRED_MESSAGE = 'This patient has not completed the HIPAA authorization for your organization, so their clinical ' + 'record cannot be opened yet. They can accept it in the patient portal, or the front desk can ' + 'record their agreement in person.'; /** * `undefined` means the status probe itself failed - fall back to the generic message rather than * asserting an authorization problem we could not verify. Telling a clinician mid-visit that their * patient has not consented, when we simply could not reach the service, is a false statement about a * legal record; a needless retry is merely an annoyance. Fail toward the annoyance. */ export function startEncounterFailureMessage( status: OrgAuthorizationStatusValue | undefined, ): string { // - `declined` BELONGS HERE, and it is not the nag the fence forbids. That fence is about // chasing the PATIENT for an answer they already gave. This message is shown to a CLINICIAN who just // tried to start a visit and could not, and the alternative is the generic "something went wrong" - which // sends them hunting for a technical fault that does not exist. Telling them the real reason is the // honest answer, and it is the same reason `proposed` and `none` are here. if (status === 'proposed' || status === 'none' || status === 'declined') { return AUTHORIZATION_REQUIRED_MESSAGE; } return GENERIC_START_FAILURE_MESSAGE; }