Exporting DICOM metadata to BigQuery

This page explains how to export DICOM metadata to BigQuery for exploration and analysis. For information on the BigQuery schema that is created when exporting DICOM metadata, see Understanding the BigQuery DICOM schema.

Setting BigQuery permissions

Before exporting DICOM metadata to BigQuery, you must grant additional permissions to the Cloud Healthcare Service Agent service account. For more information, see DICOM store BigQuery permissions.

Exporting DICOM metadata

The following samples show how to export DICOM metadata to a BigQuery table. In these samples, the DICOM store and the BigQuery table are in the same project. To export DICOM metadata to another project, see Exporting DICOM metadata to a different project.

When setting the BigQuery destination, use the fully qualified URI, like so:

bq://PROJECT_ID.BIGQUERY_DATASET_ID.BIGQUERY_TABLE_ID

The behavior of the export operation can vary depending on whether the destination table exists and whether you have set the force field (using the API) or the --overwrite-table flag (using the gcloud command-line tool):

  • If the destination table already exists and force is set to true or the --overwrite-table flag is specified, the export operation overwrites the existing table.
  • If the destination table already exists and force is set to false or the --overwrite-table flag is not specified, an error occurs.
  • If the destination table does not already exist, then a new table is created, regardless of whether you specify the force field or the --overwrite-table flag.

gcloud

To export DICOM metadata to BigQuery, use the gcloud beta healthcare dicom-stores export bq command. Specify the following information:

  • The name of the parent dataset
  • The name of the DICOM store
  • The name of an existing BigQuery dataset
  • The BigQuery table name. The table name can contain only letters (upper or lower case), numbers, and underscores.

The following sample shows the gcloud beta dicom-stores export bq command.

gcloud beta healthcare dicom-stores export bq DICOM_STORE \
  --dataset=DATASET_ID \
  --location=REGION \
  --bq-table=bq://PROJECT_ID.BIGQUERY_DATASET_ID.BIGQUERY_TABLE_ID \
  [--overwrite-table]

After you run the command, it returns the operation name:

name: projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/operations/OPERATION_ID

To view more details about the operation, run the gcloud beta healthcare operations describe command, providing the OPERATION_ID from the response:

gcloud beta healthcare operations describe OPERATION_ID \
  --dataset=DATASET_ID 

When the operation finishes, the response includes done: true.

done: true
metadata:
  '@type': type.googleapis.com/google.cloud.healthcare.v1beta1.OperationMetadata
  apiMethodName: google.cloud.healthcare.v1beta1.dicom.DicomService.ExportDicomData
  createTime: 'CREATE_TIME'
  endTime: 'END_TIME'
name: projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID
response:
  '@type': '...'

API

To export DICOM metadata to BigQuery, use the projects.locations.datasets.dicomStores.export method.

curl command

To export DICOM metadata, make a POST request and specify the following information:

  • The name of the parent dataset
  • The name of the DICOM store
  • The name of an existing BigQuery dataset
  • A name for the BigQuery export table. The name can contain only letters (upper or lower case), numbers, and underscores. The BigQuery dataset must exist but the Cloud Healthcare API can update an existing table or create a new one.
  • An access token

The following sample shows a POST request using curl.

curl -X POST \
    -H "Authorization: Bearer "$(gcloud auth print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    --data "{
      'bigqueryDestination': {
        'tableUri': 'bq://PROJECT_ID.BIGQUERY_DATASET_ID.BIGQUERY_TABLE_ID'
      }
    }" "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID:export"

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

The response contains an operation name. To track the status of the operation, you can use the Operation get method:

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

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_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1beta1.OperationMetadata",
    "apiMethodName": "google.cloud.healthcare.v1beta1.dicom.DicomService.ExportDicomData",
    "createTime": "CREATE_TIME",
    "endTime": "END_TIME"
  },
  "done": true,
  "response": {
    "@type": "..."
  }
}

PowerShell

To export DICOM metadata, make a POST request and specify the following information:

  • The name of the parent dataset
  • The name of the DICOM store
  • The name of an existing BigQuery dataset
  • The BigQuery table
  • An access token

The following sample shows a POST request using Windows PowerShell.

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

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body "{
    'bigqueryDestination': {
      'tableUri': 'bq://PROJECT_ID.BIGQUERY_DATASET_ID.BIGQUERY_TABLE_ID'
    }
  }" `
  -Uri "https://healthcare.googleapis.com/v1beta1/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID:export" | 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_ID"
}

The response contains an operation name. To track the status of the operation, you can use the Operation get method:

$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_ID" | 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_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1beta1.OperationMetadata",
    "apiMethodName": "google.cloud.healthcare.v1beta1.dicom.DicomService.ExportDicomData",
    "createTime": "CREATE_TIME",
    "endTime": "END_TIME"
  },
  "done": true,
  "response": {
    "@type": "..."
  }
}

