创建和管理 DICOM 存储区

本页面介绍了如何创建、修改、查看和删除医学数字成像和通信 (DICOM) 存储区。如需详细了解 Cloud Healthcare API 如何符合 DICOM 标准,请参阅 DICOM 一致性声明

创建 DICOM 存储区

您必须先创建一个数据集,然后才能创建 DICOM 存储区。

以下示例展示了如何创建 DICOM 存储区:

控制台

要创建 DICOM 存储区,请执行以下操作:

  1. 在 Cloud Console 中,转到“数据集”页面。

    转到“数据集”页面

  2. 打开要在其中创建 DICOM 存储区的数据集。
  3. 点击创建数据存储区
  4. 输入您选择的名称,该名称在您的数据集中必须是独一无二的。如果名称不是唯一的,则创建数据存储区会失败。
  5. 选择 DICOM 作为数据存储区类型。
  6. 如果要为数据存储区配置 Pub/Sub 主题,请键入主题名称。 指定 Pub/Sub 主题时,请输入主题的限定 URI,如以下示例所示:
    projects/PROJECT_ID/topics/PUBSUB_TOPIC
    
  7. 点击创建

新的数据存储区会显示在列表中。

gcloud

要在数据集中创建 DICOM 存储区,请运行 gcloud healthcare dicom-stores create 命令。

  • DICOM 存储区 ID 在数据集中必须具有唯一性。它可以是从 1 到 256 个字符的任意 Unicode 字符串,由数字、字母、下划线、短划线和句点组成。
  • 要向 Pub/Sub 主题通知 DICOM 存储区的更改,请使用 --pubsub-topic 参数指定现有 Pub/Sub 主题名称。指定 Pub/Sub 主题时,请输入主题的限定 URI,如以下示例所示:
    projects/PROJECT_ID/topics/PUBSUB_TOPIC
    

以下示例展示了如何创建 DICOM 存储区。

gcloud healthcare dicom-stores create DICOM_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION \
  [--pubsub-topic=projects/PROJECT_ID/topics/PUBSUB_TOPIC]

如果请求成功,命令提示符将显示以下内容:

Created dicomStore [DICOM_STORE_ID].

API

如需创建 DICOM 存储区,请使用 projects.locations.datasets.dicomStores.create 方法。

curl

如需创建 DICOM 存储区,请发出 POST 请求并指定以下信息:

  • 父级数据集的名称和位置
  • DICOM 存储区的名称。DICOM 存储区 ID 在其父数据集中必须唯一。它可以是从 1 到 256 个字符的任意 Unicode 字符串,由数字、字母、下划线、短划线和句点组成。
  • 访问令牌
  • (可选)Cloud Healthcare API 将向其发送 DICOM 存储区更改通知的现有 Pub/Sub 主题。如需了解如何配置 Pub/Sub 主题,请参阅修改 DICOM 存储区

以下示例展示了使用 curlPOST 请求。

curl -X POST \
    --data "" \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores?dicomStoreId=DICOM_STORE_ID"

如果请求成功,则服务器会返回 JSON 格式的以下响应:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID"
}

PowerShell

如需创建 DICOM 存储区,请发出 POST 请求并指定以下信息:

  • 父级数据集的名称和位置
  • DICOM 存储区的名称。DICOM 存储区 ID 在其父数据集中必须唯一。它可以是从 1 到 256 个字符的任意 Unicode 字符串,由数字、字母、下划线、短划线和句点组成。
  • 访问令牌
  • (可选)Cloud Healthcare API 将向其发送 DICOM 存储区更改通知的现有 Pub/Sub 主题。如需了解如何配置 Pub/Sub 主题,请参阅修改 DICOM 存储区

以下示例展示了使用 Windows PowerShell 的 POST 请求:

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores?dicomStoreId=DICOM_STORE_ID" | Select-Object -Expand Content

