import {z} from 'zod' export type GetApiStudiesStudyIdPatientsArgs = {direction?: ('ASC' | 'DESC') | undefined, pageNumber?: number | undefined, pageSize?: number | undefined, projection?: ('DETAILED' | 'ID' | 'META' | 'SUMMARY') | undefined, sortBy?: 'patientId' | undefined, studyId: string}; export type GetApiStudiesStudyIdPatientsOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; export const typeOfCancer = z.object({cancerTypeId: z.string(), dedicatedColor: z.string().optional(), name: z.string().optional(), parent: z.string().optional(), shortName: z.string().optional()}); export const cancerStudy = z.object({allSampleCount: z.number().int().optional(), cancerType: typeOfCancer.optional(), cancerTypeId: z.string().optional(), citation: z.string().optional(), cnaSampleCount: z.number().int().optional(), completeSampleCount: z.number().int().optional(), description: z.string().optional(), groups: z.string().optional(), importDate: z.string().optional(), massSpectrometrySampleCount: z.number().int().optional(), methylationHm27SampleCount: z.number().int().optional(), miRnaSampleCount: z.number().int().optional(), mrnaMicroarraySampleCount: z.number().int().optional(), mrnaRnaSeqSampleCount: z.number().int().optional(), mrnaRnaSeqV2SampleCount: z.number().int().optional(), name: z.string().optional(), pmid: z.string().optional(), publicStudy: z.boolean().optional(), readPermission: z.boolean().optional(), referenceGenome: z.string().optional(), rppaSampleCount: z.number().int().optional(), sequencedSampleCount: z.number().int().optional(), status: z.number().int().optional(), studyId: z.string(), treatmentCount: z.number().int().optional()}); export const patient = z.object({cancerStudy: cancerStudy.optional(), patientId: z.string(), studyId: z.string(), uniquePatientKey: z.string().optional(), uniqueSampleKey: z.string().optional()}); export const getApiStudiesStudyIdPatientsResponse = z.array(patient); 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 all patients in a study * * GET /studies/{studyId}/patients */ export const getApiStudiesStudyIdPatients = async (args: GetApiStudiesStudyIdPatientsArgs, options: GetApiStudiesStudyIdPatientsOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/json") if (args.direction != null) query.append("direction", String(args.direction)) if (args.pageNumber != null) query.append("pageNumber", String(args.pageNumber)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (args.projection != null) query.append("projection", String(args.projection)) if (args.sortBy != null) query.append("sortBy", String(args.sortBy)) const url = `${baseUrl.replace(/\/+$/, '')}/studies/${encodeURIComponent(String(args.studyId))}/patients${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(getApiStudiesStudyIdPatientsResponse, await res.json()) };