import { useCallback } from 'react'; import { environment } from '../environments/environment.ts'; import { useHttpService } from './HttpService.tsx'; import { announceSupportTicketRaised } from '../utils/supportTicketRaised.ts'; /** * A patient raising a support ticket about the product itself. * * POST {fhirIdentityApi}/patient-support/tickets * { subject, body, workspace, route, lastQuestion? } -> { ticketId, reference } * * Its own service rather than a flag on the practice one - see * `_TESTS/__tests__/aPatientTicketNeverReachesThePracticeSurface.test.ts`, which holds that fence. * * Nothing clinical travels. The context attached is the surface they were on, the route, and the * question the assistant failed to answer - their own words, never a capture of the screen. */ const API_URL = environment.fhirIdentityApi; export type PatientSupportTicketDraft = { /** One line, in their own words. Required - a ticket with no subject cannot be triaged. */ subject: string; /** What happened. */ body: string; /** The surface in the reader's terms, which on this side is always the patient portal. */ workspace: string; /** The in-app route, so whoever answers can open the same screen. */ route: string; /** The last thing they asked the assistant, when there was one. */ lastQuestion?: string; }; export type PatientSupportTicketReceipt = { ticketId: string; /** The human reference to quote if they get in touch - "AKS-1042". */ reference: string; }; export const usePatientSupportService = () => { const { post } = useHttpService(); const submitPatientSupportTicket = useCallback( async (draft: PatientSupportTicketDraft): Promise => { const receipt = await post(`${API_URL}/patient-support/tickets`, draft); announceSupportTicketRaised(); return receipt; }, [post], ); return { submitPatientSupportTicket }; };