import { useCallback } from "react"; import { useHttpService } from "../services/HttpService.tsx"; import { environment } from "../environments/environment.ts"; /** * The laboratory would not take the order. * * NOT THE SAME ACT AS REFUSING A SAMPLE, and the two must not be offered as one. A refused sample * means draw again; a refused order means fix the order. Their compendium changed, or the account * is closed, and the tube may be perfect and sitting in their fridge. * * WHY THE BENCH TYPES THIS IN. Nothing transmits yet, so a refusal arrives on paper or over the * telephone -- the same way an inbound requisition does, and recorded the same way. When a * transport exists it writes the same marker and this screen does not change. * * THE REASONS ARE LISTED HERE AND CHECKED ON THE SERVER. The server is the boundary and refuses * anything not on its own list; this copy exists so somebody can pick rather than type, and a * refusal it does not recognise comes back with the server's list attached. */ export const ORDER_REFUSAL_REASONS = [ { code: "unknown-test", label: "They do not have that test code" }, { code: "retired-test", label: "They have retired that test" }, { code: "unknown-account", label: "They do not recognise the account" }, { code: "missing-field", label: "The order was missing something they require" }, { code: "not-authorised", label: "The account may not order that test" }, { code: "other", label: "Something else" }, ] as const; /** * What happens next, which is what decides whether anybody looks at this again. * * `contact` is the one worth having separately: a closed account or an unknown client code cannot * be fixed from this screen, and offering only resend or cancel would make somebody choose a lie. */ export const REFUSAL_NEXT_STEPS = [ { id: "resend", label: "Fix it and send again" }, { id: "contact", label: "Ring them — this cannot be fixed here" }, { id: "cancel", label: "Give up on this order" }, ] as const; export interface OrderRefusal { reasonCode: string; nextStep: string; /** Their code for it, where they gave one. */ theirCode?: string; /** Their words, not ours. A practice ringing them has to quote what was actually said. */ theirMessage?: string; note?: string; } export const useRecordOrderRefusal = () => { const { post } = useHttpService(); const record = useCallback( (orderId: string, refusal: OrderRefusal, admit?: () => void) => post(`${environment.fhirBaseApi}/diagnostic-order/${orderId}/refusal`, refusal, ...(admit ? [{ admit }] : [])), [post], ); /** Marked dealt with, never deleted: asking why this took three days needs it still there. */ const markDealtWith = useCallback( (orderId: string) => post(`${environment.fhirBaseApi}/diagnostic-order/${orderId}/refusal`, { resolved: true }), [post], ); return { record, markDealtWith }; };