Creating and managing datasets

This page explains how to create, edit, view, and delete datasets. For an overview of datasets, see the Data model documentation.

Creating a dataset

To use the Cloud Healthcare API, you must create at least one dataset.

The following examples show how to create a dataset.

Console

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

    Go to the Datasets page

  2. Click Create dataset.
  3. Choose a dataset identifier that's unique in your project and region. If the identifier is not unique, the dataset creation fails.
  4. Choose the region where the dataset permanently resides and then click Create.
The new dataset appears in the list.

gcloud

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

To create a dataset, run the gcloud alpha healthcare datasets create command.

  • The DATASET_ID must be unique within the region. It can be any Unicode string of 1 to 256 characters consisting of numbers, letters, underscores, dashes, and periods.
  • The region can be us-central1, europe-west2, or northamerica-northeast1. To use the default region for the project, omit the --location option.
gcloud alpha healthcare datasets create DATASET_ID \
  --location=REGION

If the request is successful, the command prompt displays:

Created dataset [DATASET_ID]

API

To create a dataset, use the projects.locations.datasets.create method.

curl command

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

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?datasetId=DATASET_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/operations/OPERATION_NAME",
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1beta1.dataset.Dataset",
    "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID"
  }
}

The response contains an operation name. Use the Operation get method to track the status of the operation and view more details:

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

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

200 OK
{
  "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/operations/OPERATION_NAME",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1beta1.OperationMetadata",
    "apiMethodName": "google.cloud.healthcare.v1beta1.dataset.DatasetService.CreateDataset",
    "createTime": "2018-01-01T00:00:00+00:00",
    "endTime": "2018-01-01T00:00:00+00:00"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1beta1.dataset.Dataset",
    "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID"
  }
}

PowerShell

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

$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?datasetId=DATASET_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/operations/OPERATION_NAME",
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1beta1.dataset.Dataset",
    "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID"
  }
}

The response contains an operation name. Use the Operation get method to track the status of the operation and view more details:

$cred = gcloud auth application-default 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/operations/OPERATION_NAME" | Select-Object -Expand Content

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

200 OK
{
  "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/operations/OPERATION_NAME",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1beta1.OperationMetadata",
    "apiMethodName": "google.cloud.healthcare.v1beta1.dataset.DatasetService.CreateDataset",
    "createTime": "2018-01-01T00:00:00+00:00",
    "endTime": "2018-01-01T00:00:00+00:00"
  },
  "done": true,
  "response": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1beta1.dataset.Dataset",
    "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID"
  }
}

Go

import (
	"context"
	"fmt"
	"io"

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

// createDataset creates a dataset.
func createDataset(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)
	}

	datasetsService := healthcareService.Projects.Locations.Datasets

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

	resp, err := datasetsService.Create(parent, &healthcare.Dataset{}).DatasetId(datasetID).Do()
	if err != nil {
		return fmt.Errorf("Create: %v", err)
	}

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

Java

import com.google.HealthcareQuickstart;
import com.google.api.services.healthcare.v1beta1.CloudHealthcare.Projects.Locations.Datasets.Create;
import com.google.api.services.healthcare.v1beta1.model.Dataset;

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

public class DatasetCreate {
  public static void createDataset(String projectId, String cloudRegion, String datasetId)
      throws IOException {
    Dataset dataset = new Dataset();
    cloudRegion = Optional.of(cloudRegion).orElse("us-central1");

    String parentName = String.format("projects/%s/locations/%s", projectId, cloudRegion);
    Create createRequest = HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .create(parentName, dataset);

    createRequest.setDatasetId(datasetId);
    createRequest.execute();

    System.out.println("Created Dataset: " + createRequest.getDatasetId());
  }
}

Node.js

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

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

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

  await healthcare.projects.locations.datasets.create(request);
  console.log(`Created dataset: ${datasetId}`);
}

createDataset();

Python

def create_dataset(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id):
    """Creates a dataset."""
    client = get_client(service_account_json)
    dataset_parent = 'projects/{}/locations/{}'.format(
        project_id, cloud_region)

    body = {}

    request = client.projects().locations().datasets().create(
        parent=dataset_parent, body=body, datasetId=dataset_id)

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

Editing a dataset

The following examples show how to edit an existing dataset.

Console

GCP Console does not support editing a healthcare dataset. Instead, use curl, Windows PowerShell, or your preferred language.

gcloud

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

To edit a dataset, run the gcloud alpha healthcare datasets update command, specifying the new time zone. For example, you can set the time zone to "Canada/Eastern".

gcloud alpha healthcare datasets update DATASET_ID \
  --location=REGION \
  --time-zone=TIME_ZONE

If the request is successful, the command prompt displays the operation and dataset details:

Updated dataset [DATASET_ID].
name: projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID
timeZone: TIME_ZONE

API

To edit a dataset, use the projects.locations.datasets.patch method.

curl command

To edit a dataset, make a PATCH request and provide the name of the dataset, the metadata to update, an update mask, and an access token. The following sample shows how to update the timezone by making a PATCH request using curl.

Replace the TIMEZONE variable with a value, such as UTC. Note that the timezone value must be in uppercase.

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

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"
  "timeZone": "TIMEZONE"
}

PowerShell

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

Replace the TIMEZONE variable with a value, such as UTC. Note that the timezone value must be in uppercase.

$cred = gcloud auth print-access-token
$headers = @{ Authorization = "Bearer $cred" }
Invoke-WebRequest `
  -Method Patch `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body "{
      'timeZone': 'TIMEZONE'
  }" `
  -Uri "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID?updateMask=timeZone" | 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"
  "timeZone": "TIMEZONE"
}

Go

import (
	"context"
	"fmt"
	"io"

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

// patchDataset updates (patches) a dataset by updating its timezone..
func patchDataset(w io.Writer, projectID, location, datasetID, newTimeZone string) error {
	ctx := context.Background()

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

	datasetsService := healthcareService.Projects.Locations.Datasets

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

	if _, err := datasetsService.Patch(name, &healthcare.Dataset{
		TimeZone: newTimeZone,
	}).UpdateMask("timeZone").Do(); err != nil {
		return fmt.Errorf("Patch: %v", err)
	}

	fmt.Fprintf(w, "Patched dataset %s with timeZone %s\n", datasetID, newTimeZone)

	return nil
}

Java

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

import java.io.IOException;

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

  public static void patchDataset(String datasetName, String timeZone) throws IOException {
    Dataset patched = HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .get(datasetName)
        .execute();
    patched.setTimeZone(timeZone);
    Dataset response = HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .patch(datasetName, patched)
        .setUpdateMask("timeZone")
        .execute();
    System.out.println("Patched Dataset: " + GSON.toJson(response));
  }
}

Node.js

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

  const request = {
    name: datasetName,
    updateMask: 'timeZone',
    resource: {timeZone: timeZone},
  };

  client.projects.locations.datasets
    .patch(request)
    .then(results => {
      console.log(
        `Dataset ${datasetId} patched with time zone ${results.data.timeZone}`
      );
    })
    .catch(err => {
      console.error(err);
    });
}

Python

def patch_dataset(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id,
        time_zone):
    """Updates dataset metadata."""
    client = get_client(service_account_json)
    dataset_parent = 'projects/{}/locations/{}'.format(
        project_id, cloud_region)
    dataset_name = '{}/datasets/{}'.format(dataset_parent, dataset_id)

    # Sets the time zone to GMT
    patch = {
        'timeZone': time_zone
    }

    request = client.projects().locations().datasets().patch(
        name=dataset_name, updateMask='timeZone', body=patch)

    try:
        response = request.execute()
        print(
            'Patched dataset {} with time zone: {}'.format(
                dataset_id,
                time_zone))
        return response
    except HttpError as e:
        print('Error, dataset not patched: {}'.format(e))
        return ""

Getting dataset details

The following examples show how to get details about 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 view details about a dataset, run the gcloud alpha healthcare datasets describe command.

gcloud alpha healthcare datasets describe DATASET_ID \
  --location=REGION

If the request is successful, the command prompt displays the dataset details:

name: projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID
timeZone: TIME_ZONE

API

To get details about a dataset, use the projects.locations.datasets.get method.

curl command

To get details about 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"

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"
  "timeZone": "UTC"
}

PowerShell

To get details about 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" | 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"
  "timeZone": "UTC"
}

Go

import (
	"context"
	"fmt"
	"io"

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

// getDataset gets a dataset.
func getDataset(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)
	}

	datasetsService := healthcareService.Projects.Locations.Datasets

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

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

	fmt.Fprintf(w, "Name: %s\n", resp.Name)
	fmt.Fprintf(w, "Time zone: %s\n", resp.TimeZone)

	return nil
}

Java

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

import java.io.IOException;

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

  public static void getDataset(String datasetName) throws IOException {
    Dataset dataset = HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .get(datasetName)
        .execute();
    System.out.println("Retrieved Dataset: " + GSON.toJson(dataset));
  }
}

Node.js

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

  const request = {name: datasetName};

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

Python

def get_dataset(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id):
    """Gets any metadata associated with a dataset."""
    client = get_client(service_account_json)
    dataset_name = 'projects/{}/locations/{}/datasets/{}'.format(
        project_id, cloud_region, dataset_id)

    datasets = client.projects().locations().datasets()
    dataset = datasets.get(name=dataset_name).execute()

    print('Name: {}'.format(dataset.get('name')))
    print('Time zone: {}'.format(dataset.get('timeZone')))

    return dataset

