import {z} from 'zod' export type GetApiV1PatientArgs = {guardian?: string | undefined, prefix?: ('Mr.' | 'Ms.' | 'Mrs.' | 'Miss' | 'Ms' | 'Prof' | 'Sir') | undefined, suffix?: ('Jr.' | 'Sr.' | 'I' | 'II' | 'III' | 'IV' | 'V') | undefined, first_name: string, last_name: string, gender: 'male' | 'female' | 'unknown', dob: string, zip?: string | undefined, species?: ('Human' | 'Crocodile' | 'Frog' | 'Iguana' | 'Lizard' | 'Snake' | 'Tortoise' | 'Turtle' | 'Spider' | 'Other Arthopoda' | 'Chicken' | 'African Goshawk' | 'Budgerigar' | 'Cockatiel' | 'Cockatoo' | 'Common Canary' | 'Crow' | 'Duck' | 'Eagle' | 'Goose' | 'Guinea Fowl' | 'Kestrel' | 'Kite' | 'Macaw' | 'Ostrich' | 'Other Aves' | 'Owl' | 'Parakeet' | 'Parrot' | 'Partridge' | 'Peregrin Falcon' | 'Pheasant' | 'Pigeon' | 'Quail' | 'Snipe' | 'Sparrow' | 'Starling' | 'Swan' | 'Turtle Dove' | 'Bison' | 'Cattle/Bovine' | 'Buffalo' | 'Other Bovinae' | 'Alpaca' | 'Camel' | 'Llama' | 'Other Camelidae' | 'Dog/Canine' | 'Fox' | 'Jackal' | 'Raccoon Dog' | 'Wolf' | 'Other Caprinae' | 'Goat/Carpine' | 'Sheep/Ovine' | 'Elk' | 'Moose' | 'Fallow' | 'Other Cervidae' | 'Red Deer' | 'Reindeer' | 'Roe Deer' | 'Donkey/Asinine' | 'Horse/Equine' | 'Hybrid' | 'Other Equidae' | 'Zebra' | 'Bobcat' | 'Cougar' | 'Puma' | 'European Lynx' | 'Cat/Feline' | 'Jaguar' | 'Leopard' | 'Lion' | 'Other Felidae' | 'Tiger' | 'Wild Cat' | 'European Rabbit' | 'Hare' | 'Other Leporidae' | 'Bivalvia' | 'Cephalopoda' | 'Other Mollusca' | 'Badger' | 'Ferret' | 'Mink' | 'Other Mustelidae' | 'Bat' | 'Bear' | 'Hedgehog' | 'Monkey' | 'Other Mammalia' | 'Arctic Char' | 'Atlantic Salmon' | 'Brill' | 'Carp' | 'Catfish' | 'Cod' | 'Crucian Carp' | 'European Eel' | 'Gilthead' | 'Goldfish' | 'Gudgeon' | 'Halibut' | 'Largemouth Bass' | 'Mullet' | 'Other Pisces' | 'Perch' | 'Pike' | 'Roach' | 'Sea Bream' | 'Seabass' | 'Sharpsnout Seabream' | 'Sole' | 'Sturgeon' | 'Tench' | 'Trout' | 'Turbot' | 'Rockfish/Wolffish' | 'Beaver' | 'Chinchilla' | 'Dormouse' | 'Dwarf Hamster' | 'European Hamster' | 'Gerbil' | 'Guinea Pig' | 'House Mouse' | 'Other Rodentia' | 'Rat' | 'Russian Hamster' | 'Syrian Hamster' | 'Golden Hamster' | 'Vole' | 'Other Suidae' | 'Pig/Porcine' | 'Wild Boar' | 'Addax') | undefined}; export type GetApiV1PatientOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; export const model23 = z.object({guardian: z.string().optional(), prefix: z.enum(["Mr.", "Ms.", "Mrs.", "Miss", "Ms", "Prof", "Sir"]).optional(), suffix: z.enum(["Jr.", "Sr.", "I", "II", "III", "IV", "V"]).optional(), first_name: z.string(), last_name: z.string(), gender: z.enum(["male", "female", "unknown"]), dob: z.string(), zip: z.string().optional(), species: z.enum(["Human", "Crocodile", "Frog", "Iguana", "Lizard", "Snake", "Tortoise", "Turtle", "Spider", "Other Arthopoda", "Chicken", "African Goshawk", "Budgerigar", "Cockatiel", "Cockatoo", "Common Canary", "Crow", "Duck", "Eagle", "Goose", "Guinea Fowl", "Kestrel", "Kite", "Macaw", "Ostrich", "Other Aves", "Owl", "Parakeet", "Parrot", "Partridge", "Peregrin Falcon", "Pheasant", "Pigeon", "Quail", "Snipe", "Sparrow", "Starling", "Swan", "Turtle Dove", "Bison", "Cattle/Bovine", "Buffalo", "Other Bovinae", "Alpaca", "Camel", "Llama", "Other Camelidae", "Dog/Canine", "Fox", "Jackal", "Raccoon Dog", "Wolf", "Other Caprinae", "Goat/Carpine", "Sheep/Ovine", "Elk", "Moose", "Fallow", "Other Cervidae", "Red Deer", "Reindeer", "Roe Deer", "Donkey/Asinine", "Horse/Equine", "Hybrid", "Other Equidae", "Zebra", "Bobcat", "Cougar", "Puma", "European Lynx", "Cat/Feline", "Jaguar", "Leopard", "Lion", "Other Felidae", "Tiger", "Wild Cat", "European Rabbit", "Hare", "Other Leporidae", "Bivalvia", "Cephalopoda", "Other Mollusca", "Badger", "Ferret", "Mink", "Other Mustelidae", "Bat", "Bear", "Hedgehog", "Monkey", "Other Mammalia", "Arctic Char", "Atlantic Salmon", "Brill", "Carp", "Catfish", "Cod", "Crucian Carp", "European Eel", "Gilthead", "Goldfish", "Gudgeon", "Halibut", "Largemouth Bass", "Mullet", "Other Pisces", "Perch", "Pike", "Roach", "Sea Bream", "Seabass", "Sharpsnout Seabream", "Sole", "Sturgeon", "Tench", "Trout", "Turbot", "Rockfish/Wolffish", "Beaver", "Chinchilla", "Dormouse", "Dwarf Hamster", "European Hamster", "Gerbil", "Guinea Pig", "House Mouse", "Other Rodentia", "Rat", "Russian Hamster", "Syrian Hamster", "Golden Hamster", "Vole", "Other Suidae", "Pig/Porcine", "Wild Boar", "Addax"]).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 }; /** * Patient search * * GET /v1/patient */ export const getApiV1Patient = async (args: GetApiV1PatientArgs, options?: GetApiV1PatientOptions) => { const {baseUrl = "https://api.truepill.com", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.guardian != null) query.append("guardian", String(args.guardian)) if (args.prefix != null) query.append("prefix", String(args.prefix)) if (args.suffix != null) query.append("suffix", String(args.suffix)) if (args.first_name != null) query.append("first_name", String(args.first_name)) if (args.last_name != null) query.append("last_name", String(args.last_name)) if (args.gender != null) query.append("gender", String(args.gender)) if (args.dob != null) query.append("dob", String(args.dob)) if (args.zip != null) query.append("zip", String(args.zip)) if (args.species != null) query.append("species", String(args.species)) if (apiKey !== undefined) headers.set("Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v1/patient${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(model23, await res.json()) };