如果请求成功,则服务器返回 JSON 格式的类似下列示例的响应:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID"
}

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// createDICOMStore creates a DICOM store.
func createDICOMStore(w io.Writer, projectID, location, datasetID, dicomStoreID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %v", err)
	}

	storesService := healthcareService.Projects.Locations.Datasets.DicomStores

	store := &healthcare.DicomStore{}
	parent := fmt.Sprintf("projects/%s/locations/%s/datasets/%s", projectID, location, datasetID)

	resp, err := storesService.Create(parent, store).DicomStoreId(dicomStoreID).Do()
	if err != nil {
		return fmt.Errorf("Create: %v", err)
	}

	fmt.Fprintf(w, "Created DICOM store: %q\n", resp.Name)
	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.DicomStore;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class DicomStoreCreate {
  private static final String DATASET_NAME = "projects/%s/locations/%s/datasets/%s";
  private static final JsonFactory JSON_FACTORY = new JacksonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void dicomStoreCreate(String datasetName, String dicomStoreId) throws IOException {
    // String datasetName =
    //     String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-dataset-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    // Configure the dicomStore to be created.
    Map<String, String> labels = new HashMap<String, String>();
    labels.put("key1", "value1");
    labels.put("key2", "value2");
    DicomStore content = new DicomStore().setLabels(labels);

    // Create request and configure any parameters.
    DicomStores.Create request =
        client
            .projects()
            .locations()
            .datasets()
            .dicomStores()
            .create(datasetName, content)
            .setDicomStoreId(dicomStoreId);

    // Execute the request and process the results.
    DicomStore response = request.execute();
    System.out.println("DICOM store created: " + response.toPrettyString());
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }
}

Node.js

const {google} = require('googleapis');
const healthcare = google.healthcare('v1');

const createDicomStore = async () => {
  const auth = await google.auth.getClient({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  });
  google.options({auth});

  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const dicomStoreId = 'my-dicom-store';
  const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
  const request = {parent, dicomStoreId};

  await healthcare.projects.locations.datasets.dicomStores.create(request);
  console.log(`Created DICOM store: ${dicomStoreId}`);
};

createDicomStore();

Python

def create_dicom_store(project_id, cloud_region, dataset_id, dicom_store_id):
    """Creates a new DICOM store within the parent dataset."""
    client = get_client()
    dicom_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, cloud_region, dataset_id
    )

    request = (
        client.projects()
        .locations()
        .datasets()
        .dicomStores()
        .create(parent=dicom_store_parent, body={}, dicomStoreId=dicom_store_id)
    )

    response = request.execute()
    print("Created DICOM store: {}".format(dicom_store_id))
    return response

编辑 DICOM 存储区

以下示例展示了如何对 DICOM 存储区进行以下更改:

  • 修改 Cloud Healthcare API 将向其发送 DICOM 存储区更改通知的 Pub/Sub 主题。
  • 修改标签。标签是帮助您整理 Google Cloud 资源的键值对。
指定 Pub/Sub 主题时,请输入主题的限定 URI,如以下示例所示:
projects/PROJECT_ID/topics/PUBSUB_TOPIC
要使通知正常工作,必须向 Cloud Healthcare Service Agent 服务帐号授予其他权限。如需了解详情,请参阅 DICOM、FHIR 和 HL7v2 存储区 Pub/Sub 权限

控制台

Cloud Console 不支持修改 Pub/Sub 主题或标签。请改用 curl、Windows PowerShell 或您的首选语言。

gcloud

要更新 DICOM 存储区,请运行 gcloud healthcare dicom-stores update 命令。

以下示例展示了如何更新 DICOM 存储区的 Pub/Sub 主题。gcloud 工具不支持修改标签。

gcloud healthcare dicom-stores update DICOM_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION \
  --pubsub-topic=projects/PROJECT_ID/topics/PUBSUB_TOPIC

如果请求成功,命令提示符将显示 DICOM 存储区详情,包括新主题名称:

Updated dicomStore [DICOM_STORE_ID].
name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicom-stores/DICOM_STORE_ID
notificationConfig:
pubsubTopic: projects/PROJECT_ID/topics/PUBSUB_TOPIC

API

如需修改 DICOM 存储区,请使用 projects.locations.datasets.dicomStores.patch 方法。

