import {z} from 'zod' export type GetApiAssessmentApiFetchInterviewsV2Args = {practitioner_uuid?: string | undefined, patient_uuid?: string | undefined, unique_identifier?: string | undefined, transaction_id?: string | undefined, username_alias?: ('practitioner_uuid' | 'patient_uuid' | 'unique_identifier' | 'transaction_id') | undefined, wfids?: string | undefined, status?: ('NEW' | 'IN_REVIEW' | 'COMPLETED' | 'PARTIAL') | undefined}; export type GetApiAssessmentApiFetchInterviewsV2Options = {baseUrl?: string | undefined, apiKeyAuth?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiAssessmentApiFetchInterviewsV2Response = z.object({conversations: z.array(z.object({practitioner_uuid: z.string().optional(), patient_uuid: z.string().optional(), unique_identifier: z.string().optional(), transaction_id: z.string().optional(), conversations: z.array(z.object({conversationid: z.string().optional(), created_at: z.string().optional(), wflow_wfid: z.number().int().nullable().optional()})).optional()})).optional()}); 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 }; /** * Fetch Grouped Assessments * * GET /assessment/api/fetch_interviews/v2/ */ export const getApiAssessmentApiFetchInterviewsV2 = async (args: GetApiAssessmentApiFetchInterviewsV2Args, options?: GetApiAssessmentApiFetchInterviewsV2Options) => { const {baseUrl = "https://api.eka.care", fetch: fetchFn = fetch, apiKeyAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.practitioner_uuid != null) query.append("practitioner_uuid", String(args.practitioner_uuid)) if (args.patient_uuid != null) query.append("patient_uuid", String(args.patient_uuid)) if (args.unique_identifier != null) query.append("unique_identifier", String(args.unique_identifier)) if (args.transaction_id != null) query.append("transaction_id", String(args.transaction_id)) if (args.username_alias != null) query.append("username_alias", String(args.username_alias)) if (args.wfids != null) query.append("wfids", String(args.wfids)) if (args.status != null) query.append("status", String(args.status)) if (apiKeyAuth !== undefined) headers.set('authorization', `Bearer ${apiKeyAuth}`) const url = `${baseUrl.replace(/\/+$/, '')}/assessment/api/fetch_interviews/v2/${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(getApiAssessmentApiFetchInterviewsV2Response, await res.json()) };