FHIR ストアの作成と管理

このページでは、Fast Healthcare Interoperability Resources(FHIR)ストアを作成、編集、表示、一覧表示、削除する方法について説明します。FHIR ストアは、申請リソース、患者リソース、投薬リソースなどの FHIR リソースを保持します。

Cloud Healthcare API は、次の FHIR バージョンをサポートしています。

FHIR ストアの作成

FHIR ストアを作成する前に、データセットを作成する必要があります。

次のサンプルでは、projects.locations.datasets.fhirStores.createメソッドを使用して FHIR ストアを作成する方法を説明します。

コンソール

FHIR ストアを作成するには、次の手順を行います。

  1. Google Cloud コンソールで、[データセット] ページに移動します。

    [データセット] に移動

  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. [オブジェクトの選択] パネルで、Cloud Storage のロケーションからプロファイル検証バンドル リソースを選択します。詳細については、Google Cloud コンソールを使用して実装ガイドを有効にするをご覧ください。
    6. [選択] をクリックします。
      • 選択した実装ガイドが、バージョン、URL、ステータスとともに表に表示されます。
      • 実装ガイドを有効にしているものの、プロファイルの検証を有効にしていない場合、実装ガイドは適用されません。
      • [次へ] をクリックします。
  9. 省略可: ストア内の FHIR リソースが作成、更新、パッチ適用、または削除されるたびにリソースの変更を BigQuery にエクスポートするには、次の手順を行います。
    1. [リソースの変更を BigQuery にストリーミングする] をクリックします。
    2. [ストリーミング構成を追加] をクリックします。BigQuery ストリーミングの詳細については、BigQuery への FHIR リソースの変更をストリーミングをご覧ください。
    3. [Recursive Structure Depth] スライダーで深度レベルを選択して、出力スキーマ内のすべての再帰構造の深度を設定します。デフォルトでは、再帰的深度の値は 2 です。
    4. [完了] をクリックしてストリーミング構成を保存します。
    5. [次へ] をクリックします。
  10. 省略可: FHIR ストアの Pub/Sub トピックを構成するには、次の手順を行います。
    1. [Cloud Pub/Sub 通知の受信] をクリックします。
    2. [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 文字列。
      • 数字
      • 文字
      • アンダースコア
      • ダッシュ
      • ピリオド
  • 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 文字列。
      • 数字
      • 文字
      • アンダースコア
      • ダッシュ
      • ピリオド
  • 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

API Explorer

リクエスト本文をコピーして、メソッド リファレンス ページを開きます。ページの右側に [API Explorer] パネルが開きます。このツールを操作してリクエストを送信できます。このツールにリクエスト本文を貼り付け、その他の必須フィールドに入力して、[Execute] をクリックします。

次のような 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 リソースの整理で役立つ Key-Value ペアです。
Pub/Sub トピックを指定する場合は、次のサンプルに示すようにトピックの修飾 URI を入力します。
projects/PROJECT_ID/topics/PUBSUB_TOPIC
通知を送信するには、Cloud Healthcare Service Agentサービス アカウントに追加の権限を付与する必要があります。詳しくは、DICOM、FHIR、HL7v2 ストアの Pub/Sub 権限をご覧ください。

コンソール

FHIR ストアを編集するには、次の手順を行います。

  1. Google Cloud コンソールで、[データセット] ページに移動します。
    データセットに移動

  2. 編集する FHIR ストアを含むデータセットを選択します。

  3. [データストア] リストで、編集する FHIR ストアを選択します。

  4. ストアの構成を編集するには、[ FHIR ストアの構成] をクリックします。

    FHIR ストアの構成オプションの詳細については、FHIR ストアの作成をご覧ください。

  5. ストアの実装ガイドを編集するには、 [実装ガイド] をクリックし、該当する実装ガイドを選択するか、Cloud Storage からカスタム実装ガイドをインポートします。詳細については、Google Cloud コンソールを使用して実装ガイドを有効にするをご覧ください。

    実装ガイドを編集するか、有効な実装ガイドを適用するには、[FHIR ストア構成] セクションでプロファイル検証を有効にする必要があります。

  6. ストアで FHIR リソースが作成、更新、パッチ適用、または削除されるたびにリソースの変更を BigQuery にエクスポートするには、[データセット] フィールドの [新しいストリーミング構成を追加] をクリックします。

  7. リソースの変更がストリーミングされる BigQuery データセットを選択します。BigQuery ストリーミングの詳細については、BigQuery に FHIR リソースの変更をストリーミングをご覧ください。

  8. 出力スキーマ内のすべての再帰的構造の深度を設定するには、[再帰的構造の深さ] スライダーで該当する深度をクリックします。デフォルトでは、再帰的深度は 2 です。

  9. 特定のリソースタイプのみのリソース変更をエクスポートするには、[FHIR リソースタイプを選択する] リストからリソースタイプを選択します。

  10. データストアの Pub/Sub トピックを構成するには、[Cloud Pub/Sub 通知] セクションでトピック名を選択します。Pub/Sub トピックを指定する場合は、次のサンプルに示すように、トピックの修飾 URI を入力します。

    projects/PROJECT_ID/topics/PUBSUB_TOPIC
    

  11. ストアに 1 つ以上のラベルを追加するには、 [ラベル] をクリックし、[ラベルを追加] をクリックして、Key-Value ラベルを入力します。リソースラベルの詳細については、リソースラベルの使用をご覧ください。

  12. [保存] をクリックします。

gcloud

FHIR ストアを編集するには、gcloud healthcare fhir-stores update コマンドを実行します。

後述のコマンドデータを使用する前に、次のように置き換えます。

  • 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 トピック ID。Pub/Sub 通知に含めるデータを決定するには、FHIR Pub/Sub 通知をご覧ください。
  • KEY1: 最初のラベルキー
  • VALUE1: 最初のラベル値
  • KEY2: 2 番目のラベルキー
  • VALUE2: 2 番目のラベル値

JSON 本文のリクエスト:

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

リクエストを送信するには、次のいずれかのオプションを選択します。

curl

リクエスト本文を request.json という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。

cat > request.json << 'EOF'
{
  "notificationConfig": {
    "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 という名前のファイルに保存します。ターミナルで次のコマンドを実行して、このファイルを現在のディレクトリに作成または上書きします。

@'
{
  "notificationConfig": {
    "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

API Explorer

リクエスト本文をコピーして、メソッド リファレンス ページを開きます。ページの右側に [API Explorer] パネルが開きます。このツールを操作してリクエストを送信できます。このツールにリクエスト本文を貼り付け、その他の必須フィールドに入力して、[Execute] をクリックします。

次のような 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)

	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: %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.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 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
    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/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
    fhir_store_parent = "projects/{}/locations/{}/datasets/{}".format(
        project_id, location, dataset_id
    )
    fhir_store_name = f"{fhir_store_parent}/fhirStores/{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(f"Patched FHIR store {fhir_store_id} with Cloud Pub/Sub topic: None")

    return response

FHIR ストアの詳細を取得する

以下のサンプルは、FHIR ストアの詳細を取得する方法を示しています。

コンソール

FHIR ストアの詳細を表示するには:

  1. Google Cloud コンソールで、[データセット] ページに移動します。

    [データセット] に移動

  2. FHIR ストアを含むデータセットを選択します。
  3. FHIR ストアの名前をクリックsみあす。

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

API Explorer

メソッド リファレンス ページを開きます。ページの右側に [API Explorer] パネルが開きます。このツールを操作してリクエストを送信できます。必須フィールドを入力して、[Execute] をクリックします。

次のようなレスポンスが返されます。

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 コンソールで、[データセット] ページに移動します。

    [データセット] に移動

  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

API Explorer

メソッド リファレンス ページを開きます。ページの右側に [API Explorer] パネルが開きます。このツールを操作してリクエストを送信できます。必須フィールドを入力して、[Execute] をクリックします。

次のようなレスポンスが返されます。

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 ストアの機能(STU3 または R4)または適合性(DSTU2)宣言を取得する方法を示しています。

機能または適合性宣言の情報は、FHIR ストアの設定を反映しています。たとえば、FhirStore.enableUpdateCreatetrue に設定されている場合、これは機能宣言の CapabilityStatement.rest.resource.updateCreate フィールドに反映されます。

次の表に、FHIR ストアの機能または適合性宣言を取得する Healthcare API メソッドと、FHIR 仕様での同等操作を示しています。

Cloud Healthcare API メソッド FHIR 仕様での操作
projects.locations.datasets.fhirStores.fhir.capabilities 機能(STU3 または R4)または 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

API Explorer

メソッド リファレンス ページを開きます。ページの右側に [API Explorer] パネルが開きます。このツールを操作してリクエストを送信できます。必須フィールドを入力して、[Execute] をクリックします。

次のような JSON レスポンスが返されます。

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: %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 := ioutil.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 ストアに対してこれらのタイプの基本リソース検証を 1 つ以上無効にすることで、基本リソース検証を緩やかにできます。

コンソール

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

API Explorer

リクエスト本文をコピーして、メソッド リファレンス ページを開きます。ページの右側に [API Explorer] パネルが開きます。このツールを操作してリクエストを送信できます。このツールにリクエスト本文を貼り付け、その他の必須フィールドに入力して、[Execute] をクリックします。

次のようなレスポンスが返されます。

FhirStore リソースでフィールドを構成した場合は、そのフィールドもレスポンスに表示されます。

FHIR ストアを削除する

以下のサンプルは、FHIR ストアを削除する方法を示しています。

コンソール

データストアを削除するには:

  1. Google Cloud コンソールで、[データセット] ページに移動します。

    [データセット] に移動

  2. 削除するデータストアを含むデータセットを選択します。
  3. 削除するデータストアの [アクション] プルダウン リストから [削除] を選択します。
  4. 確認のために、データストア名を入力して [削除] をクリックします。

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

API Explorer

メソッド リファレンス ページを開きます。ページの右側に [API Explorer] パネルが開きます。このツールを操作してリクエストを送信できます。必須フィールドを入力して、[Execute] をクリックします。

次のような 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 のリソースを作成して操作する方法を学習する