curl

如需修改 DICOM 存储区,请发出 PATCH 请求并指定以下信息:

  • 父级数据集的名称和位置
  • DICOM 存储区的名称
  • 要更新的元数据。在此示例中,Pub/Sub 主题的限定 URI 以及要更新为以逗号分隔的键值对列表的标签。
  • 更新掩码
  • 访问令牌

以下示例展示了使用 curlPATCH 请求。

curl -X PATCH \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    --data "{
      'notificationConfig': {
        'pubsubTopic':'projects/PROJECT_ID/topics/PUBSUB_TOPIC'
      },
      'labels': {
        'KEY1':'VALUE1','KEY2':'VALUE2'
      }
    }" \
    "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID?updateMask=notificationConfig,labels"

如果请求成功,则服务器返回 JSON 格式的类似下列示例的响应:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID",
  "notificationConfig": {
    "pubsubTopic": "projects/PROJECT_ID/topics/PUBSUB_TOPIC"
  },
  'labels': {
    'KEY1':'VALUE1','KEY2':'VALUE2'
  }
}

PowerShell

如需修改 DICOM 存储区,请发出 PATCH 请求并指定以下信息:

  • 父级数据集的名称和位置
  • DICOM 存储区的名称
  • 要更新的元数据。在此示例中,Pub/Sub 主题的限定 URI 以及要更新为以逗号分隔的键值对列表的标签。
  • 更新掩码
  • 访问令牌

以下示例展示了使用 Windows PowerShell 的 PATCH 请求:

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Patch `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body "{
      'notificationConfig': {
        'pubsubTopic': 'projects/PROJECT_ID/topics/PUBSUB_TOPIC'
      },
      'labels': {
        'KEY1':'VALUE1','KEY2':'VALUE2'
      }
  }" `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID?updateMask=notificationConfig,labels" | Select-Object -Expand Content

如果请求成功,则服务器返回 JSON 格式的类似下列示例的响应:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID",
  "notificationConfig": {
    "pubsubTopic": "projects/PROJECT_ID/topics/PUBSUB_TOPIC"
  },
  'labels': {
    'KEY1':'VALUE1','KEY2':'VALUE2'
  }
}

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// patchDICOMStore updates (patches) a DICOM store by updating its Pub/sub topic name.
func patchDICOMStore(w io.Writer, projectID, location, datasetID, dicomStoreID, topicName string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %v", err)
	}

	storesService := healthcareService.Projects.Locations.Datasets.DicomStores

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/dicomStores/%s", projectID, location, datasetID, dicomStoreID)

	if _, err := storesService.Patch(name, &healthcare.DicomStore{
		NotificationConfig: &healthcare.NotificationConfig{
			PubsubTopic: topicName, // format is "projects/*/locations/*/topics/*"
		},
	}).UpdateMask("notificationConfig").Do(); err != nil {
		return fmt.Errorf("Patch: %v", err)
	}

	fmt.Fprintf(w, "Patched DICOM store %s with Pub/sub topic %s\n", datasetID, topicName)

	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.DicomStore;
import com.google.api.services.healthcare.v1.model.NotificationConfig;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;

public class DicomStorePatch {
  private static final String DICOM_NAME = "projects/%s/locations/%s/datasets/%s/dicomStores/%s";
  private static final JsonFactory JSON_FACTORY = new JacksonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void patchDicomStore(String dicomStoreName, String pubsubTopic) throws IOException {
    // String dicomStoreName =
    //    String.format(
    //        DICOM_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-dicom-id");
    // String pubsubTopic = "your-pubsub-topic";

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    // Fetch the initial state of the DICOM store.
    DicomStores.Get getRequest =
        client.projects().locations().datasets().dicomStores().get(dicomStoreName);
    DicomStore store = getRequest.execute();

    // Update the DicomStore fields as needed as needed. For a full list of DicomStore fields, see:
    // https://cloud.google.com/healthcare/docs/reference/rest/v1/projects.locations.datasets.dicomStores#DicomStore
    store.setNotificationConfig(new NotificationConfig().setPubsubTopic(pubsubTopic));

    // Create request and configure any parameters.
    DicomStores.Patch request =
        client
            .projects()
            .locations()
            .datasets()
            .dicomStores()
            .patch(dicomStoreName, store)
            .setUpdateMask("notificationConfig");

    // Execute the request and process the results.
    store = request.execute();
    System.out.println("DICOM store patched: \n" + store.toPrettyString());
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }
}

