Creating and managing FHIR stores

This page explains how to create, edit, view, and delete Fast Healthcare Interoperability Resources (FHIR) stores.

Creating a FHIR store

Before you can create a FHIR store, you need to create a dataset.

The following samples show how to create a FHIR store.

Console

To create a FHIR store:
  1. In the GCP Console, go to the Datasets page.

    Go to the Datasets page

  2. Open the dataset where you want to create a FHIR store.
  3. Click Create Data Store.
  4. Enter a name of your choice that's unique in your dataset. If the name is not unique, the data store creation fails.
  5. Select FHIR as the data store type.
  6. Click Create.
  7. If you want to configure a Cloud Pub/Sub topic for the data store, type the topic name. When specifying a Cloud Pub/Sub topic, enter the qualified URI to the topic, like so:
    projects/PROJECT_ID/topics/PUBSUB_TOPIC
    
  8. Click Create.
The new data store appears in the list.

gcloud

The following sample works with the v1alpha2 version of the Cloud Healthcare API.

To create a FHIR store in the dataset, run the gcloud alpha healthcare fhir-stores create command.

  • The FHIR store ID must be unique in the dataset. It can be any Unicode string of 1 to 256 characters consisting of numbers, letters, underscores, dashes, and periods.
  • To notify a Cloud Pub/Sub topic of FHIR store changes, specify an existing Cloud Pub/Sub topic name using the --pubsub-topic argument.
When specifying a Cloud Pub/Sub topic, enter the qualified URI to the topic, like so:
projects/PROJECT_ID/topics/PUBSUB_TOPIC

The following sample shows how to create a FHIR store.

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

If the request is successful, the command prompt displays the following message:

Created fhirStore [FHIR_STORE_ID].

API

To create a FHIR store, use the projects.locations.datasets.fhirStores.create method.

curl command

To create a FHIR store, make a POST request and provide the name of the parent dataset, the name of the FHIR store, and an access token. The following sample shows a POST request using curl. Set a name for the FHIR store in the FHIR_STORE_ID variable. The FHIR store must be unique in its parent dataset. It can be any Unicode string of 1 to 256 characters consisting of numbers, letters, underscores, dashes, and periods.

You can optionally configure an existing Cloud Pub/Sub topic to which the Cloud Healthcare API sends notifications of FHIR store changes. See Editing a FHIR store for information on how to configure the Cloud Pub/Sub topic.

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

If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:

200 OK
{
  "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID"
}

PowerShell

To create a FHIR store, make a POST request and provide the name of the parent dataset, the name of the FHIR store, and an access token. The following sample shows a POST request using Windows PowerShell. Set a name for the FHIR store in the FHIR_STORE_ID variable. The FHIR store must be unique in its parent dataset. It can be any Unicode string of 1 to 256 characters consisting of numbers, letters, underscores, dashes, and periods.

You can optionally configure an existing Cloud Pub/Sub topic to which the Cloud Healthcare API sends notifications of FHIR store changes. See Editing a FHIR store for information on how to configure the Cloud Pub/Sub topic.

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

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

If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:

200 OK
{
  "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID"
}

Go

