import { useCallback } from "react"; import { useHttpService } from "../services/HttpService.tsx"; import { environment } from "../environments/environment.ts"; import type { DiagnosticOrderState } from "../utils/diagnosticOrderQueue"; import type { DiagnosticOrderReview } from "../utils/diagnosticOrderReview"; import type { SaveTransport } from "../utils/saveOperation"; /** * A practitioner acknowledging a result. * * WHY THIS IS ITS OWN HOOK RATHER THAN THE QUEUE'S `advance`. That one reloads the whole lab queue * after every move, and reading the queue needs `diagnostics: view` -- a permission a practitioner * reviewing their own patient's result has no reason to hold. Reusing it would 403 the reload for * exactly the caller this is for. * * `reviewed` IS THE CLINICALLY IMPORTANT STATE. A result nobody acknowledged is the classic * patient-harm case in this whole area, and the server refuses this move to anybody without the * practitioner role for that reason -- acknowledging a result is a clinical act, not lab work. * * IT IS ALSO IRREVERSIBLE, because the machine only moves forward. Nothing can walk an order back * from `reviewed`, so the caller is expected to confirm before this is invoked. */ export const useMarkDiagnosticOrderReviewed = () => { const { put } = useHttpService(); return useCallback( async ( orderId: string, transport?: SaveTransport, ): Promise<{ orderId?: string; state?: DiagnosticOrderState; review?: DiagnosticOrderReview }> => // On the base API, where 02-fhir-base.yaml declares the diagnostic-order routes -- the // ServiceRequest resource itself lives on the clinical gateway, and the placing hook records // what happens when the two are confused. put(`${environment.fhirBaseApi}/diagnostic-order/${orderId}/state`, { state: "reviewed" }, transport), [put], ); };