Creating and managing annotation records

This page explains how to create, view, and delete annotation records. For an overview of annotation stores and annotation records, see Annotations.

Creating an annotation record

Before you can create an annotation record, you need to create an annotation store.

The following samples show how to create an annotation record.

API

To create an annotation record, use the projects.locations.datasets.annotationStores.annotations.create method.

curl command

To create an annotation record, make a POST request and provide the name of the parent dataset, the name of the parent annotation store, the source of the annotation record, the type of annotation record, and an access token. The following sample shows a POST request using curl that creates an annotation record for a DICOM image. The annotation uses a bounding box to mark the dimensions of a part of the image and labels the bounded area with the name "bounding-box." This sample assumes that you have already stored a DICOM instance in a DICOM store. This DICOM instance is referenced in the name field of cloudHealthcareSource.

curl -X POST \
    -H "Authorization: Bearer "$(gcloud auth print-access-token) \
    -H "Content-Type: application/json; charset=utf-8" \
    --data "{
      'annotationSource': {
        'cloudHealthcareSource': {
          'name': 'projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID/dicomWeb/studies/STUDY_UID'
        }
      },
      'imageAnnotation': {
        'boundingPolys': [
          {
            'vertices': [
              {
                'x': 100,
                'y': 100
              },
              {
                'x': 100,
                'y': 400
              },
              {
                'x': 400,
                'y': 100
              },
              {
                'x': 400,
                'y': 400
              }
            ],
            'label': 'bounding-box'
          }
        ]
      }
    }" \
    "https://healthcare.googleapis.com/v1alpha2/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID/annotations"

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/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_ID",
  "annotationSource": {
    "cloudHealthcareSource": {
      "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID/dicomWeb/studies/STUDY_UID"
    }
  },
  "imageAnnotation": {
    "boundingPolys": [
      {
        "vertices": [
          {
            "x": 100,
            "y": 100
          },
          {
            "x": 100,
            "y": 400
          },
          {
            "x": 400,
            "y": 100
          },
          {
            "x": 400,
            "y": 400
          }
        ],
        "label": "bounding-box"
      }
    ]
  }
}

PowerShell

To create an annotation record, make a POST request and provide the name of the parent dataset, the name of the parent annotation store, the source of the annotation record, the type of annotation record, and an access token. The following sample shows a POST request using Windows PowerShell that creates an annotation record for a DICOM image. The annotation uses a bounding box to mark the dimensions of a part of the image and labels the bounded area with the name "bounding-box." This sample assumes that you have already stored a DICOM instance in a DICOM store. This DICOM instance is referenced in the name field of cloudHealthcareSource.

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

Invoke-WebRequest `
  -Method Post `
  -Headers $headers `
  -ContentType: "application/json; charset=utf-8" `
  -Body "{
    'annotationSource': {
      'cloudHealthcareSource': {
        'name': 'projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID/dicomWeb/studies/STUDY_UID'
      }
    },
    'imageAnnotation': {
      'boundingPolys': [
        {
          'vertices': [
            {
              'x': 100,
              'y': 100
            },
            {
              'x': 100,
              'y': 400
            },
            {
              'x': 400,
              'y': 100
            },
            {
              'x': 400,
              'y': 400
            }
          ],
          'label': 'bounding-box'
        }
      ]
    }
  }" `
  -Uri "https://healthcare.googleapis.com/v1alpha2/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID/annotations" | 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/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_ID",
  "annotationSource": {
    "cloudHealthcareSource": {
      "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID/dicomWeb/studies/STUDY_UID"
    }
  },
  "imageAnnotation": {
    "boundingPolys": [
      {
        "vertices": [
          {
            "x": 100,
            "y": 100
          },
          {
            "x": 100,
            "y": 400
          },
          {
            "x": 400,
            "y": 100
          },
          {
            "x": 400,
            "y": 400
          }
        ],
        "label": "bounding-box"
      }
    ]
  }
}

Editing an annotation record

The following samples show how to edit the annotation record from Creating an annotation so that it has a resource type label.

API