import (
	"context"
	"fmt"
	"io"

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

// createFHIRStore creates an FHIR store.
func createFHIRStore(w io.Writer, projectID, location, datasetID, fhirStoreID string) error {
	ctx := context.Background()

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

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

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

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

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

Java

import com.google.HealthcareQuickstart;
import com.google.api.services.healthcare.v1beta1.CloudHealthcare;
import com.google.api.services.healthcare.v1beta1.model.FhirStore;

import java.io.IOException;
import java.util.Optional;

public class FhirStoreCreate {
  public static void createFhirStore(String projectId, String cloudRegion, String datasetId, String fhirStoreId)
      throws IOException {
    FhirStore fhirStore = new FhirStore();
    cloudRegion = Optional.of(cloudRegion).orElse("us-central1");

    String parentName = String.format("projects/%s/locations/%s/datasets/%s", projectId, cloudRegion, datasetId);
    CloudHealthcare.Projects.Locations.Datasets.FhirStores.Create createRequest = HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .fhirStores()
        .create(parentName, fhirStore);

    createRequest.setFhirStoreId(fhirStoreId);
    createRequest.execute();

    System.out.println("Created FHIR store: " + createRequest.getFhirStoreId());
  }
}

Node.js

function createFhirStore(
  client,
  projectId,
  cloudRegion,
  datasetId,
  fhirStoreId
) {
  // Client retrieved in callback
  // getClient(serviceAccountJson, function(cb) {...});
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  const parentName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;

  const request = {parent: parentName, fhirStoreId: fhirStoreId};

  client.projects.locations.datasets.fhirStores
    .create(request)
    .then(() => {
      console.log(`Created FHIR store: ${fhirStoreId}`);
    })
    .catch(err => {
      console.error(err);
    });
}

Python

def create_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id):
    """Creates a new FHIR store within the parent dataset."""
    client = get_client(service_account_json)
    fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
        project_id, cloud_region, dataset_id)

    body = {}

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

    try:
        response = request.execute()
        print('Created FHIR store: {}'.format(fhir_store_id))
        return response
    except HttpError as e:
        print('Error, FHIR store not created: {}'.format(e))
        return ""

Editing a FHIR store

The following samples show how to edit the Cloud Pub/Sub topic to which the Cloud Healthcare API sends notifications of FHIR store changes.

When specifying a Cloud Pub/Sub topic, enter the qualified URI to the topic, like so:
projects/PROJECT_ID/topics/PUBSUB_TOPIC
For notifications to work, you must grant additional permissions to the Cloud Healthcare Service Agent service account. For more information, see DICOM, FHIR, and HL7v2 store Cloud Pub/Sub permissions.

Console

GCP Console does not support editing the Cloud Pub/Sub topic. Instead, use curl, Windows PowerShell, or your preferred language.

gcloud

The following sample works with the v1alpha2 version of the Cloud Healthcare API.

To update the FHIR store, run the gcloud alpha healthcare fhir-stores update command.

The following sample shows how to update the Cloud Pub/Sub topic for the FHIR store.

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

If the request is successful, the command prompt displays the FHIR store details including the new topic name:

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

API

To edit a FHIR store, use the projects.locations.datasets.fhirStores.patch method.

curl command

To edit a FHIR store, make a PATCH request and provide the name of the parent dataset, the name of the FHIR store, the metadata to update, an update mask, and an access token. The following sample shows a PATCH request using curl.

curl -X PATCH \
    -H "Authorization: Bearer "$(gcloud auth print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    --data "{
      'notificationConfig': {
        'pubsubTopic': 'projects/PROJECT_ID/topics/PUBSUB_TOPIC'
      }
    }" "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID?updateMask=notificationConfig"

If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:

200 OK
{
  "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID",
  "notificationConfig": {
    "pubsubTopic": "projects/PROJECT_ID/topics/PUBSUB_TOPIC"
  }
}

PowerShell

To edit a FHIR store, make a PATCH request and provide the name of the parent dataset, the name of the FHIR store, the metadata to update, an update mask, and an access token. The following sample shows a PATCH request using Windows PowerShell.

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

Invoke-WebRequest `
  -Method Patch `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body "{
      'notificationConfig': {
        'pubsubTopic': 'projects/PROJECT_ID/topics/PUBSUB_TOPIC'
      }
  }" `
  -Uri "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID?updateMask=notificationConfig" | Select-Object -Expand Content

If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:

200 OK
{
  "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID",
  "notificationConfig": {
    "pubsubTopic": "projects/PROJECT_ID/topics/PUBSUB_TOPIC"
  }
}

Go

import (
	"context"
	"fmt"
	"io"

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

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

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

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

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

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

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

	return nil
}

Java