Node.js

const {google} = require('googleapis');
const healthcare = google.healthcare('v1');

const patchDicomStore = async () => {
  const auth = await google.auth.getClient({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  });
  google.options({auth});

  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const dicomStoreId = 'my-dicom-store';
  // const pubsubTopic = 'my-topic'
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/dicomStores/${dicomStoreId}`;
  const request = {
    name,
    updateMask: 'notificationConfig',
    resource: {
      notificationConfig: {
        pubsubTopic: `projects/${projectId}/topics/${pubsubTopic}`,
      },
    },
  };

  await healthcare.projects.locations.datasets.dicomStores.patch(request);
  console.log(
    `Patched DICOM store ${dicomStoreId} with Cloud Pub/Sub topic ${pubsubTopic}`
  );
};

patchDicomStore();

Python

def patch_dicom_store(
    project_id, cloud_region, dataset_id, dicom_store_id, pubsub_topic
):
    """Updates the DICOM store."""
    client = get_client()
    dicom_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, cloud_region, dataset_id
    )
    dicom_store_name = "{}/dicomStores/{}".format(dicom_store_parent, dicom_store_id)

    patch = {
        "notificationConfig": {
            "pubsubTopic": "projects/{}/topics/{}".format(project_id, pubsub_topic)
        }
    }

    request = (
        client.projects()
        .locations()
        .datasets()
        .dicomStores()
        .patch(name=dicom_store_name, updateMask="notificationConfig", body=patch)
    )

    response = request.execute()
    print(
        "Patched DICOM store {} with Cloud Pub/Sub topic: {}".format(
            dicom_store_id, pubsub_topic
        )
    )

    return response

获取 DICOM 存储区详细信息

以下示例展示了如何获取 DICOM 存储区的详情。

控制台

如需查看 DICOM 存储区的详情,请执行以下操作:

  1. 在 Cloud Console 中,转到“数据集”页面。

    转到“数据集”页面

  2. 点击包含 DICOM 存储区的数据集的 ID。
  3. 点击 DICOM 存储区的名称。

gcloud

如需查看 DICOM 存储区的相关详情,请运行 gcloud healthcare dicom-stores describe 命令。

以下示例展示了如何获取 DICOM 存储区的详细信息:

gcloud healthcare dicom-stores describe DICOM_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION

如果请求成功,命令提示符会显示 DICOM 存储区详情:

name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicom-stores/DICOM_STORE_ID

API

如需获取 DICOM 存储区的相关详情,请使用 projects.locations.datasets.dicomStores.get 方法。

curl

如需获取 DICOM 存储区的相关详情,请发出 GET 请求并指定以下信息:

  • 父级数据集的名称和位置
  • DICOM 存储区的名称
  • 访问令牌

以下示例展示了使用 curlGET 请求。

curl -X GET \
     -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
     "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID"

如果请求成功,则服务器返回 JSON 格式的类似下列示例的响应:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID"
}

如果您在 DicomStore 资源中配置了任何字段,它们也会出现在响应中。

PowerShell

如需获取 DICOM 存储区的相关详情,请发出 GET 请求并指定以下信息:

  • 父级数据集的名称和位置
  • DICOM 存储区的名称
  • 访问令牌

以下示例展示了使用 Windows PowerShell 的 GET 请求:

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID" | Select-Object -Expand Content

如果请求成功,则服务器返回 JSON 格式的类似下列示例的响应:

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID"
}

如果您在 DicomStore 资源中配置了任何字段,它们也会出现在响应中。

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// getDICOMStore gets a DICOM store.
func getDICOMStore(w io.Writer, projectID, location, datasetID, dicomStoreID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %v", err)
	}

	storesService := healthcareService.Projects.Locations.Datasets.DicomStores

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/dicomStores/%s", projectID, location, datasetID, dicomStoreID)

	store, err := storesService.Get(name).Do()
	if err != nil {
		return fmt.Errorf("Get: %v", err)
	}

	fmt.Fprintf(w, "Got DICOM store: %+v\n", store)
	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.DicomStore;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;

public class DicomStoreGet {
  private static final String DICOM_NAME = "projects/%s/locations/%s/datasets/%s/dicomStores/%s";
  private static final JsonFactory JSON_FACTORY = new JacksonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void dicomeStoreGet(String dicomStoreName) throws IOException {
    // String dicomStoreName =
    //    String.format(
    //        DICOM_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-dicom-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    // Create request and configure any parameters.
    DicomStores.Get request =
        client.projects().locations().datasets().dicomStores().get(dicomStoreName);

    // Execute the request and process the results.
    DicomStore store = request.execute();
    System.out.println("DICOM store retrieved: \n" + store.toPrettyString());
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }
}

Node.js

const {google} = require('googleapis');
const healthcare = google.healthcare('v1');

const getDicomStore = async () => {
  const auth = await google.auth.getClient({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  });
  google.options({auth});

  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const dicomStoreId = 'my-dicom-store';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/dicomStores/${dicomStoreId}`;
  const request = {name};

  const dicomStore = await healthcare.projects.locations.datasets.dicomStores.get(
    request
  );
  console.log(dicomStore.data);
};