Exporting DICOM metadata to a different project

To export DICOM metadata from one project to another project, first see Exporting DICOM metadata to a different project permissions for information on how to set Cloud IAM permissions in the destination project.

gcloud

To export DICOM metadata from a DICOM store in one project to a BigQuery table in another project, use the gcloud beta healthcare dicom-stores export bq command. Specify the name of the parent dataset, the name of the DICOM store, the destination project, the name of an existing BigQuery dataset in the destination project, and the BigQuery table.

The following sample shows the gcloud beta dicom-stores export bq command.

gcloud beta healthcare dicom-stores export bq DICOM_STORE \
  --dataset=DATASET_ID \
  --location=REGION \
  --bq-table=bq://DESTINATION_PROJECT_ID.BIGQUERY_DATASET_ID.BIGQUERY_TABLE_ID \
  [--overwrite-table]

The command line displays the operation ID and, after the operation completes, done:

Request issued for: [DICOM_STORE_ID]
Waiting for operation [projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/OPERATION_ID] to complete...done.
name: projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID

To view more details about the operation, run the gcloud beta healthcare operations describe command, providing the OPERATION_ID from the response:

gcloud beta healthcare operations describe OPERATION_ID \
  --dataset=DATASET_ID 

When the operation finishes, the response includes done: true.

done: true
metadata:
  '@type': type.googleapis.com/google.cloud.healthcare.v1beta1.OperationMetadata
  apiMethodName: google.cloud.healthcare.v1beta1.dicom.DicomService.ExportDicomData
  createTime: 'CREATE_TIME'
  endTime: 'END_TIME'
name: projects/SOURCE_PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID
response:
  '@type': '...'

API

To export DICOM metadata to BigQuery, use the projects.locations.datasets.dicomStores.export method.

curl command

To export DICOM metadata from a DICOM store in one project to a BigQuery table in another project, make a POST request and specify the following information:

  • The source project
  • The name of the parent dataset
  • The name of the DICOM store
  • The destination project
  • The name of an existing BigQuery dataset in the destination project
  • The BigQuery table
  • An access token

The following sample shows a POST request using curl.

curl -X POST \
    -H "Authorization: Bearer "$(gcloud auth print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    --data "{
      'bigqueryDestination': {
        'tableUri': 'bq://DESTINATION_PROJECT_ID.BIGQUERY_DATASET_ID.BIGQUERY_TABLE_ID'
      }
    }" "https://healthcare.googleapis.com/v1beta1/projects/SOURCE_PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID:export"

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

200 OK
{
  "name": "projects/SOURCE_PROJECT_ID/locations/REGION/datasets/DATASET_ID/operations/OPERATION_ID"
}

The response contains an operation name. To track the status of the operation, you can use the Operation get method:

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

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/SOURCE_PROJECT_ID/locations/REGION/datasets/DATASET_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1beta1.OperationMetadata",
    "apiMethodName": "google.cloud.healthcare.v1beta1.dicom.DicomService.ExportDicomData",
    "createTime": "CREATE_TIME",
    "endTime": "END_TIME"
  },
  "done": true,
  "response": {
    "@type": "..."
  }
}

PowerShell

To export DICOM metadata from a DICOM store in one project to a BigQuery table in another project, make a POST request and specify the following information:

  • The source project
  • The name of the parent dataset
  • The name of the DICOM store
  • The destination project
  • The name of an existing BigQuery dataset in the destination project
  • The BigQuery table
  • An access token

The following sample shows a POST request using Windows PowerShell.

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

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body "{
    'bigqueryDestination': {
      'tableUri': 'bq://DESTINATION_PROJECT_ID.BIGQUERY_DATASET_ID.BIGQUERY_TABLE_ID'
    }
  }" `
  -Uri "https://healthcare.googleapis.com/v1beta1/projects/SOURCE_PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID:export" | 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/SOURCE_PROJECT_ID/locations/REGION/datasets/DATASET_ID/operations/OPERATION_ID"
}

The response contains an operation name. To track the status of the operation, you can use the Operation get method:

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

Invoke-WebRequest `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1beta1/projects/SOURCE_PROJECT_ID/locations/REGION/datasets/DATASET_ID/operations/OPERATION_ID" | 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/SOURCE_PROJECT_ID/locations/REGION/datasets/DATASET_ID/operations/OPERATION_ID",
  "metadata": {
    "@type": "type.googleapis.com/google.cloud.healthcare.v1beta1.OperationMetadata",
    "apiMethodName": "google.cloud.healthcare.v1beta1.dicom.DicomService.ExportDicomData",
    "createTime": "CREATE_TIME",
    "endTime": "END_TIME"
  },
  "done": true,
  "response": {
    "@type": "..."
  }
}

Var denne siden nyttig? Si fra hva du synes:

Send tilbakemelding om ...

Cloud Healthcare API