import com.google.HealthcareQuickstart;
import com.google.api.services.healthcare.v1beta1.model.FhirStore;
import com.google.api.services.healthcare.v1beta1.model.NotificationConfig;
import com.google.gson.Gson;

import java.io.IOException;

public class FhirStorePatch {
  private static final Gson GSON = new Gson();

  public static void patchFhirStore(String fhirStoreName, String pubsubTopic) throws IOException {
    FhirStore patched = HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .fhirStores()
        .get(fhirStoreName)
        .execute();
    NotificationConfig notificationConfig = new NotificationConfig();
    notificationConfig.setPubsubTopic(pubsubTopic);
    patched.setNotificationConfig(notificationConfig);
    FhirStore response = HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .fhirStores()
        .patch(fhirStoreName, patched)
        .setUpdateMask("notificationConfig")
        .execute();
    System.out.println("Patched FHIR store: " + GSON.toJson(response));
  }
}

Node.js

function patchFhirStore(
  client,
  projectId,
  cloudRegion,
  datasetId,
  fhirStoreId,
  pubsubTopic
) {
  // Client retrieved in callback
  // getClient(serviceAccountJson, function(cb) {...});
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  // const pubsubTopic = 'my-topic'
  const fhirStoreName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`;

  const request = {
    name: fhirStoreName,
    updateMask: 'notificationConfig',
    resource: {
      notificationConfig: {
        pubsubTopic: `projects/${projectId}/locations/${cloudRegion}/topics/${pubsubTopic}`,
      },
    },
  };

  client.projects.locations.datasets.fhirStores
    .patch(request)
    .then(results => {
      console.log(
        'Patched FHIR store with Cloud Pub/Sub topic',
        results['data']['notificationConfig']['pubsubTopic']
      );
    })
    .catch(err => {
      console.error(err);
    });
}

Python

def patch_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id):
    """Updates the FHIR store."""
    client = get_client(service_account_json)
    fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
        project_id, cloud_region, dataset_id)
    fhir_store_name = '{}/fhirStores/{}'.format(
        fhir_store_parent, fhir_store_id)

    patch = {
        'notificationConfig': None}

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

    try:
        response = request.execute()
        print(
            'Patched FHIR store {} with Cloud Pub/Sub topic: None'.format(
                fhir_store_id))
        return response
    except HttpError as e:
        print('Error, FHIR store not patched: {}'.format(e))
        return ""

Getting FHIR store details

The following samples show how to get details about a FHIR store.

Console

To view a FHIR store's details:
  1. In the GCP Console, go to the Datasets page.

    Go to the Datasets page

  2. Click the ID of the dataset that contains the FHIR store.
  3. Click the name of the FHIR store.
Note: GCP Console does not display the Cloud Pub/Sub topic to which the Healthcare API sends notifications.

gcloud

The following sample works with the v1alpha2 version of the Cloud Healthcare API.

To view details about a FHIR store, run the gcloud alpha healthcare fhir-stores describe command.

The following sample shows how to get details about a FHIR store.

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

If the request is successful, the command prompt displays the FHIR store details:

name: projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhir-stores/FHIR_STORE_ID

API

To get details about a FHIR store, use the projects.locations.datasets.fhirStores.get method.

curl command

To get details about a FHIR store, make a GET request and provide the name of the parent dataset, the name of the FHIR store, and an access token. The following sample shows a GET request using curl.

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

If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:

200 OK
{
  "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID"
}

If you configured any fields in the FhirStore resource, they also appear in the response.

PowerShell

To get details about a FHIR store, make a GET request and provide the name of the parent dataset, the name of the FHIR store, and an access token. The following sample shows a GET request using Windows PowerShell.

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

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

If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:

200 OK
{
  "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID"
}

If you configured any fields in the FhirStore resource, they also appear in the response.

Go

import (
	"context"
	"fmt"
	"io"

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

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

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

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

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

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

	fmt.Fprintf(w, "Got FHIR store: %q\n", store.Name)
	return nil
}

Java

import com.google.HealthcareQuickstart;
import com.google.api.services.healthcare.v1beta1.model.FhirStore;
import com.google.gson.Gson;

import java.io.IOException;

public class FhirStoreGet {
  private static final Gson GSON = new Gson();

  public static void getFhirStore(String fhirStoreName) throws IOException {
    FhirStore fhirStore = HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .fhirStores()
        .get(fhirStoreName)
        .execute();
    System.out.println("Retrieved FHIR store: " + GSON.toJson(fhirStore));
  }
}

Node.js

function getFhirStore(client, projectId, cloudRegion, datasetId, fhirStoreId) {
  // Client retrieved in callback
  // getClient(serviceAccountJson, function(cb) {...});
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  const fhirStoreName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`;

  const request = {name: fhirStoreName};

  client.projects.locations.datasets.fhirStores
    .get(request)
    .then(results => {
      console.log('Got FHIR store:\n', results['data']);
    })
    .catch(err => {
      console.error(err);
    });
}

