import {z} from 'zod' export type GetApiDrV1DoctorDoctorIdArgs = {auth: string, doctor_id: string}; export type GetApiDrV1DoctorDoctorIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const personal = z.object({first_name: z.string(), middle_name: z.string(), last_name: z.string(), dob: z.string(), gender: z.string()}); export const language = z.object({code: z.string(), language: z.string()}); export const degree = z.object({name: z.string(), branch_name: z.string(), college_name: z.string(), start_year: z.string(), end_year: z.string()}); export const majorSpeciality = z.object({name: z.string(), code: z.string()}); export const speciality = z.object({name: z.string()}); export const contact = z.object({name: z.string(), number: z.string()}); export const address2 = z.object({line1: z.string(), city: z.string(), country: z.string(), state: z.string(), pin: z.string()}); export const clinic = z.object({id: z.string(), name: z.string(), contacts: z.array(contact), address: address2}); export const professional = z.object({active: z.boolean(), about: z.string(), language: z.array(language), degree: z.array(degree), major_speciality: majorSpeciality, speciality: z.array(speciality), clinics: z.array(clinic), default_clinic: z.string()}); export const profile1 = z.object({personal: personal, professional: professional}); export const getApiDrV1DoctorDoctorIdResponse = z.object({id: z.string(), profile: profile1}); 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 Doctor profile * * GET /dr/v1/doctor/{doctor_id} */ export const getApiDrV1DoctorDoctorId = async (args: GetApiDrV1DoctorDoctorIdArgs, options?: GetApiDrV1DoctorDoctorIdOptions) => { 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.auth != null) headers.set("auth", String(args.auth)) const url = `${baseUrl.replace(/\/+$/, '')}/dr/v1/doctor/${encodeURIComponent(String(args.doctor_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(getApiDrV1DoctorDoctorIdResponse, await res.json()) };