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

Note that 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 will be created, regardless of whether you specify the force field or the --overwrite-table flag.

gcloud

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

To export DICOM metadata to BigQuery, use the gcloud alpha healthcare dicom-stores export command. Specify the name of the parent dataset, the name of the DICOM store, the name of an existing BigQuery dataset, and the BigQuery table.

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

gcloud alpha healthcare dicom-stores export 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 alpha healthcare operations describe command, providing the OPERATION_ID from the response:

gcloud alpha 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.v1alpha2.OperationMetadata
  apiMethodName: google.cloud.healthcare.v1alpha2.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 provide the name of the parent dataset, the name of the DICOM store, the name of an existing BigQuery dataset, the BigQuery table, and 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. You can use the Operation get method to track the status of the operation:

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:

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 provide the name of the parent dataset, the name of the DICOM store, the name of an existing BigQuery dataset, the BigQuery table, and 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. You can use the Operation get method to track the status of the operation:

$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:

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

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

To export DICOM metadata from a DICOM store in one project to a BigQuery table in another project, use the gcloud alpha healthcare dicom-stores export 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 alpha dicom-stores export command.

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

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

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

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

gcloud alpha 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.v1alpha2.OperationMetadata
  apiMethodName: google.cloud.healthcare.v1alpha2.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 provide 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, and 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. You can use the Operation get method to track the status of the operation:

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_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/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 provide 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, and 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. You can use the Operation get method to track the status of the operation:

$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_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/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