import {z} from 'zod' export type GetApiEstimatesIdItemsLineIdTakeHomeComponentsArgs = {id: string, lineId: string}; export type GetApiEstimatesIdItemsLineIdTakeHomeComponentsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; export const chargeTakeHomeComponentDto = z.object({transactionId: z.string().optional(), inventoryItemId: z.string().optional(), itemName: z.string().optional(), quantity: z.union([z.number(), z.string()]).optional(), sigFilled: z.boolean().optional()}); export const getApiEstimatesIdItemsLineIdTakeHomeComponentsResponse = z.array(chargeTakeHomeComponentDto); 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 }; /** * List a performed charge line's take-home component dispenses (per-component * disposition). A charge fans out to N component transactions; the ones dispensed * take-home (DispenseType=Prescription) may have a deferred SIG. This returns each * with whether its SIG/label is filled, so the UI can walk the unfilled ones * through the post-dispense prescription flow and clear the SIG_REQUIRED convert * block. See docs/june-updates/charge-component-disposition.md. * * GET /Estimates/{id}/items/{lineId}/take-home-components */ export const getApiEstimatesIdItemsLineIdTakeHomeComponents = async (args: GetApiEstimatesIdItemsLineIdTakeHomeComponentsArgs, options?: GetApiEstimatesIdItemsLineIdTakeHomeComponentsOptions) => { const {baseUrl = "https://api.clinicos.vet/backend/business", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/Estimates/${encodeURIComponent(String(args.id))}/items/${encodeURIComponent(String(args.lineId))}/take-home-components${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(getApiEstimatesIdItemsLineIdTakeHomeComponentsResponse, await res.json()) };