import {z} from 'zod' export type GetApiMedicalDbV1SymAndDiagArgs = {q: string, limit?: number | undefined, s_type?: ('symptom' | 'diagnosis') | undefined}; export type GetApiMedicalDbV1SymAndDiagOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const symptomB6c8896 = z.object({id: z.string(), name: z.string(), common_name: z.string()}); export const diagnosisE57b7a5 = z.object({id: z.string(), name: z.string(), common_name: z.string(), icd10_code: z.string(), icd10_name: z.string()}); export const symptomsAndDiagnosesResponseA9993e3 = z.object({symptoms: z.array(symptomB6c8896), diagnoses: z.array(diagnosisE57b7a5)}); 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 }; /** * Search Symptoms and Diagnoses * * GET /medical-db/v1/sym-and-diag */ export const getApiMedicalDbV1SymAndDiag = async (args: GetApiMedicalDbV1SymAndDiagArgs, options?: GetApiMedicalDbV1SymAndDiagOptions) => { const {baseUrl = "https://api.eka.care", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.q != null) query.append("q", String(args.q)) if (args.limit != null) query.append("limit", String(args.limit)) if (args.s_type != null) query.append("s_type", String(args.s_type)) const url = `${baseUrl.replace(/\/+$/, '')}/medical-db/v1/sym-and-diag${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(symptomsAndDiagnosesResponseA9993e3, await res.json()) };