Python

def get_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id):
    """Gets the specified FHIR store."""
    client = get_client(service_account_json)
    fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
        project_id, cloud_region, dataset_id)
    fhir_store_name = '{}/fhirStores/{}'.format(
        fhir_store_parent, fhir_store_id)

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

    print('Name: {}'.format(fhir_store.get('name')))
    print('Enable update/create: {}'.format(fhir_store.get(
        'enableUpdateCreate')))
    print('Notification config:')
    if fhir_store.get('notificationConfig') is not None:
        notification_config = fhir_store.get('notificationConfig')
        print('\tCloud Pub/Sub topic: {}'.format(
            notification_config.get('pubsubTopic')))
    print('Disable referential integrity: {}'.format(
        fhir_store.get('disableReferentialIntegrity')))

    return fhir_store

The following samples show how to list the FHIR stores in a dataset.

Console

To view the data stores in a dataset:
  1. In the GCP Console, go to the Datasets page.

    Go to the Datasets page

  2. Click the ID of the dataset whose data stores you want to view.

gcloud

The following sample works with the v1alpha2 version of the Cloud Healthcare API.

To list the FHIR stores in a dataset, run the gcloud alpha healthcare fhir-stores list command.

gcloud alpha healthcare fhir-stores list --dataset=DATASET_ID

If the request is successful, the command prompt lists the FHIR stores:

ID             LOCATION     REF_INT  RES_VER  UPDATE_CREATE  TOPIC
FHIR_STORE_ID  REGION

API

To list the FHIR stores in a dataset, use the projects.locations.datasets.fhirStores.list method.

curl command

To list the FHIR stores in a dataset, make a GET request and provide the name of the dataset and an access token. The following sample shows a GET request using curl.

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

If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:

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

If you configured any fields in the FhirStore resource, they also appear in the response.

PowerShell

To list the FHIR stores in a dataset, make a GET request and provide the name of the dataset and an access token. The following sample shows a GET request using Windows PowerShell.

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

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

If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:

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

If you configured any fields in the FhirStore resource, they also appear in the response.

Go

import (
	"context"
	"fmt"
	"io"

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

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

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

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

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

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

	fmt.Fprintln(w, "FHIR stores:")
	for _, s := range resp.FhirStores {
		fmt.Fprintln(w, s.Name)
	}
	return nil
}

Java

import com.google.HealthcareQuickstart;
import com.google.api.services.healthcare.v1beta1.model.FhirStore;
import com.google.api.services.healthcare.v1beta1.model.ListFhirStoresResponse;

import java.io.IOException;
import java.util.List;

public class FhirStoreList {
  public static void listFhirStores(String projectId, String cloudRegion, String datasetId) throws IOException {
    String parentName = String.format("projects/%s/locations/%s/datasets/%s", projectId, cloudRegion, datasetId);
    ListFhirStoresResponse response = HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .fhirStores()
        .list(parentName)
        .execute();
    List<FhirStore> fhirStores = response.getFhirStores();
    if (fhirStores == null) {
      System.out.println("Retrieved 0 FHIR stores");
      return;
    }
    System.out.println("Retrieved " + fhirStores.size() + " FHIR stores");
    for (int i = 0; i < fhirStores.size(); i++) {
      System.out.println("  - " + fhirStores.get(i).getName());
    }
  }
}

