import {z} from 'zod' export type Hl7V2NotificationConfig = {filter?: string | undefined, pubsubTopic?: string | undefined}; export type SchemaSegment = {maxOccurs?: number | undefined, minOccurs?: number | undefined, type?: string | undefined}; export type GroupOrSegment = {group?: SchemaGroup | undefined, segment?: SchemaSegment | undefined}; export type SchemaGroup = {choice?: boolean | undefined, maxOccurs?: number | undefined, members?: Array | undefined, minOccurs?: number | undefined, name?: string | undefined}; export type VersionSource = {mshField?: string | undefined, value?: string | undefined}; export type Hl7SchemaConfig = {messageSchemaConfigs?: {[key: string]: SchemaGroup} | undefined, version?: Array | undefined}; export type Field = {maxOccurs?: number | undefined, minOccurs?: number | undefined, name?: string | undefined, table?: string | undefined, type?: string | undefined}; export type Type = {fields?: Array | undefined, name?: string | undefined, primitive?: ('PRIMITIVE_UNSPECIFIED' | 'STRING' | 'VARIES' | 'UNESCAPED_STRING') | undefined}; export type Hl7TypesConfig = {type?: Array | undefined, version?: Array | undefined}; export type SchemaPackage = {ignoreMinOccurs?: boolean | undefined, schemas?: Array | undefined, schematizedParsingType?: ('SCHEMATIZED_PARSING_TYPE_UNSPECIFIED' | 'SOFT_FAIL' | 'HARD_FAIL') | undefined, types?: Array | undefined, unexpectedSegmentHandling?: ('UNEXPECTED_SEGMENT_HANDLING_MODE_UNSPECIFIED' | 'FAIL' | 'SKIP' | 'PARSE') | undefined}; export type ParserConfig = {allowNullHeader?: boolean | undefined, schema?: SchemaPackage | undefined, segmentTerminator?: string | undefined, version?: ('PARSER_VERSION_UNSPECIFIED' | 'V1' | 'V2' | 'V3') | undefined}; export type Hl7V2Store = {labels?: {[key: string]: string} | undefined, name?: string | undefined, notificationConfigs?: Array | undefined, parserConfig?: ParserConfig | undefined, rejectDuplicateMessage?: boolean | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdHl7V2StoresArgs = {projectsId: string, locationsId: string, datasetsId: string, hl7V2StoreId?: string | undefined, body: Hl7V2Store}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdHl7V2StoresOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const hl7V2NotificationConfig = z.object({filter: z.string().optional(), pubsubTopic: z.string().optional()}); export const schemaSegment = z.object({maxOccurs: z.number().int().optional(), minOccurs: z.number().int().optional(), type: z.string().optional()}); export const groupOrSegment = z.object({group: z.lazy(() => schemaGroup.optional()), segment: schemaSegment.optional()}); export const schemaGroup: z.ZodType = z.object({choice: z.boolean().optional(), maxOccurs: z.number().int().optional(), members: z.array(groupOrSegment).optional(), minOccurs: z.number().int().optional(), name: z.string().optional()}); export const versionSource = z.object({mshField: z.string().optional(), value: z.string().optional()}); export const hl7SchemaConfig = z.object({messageSchemaConfigs: z.record(z.string(), schemaGroup).optional(), version: z.array(versionSource).optional()}); export const field = z.object({maxOccurs: z.number().int().optional(), minOccurs: z.number().int().optional(), name: z.string().optional(), table: z.string().optional(), type: z.string().optional()}); export const type = z.object({fields: z.array(field).optional(), name: z.string().optional(), primitive: z.enum(["PRIMITIVE_UNSPECIFIED", "STRING", "VARIES", "UNESCAPED_STRING"]).optional()}); export const hl7TypesConfig = z.object({type: z.array(type).optional(), version: z.array(versionSource).optional()}); export const schemaPackage = z.object({ignoreMinOccurs: z.boolean().optional(), schemas: z.array(hl7SchemaConfig).optional(), schematizedParsingType: z.enum(["SCHEMATIZED_PARSING_TYPE_UNSPECIFIED", "SOFT_FAIL", "HARD_FAIL"]).optional(), types: z.array(hl7TypesConfig).optional(), unexpectedSegmentHandling: z.enum(["UNEXPECTED_SEGMENT_HANDLING_MODE_UNSPECIFIED", "FAIL", "SKIP", "PARSE"]).optional()}); export const parserConfig = z.object({allowNullHeader: z.boolean().optional(), schema: schemaPackage.optional(), segmentTerminator: z.string().optional(), version: z.enum(["PARSER_VERSION_UNSPECIFIED", "V1", "V2", "V3"]).optional()}); export const hl7V2Store = z.object({labels: z.record(z.string(), z.string()).optional(), name: z.string().optional(), notificationConfigs: z.array(hl7V2NotificationConfig).optional(), parserConfig: parserConfig.optional(), rejectDuplicateMessage: z.boolean().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 }; /** * Creates a new HL7v2 store within the parent dataset. * * POST /v1/projects/{projectsId}/locations/{locationsId}/datasets/{datasetsId}/hl7V2Stores * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdHl7V2Stores = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdHl7V2StoresArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdHl7V2StoresOptions) => { const {baseUrl = "https://healthcare.googleapis.com", fetch: fetchFn = fetch, Oauth2, Oauth2c} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "application/json") if (args.hl7V2StoreId != null) query.append("hl7V2StoreId", String(args.hl7V2StoreId)) if (Oauth2 !== undefined) headers.set('authorization', `Bearer ${Oauth2}`) if (Oauth2c !== undefined) headers.set('authorization', `Bearer ${Oauth2c}`) const url = `${baseUrl.replace(/\/+$/, '')}/v1/projects/${encodeURIComponent(String(args.projectsId))}/locations/${encodeURIComponent(String(args.locationsId))}/datasets/${encodeURIComponent(String(args.datasetsId))}/hl7V2Stores${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", 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(hl7V2Store, await res.json()) };