import {z} from 'zod' export type GetApiDrV1PatientPatientIdArgs = {auth: string, patient_id: string}; export type GetApiDrV1PatientPatientIdOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; export const getApiDrV1PatientPatientIdResponse = z.object({patient_id: z.string().optional(), partner_patient_id: z.string().optional(), first_name: z.string().optional(), middle_name: z.string().optional(), last_name: z.string().optional(), gender: z.enum(["M", "F", "O"]).optional(), dob: z.string().optional(), email: z.string().optional(), mobile: z.string().optional(), address: z.object({line1: z.string().optional(), city: z.string().optional(), pincode: z.string().optional()}).optional(), tag: z.string().optional(), partner_meta: z.record(z.string(), z.unknown()).optional(), created_at: z.number().int().optional(), relations: z.array(z.object({relation: z.enum(["Husband", "Wife", "Father", "Mother", "Son", "Daughter", "Brother", "Sister", "Grandfather", "Grandmother", "Spouse", "Father & Mother", "Cousin Brother", "Cousin Sister", "Paternal Uncle", "Paternal Aunt", "Maternal Uncle", "Maternal Aunt", "Paternal Grandfather", "Paternal Grandmother", "Maternal Grandfather", "Maternal Grandmother", "Great grandfather", "Great grandmother", "Niece", "Nephew"]).optional(), pid: z.string().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 }; /** * Get patient details by profile id * * GET /dr/v1/patient/{patient_id} */ export const getApiDrV1PatientPatientId = async (args: GetApiDrV1PatientPatientIdArgs, options?: GetApiDrV1PatientPatientIdOptions) => { 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/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(getApiDrV1PatientPatientIdResponse, await res.json()) };