建立及管理 FHIR 儲存庫

本頁說明如何建立、編輯、查看、列出及刪除快速醫療照護互通資源 (FHIR) 儲存庫。FHIR 存放區會保留 FHIR 資源,例如索賠資源、病患資源、藥物資源等。

Cloud Healthcare API 支援下列 FHIR 版本:

建立 FHIR 儲存庫

您必須先建立資料集,才能建立 FHIR 儲存庫。

以下範例說明如何使用 projects.locations.datasets.fhirStores.create 方法建立 FHIR 儲存庫。

控制台

如要建立 FHIR 儲存庫,請完成下列步驟:

  1. 在 Google Cloud 控制台中,前往「Datasets」(資料集) 頁面。

    前往「資料集」

  2. 選取要建立 FHIR 儲存庫的資料集。
  3. 按一下「建立資料儲存庫」
  4. 選取 FHIR 做為資料儲存庫類型。
  5. 請輸入資料集中不重複的名稱。如果名稱不具唯一性,FHIR 儲存庫建立作業就會失敗。
  6. 點選「下一步」
  7. 如要設定 FHIR 儲存庫,請按照下列步驟操作:
    1. 選擇 FHIR 存放區的 FHIR 版本,可選 DSTU2STU3R4
    2. 從下列選項中選取適用的進階設定:
      • 允許透過更新建立:選取此選項,即可使用更新作業 (使用者指定的 ID) 建立新資源。
      • 參照完整性檢查:選取這個選項,即可在商店中啟用參照完整性。 建立商店後即無法變更。
      • 資源版本管理:選取此選項,系統就會自動記錄資源的歷來版本。 建立商店後即無法變更。
    3. 在下列欄位中,選取適用的設定檔驗證設定。詳情請參閱 ValidationConfig
      • 啟用設定檔驗證功能:選取此選項即可啟用設定檔驗證功能。如要強制執行 FHIR 儲存庫中已啟用的實作指南,您必須啟用設定檔驗證功能。
      • 啟用必填欄位驗證功能:選取此選項,即可依據 FHIR 設定檔中的結構定義,啟用資源欄位驗證功能。
      • 啟用參照類型驗證:選取此選項即可啟用參照類型驗證功能。
      • 啟用 FHIRPath 驗證功能:選取此選項可啟用 FHIRPath 相容性檢查功能。
    4. 點選「下一步」
  8. 選用步驟:如要在 FHIR 儲存庫中啟用實作指南,請執行下列操作:
    1. 按一下「啟用實作指南」
    2. 按一下並展開「導入指南」清單。
    3. 在清單中選取適用的實作指南。

      每份實作指南都支援特定的 FHIR 版本。清單只會顯示與所選 FHIR 儲存庫版本相容的實作指南。

    4. 按一下「從 Cloud Storage 匯入自訂 IG」,即可從 Cloud Storage 位置匯入任何自訂個人資料驗證套件。
    5. 在「Select object」面板中,從 Cloud Storage 位置選取設定檔驗證套件資源。詳情請參閱「使用 Google Cloud 控制台啟用導入指南」。
    6. 按一下「選取」
      • 系統會在表格中列出所選導入指南,並顯示版本、網址和狀態。
      • 如果您已啟用實作指南,但未啟用設定檔驗證功能,則實作指南不會生效。
      • 點選「下一步」
  9. 選用:如要每次在儲存庫中建立、更新、修補或刪除 FHIR 資源時,將資源變更匯出至 BigQuery,請執行下列操作:
    1. 按一下「將資源變更串流至 BigQuery」
    2. 按一下「新增串流設定」。如要進一步瞭解 BigQuery 串流功能,請參閱「將 FHIR 資源變更串流至 BigQuery」一文。
    3. 在「遞迴結構深度」滑桿上選取深度層級,為輸出結構定義中所有遞迴結構設定深度。根據預設,遞迴深度值為 2。
    4. 按一下「完成」,儲存串流設定。
    5. 點選「下一步」
  10. 選用:如要為 FHIR 儲存庫設定 Pub/Sub 主題,請按照下列步驟操作:
    1. 按一下「接收 Cloud Pub/Sub 通知」
    2. 按一下「Add a Cloud Pub/Sub topic」(新增 Cloud Pub/Sub 主題),然後選取主題名稱。

      指定 Pub/Sub 主題時,請輸入主題的完整 URI,如以下範例所示:

      projects/PROJECT_ID/topics/PUBSUB_TOPIC

    3. 點選「下一步」
  11. 選用步驟:如要為商店新增標籤,請按照下列步驟操作:
    1. 按一下「新增標籤以便整理資料儲存庫」
    2. 輸入標籤的鍵和值。如要進一步瞭解資源標籤,請參閱「使用資源標籤」一文。
    3. 按一下 [建立]。

