import {z} from 'zod' export type HcpcsProcedure = {hcpcs_code?: string | undefined, generic_name?: string | undefined, description?: string | undefined, brand_names?: Array | undefined, strength?: string | undefined, fda_approval_year?: string | undefined, fda_discontinuation_year?: string | undefined, cms_approval_date?: string | undefined, cms_discontinuation_date?: string | undefined, categories?: (Array<'HORMONAL_THERAPY' | 'ANCILLARY' | 'CHEMOTHERAPY' | 'IMMUNOTHERAPY' | 'RADIOPHARMACEUTICAL' | 'HEME_TRANSPLANT_ENDOCRINE_PROCEDURE'>) | undefined, major_drug_class?: string | undefined, minor_drug_class?: string | undefined, oral?: boolean | undefined, date_added?: string | undefined, date_modified?: string | undefined, score?: number | undefined}; export type UpdateApiRestHcpcsCodeCodeArgs = {code: string, body: HcpcsProcedure}; export type UpdateApiRestHcpcsCodeCodeOptions = {baseUrl?: string | undefined, apiKeyScheme?: string | undefined, fetch?: typeof fetch | undefined}; export const hcpcsProcedure = z.object({hcpcs_code: z.string().optional(), generic_name: z.string().optional(), description: z.string().optional(), brand_names: z.array(z.string()).optional(), strength: z.string().optional(), fda_approval_year: z.string().optional(), fda_discontinuation_year: z.string().optional(), cms_approval_date: z.string().optional(), cms_discontinuation_date: z.string().optional(), categories: z.array(z.enum(["HORMONAL_THERAPY", "ANCILLARY", "CHEMOTHERAPY", "IMMUNOTHERAPY", "RADIOPHARMACEUTICAL", "HEME_TRANSPLANT_ENDOCRINE_PROCEDURE"])).optional(), major_drug_class: z.string().optional(), minor_drug_class: z.string().optional(), oral: z.boolean().optional(), date_added: z.string().optional(), date_modified: z.string().optional(), score: z.number().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 }; /** * Update a procedure * * PUT /rest/hcpcs/code/{code} */ export const updateApiRestHcpcsCodeCode = async (args: UpdateApiRestHcpcsCodeCodeArgs, options?: UpdateApiRestHcpcsCodeCodeOptions) => { const {baseUrl = "https://api.seer.cancer.gov", fetch: fetchFn = fetch, apiKeyScheme} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (apiKeyScheme !== undefined) headers.set("X-SEERAPI-Key", apiKeyScheme) const url = `${baseUrl.replace(/\/+$/, '')}/rest/hcpcs/code/${encodeURIComponent(String(args.code))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "PUT", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return validateResponse(hcpcsProcedure, await res.json()) };