Node.js

function listFhirStores(client, projectId, cloudRegion, datasetId) {
  // Client retrieved in callback
  // getClient(serviceAccountJson, function(cb) {...});
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  const parentName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}`;

  const request = {parent: parentName};

  client.projects.locations.datasets.fhirStores
    .list(request)
    .then(results => {
      console.log('FHIR stores:\n', results['data']['fhirStores']);
    })
    .catch(err => {
      console.error(err);
    });
}

Python

def list_fhir_stores(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id):
    """Lists the FHIR stores in the given dataset."""
    client = get_client(service_account_json)
    fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
        project_id, cloud_region, 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: {}\n'
              'Enable update/create: {}\n'
              'Notification config: {}\n'
              'Disable referential integrity: {}'.format(
                  fhir_store.get('name'),
                  fhir_store.get('enableUpdateCreate'),
                  fhir_store.get('notificationConfig'),
                  fhir_store.get('disableReferentialIntegrity')
              ))

    return fhir_stores

Getting the capabilities statement for a FHIR store

The following samples show how to get the capabilities statement for a FHIR store. The information in the capabilities statement reflects the settings in the FHIR store. For example, if FhirStore.enableUpdateCreate is set to true, then this will be reflected in the capabilities statement's CapabilityStatement.rest.resource.updateCreate field.

The following table shows the Cloud Healthcare API method for getting the capabilities statement for a FHIR store and its equivalent FHIR specification interaction:

Cloud Healthcare API method FHIR specification interaction
projects.locations.datasets.fhirStores.fhir.capabilities capabilities

Console

GCP Console does not support getting the capabilities statement. Instead, use curl, Windows PowerShell, or your preferred language.

gcloud

The gcloud tool does not support getting the capabilities statement. Instead, use curl, Windows PowerShell, or your preferred language.

API

To get the capabilities statement for a FHIR store, use the projects.locations.datasets.fhirStores.fhir.capabilities method.

curl command

To get the capabilities statement for a FHIR store, make a GET request and provide the name of the dataset, the name of the FHIR store, and an access token. The following sample shows a GET request using curl.

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

If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:

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

PowerShell

To get the capabilities statement for a FHIR store, make a GET request and provide the name of the dataset, the name of the FHIR store, and an access token. The following sample shows a GET request using Windows PowerShell.

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

Invoke-WebRequest `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID/fhir/metadata" | Select-Object -Expand Content

If the request is successful, the server returns a 200 OK HTTP status code and the response in JSON format:

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

Go

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

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

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

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

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

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

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

	defer resp.Body.Close()

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

	if resp.StatusCode > 299 {
		return fmt.Errorf("Capabilities: status %d %s: %s", resp.StatusCode, resp.Status, respBytes)
	}
	fmt.Fprintf(w, "%s", respBytes)
	return nil
}

Node.js

