import {z} from 'zod' export type GetApiSpakinectGfePatientPatientIdArgs = {TENANT: string, 'API-KEY': string, patient_id: string}; export type GetApiSpakinectGfePatientPatientIdOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const gFEStatus = z.enum(["Processing", "Pending Review", "Approved", "Rejected", "Completed", "Cancelled", "Cancelled by client"]); export const patientDetails = z.object({name: z.string().nullable().optional(), first_name: z.string(), last_name: z.string(), email: z.string(), phone: z.string().nullable().optional()}); export const documentType = z.enum(["LAB", "PHARMACY", "IMAGE", "REPORT", "OTHER", "CONSENT", "NOTE_UPLOAD"]); export const documentSummary = z.object({id: z.string(), patientId: z.string(), filePath: z.string(), fileType: z.string(), title: z.string(), summary: z.string().nullable(), docType: documentType, signatureUrl: z.string().nullable()}); export const gFEDetail = z.object({id: z.string(), patientId: z.string(), spakinectGfeId: z.string(), createdDate: z.string(), updatedDate: z.string().nullable().optional(), status: gFEStatus, requestedTreatments: z.array(z.string()), patientDetails: patientDetails, document: documentSummary.nullable().optional()}); export const getApiSpakinectGfePatientPatientIdResponse = z.array(gFEDetail); export const validateResponse = async ( schema: { readonly '~standard': { readonly validate: (value: unknown) => ({ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }) | Promise<{ readonly value: Output; readonly issues?: undefined } | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray | undefined }> }> } }, value: unknown ): Promise => { const result = await schema['~standard'].validate(value) if (result.issues !== undefined) { const detail = result.issues .map(({ message, path }) => path?.length ? `${path.map((segment) => String(typeof segment === 'object' ? segment.key : segment)).join('.')}: ${message}` : message ) .join('; ') throw new Error(`Response does not match the schema: ${detail}`, { cause: { issues: result.issues } }) } return result.value }; /** * Get Patient Gfes * * GET /spakinect/gfe/patient/{patient_id} */ export const getApiSpakinectGfePatientPatientId = async (args: GetApiSpakinectGfePatientPatientIdArgs, options: GetApiSpakinectGfePatientPatientIdOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.TENANT != null) headers.set("TENANT", String(args.TENANT)) if (args['API-KEY'] != null) headers.set("API-KEY", String(args['API-KEY'])) const url = `${baseUrl.replace(/\/+$/, '')}/spakinect/gfe/patient/${encodeURIComponent(String(args.patient_id))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(getApiSpakinectGfePatientPatientIdResponse, await res.json()) };