创建和管理 FHIR 存储区

本页面介绍了如何创建、修改、查看、列出和删除“快速医疗互操作性资源”(FHIR) 存储区。FHIR 存储区用于存储 FHIR 资源,如声明资源、患者资源、药物资源等。

Cloud Healthcare API 支持以下 FHIR 版本:

创建 FHIR 存储区

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

以下示例展示了如何使用 projects.locations.datasets.fhirStores.create 方法创建 FHIR 存储区。

控制台

如需创建 FHIR 存储区,请执行以下操作:

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

    转到“数据集”页面

  2. 选择要在其中创建 FHIR 存储区的数据集。
  3. 点击创建数据存储区
  4. 输入您选择的名称,该名称在您的数据集中必须是独一无二的。如果名称不是唯一的,则创建 FHIR 存储区会失败。
  5. 选择 FHIR 作为数据存储区类型。
  6. 点击 Next(下一步)。
  7. 为 FHIR 存储区选择以下其中一个 FHIR 版本:DSTU2STU3R4
  8. 要使客户端能够使用更新操作来创建具有客户端指定 ID 的新资源,请点击允许更新创建
  9. 如需在此存储区中启用参照完整性,请点击参照完整性检查
    注意:存储区创建后,您将无法更改此设置。
  10. 如需自动记录存储区中资源的历史版本,请点击资源版本控制
    注意:存储区创建后,您将无法更改此设置。
  11. 点击 Next(下一步)。
  12. 每当您创建、更新、修补或删除存储区中的 FHIR 资源时,如需将资源更改导出到 BigQuery,请点击将资源更改流式传输到 BigQuery,然后点击添加新的流处理配置。如需详细了解 BigQuery 流式传输,请参阅将 FHIR 资源更改流式传输到 BigQuery
  13. 如需在输出架构中设置所有递归结构的深度,请点击递归结构深度滑块中的相关深度级别。默认情况下,递归值为 2。
  14. 点击完成以保存流式传输配置。
  15. 点击 Next(下一步)。
  16. 如果要为 FHIR 存储区配置 Pub/Sub 主题,请点击接收 Cloud Pub/Sub 通知并选择主题名称。指定 Pub/Sub 主题时,请输入主题的限定 URI,如以下示例所示:
    projects/PROJECT_ID/topics/PUBSUB_TOPIC
    
  17. 点击下一步
  18. 如需向存储区添加一个或多个标签,请点击添加标签以整理您的数据存储区,然后输入键值对标签。如需详细了解资源标签,请参阅使用资源标签
  19. 点击创建

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

gcloud

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

  • FHIR 存储区 ID 在数据集中必须是独一无二的。它可以是 1 到 256 个字符的任意 Unicode 字符串,由数字、字母、下划线、短划线和句点组成。
  • 如需设置 FHIR 版本,请指定可选的 --version 参数。这会将 FHIR 版本定义为 DSTU2STU3R4。如果未指定此参数,则版本默认设置为 STU3
  • 要向 Pub/Sub 主题通知 FHIR 存储区的更改,请使用 --pubsub-topic 参数指定现有 Pub/Sub 主题名称。

    指定 Pub/Sub 主题时,请输入主题的限定 URI,如以下示例所示:
    projects/PROJECT_ID/topics/PUBSUB_TOPIC
    

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

gcloud healthcare fhir-stores create FHIR_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION \
  --version=FHIR_STORE_VERSION \
  [--pubsub-topic=projects/PROJECT_ID/topics/PUBSUB_TOPIC]

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

Created fhirStore [FHIR_STORE_ID].

API

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

curl

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

  • 父数据集的名称
  • FHIR 存储区的名称。FHIR 存储区名称在其父数据集中必须是独一无二的。它可以是 1 到 256 个字符的任意 Unicode 字符串,由数字、字母、下划线、短划线和句点组成。
  • FHIR 存储区的 FHIR 版本:DSTU2STU3R4
  • 访问令牌

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

您可以选择性地配置 Cloud Healthcare API 将向其发送 FHIR 存储区更改通知的现有 Pub/Sub 主题。如需了解如何配置 Pub/Sub 主题,请参阅修改 FHIR 存储区

curl -X POST \
    -H "Authorization: Bearer $(gcloud auth application-default print-access-token)" \
    -H "Content-Type: application/json; charset=utf-8" \
    --data "{
      'version': 'FHIR_STORE_VERSION'
    }" "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores?fhirStoreId=FHIR_STORE_ID"

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

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID",
  "version": "FHIR_STORE_VERSION"
}