新的 FHIR 儲存庫會顯示在清單中。

gcloud

如要在資料集中建立 FHIR 儲存庫,請執行 gcloud healthcare fhir-stores create 指令。

使用下列任何指令資料之前,請先替換以下項目:

  • LOCATION:資料集位置
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • FHIR_STORE_ID:FHIR 儲存庫的 ID。FHIR 儲存庫 ID 必須符合下列規定:
    • 資料集中的專屬 ID
    • 1 到 256 個字元的 Unicode 字串,包含下列項目:
      • Numbers
      • 信件
      • 底線
      • 破折號
      • 週期
  • FHIR_STORE_VERSION:FHIR 存放區的 FHIR 版本。可用的選項包括 DSTU2、STU3 或 R4。

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud healthcare fhir-stores create FHIR_STORE_ID \
  --dataset=DATASET_ID \
  --location=LOCATION \
  --version=FHIR_STORE_VERSION

Windows (PowerShell)

gcloud healthcare fhir-stores create FHIR_STORE_ID `
  --dataset=DATASET_ID `
  --location=LOCATION `
  --version=FHIR_STORE_VERSION

Windows (cmd.exe)

gcloud healthcare fhir-stores create FHIR_STORE_ID ^
  --dataset=DATASET_ID ^
  --location=LOCATION ^
  --version=FHIR_STORE_VERSION

您應該會收到類似以下的回應:

回應

Created fhirStore [FHIR_STORE_ID].

REST

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID: Google Cloud 專案的 ID
  • LOCATION:資料集位置
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • FHIR_STORE_ID:FHIR 儲存庫的 ID。FHIR 儲存庫 ID 必須符合下列規定:
    • 資料集中的專屬 ID
    • 1 到 256 個字元的 Unicode 字串,包含下列項目:
      • Numbers
      • 信件
      • 底線
      • 破折號
      • 週期
  • FHIR_STORE_VERSION:FHIR 存放區的 FHIR 版本。可用的選項包括 DSTU2、STU3 或 R4。

JSON 要求主體:

{
  "version": "FHIR_STORE_VERSION"
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中。在終端機中執行下列指令,在目前目錄中建立或覆寫此檔案:

cat > request.json << 'EOF'
{
  "version": "FHIR_STORE_VERSION"
}
EOF

接著,執行下列指令來傳送 REST 要求:

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

PowerShell

將要求主體儲存在名為 request.json 的檔案中。在終端機中執行下列指令,在目前目錄中建立或覆寫此檔案:

@'
{
  "version": "FHIR_STORE_VERSION"
}
'@  | Out-File -FilePath request.json -Encoding utf8

接著,執行下列指令來傳送 REST 要求:

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

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

APIs Explorer

複製要求主體並開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。將要求主體貼到這項工具中,並填妥其他必填欄位,然後按一下「執行」

您應該會收到如下的 JSON 回應:

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: %w", 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: %w", 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.gson.GsonFactory;
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 GsonFactory();
  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<>();
    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/main/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(f"Created FHIR store: {fhir_store_id}")

    return response

編輯 FHIR 儲存庫

下列範例說明如何編輯 FHIR 儲存庫。您可以編輯 FHIR 儲存庫,修改下列屬性:

  • Cloud Healthcare API 會傳送 FHIR 儲存庫變更通知的 Pub/Sub 主題。
  • FHIR 儲存庫的標籤。標籤是鍵/值組合,可協助您整理 Google Cloud 資源。
指定 Pub/Sub 主題時,請輸入主題的完整 URI,如以下範例所示:
projects/PROJECT_ID/topics/PUBSUB_TOPIC
如要啟用通知功能,您必須將其他權限授予 Cloud Healthcare 服務代理人 服務帳戶。詳情請參閱「DICOM、FHIR 和 HL7v2 儲存庫的 Pub/Sub 權限」。

控制台

如要編輯 FHIR 儲存庫,請完成下列步驟:

  1. 在 Google Cloud 控制台中,前往「Datasets」頁面。
    前往「Datasets」

  2. 選取含有要編輯的 FHIR 儲存庫的資料集。

  3. 在「資料儲存庫」清單中,選取要編輯的 FHIR 儲存庫。

  4. 如要編輯儲存庫設定,請按一下 FHIR 儲存庫設定

    如要進一步瞭解 FHIR 儲存庫的設定選項,請參閱「建立 FHIR 儲存庫」。

  5. 如要編輯商店的實作指南,請按一下 「實作指南」,然後選取適用的實作指南,或從 Cloud Storage 匯入自訂實作指南。詳情請參閱「使用 Google Cloud 控制台啟用導入指南」。

    如要編輯實作指南或強制執行已啟用的實作指南,您必須在「FHIR 儲存庫設定」部分啟用設定檔驗證功能。

  6. 如要每次在儲存庫中建立、更新、修補或刪除 FHIR 資源時,將資源變更匯出至 BigQuery,請按一下「Dataset」欄位中的「Add new streaming config」

  7. 選取要串流資源變更的 BigQuery 資料集。如要進一步瞭解 BigQuery 串流功能,請參閱「將 FHIR 資源變更串流至 BigQuery」。

  8. 如要為輸出結構定義所有遞迴結構的深度,請在「遞迴結構深度」滑桿中點選相關深度。依預設,遞迴深度為 2。

  9. 如要只匯出特定資源類型的資源變更,請從「選取 FHIR 資源類型」清單中選取資源類型。

  10. 如要為資料儲存庫設定 Pub/Sub 主題,請在「Cloud Pub/Sub Notifications」部分中選取主題名稱。指定 Pub/Sub 主題時,請輸入主題的完整 URI,如以下範例所示:

    projects/PROJECT_ID/topics/PUBSUB_TOPIC

  11. 如要為商店新增一或多個標籤,請依序按一下 「標籤」和「新增標籤」,然後輸入鍵/值標籤。如要進一步瞭解資源標籤,請參閱「使用資源標籤」一文。

  12. 按一下「儲存」

gcloud

如要編輯 FHIR 儲存庫,請執行 gcloud healthcare fhir-stores update 指令。

使用下列任何指令資料之前,請先替換以下項目:

  • PROJECT_ID: Google Cloud 專案的 ID
  • LOCATION:資料集位置
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • FHIR_STORE_ID:FHIR 儲存庫 ID
  • PUBSUB_TOPIC_ID:當資料儲存庫發生事件時,訊息會發布至此 Pub/Sub 主題

執行下列指令:

Linux、macOS 或 Cloud Shell

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

Windows (PowerShell)

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

Windows (cmd.exe)

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

您應該會收到類似以下的回應:

回應

Updated fhirStore [FHIR_STORE_ID].
name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID
notificationConfig:
 pubsubTopic: projects/PROJECT_ID/topics/PUBSUB_TOPIC_ID
version: FHIR_STORE_VERSION

REST

如要編輯 FHIR 儲存庫,請使用 projects.locations.datasets.fhirStores.patch 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID: Google Cloud 專案的 ID
  • LOCATION:資料集位置
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • FHIR_STORE_ID:FHIR 儲存庫 ID
  • PUBSUB_TOPIC_ID:當資料儲存庫發生事件時,會將訊息發布至此 Pub/Sub 主題。如要判斷 Pub/Sub 通知應包含哪些資料,請參閱 FHIR Pub/Sub 通知
  • KEY1:第一個標籤鍵
  • VALUE1:第一個標籤值
  • KEY2:第二個標籤鍵
  • VALUE2:第二個標籤值

JSON 要求主體:

{
  "notificationConfigs": [
    {
      "pubsubTopic": "projects/PROJECT_ID/topics/PUBSUB_TOPIC_ID"
    }
  ],
  "labels": {
    "KEY1": "VALUE1",
    "KEY2": "VALUE2"
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中。在終端機中執行下列指令,在目前目錄中建立或覆寫此檔案:

cat > request.json << 'EOF'
{
  "notificationConfigs": [
    {
      "pubsubTopic": "projects/PROJECT_ID/topics/PUBSUB_TOPIC_ID"
    }
  ],
  "labels": {
    "KEY1": "VALUE1",
    "KEY2": "VALUE2"
  }
}
EOF

接著,執行下列指令來傳送 REST 要求:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID?updateMask=notificationConfig,labels"

PowerShell

將要求主體儲存在名為 request.json 的檔案中。在終端機中執行下列指令,在目前目錄中建立或覆寫此檔案:

@'
{
  "notificationConfigs": [
    {
      "pubsubTopic": "projects/PROJECT_ID/topics/PUBSUB_TOPIC_ID"
    }
  ],
  "labels": {
    "KEY1": "VALUE1",
    "KEY2": "VALUE2"
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

接著,執行下列指令來傳送 REST 要求:

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

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-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

APIs Explorer

複製要求主體並開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。將要求主體貼到這項工具中,並填妥其他必填欄位,然後按一下「執行」

您應該會收到如下的 JSON 回應:

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: %w", err)
	}

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

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

	// topicName format is "projects/*/locations/*/topics/*"
	notificationConfig := &healthcare.FhirNotificationConfig{
		PubsubTopic: topicName,
	}

	fhirStore := &healthcare.FhirStore{
		NotificationConfigs: []*healthcare.FhirNotificationConfig{notificationConfig},
	}

	patchRequest := storesService.Patch(name, fhirStore).UpdateMask("notificationConfigs")

	if _, err := patchRequest.Do(); err != nil {
		return fmt.Errorf("Patch: %w", 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.gson.GsonFactory;
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.FhirNotificationConfig;
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 FhirStorePatch {
  private static final String FHIR_NAME = "projects/%s/locations/%s/datasets/%s/fhirStores/%s";
  private static final JsonFactory JSON_FACTORY = new GsonFactory();
  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
    FhirNotificationConfig notificationConfig = new FhirNotificationConfig()
        .setPubsubTopic(pubsubTopic);
    store.setNotificationConfigs(Collections.singletonList(notificationConfig));

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

    // 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: 'notificationConfigs',
    resource: {
      notificationConfigs: [
        {
          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, pubsub_topic):
    """Updates the FHIR store.

    See https://github.com/GoogleCloudPlatform/python-docs-samples/tree/main/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
    # pubsub_topic = 'projects/{project_id}/topics/{topic_id}'  # replace with your Pub/Sub topic
    fhir_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    fhir_store_name = f"{fhir_store_parent}/fhirStores/{fhir_store_id}"

    patch = {
        "notificationConfigs": [{"pubsubTopic": pubsub_topic}] if pubsub_topic else []
    }

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

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

    return response

取得 FHIR 儲存庫詳細資料

下列範例說明如何取得 FHIR 儲存庫的詳細資料。

控制台

如要查看 FHIR 儲存庫的詳細資料,請按照下列步驟操作:

  1. 在 Google Cloud 控制台中,前往「Datasets」(資料集) 頁面。

    前往「資料集」

  2. 選取含有 FHIR 儲存庫的資料集。
  3. 按一下 FHIR 儲存庫的名稱。

gcloud

如要取得 FHIR 儲存庫的詳細資料,請執行 gcloud healthcare fhir-stores describe 指令。

使用下列任何指令資料之前,請先替換以下項目:

  • LOCATION:資料集位置
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • FHIR_STORE_ID:FHIR 儲存庫 ID

執行下列指令:

Linux、macOS 或 Cloud Shell

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

Windows (PowerShell)

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

Windows (cmd.exe)

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

您應該會收到類似以下的回應。

如果您在 FhirStore 資源中設定了任何欄位,這些欄位也會顯示在回應中。

回應

...
name: projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID
...
version: FHIR_STORE_VERSION

REST

如要進一步瞭解 FHIR 儲存庫,請使用 projects.locations.datasets.fhirStores.get 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID: Google Cloud 專案的 ID
  • LOCATION:資料集位置
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • FHIR_STORE_ID:FHIR 儲存庫 ID

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

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

PowerShell

執行下列指令:

$cred = gcloud auth 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

APIs Explorer

開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。完成所有必填欄位,然後按一下「執行」

您應該會收到類似以下的回應。

如果您在 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: %w", 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: %w", 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.gson.GsonFactory;
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 GsonFactory();
  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/main/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 = f"{fhir_store_parent}/fhirStores/{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. 在 Google Cloud 控制台中,前往「Datasets」(資料集) 頁面。

    前往「資料集」

  2. 選取包含要查看的資料儲存庫的資料集。

gcloud

如要查看 FHIR 儲存庫的詳細資料,請執行 gcloud healthcare fhir-stores list 指令。

使用下列任何指令資料之前,請先替換以下項目:

  • DATASET_ID:FHIR 儲存庫的父項資料集
  • LOCATION:資料集位置

執行下列指令:

Linux、macOS 或 Cloud Shell

gcloud healthcare fhir-stores list --dataset=DATASET_ID --location=LOCATION

Windows (PowerShell)

gcloud healthcare fhir-stores list --dataset=DATASET_ID --location=LOCATION

Windows (cmd.exe)

gcloud healthcare fhir-stores list --dataset=DATASET_ID --location=LOCATION

您應該會收到類似以下的回應。

如果您在 FhirStore 資源中設定了任何欄位,這些欄位也會顯示在回應中。

ID             LOCATION     REF_INT  RES_VER  UPDATE_CREATE  TOPIC
FHIR_STORE_ID  LOCATION                                       PUBSUB_TOPIC
...

REST

如要列出資料集中的 FHIR 存放區,請使用 projects.locations.datasets.fhirStores.list 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID: Google Cloud 專案的 ID
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • LOCATION:資料集位置

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

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

PowerShell

執行下列指令:

$cred = gcloud auth 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

APIs Explorer

開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。完成所有必填欄位,然後按一下「執行」

您應該會收到類似以下的回應。

如果您在 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: %w", 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: %w", 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.gson.GsonFactory;
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 GsonFactory();
  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/main/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 儲存庫的功能 (STU3R4R5) 或相容性 (DSTU2) 陳述式。

能力或符合聲明中的資訊會反映 FHIR 存放區中的設定。舉例來說,如果 FhirStore.enableUpdateCreate 設為 true,則會反映在功能聲明的 CapabilityStatement.rest.resource.updateCreate 欄位中。

下表列出 Cloud Healthcare API 方法,可用來取得 FHIR 儲存庫的功能或符合聲明,以及相應的 FHIR 規格互動:

Cloud Healthcare API 方法 FHIR 規格互動
projects.locations.datasets.fhirStores.fhir.capabilities 功能 (STU3R4R5) 或 conformance (DSTU2)

控制台

Google Cloud 控制台和 gcloud CLI 不支援這項操作。請改用 curl、PowerShell 或您偏好的語言。

gcloud

Google Cloud 控制台和 gcloud CLI 不支援這項操作。請改用 curl、PowerShell 或您偏好的語言。

REST

如要取得 FHIR 儲存庫的功能或符合性聲明,請使用 projects.locations.datasets.fhirStores.fhir.capabilities 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID: Google Cloud 專案的 ID
  • LOCATION:資料集位置
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • FHIR_STORE_ID:FHIR 儲存庫 ID

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

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

PowerShell

執行下列指令:

$cred = gcloud auth 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" | Select-Object -Expand Content

APIs Explorer

開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。完成所有必填欄位,然後按一下「執行」

您應該會收到如下的 JSON 回應:

Go

import (
	"context"
	"fmt"
	"io"

	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: %w", 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: %w", err)
	}

	defer resp.Body.Close()

	respBytes, err := io.ReadAll(resp.Body)
	if err != nil {
		return fmt.Errorf("could not read response: %w", 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.gson.GsonFactory;
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 GsonFactory();
  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/main/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 = f"{fhir_store_parent}/fhirStores/{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 儲存庫中的所有資源都會套用基本資源驗證。這項驗證可確保在建立資源時,下列項目皆為真:

  • 已定義所有必填欄位。
  • 所有提及的資源類型皆有效。
  • 資源符合所有 FHIRPath 限制。

您可以為 FHIR 儲存庫停用一或多種這類基本資源驗證,讓基本資源驗證的嚴格程度降低。

控制台

Google Cloud 控制台和 gcloud CLI 不支援這項操作。請改用 curl、PowerShell 或您偏好的語言。

gcloud

Google Cloud 主控台和 gcloud CLI 不支援這項操作。請改用 curl、PowerShell 或您偏好的語言。

REST

如要在現有 FHIR 儲存庫中停用基本資源驗證功能,請使用 projects.locations.datasets.fhirStores.patch 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID: Google Cloud 專案的 ID
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • LOCATION:資料集位置
  • BASE_RESOURCE_VALIDATION_TYPE:您要停用的基礎資源驗證類型。如要停用驗證功能,請將下列任一欄位設為 true
    • disableRequiredFieldValidation
    • disableReferenceTypeValidation
    • disableFhirpathValidation

JSON 要求主體:

{
  "validationConfig": {
    "BASE_RESOURCE_VALIDATION_TYPE": true
  }
}

如要傳送要求,請選擇以下其中一個選項:

curl

將要求主體儲存在名為 request.json 的檔案中。在終端機中執行下列指令,在目前目錄中建立或覆寫此檔案:

cat > request.json << 'EOF'
{
  "validationConfig": {
    "BASE_RESOURCE_VALIDATION_TYPE": true
  }
}
EOF

接著,執行下列指令來傳送 REST 要求:

curl -X PATCH \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID?updateMask=validationConfig"

PowerShell

將要求主體儲存在名為 request.json 的檔案中。在終端機中執行下列指令,在目前目錄中建立或覆寫此檔案:

@'
{
  "validationConfig": {
    "BASE_RESOURCE_VALIDATION_TYPE": true
  }
}
'@  | Out-File -FilePath request.json -Encoding utf8

接著,執行下列指令來傳送 REST 要求:

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

Invoke-WebRequest `
-Method PATCH `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://healthcare.googleapis.com/v1/projects/PROJECT_ID/locations/LOCATION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID?updateMask=validationConfig" | Select-Object -Expand Content

APIs Explorer

複製要求主體並開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。將要求主體貼到這項工具中,並填妥其他必填欄位,然後按一下「執行」

您應該會收到類似以下的回應。

如果您在 FhirStore 資源中設定了任何欄位,這些欄位也會顯示在回應中。

刪除 FHIR 儲存庫

下列範例說明如何刪除 FHIR 儲存庫。

控制台

如何刪除資料儲存庫:

  1. 在 Google Cloud 控制台中,前往「Datasets」(資料集) 頁面。

    前往「資料集」

  2. 選取含有要刪除資料儲存庫的資料集。
  3. 在「動作」下拉式清單中,為要刪除的資料儲存庫選擇「刪除」
  4. 如要確認,請輸入資料儲存庫名稱,然後按一下「Delete」

gcloud

如要刪除 FHIR 儲存庫,請執行 gcloud healthcare fhir-stores delete 指令。

使用下列任何指令資料之前,請先替換以下項目:

  • LOCATION:資料集位置
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • FHIR_STORE_ID:FHIR 儲存庫 ID

執行下列指令:

Linux、macOS 或 Cloud Shell

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

Windows (PowerShell)

gcloud healthcare fhir-stores delete FHIR_STORE_ID `
  --dataset=DATASET_ID `
  --location=LOCATION

Windows (cmd.exe)

gcloud healthcare fhir-stores delete FHIR_STORE_ID ^
  --dataset=DATASET_ID ^
  --location=LOCATION

您應該會收到類似以下的回應:

Deleted fhirStore [FHIR_STORE_ID].

REST

如要刪除 FHIR 儲存庫,請使用 projects.locations.datasets.fhirStores.delete 方法。

使用任何要求資料之前,請先替換以下項目:

  • PROJECT_ID: Google Cloud 專案的 ID
  • LOCATION:資料集位置
  • DATASET_ID:FHIR 儲存庫的父項資料集
  • FHIR_STORE_ID:FHIR 儲存庫 ID

如要傳送要求,請選擇以下其中一個選項:

curl

執行下列指令:

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

PowerShell

執行下列指令:

$cred = gcloud auth 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

APIs Explorer

開啟方法參考頁面。系統會在頁面右側開啟 API Explorer 面板。 您可以使用這項工具來傳送要求。完成所有必填欄位,然後按一下「執行」

您應該會收到如下的 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: %w", 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: %w", 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.gson.GsonFactory;
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 GsonFactory();
  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/main/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 = f"{fhir_store_parent}/fhirStores/{fhir_store_id}"

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

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

    return response

後續步驟

瞭解如何建立及使用 FHIR 資源