To edit an annotation record, use the projects.locations.datasets.annotationStores.annotations.patch method.

curl command

To edit an annotation record, make a PATCH request and provide the name of the parent dataset, the name of the parent annotation store, the annotation record ID, the data 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 "{
      'resourceAnnotation': {
        'label': 'VALUE'
      }
    }" \
    "https://healthcare.googleapis.com/v1alpha2/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_ID/ANNOTATION_ID?updateMask=resourceAnnotation"

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/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_ID",
  "annotationSource": {
    "cloudHealthcareSource": {
      "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID/dicomWeb/studies/STUDY_UID"
    }
  },
  "resourceAnnotation": {
    "label": "VALUE"
  }
}

PowerShell

To edit an annotation record, make a PATCH request and provide the name of the parent dataset, the name of the parent annotation store, the annotation record ID, the data 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 "{
    'resourceAnnotation': {
      'label': 'VALUE'
    }
  }" `
  -Uri "https://healthcare.googleapis.com/v1alpha2/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_ID?updateMask=resourceAnnotation" | 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/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_ID",
  "annotationSource": {
    "cloudHealthcareSource": {
      "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID/dicomWeb/studies/STUDY_UID"
    }
  },
  "resourceAnnotation": {
    "label": "VALUE"
  }
}

Getting annotation record details

The following samples show how to get details about an annotation record.

API

To get details about an annotation record, use the projects.locations.datasets.annotationStores.annotations.get method.

curl command

To get details about an annotation record, make a GET request and provide the name of the parent dataset, the name of the parent annotation store, the annotation record ID, and an access token. The following sample shows a GET request using curl to view an annotation record for a DICOM instance.

curl -X GET \
    -H "Authorization: Bearer "$(gcloud auth print-access-token) \
    "https://healthcare.googleapis.com/v1alpha2/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_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/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_ID",
  "annotationSource": {
    "cloudHealthcareSource": {
      "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID/dicomWeb/studies/STUDY_UID"
    }
  }
}

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

PowerShell

To get details about an annotation record, make a GET request and provide the name of the parent dataset, the name of the parent annotation store, the annotation record ID, and an access token. The following sample shows a GET request using Windows PowerShell to view an annotation record for a DICOM instance.

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

Invoke-WebRequest `
  -Method Get `
  -Headers $headers `
  -Uri "https://healthcare.googleapis.com/v1alpha2/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_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/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_ID",
  "annotationSource": {
    "cloudHealthcareSource": {
      "name": "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/dicomStores/DICOM_STORE_ID/dicomWeb/studies/STUDY_UID"
    }
  }
}

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

Listing annotation records in an annotation store

The following samples show how to list the annotation records in an annotation store.

API

To list the annotation records in an annotation store, use the projects.locations.datasets.annotationStores.annotations.list method.

curl command

To list the annotations records in an annotation store, make a GET request and provide the name of the parent dataset, the name of the annotation 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/v1alpha2/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID/annotations"

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

200 OK
{
  "annotations": [
      "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID",
      ...
  ]
}

PowerShell

To list the annotations records in an annotation store, make a GET request and provide the name of the parent dataset, the name of the annotation 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/v1alpha2/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID/annotations" | 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
{
  "annotations": [
      "projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID",
      ...
  ]
}

Deleting an annotation record

The following samples show how to delete an annotation record.

API

To delete an annotation record, use the projects.locations.datasets.annotationStores.annotations.delete method.

curl command

To delete an annotation record, make a DELETE request and provide the name of the parent dataset, the name of the parent annotation store, the annotation record ID, 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/v1alpha2/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_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 an annotation record, make a DELETE request and provide the name of the parent dataset, the name of the parent annotation store, the annotation record ID, 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 `
  -Uri "https://healthcare.googleapis.com/v1alpha2/projects/PROJECT_ID/locations/REGION/datasets/DATASET_ID/annotationStores/ANNOTATION_STORE_ID/annotations/ANNOTATION_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
{}

¿Te ha resultado útil esta página? Enviar comentarios:

Enviar comentarios sobre...

Cloud Healthcare API