getDicomStore();

Python

def get_dicom_store(project_id, cloud_region, dataset_id, dicom_store_id):
    """Gets the specified DICOM store."""
    client = get_client()
    dicom_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, cloud_region, dataset_id
    )
    dicom_store_name = "{}/dicomStores/{}".format(dicom_store_parent, dicom_store_id)

    dicom_stores = client.projects().locations().datasets().dicomStores()
    dicom_store = dicom_stores.get(name=dicom_store_name).execute()

    print(json.dumps(dicom_store, indent=2))
    return dicom_store

列出数据集中的 DICOM 存储区

以下示例展示了如何列出数据集中的 DICOM 存储区:

控制台

要查看数据集中的数据存储,请执行以下操作:

  1. 在 Cloud Console 中,转到“数据集”页面。

    转到“数据集”页面

  2. 点击要查看其数据存储的数据集的 ID。

gcloud

如需列出数据集中的 DICOM 存储区,请运行 gcloud healthcare dicom-stores list 命令。

gcloud healthcare dicom-stores list --dataset=DATASET_ID

如果请求成功,命令提示符将列出 DICOM 存储区:

ID              LOCATION     TOPIC
DICOM_STORE_ID  LOCATION       projects/PROJECT_ID/topics/PUBSUB_TOPIC

API

如需列出数据集中的 DICOM 存储区,请使用 projects.locations.datasets.dicomStores.list 方法。

curl

如需列出数据集中的 DICOM 存储区,请发出 GET 请求并指定以下信息:

  • 父级数据集的名称和位置
  • 访问令牌

以下示例展示了使用 curlGET 请求。

curl -X GET \
     -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
     "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores"

如果请求成功,则服务器返回 JSON 格式的类似下列示例的响应:

{
  "dicomStores": [
    {
      "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID"
    },
    {
      ...
    }
  ]
}

如果您在 DicomStore 资源中配置了任何字段,它们也会出现在响应中。

PowerShell

如需列出数据集中的 DICOM 存储区,请发出 GET 请求并指定以下信息:

  • 父数据集的名称
  • 访问令牌

以下示例展示了使用 Windows PowerShell 的 GET 请求:

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores" | Select-Object -Expand Content

如果请求成功,则服务器返回 JSON 格式的类似下列示例的响应:

{
  "dicomStores": [
    {
      "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID"
    },
    {
      ...
    }
  ]
}