The following examples show how to list the datasets in your project.

Console

To list the datasets in your project, in the GCP Console, go to the Healthcare Datasets page.

Go to the Datasets page

gcloud

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

To list the datasets in your project, run the gcloud alpha healthcare datasets list command.

gcloud alpha healthcare datasets list

If the request is successful, the command prompt lists the datasets:

ID           LOCATION     TIMEZONE
DATASET_ID   REGION       TIME_ZONE

API

To list the datasets in your project, use the projects.locations.datasets.list method.

curl command

To list the datasets in your project, make a GET request and provide the name of your project 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"

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

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

PowerShell

To list the datasets in your project, make a GET request and provide the name of your project 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" | 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
{
  "datasets": [
    {
      "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID",
      "timeZone": "UTC"
    },
    {
      ...
      ...
    }
  ]
}

Go

import (
	"context"
	"fmt"
	"io"

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

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

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

	datasetsService := healthcareService.Projects.Locations.Datasets

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

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

	fmt.Fprintln(w, "Datasets:")
	for _, d := range resp.Datasets {
		fmt.Fprintln(w, d.Name)
	}

	return nil
}

Java

import com.google.HealthcareQuickstart;
import com.google.api.services.healthcare.v1beta1.model.Dataset;
import com.google.api.services.healthcare.v1beta1.model.ListDatasetsResponse;

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

public class DatasetList {
  public static void listDatasets(String projectId, String cloudRegion) throws IOException {
    cloudRegion = Optional.of(cloudRegion).orElse("us-central1");
    String parentName = String.format("projects/%s/locations/%s", projectId, cloudRegion);
    ListDatasetsResponse response = HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .list(parentName)
        .execute();
    List<Dataset> datasets = response.getDatasets();
    if (datasets == null) {
      System.out.println("Retrieved 0 datasets");
      return;
    }
    System.out.println("Retrieved " + datasets.size() + " datasets");
    for (Dataset dataset : datasets) {
      System.out.println("  - " + dataset.getName());
    }
  }
}

Node.js

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

  const request = {parent: parentName};

  client.projects.locations.datasets
    .list(request)
    .then(results => {
      console.log('Datasets:', results.data);
    })
    .catch(err => {
      console.error(err);
    });
}

Python

def list_datasets(service_account_json, project_id, cloud_region):
    """Lists the datasets in the project."""
    client = get_client(service_account_json)
    dataset_parent = 'projects/{}/locations/{}'.format(
        project_id, cloud_region)

    datasets = client.projects().locations().datasets().list(
        parent=dataset_parent).execute().get('datasets', [])

    for dataset in datasets:
        print('Dataset: {}\nTime zone: {}'.format(
            dataset.get('name'),
            dataset.get('timeZone')
        ))

    return datasets

Deleting a dataset

The following examples show how to delete a dataset.

Console

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

    Go to the Datasets page

  2. Select the dataset that you want to delete and then click Delete.
  3. To confirm, type the dataset identifier and then click Delete.

gcloud

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

To delete a dataset, run the gcloud alpha healthcare datasets delete command:

  1. Run the delete command.
    gcloud alpha healthcare datasets delete DATASET_ID \
      --location=REGION
    
  2. To confirm, type Y.

If the request is successful, the command prompt displays:

Deleted dataset [DATASET_ID]

API

To delete a dataset, use the projects.locations.datasets.delete method.

curl command

To delete a dataset, make a DELETE request and provide the name of the dataset 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"

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

200 OK
{}

PowerShell

To delete a dataset, make a DELETE request and provide the name of the dataset 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" | 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
{}

Go

import (
	"context"
	"fmt"
	"io"

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

// deleteDataset deletes the given dataset.
func deleteDataset(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)
	}

	datasetsService := healthcareService.Projects.Locations.Datasets

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

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

Java

import com.google.HealthcareQuickstart;

import java.io.IOException;

public class DatasetDelete {
  public static void deleteDataset(String datasetName) throws IOException {
    HealthcareQuickstart.getCloudHealthcareClient()
        .projects()
        .locations()
        .datasets()
        .delete(datasetName)
        .execute();
  }
}

Node.js

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

  const request = {name: datasetName};

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

Python

def delete_dataset(
        service_account_json,
        project_id,
        cloud_region,
        dataset_id):
    """Deletes a dataset."""
    client = get_client(service_account_json)
    dataset_name = 'projects/{}/locations/{}/datasets/{}'.format(
        project_id, cloud_region, dataset_id)

    request = client.projects().locations().datasets().delete(
        name=dataset_name)

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

What's next

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

Send feedback about...

Cloud Healthcare API