PowerShell

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

  • 父数据集的名称
  • FHIR 存储区的名称。FHIR 存储区名称在其父数据集中必须是独一无二的。它可以是 1 到 256 个字符的任意 Unicode 字符串,由数字、字母、下划线、短划线和句点组成。
  • FHIR 存储区的 FHIR 版本:DSTU2STU3R4
  • 访问令牌

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

您可以选择性地配置 Cloud Healthcare API 将向其发送 FHIR 存储区更改通知的现有 Pub/Sub 主题。如需了解如何配置 Pub/Sub 主题,请参阅修改 FHIR 存储区

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

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body "{
      'version': 'FHIR_STORE_VERSION'
  }" `
  -Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores?fhirStoreId=FHIR_STORE_ID" | Select-Object -Expand Content

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

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID",
  "version": "FHIR_STORE_VERSION"
}

Go

import (
	"context"
	"fmt"
	"io"

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

// createFHIRStore creates an FHIR store.
func createFHIRStore(w io.Writer, projectID, location, datasetID, fhirStoreID 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.FhirStores

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

	resp, err := storesService.Create(parent, &healthcare.FhirStore{Version: version}).FhirStoreId(fhirStoreID).Do()
	if err != nil {
		return fmt.Errorf("Create: %v", err)
	}

	fmt.Fprintf(w, "Created FHIR 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.FhirStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.FhirStore;
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 FhirStoreCreate {
  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 fhirStoreCreate(String datasetName, String fhirStoreId) throws IOException {
    // String datasetName =
    //     String.format(DATASET_NAME, "your-project-id", "your-region-id", "your-dataset-id");
    // String fhirStoreId = "your-fhir-id"

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

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

    // Create request and configure any parameters.
    FhirStores.Create request =
        client
            .projects()
            .locations()
            .datasets()
            .fhirStores()
            .create(datasetName, content)
            .setFhirStoreId(fhirStoreId);

    // Execute the request and process the results.
    FhirStore response = request.execute();
    System.out.println("FHIR 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/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const createFhirStore = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const version = 'STU3';
  const parent = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;
  const request = {
    parent,
    fhirStoreId,
    resource: {
      version,
    },
  };

  await healthcare.projects.locations.datasets.fhirStores.create(request);
  console.log(`Created FHIR store: ${fhirStoreId}`);
};

createFhirStore();

Python

def create_fhir_store(project_id, location, dataset_id, fhir_store_id, version):
    """Creates a new FHIR store within the parent dataset.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/fhir
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the FHIR store's parent dataset ID
    # fhir_store_id = 'my-fhir-store'  # replace with the FHIR store's ID
    # version = 'R4'  # replace with the FHIR store version
    fhir_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )

    body = {"version": version}

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .create(parent=fhir_store_parent, body=body, fhirStoreId=fhir_store_id)
    )

    response = request.execute()
    print("Created FHIR store: {}".format(fhir_store_id))

    return response

修改 FHIR 存储区

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

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

控制台

如需修改 FHIR 存储区,请完成以下步骤:

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

  2. 选择包含您要修改的 FHIR 存储区的数据集。

  3. 数据存储区列表中,选择要修改的 FHIR 存储区。

  4. 如需修改存储区配置,请点击 FHIR 存储区配置修改按钮。

    如需详细了解 FHIR 存储区的配置选项,请参阅创建 FHIR 存储区

  5. 每当您创建、更新、修补或删除存储区中的 FHIR 资源时,如需将资源更改导出到 BigQuery,请点击数据集字段中的添加新的流处理配置

  6. 选择将资源更改流式传输到的目标 BigQuery 数据集。如需详细了解 BigQuery 流式传输,请参阅将 FHIR 资源更改流式传输到 BigQuery

  7. 如需在输出架构中设置所有递归结构的深度,请点击递归结构深度滑块中的相关深度。默认情况下,递归深度为 2。

  8. 如需仅导出特定资源类型的资源更改,请从选择 FHIR 资源类型列表中选择资源类型。

  9. 如需为数据存储区配置 Pub/Sub 主题,请在 Cloud Pub/Sub 通知部分选择主题名称。指定 Pub/Sub 主题时,请输入主题的限定 URI,如以下示例所示:

    projects/PROJECT_ID/topics/PUBSUB_TOPIC
    

  10. 如需向存储区添加一个或多个标签,请点击标签部分中的修改按钮,接着点击添加标签,然后输入键值对标签。如需详细了解资源标签,请参阅使用资源标签

  11. 如果您已添加标签,请点击保存

gcloud

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

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

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

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

Updated fhirStore [FHIR_STORE_ID].
name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhir-stores/FHIR_STORE_ID
notificationConfig:
pubsubTopic: projects/PROJECT_ID/topics/PUBSUB_TOPIC
version: FHIR_STORE_VERSION

API

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

curl

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

  • 父数据集的名称
  • FHIR 存储区的名称
  • 要更新的元数据
  • 更新掩码
  • 访问令牌

以下示例展示了使用 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/fhirStores/FHIR_STORE_ID?updateMask=notificationConfig,labels"

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

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID",
  "notificationConfig": {
    "pubsubTopic": "projects/PROJECT_ID/topics/PUBSUB_TOPIC"
  },
  'labels': {
    'KEY1':'VALUE1','KEY2':'VALUE2'
  }
  'version': FHIR_STORE_VERSION
}

PowerShell

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

  • 父数据集的名称
  • FHIR 存储区的名称
  • 要更新的元数据
  • 更新掩码
  • 访问令牌

以下示例展示了使用 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/fhirStores/FHIR_STORE_ID?updateMask=notificationConfig,labels" | Select-Object -Expand Content

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

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID",
  "notificationConfig": {
    "pubsubTopic": "projects/PROJECT_ID/topics/PUBSUB_TOPIC"
  },
  'labels': {
    'KEY1':'VALUE1','KEY2':'VALUE2'
  }
  'version': FHIR_STORE_VERSION
}

Go

import (
	"context"
	"fmt"
	"io"

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

// patchFHIRStore updates (patches) a FHIR store by updating its Pub/sub topic name.
func patchFHIRStore(w io.Writer, projectID, location, datasetID, fhirStoreID, 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.FhirStores

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

	if _, err := storesService.Patch(name, &healthcare.FhirStore{
		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 FHIR 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.FhirStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.FhirStore;
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 FhirStorePatch {
  private static final String FHIR_NAME = "projects/%s/locations/%s/datasets/%s/fhirStores/%s";
  private static final JsonFactory JSON_FACTORY = new JacksonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void fhirStorePatch(String fhirStoreName, String pubsubTopic) throws IOException {
    // String fhirStoreName =
    //    String.format(
    //        FHIR_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-fhir-id");
    // String pubsubTopic = "projects/your-project-id/topics/your-pubsub-topic";

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

    // Fetch the initial state of the FHIR store.
    FhirStores.Get getRequest =
        client.projects().locations().datasets().fhirStores().get(fhirStoreName);
    FhirStore store = getRequest.execute();

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

    // Create request and configure any parameters.
    FhirStores.Patch request =
        client
            .projects()
            .locations()
            .datasets()
            .fhirStores()
            .patch(fhirStoreName, store)
            .setUpdateMask("notificationConfig");

    // Execute the request and process the results.
    store = request.execute();
    System.out.println("Fhir 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/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

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

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

patchFhirStore();

Python

def patch_fhir_store(project_id, location, dataset_id, fhir_store_id):
    """Updates the FHIR store.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/fhir
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Instantiates an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the dataset's location
    # dataset_id = 'my-dataset'  # replace with your dataset ID
    # fhir_store_id = 'my-fhir-store'  # replace with the FHIR store's ID
    fhir_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    fhir_store_name = "{}/fhirStores/{}".format(fhir_store_parent, fhir_store_id)

    # TODO(developer): Replace with the full URI of an existing Pub/Sub topic
    patch = {"notificationConfig": None}

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

    response = request.execute()
    print("Patched FHIR store {} with Cloud Pub/Sub topic: None".format(fhir_store_id))

    return response

获取 FHIR 存储区详情

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

控制台

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

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

    转到“数据集”页面

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

gcloud

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

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

gcloud healthcare fhir-stores describe FHIR_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION

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

name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhir-stores/FHIR_STORE_ID
version: FHIR_STORE_VERSION

API

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

curl

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

  • 父数据集的名称
  • FHIR 存储区的名称
  • 访问令牌

以下示例展示了使用 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/fhirStores/FHIR_STORE_ID"

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

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID",
  "version": FHIR_STORE_VERSION
}

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

PowerShell

如需获取 FHIR 存储区的相关详情,请发出 GET 请求并指定以下信息: * 父数据集的名称 * FHIR 存储区的名称 * 访问令牌

以下示例展示了使用 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/fhirStores/FHIR_STORE_ID" | Select-Object -Expand Content

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

{
  "name": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID",
  "version": FHIR_STORE_VERSION
}

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

Go

import (
	"context"
	"fmt"
	"io"

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

// getFHIRStore gets an FHIR store.
func getFHIRStore(w io.Writer, projectID, location, datasetID, fhirStoreID 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.FhirStores

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

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

	fmt.Fprintf(w, "Got FHIR store: %q\n", store.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.FhirStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.FhirStore;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;

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

  public static void fhirStoreGet(String fhirStoreName) throws IOException {
    // String fhirStoreName =
    //    String.format(
    //        FHIR_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-fhir-id");

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

    // Create request and configure any parameters.
    FhirStores.Get request =
        client.projects().locations().datasets().fhirStores().get(fhirStoreName);

    // Execute the request and process the results.
    FhirStore store = request.execute();
    System.out.println("FHIR 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/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

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

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

getFhirStore();

Python

def get_fhir_store(project_id, location, dataset_id, fhir_store_id):
    """Gets the specified FHIR store.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/fhir
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    # Imports Python's built-in "json" module
    import json

    api_version = "v1"
    service_name = "healthcare"
    # Instantiates an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the FHIR store's parent dataset
    # fhir_store_id = 'my-fhir-store'  # replace with the FHIR store's ID
    fhir_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    fhir_store_name = "{}/fhirStores/{}".format(fhir_store_parent, fhir_store_id)

    fhir_stores = client.projects().locations().datasets().fhirStores()
    fhir_store = fhir_stores.get(name=fhir_store_name).execute()

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

列出数据集中的 FHIR 存储区

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

控制台

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

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

    转到“数据集”页面

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

gcloud

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

gcloud healthcare fhir-stores list --dataset=DATASET_ID

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

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

API

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

curl

如需列出数据集中的 FHIR 存储区,请发出 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/fhirStores"

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

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

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

PowerShell

如需列出数据集中的 FHIR 存储区,请发出 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/fhirStores" | Select-Object -Expand Content

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

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

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

Go

import (
	"context"
	"fmt"
	"io"

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

// listFHIRStores prints a list of FHIR stores to w.
func listFHIRStores(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.FhirStores

	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, "FHIR stores:")
	for _, s := range resp.FhirStores {
		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.FhirStores;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.FhirStore;
import com.google.api.services.healthcare.v1.model.ListFhirStoresResponse;
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 FhirStoreList {
  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 fhirStoreList(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<FhirStore> stores = new ArrayList<>();
    do {
      // Create request and configure any parameters.
      FhirStores.List request =
          client
              .projects()
              .locations()
              .datasets()
              .fhirStores()
              .list(datasetName)
              .setPageSize(100) // Specify pageSize up to 1000
              .setPageToken(pageToken);

      // Execute response and collect results.
      ListFhirStoresResponse response = request.execute();
      stores.addAll(response.getFhirStores());

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

    // Print results.
    System.out.printf("Retrieved %s Fhir stores: \n", stores.size());
    for (FhirStore 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/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const listFhirStores = async () => {
  // 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 fhirStores =
    await healthcare.projects.locations.datasets.fhirStores.list(request);
  console.log(JSON.stringify(fhirStores.data));
};

listFhirStores();

Python

def list_fhir_stores(project_id, location, dataset_id):
    """Lists the FHIR stores in the given dataset.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/fhir
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Instantiates an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the dataset's location
    # dataset_id = 'my-dataset'  # replace with the parent dataset's ID
    fhir_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )

    fhir_stores = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .list(parent=fhir_store_parent)
        .execute()
        .get("fhirStores", [])
    )

    for fhir_store in fhir_stores:
        print(fhir_store)

    return fhir_stores

获取 FHIR 存储区的功能或一致性声明

以下示例展示了如何获取 FHIR 存储区的功能(STU3R4)或一致性 (DSTU2) 声明。

功能或一致性声明中的信息反映了 FHIR 存储区中的设置。例如,如果 FhirStore.enableUpdateCreate 设置为 true,则会反映在功能声明的 CapabilityStatement.rest.resource.updateCreate 字段中。

下表显示用于获取 FHIR 存储区的功能或一致性声明及其等效 FHIR 规范交互的 Cloud Healthcare API 方法:

Cloud Healthcare API 方法 FHIR 规范交互
projects.locations.datasets.fhirStores.fhir.capabilities 功能(STU3R4)或 conformance (DSTU2)

控制台

Cloud Console 不支持获取功能或一致性声明。请改用 curl、Windows PowerShell 或您的首选语言。

gcloud

gcloud 工具不支持获取功能或一致性声明。请改用 curl、Windows PowerShell 或您的首选语言。

API

要获取 FHIR 存储区的功能或一致性声明,请使用 projects.locations.datasets.fhirStores.fhir.capabilities 方法。

curl

要获取 FHIR 存储区的功能或一致性声明,请发出 GET 请求并指定以下信息:

  • 数据集的名称
  • FHIR 存储区的名称
  • 访问令牌

以下示例展示了使用 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/fhirStores/FHIR_STORE_ID/fhir/metadata"

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

{
  "acceptUnknown": "both",
  "date": "2018-01-01",
  "description": "FHIR capability statement for the FHIR store specified by the request.",
  "experimental": true,
  "fhirVersion": "FHIR_VERSION",
  "format": [
    "json"
  ],
  "id": "FHIR_STORE_ID",
  "kind": "instance",
  "patchFormat": [
    "application/json-patch+json"
  ],
  "publisher": "Google",
  "resourceType": "CapabilityStatement",
  ...
  "status": "draft",
  "url": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID",
  "version": "20180101"
}

PowerShell

要获取 FHIR 存储区的功能或一致性声明,请发出 GET 请求并指定以下信息:

  • 数据集的名称
  • FHIR 存储区的名称
  • 访问令牌

以下示例展示了使用 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/fhirStores/FHIR_STORE_ID/fhir/metadata" | ConvertTo-Json

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

{
  "acceptUnknown": "both",
  "date": "2018-01-01",
  "description": "FHIR capability statement for the FHIR store specified by the request.",
  "experimental": true,
  "fhirVersion": "FHIR_VERSION",
  "format": [
    "json"
  ],
  "id": "FHIR_STORE_ID",
  "kind": "instance",
  "patchFormat": [
    "application/json-patch+json"
  ],
  "publisher": "Google",
  "resourceType": "CapabilityStatement",
  ...
  "status": "draft",
  "url": "projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID",
  "version": "20180101"
}

Go

import (
	"context"
	"fmt"
	"io"
	"io/ioutil"

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

// getFHIRMetadata gets FHIR store metadata.
func getFHIRMetadata(w io.Writer, projectID, location, datasetID, fhirStoreID string) error {
	ctx := context.Background()

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

	fhirService := healthcareService.Projects.Locations.Datasets.FhirStores.Fhir

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

	resp, err := fhirService.Capabilities(name).Do()
	if err != nil {
		return fmt.Errorf("Capabilities: %v", err)
	}

	defer resp.Body.Close()

	respBytes, err := ioutil.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("could not read response: %v", err)
	}

	if resp.StatusCode > 299 {
		return fmt.Errorf("Capabilities: status %d %s: %s", resp.StatusCode, resp.Status, respBytes)
	}
	fmt.Fprintf(w, "%s", respBytes)
	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.FhirStores.Fhir.Capabilities;
import com.google.api.services.healthcare.v1.CloudHealthcareScopes;
import com.google.api.services.healthcare.v1.model.HttpBody;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Collections;

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

  public static void fhirStoreGetMetadata(String fhirStoreName) throws IOException {
    // String fhirStoreName =
    //    String.format(
    //        FHIR_NAME, "project-id", "region-id", "dataset-id", "store-id");

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

    // Create request and configure any parameters.
    Capabilities request =
        client.projects().locations().datasets().fhirStores().fhir().capabilities(fhirStoreName);

    // Execute the request and process the results.
    HttpBody response = request.execute();
    System.out.println("FHIR store metadata retrieved: " + 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/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

const getFhirStoreCapabilities = async () => {
  // TODO(developer): uncomment these lines before running the sample
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  const name = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}/fhir/metadata`;
  const request = {name};

  const fhirStore =
    await healthcare.projects.locations.datasets.fhirStores.get(request);
  console.log(JSON.stringify(fhirStore.data, null, 2));
};

getFhirStoreCapabilities();

Python

def get_fhir_store_metadata(project_id, location, dataset_id, fhir_store_id):
    """Gets the FHIR capability statement (STU3, R4), or the conformance statement
    in the DSTU2 case for the store, which contains a description of functionality
    supported by the server.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/fhir
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    # Imports Python's built-in "json" module
    import json

    api_version = "v1"
    service_name = "healthcare"
    # Instantiates an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the parent dataset's ID
    # fhir_store_id = 'my-fhir-store' # replace with the FHIR store ID
    fhir_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    fhir_store_name = "{}/fhirStores/{}".format(fhir_store_parent, fhir_store_id)

    fhir_stores = client.projects().locations().datasets().fhirStores()
    response = fhir_stores.fhir().capabilities(name=fhir_store_name).execute()

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

删除 FHIR 存储区

以下示例展示了如何删除 FHIR 存储区。

控制台

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

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

    转到“数据集”页面

  2. 选择包含您要删除的数据存储区的数据集。
  3. 从要删除的数据存储区的操作下拉列表中选择删除
  4. 输入数据存储区名称,然后点击删除以确认删除。

gcloud

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

  1. 运行 delete 命令。

    gcloud healthcare fhir-stores delete FHIR_STORE_ID \
    --dataset=DATASET_ID \
    --location=LOCATION
    
  2. 要确认,请键入 Y

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

Deleted fhirStore [FHIR_STORE_ID].

API

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

curl

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

  • 父数据集的名称
  • FHIR 存储区的名称
  • 访问令牌

以下示例展示了使用 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/fhirStores/FHIR_STORE_ID"

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

{}

PowerShell

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

  • 父数据集的名称
  • FHIR 存储区的名称
  • 访问令牌

以下示例展示了使用 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/fhirStores/FHIR_STORE_ID" | Select-Object -Expand Content

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

{}

Go

import (
	"context"
	"fmt"
	"io"

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

// deleteFHIRStore deletes an FHIR store.
func deleteFHIRStore(w io.Writer, projectID, location, datasetID, fhirStoreID 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.FhirStores

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

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

	fmt.Fprintf(w, "Deleted FHIR store: %q\n", fhirStoreID)
	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.FhirStores;
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 FhirStoreDelete {
  private static final String FHIR_NAME = "projects/%s/locations/%s/datasets/%s/fhirStores/%s";
  private static final JsonFactory JSON_FACTORY = new JacksonFactory();
  private static final NetHttpTransport HTTP_TRANSPORT = new NetHttpTransport();

  public static void fhirStoreDelete(String fhirStoreName) throws IOException {
    // String fhirStoreName =
    //    String.format(
    //        FHIR_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-fhir-id");

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

    // Create request and configure any parameters.
    FhirStores.Delete request =
        client.projects().locations().datasets().fhirStores().delete(fhirStoreName);

    // Execute the request and process the results.
    request.execute();
    System.out.println("FHIR 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/healthcare');
const healthcare = google.healthcare({
  version: 'v1',
  auth: new google.auth.GoogleAuth({
    scopes: ['https://www.googleapis.com/auth/cloud-platform'],
  }),
});

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

  await healthcare.projects.locations.datasets.fhirStores.delete(request);
  console.log(`Deleted FHIR store: ${fhirStoreId}`);
};

deleteFhirStore();

Python

def delete_fhir_store(project_id, location, dataset_id, fhir_store_id):
    """Deletes the specified FHIR store.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/healthcare/api-client/v1/fhir
    before running the sample."""
    # Imports the Google API Discovery Service.
    from googleapiclient import discovery

    api_version = "v1"
    service_name = "healthcare"
    # Returns an authorized API client by discovering the Healthcare API
    # and using GOOGLE_APPLICATION_CREDENTIALS environment variable.
    client = discovery.build(service_name, api_version)

    # TODO(developer): Uncomment these lines and replace with your values.
    # project_id = 'my-project'  # replace with your GCP project ID
    # location = 'us-central1'  # replace with the parent dataset's location
    # dataset_id = 'my-dataset'  # replace with the FHIR store's parent dataset
    # fhir_store_id = 'my-fhir-store'  # replace with the FHIR store's ID
    fhir_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    fhir_store_name = "{}/fhirStores/{}".format(fhir_store_parent, fhir_store_id)

    request = (
        client.projects()
        .locations()
        .datasets()
        .fhirStores()
        .delete(name=fhir_store_name)
    )

    response = request.execute()
    print("Deleted FHIR store: {}".format(fhir_store_id))

    return response

后续步骤

了解如何创建和使用 FHIR 资源