如果您在 DicomStore 资源中配置了任何字段,它们也会出现在响应中。

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// listDICOMStores prints a list of DICOM stores to w.
func listDICOMStores(w io.Writer, projectID, location, datasetID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %v", err)
	}

	storesService := healthcareService.Projects.Locations.Datasets.DicomStores

	parent := fmt.Sprintf("projects/%s/locations/%s/datasets/%s", projectID, location, datasetID)

	resp, err := storesService.List(parent).Do()
	if err != nil {
		return fmt.Errorf("List: %v", err)
	}

	fmt.Fprintln(w, "DICOM Stores:")
	for _, s := range resp.DicomStores {
		fmt.Fprintln(w, s.Name)
	}
	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.DicomStore;
import com.google.api.services.healthcare.v1.model.ListDicomStoresResponse;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DicomStoreList {
  private static final String DATASET_NAME = "projects/%s/locations/%s/datasets/%s";
  private static final JsonFactory JSON_FACTORY = new JacksonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void dicomStoreList(String datasetName) throws IOException {
    // String datasetName =
    //     String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-dataset-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    // Results are paginated, so multiple queries may be required.
    String pageToken = null;
    List<DicomStore> stores = new ArrayList<>();
    do {
      // Create request and configure any parameters.
      DicomStores.List request =
          client
              .projects()
              .locations()
              .datasets()
              .dicomStores()
              .list(datasetName)
              .setPageSize(100) // Specify pageSize up to 1000
              .setPageToken(pageToken);

      // Execute response and collect results.
      ListDicomStoresResponse response = request.execute();
      stores.addAll(response.getDicomStores());

      // Update the page token for the next request.
      pageToken = response.getNextPageToken();
    } while (pageToken != null);

    // Print results.
    System.out.printf("Retrieved %s DICOM stores: \n", stores.size());
    for (DicomStore data : stores) {
      System.out.println("\t" + data.toPrettyString());
    }
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }
}

Node.js

const {google} = require('googleapis');
const healthcare = google.healthcare('v1');

const listDicomStores = async () => {
  const auth = await google.auth.getClient({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  });
  google.options({auth});

  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
  const request = {parent};

  const dicomStores = await healthcare.projects.locations.datasets.dicomStores.list(
    request
  );
  console.log(dicomStores.data);
};

listDicomStores();

Python

def list_dicom_stores(project_id, cloud_region, dataset_id):
    """Lists the DICOM stores in the given dataset."""
    client = get_client()
    dicom_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, cloud_region, dataset_id
    )

    dicom_stores = (
        client.projects()
        .locations()
        .datasets()
        .dicomStores()
        .list(parent=dicom_store_parent)
        .execute()
        .get("dicomStores", [])
    )

    for dicom_store in dicom_stores:
        print(dicom_store)

    return dicom_stores

删除 DICOM 存储区

以下示例展示了如何删除 DICOM 存储区:

控制台

如需删除数据存储区,请执行以下操作:

  1. 在 Cloud Console 中,转到“数据集”页面。

    转到“数据集”页面

  2. 点击数据集 ID 以打开数据集。
  3. 选择您想要删除的数据存储区,然后点击删除
  4. 输入数据存储区名称,然后点击删除以确认删除。

gcloud

如需删除 DICOM 存储区,请运行 gcloud healthcare dicom-stores delete 命令:

  1. 运行 delete 命令。
gcloud healthcare dicom-stores delete DICOM_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION
  1. 要确认,请键入 Y

如果请求成功,命令提示符将显示以下响应:

Deleted dicomStore [DICOM_STORE_ID].

API

如需删除 DICOM 存储区,请使用 projects.locations.datasets.dicomStores.delete 方法。

curl

如需删除 DICOM 存储区,请发出 DELETE 请求并指定以下信息:

  • 父级数据集的名称和位置
  • 要删除的 DICOM 存储区的名称
  • 访问令牌

以下示例展示了使用 curlDELETE 请求。

curl -X DELETE \
     -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
     "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID"

如果请求成功,服务器将以 JSON 格式返回空响应正文:

{}

PowerShell

如需删除 DICOM 存储区,请发出 DELETE 请求并指定以下信息:

  • 父级数据集的名称和位置
  • 要删除的 DICOM 存储区的名称
  • 访问令牌

