import {z} from 'zod' export type TagFilterList = {tags?: Array | undefined}; export type DicomConfig = {filterProfile?: ('TAG_FILTER_PROFILE_UNSPECIFIED' | 'MINIMAL_KEEP_LIST_PROFILE' | 'ATTRIBUTE_CONFIDENTIALITY_BASIC_PROFILE' | 'KEEP_ALL_PROFILE' | 'DEIDENTIFY_TAG_CONTENTS') | undefined, keepList?: TagFilterList | undefined, removeList?: TagFilterList | undefined, skipIdRedaction?: boolean | undefined}; export type FieldMetadata = {action?: ('ACTION_UNSPECIFIED' | 'TRANSFORM' | 'INSPECT_AND_TRANSFORM' | 'DO_NOT_TRANSFORM') | undefined, paths?: Array | undefined}; export type FhirConfig = {defaultKeepExtensions?: boolean | undefined, fieldMetadataList?: Array | undefined}; export type CustomRegex = {groupIndexes?: Array | undefined, pattern?: string | undefined}; export type ImageConfig = {customRegexes?: Array | undefined, textRedactionMode?: ('TEXT_REDACTION_MODE_UNSPECIFIED' | 'REDACT_ALL_TEXT' | 'REDACT_SENSITIVE_TEXT' | 'REDACT_NO_TEXT') | undefined}; export type CharacterMaskConfig = {maskingCharacter?: string | undefined}; export type KmsWrappedCryptoKey = {cryptoKey?: string | undefined, wrappedKey?: string | undefined}; export type CryptoHashConfig = {cryptoKey?: string | undefined, kmsWrapped?: KmsWrappedCryptoKey | undefined}; export type DateShiftConfig = {cryptoKey?: string | undefined, kmsWrapped?: KmsWrappedCryptoKey | undefined}; export type RedactConfig = Record; export type ReplaceWithInfoTypeConfig = Record; export type InfoTypeTransformation = {characterMaskConfig?: CharacterMaskConfig | undefined, cryptoHashConfig?: CryptoHashConfig | undefined, dateShiftConfig?: DateShiftConfig | undefined, infoTypes?: Array | undefined, redactConfig?: RedactConfig | undefined, replaceWithInfoTypeConfig?: ReplaceWithInfoTypeConfig | undefined}; export type TextConfig = {additionalTransformations?: Array | undefined, excludeInfoTypes?: Array | undefined, transformations?: Array | undefined}; export type DeidentifyConfig = {dicom?: DicomConfig | undefined, fhir?: FhirConfig | undefined, image?: ImageConfig | undefined, text?: TextConfig | undefined, useRegionalDataProcessing?: boolean | undefined}; export type DeidentifyDatasetRequest = {config?: DeidentifyConfig | undefined, destinationDataset?: string | undefined, gcsConfigUri?: string | undefined}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdDeidentifyArgs = {projectsId: string, locationsId: string, datasetsId: string, body: DeidentifyDatasetRequest}; export type CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdDeidentifyOptions = {baseUrl?: string | undefined, Oauth2?: string | undefined, Oauth2c?: string | undefined, fetch?: typeof fetch | undefined}; export const status = z.object({code: z.number().int().optional(), details: z.array(z.record(z.string(), z.unknown())).optional(), message: z.string().optional()}); export const operation = z.object({done: z.boolean().optional(), error: status.optional(), metadata: z.record(z.string(), z.unknown()).optional(), name: z.string().optional(), response: z.record(z.string(), z.unknown()).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 dataset containing de-identified data from the source dataset. The metadata field type is OperationMetadata. If the request is successful, the response field type is DeidentifySummary. If errors occur, error is set. The LRO result may still be successful if de-identification fails for some DICOM instances. The new de-identified dataset will not contain these failed resources. Failed resource totals are tracked in Operation.metadata. Error details are also logged to Cloud Logging. For more information, see [Viewing error logs in Cloud Logging](https://cloud.google.com/healthcare/docs/how-tos/logging). * * POST /v1/projects/{projectsId}/locations/{locationsId}/datasets/{datasetsId}:deidentify * * Also accepts auth: Oauth2 + Oauth2c */ export const createApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdDeidentify = async (args: CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdDeidentifyArgs, options?: CreateApiV1ProjectsProjectsIdLocationsLocationsIdDatasetsDatasetsIdDeidentifyOptions) => { 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 (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))}:deidentify${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(operation, await res.json()) };