function getMetadata(client, projectId, cloudRegion, datasetId, fhirStoreId) {
  // Client retrieved in callback
  // getClient(serviceAccountJson, function(cb) {...});
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  const fhirStoreName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`;

  const request = {name: fhirStoreName};

  client.projects.locations.datasets.fhirStores
    .getMetadata(request)
    .then(results => {
      console.log(`Capabilities statement for FHIR store ${fhirStoreId}:`);
      console.log(results);
    })
    .catch(err => {
      console.error(err);
    });
}

Python

def get_metadata(
        service_account_json,
        base_url,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id):
    """Gets the capabilities statement for a FHIR store."""
    url = '{}/projects/{}/locations/{}'.format(base_url,
                                               project_id, cloud_region)

    fhir_store_path = '{}/datasets/{}/fhirStores/{}/fhir/metadata'.format(
        url, dataset_id, fhir_store_id)

    # Make an authenticated API request
    session = get_session(service_account_json)

    response = session.get(fhir_store_path)
    response.raise_for_status()

    metadata = response.json()

    print(json.dumps(metadata, indent=2))

    return metadata

Deleting a FHIR store

The following samples show how to delete a FHIR store.

Console

To delete a data store:
  1. In the GCP Console, go to the Datasets page.

    Go to the Datasets page

  2. Open the dataset by clicking the dataset ID.
  3. Select the data store that you want to delete and then click Delete.
  4. To confirm, type the data store name and then click Delete.

gcloud

The following sample works with the v1alpha2 version of the Cloud Healthcare API.

To delete a FHIR store, run the gcloud alpha healthcare fhir-stores delete command:

  1. Run the delete command.

    gcloud alpha healthcare fhir-stores delete FHIR_STORE_ID \
    --dataset=DATASET_ID \
    --location=REGION
    
  2. To confirm, type Y.

If the request is successful, the command prompt displays the following message:

Deleted fhirStore [FHIR_STORE_ID]

API

To delete a FHIR store, use the projects.locations.datasets.fhirStores.delete method.

curl command

To delete a FHIR store, make a DELETE request and provide the name of the parent dataset, the name of the FHIR store, and an access token. The following sample shows a DELETE request using curl.

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

If the request is successful, the server returns a 200 OK HTTP status code and the empty response body in JSON format:

200 OK
{}

PowerShell

To delete a FHIR store, make a DELETE request and provide the name of the parent dataset, the name of the FHIR store, and an access token. The following sample shows a DELETE request using Windows PowerShell.

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

Invoke-WebRequest `
  -Method Delete `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/fhirStores/FHIR_STORE_ID" | Select-Object -Expand Content

If the request is successful, the server returns a 200 OK HTTP status code and the empty response body in JSON format:

200 OK
{}

Go

import (
	"context"
	"fmt"
	"io"

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

// deleteFHIRStore deletes an FHIR store.
func deleteFHIRStore(w io.Writer, projectID, location, datasetID, fhirStoreID string) error {
	ctx := context.Background()

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

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

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

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

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

Java

import com.google.HealthcareQuickstart;

import java.io.IOException;

public class FhirStoreDelete {
  public static void deleteFhirStore(String fhirStoreName) throws IOException {
    HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .fhirStores()
        .delete(fhirStoreName)
        .execute();
  }
}

Node.js

function deleteFhirStore(
  client,
  projectId,
  cloudRegion,
  datasetId,
  fhirStoreId
) {
  // Client retrieved in callback
  // getClient(serviceAccountJson, function(cb) {...});
  // const cloudRegion = 'us-central1';
  // const projectId = 'adjective-noun-123';
  // const datasetId = 'my-dataset';
  // const fhirStoreId = 'my-fhir-store';
  const fhirStoreName = `projects/${projectId}/locations/${cloudRegion}/datasets/${datasetId}/fhirStores/${fhirStoreId}`;

  const request = {name: fhirStoreName};

  client.projects.locations.datasets.fhirStores
    .delete(request)
    .then(() => {
      console.log(`Deleted FHIR store: ${fhirStoreId}`);
    })
    .catch(err => {
      console.error(err);
    });
}

Python

def delete_fhir_store(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        fhir_store_id):
    """Deletes the specified FHIR store."""
    client = get_client(service_account_json)
    fhir_store_parent = 'projects/{}/locations/{}/datasets/{}'.format(
        project_id, cloud_region, dataset_id)
    fhir_store_name = '{}/fhirStores/{}'.format(
        fhir_store_parent, fhir_store_id)

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

    try:
        response = request.execute()
        print('Deleted FHIR store: {}'.format(fhir_store_id))
        return response
    except HttpError as e:
        print('Error, FHIR store not deleted: {}'.format(e))
        return ""

What's next

Learn how to create and work with FHIR resources.

Was this page helpful? Let us know how we did:

Send feedback about...

Cloud Healthcare API