以下示例展示了使用 Windows PowerShell 的 DELETE 请求:

$cred = gcloud auth application-default print-access-token
$headers = @{ Authorization = "Bearer $cred" }

Invoke-WebRequest `
  -Method Delete `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID" | Select-Object -Expand Content

如果请求成功,服务器将以 JSON 格式返回空响应正文:

{}

Go

import (
	"context"
	"fmt"
	"io"

	healthcare "google.golang.org/api/healthcare/v1"
)

// deleteDICOMStore deletes an DICOM store.
func deleteDICOMStore(w io.Writer, projectID, location, datasetID, dicomStoreID string) error {
	ctx := context.Background()

	healthcareService, err := healthcare.NewService(ctx)
	if err != nil {
		return fmt.Errorf("healthcare.NewService: %v", err)
	}

	storesService := healthcareService.Projects.Locations.Datasets.DicomStores

	name := fmt.Sprintf("projects/%s/locations/%s/datasets/%s/dicomStores/%s", projectID, location, datasetID, dicomStoreID)
	if _, err := storesService.Delete(name).Do(); err != nil {
		return fmt.Errorf("Delete: %v", err)
	}

	fmt.Fprintf(w, "Deleted DICOM store: %q\n", name)
	return nil
}

Java

import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.services.healthcare.v1.CloudHealthcare;
import com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;

public class DicomStoreDelete {
  private static final String DICOM_NAME = "projects/%s/locations/%s/datasets/%s/dicomStores/%s";
  private static final JsonFactory JSON_FACTORY = new JacksonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void deleteDicomStore(String dicomStoreName) throws IOException {
    // String dicomStoreName =
    //    String.format(
    //        DICOM_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-dicom-id");

    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();

    // Create request and configure any parameters.
    DicomStores.Delete request =
        client.projects().locations().datasets().dicomStores().delete(dicomStoreName);

    // Execute the request and process the results.
    request.execute();
    System.out.println("DICOM store deleted.");
  }

  private static CloudHealthcare createClient() throws IOException {
    // Use Application Default Credentials (ADC) to authenticate the requests
    // For more information see https://cloud.google.com/docs/authentication/production
    GoogleCredentials credential =
        GoogleCredentials.getApplicationDefault()
            .createScoped(Collections.singleton(CloudHealthcareScopes.CLOUD_PLATFORM));

    // Create a HttpRequestInitializer, which will provide a baseline configuration to all requests.
    HttpRequestInitializer requestInitializer =
        request -> {
          new HttpCredentialsAdapter(credential).initialize(request);
          request.setConnectTimeout(60000); // 1 minute connect timeout
          request.setReadTimeout(60000); // 1 minute read timeout
        };

    // Build the client for interacting with the service.
    return new CloudHealthcare.Builder(HTTP_TRANSPORT, JSON_FACTORY, requestInitializer)
        .setApplicationName("your-application-name")
        .build();
  }
}

Node.js

const {google} = require('googleapis');
const healthcare = google.healthcare('v1');

const deleteDicomStore = async () => {
  const auth = await google.auth.getClient({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  });
  google.options({auth});

  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const dicomStoreId = 'my-dicom-store';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/dicomStores/${dicomStoreId}`;
  const request = {name};

  await healthcare.projects.locations.datasets.dicomStores.delete(request);
  console.log(`Deleted DICOM store: ${dicomStoreId}`);
};

deleteDicomStore();

Python

def delete_dicom_store(project_id, cloud_region, dataset_id, dicom_store_id):
    """Deletes the specified DICOM store."""
    client = get_client()
    dicom_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, cloud_region, dataset_id
    )
    dicom_store_name = "{}/dicomStores/{}".format(dicom_store_parent, dicom_store_id)

    request = (
        client.projects()
        .locations()
        .datasets()
        .dicomStores()
        .delete(name=dicom_store_name)
    )

    response = request.execute()
    print("Deleted DICOM store: {}".format(dicom_store_id))
    return response

后续步骤