Quickstart using curl or Windows PowerShell

This page shows you how to create a dataset and a DICOM, FHIR, or HL7v2 store using the Cloud Healthcare API with curl and Windows PowerShell.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the GCP Console, on the project selector page, select or create a GCP project.

    Go to the Project selector page

  3. Make sure that billing is enabled for your Google Cloud Platform project.

    Learn how to enable billing

  4. Set up authentication:
    1. In the GCP Console, go to the Create service account key page.

      Go to the Create Service Account Key page
    2. From the Service account list, select New service account.
    3. In the Service account name field, enter a name.
    4. From the Role list, select Project > Owner.

      Note: The Role field authorizes your service account to access resources. You can view and change this field later by using the GCP Console. If you are developing a production app, specify more granular permissions than Project > Owner. For more information, see granting roles to service accounts.
    5. Click Create. A JSON file that contains your key downloads to your computer.
  5. Set the environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key. This variable only applies to your current shell session, so if you open a new session, set the variable again.

  6. Enable the Cloud Healthcare API.

    Enable the API

  7. Install and initialize the Cloud SDK.

Tip: Need a command prompt? You can use the Google Cloud Shell. The Google Cloud Shell is a command line environment that already includes the Google Cloud SDK, so you don't need to install it. (The Google Cloud SDK also comes preinstalled on Google Compute Engine Virtual Machines.)

Create a dataset

Datasets are the basic containers that hold healthcare data in Google Cloud Platform.

Tip: You can edit placeholder values in requests, denoted by the VARIABLES syntax, directly in this page.

curl command

To create a dataset, make a POST request, providing the name of the dataset and an access token. The following sample shows a POST request using curl.

When setting the REGION variable, use us-central1, europe-west2, europe-west4, northamerica-northeast1, or us.

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. The response contains an identifier for a long-running operation. Long-running operations are returned when method calls might take a substantial amount of time to complete.

200 OK
{
  "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/operations/OPERATION_NAME",
}

Using the response returned above, call the Operation get method to track the status of the operation and view more details:

curl -X GET \
    -H "Authorization: Bearer "$(gcloud auth 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. You can tell that the operation finished when the response contains "done": true.

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, providing the name of the dataset and an access token. The following sample shows a POST request using Windows PowerShell.

When setting the REGION variable, use us-central1, europe-west2, europe-west4, northamerica-northeast1, or us.

$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. The response contains an identifier for a long-running operation. Long-running operations are returned when method calls might take a substantial amount of time to complete.

200 OK
{
  "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/operations/OPERATION_NAME",
}

Using the response returned above, call the Operation get method to track the status of the operation and view more details:

$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/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. You can tell that the operation finished when the response contains "done": true.

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"
  }
}

Get dataset details

You can view details about the dataset and verify that it was created.

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 curl.

$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"
}

Creating and managing DICOM, FHIR, and HL7v2 stores

To complete this quickstart, expand the relevant section:

Clean up

To avoid incurring charges to your GCP account for the resources used in this tutorial, you can clean up the resources you created on GCP. If you created a new project for this tutorial, follow the steps in Delete the project. Otherwise, follow the steps in Delete the dataset.

Delete the project

  1. In the GCP Console, go to the Projects page.

    Go to the Projects page

  2. In the project list, select the project you want to delete and click Delete .
  3. In the dialog, type the project ID, and then click Shut down to delete the project.

Delete the dataset

If you no longer need the dataset created in this quickstart, you can delete it. Deleting a dataset permanently deletes the dataset and any FHIR, HL7v2, or DICOM stores it contains.

curl command

To delete a dataset, make a DELETE request, providing 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, providing 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
{}

What's next

Var denne siden nyttig? Si fra hva du synes:

Send tilbakemelding om ...

Cloud Healthcare API