Updating image set metadata
Use the UpdateImageSetMetadata
action to update image set metadata
in AWS HealthImaging. You can use this asynchronous process to add, update, and remove image set metadata attributes, which are manifestations of
DICOM normalization elements that are created during import.
Using the UpdateImageSetMetadata
action, you can also remove Series and SOP Instances to keep image
sets in sync with external systems and to de-identify image set metadata. For more information, see
UpdateImageSetMetadata
in the AWS HealthImaging API Reference.
Note
Real-world DICOM imports require updating, adding, and removing attributes from the image set metadata. Keep the following points in mind when updating image set metadata:
-
Updating image set metadata creates a new version in the image set history. For more information, see Listing image set versions.
-
Updating image set metadata is an asynchronous process. Therefore,
imageSetState
andimageSetWorkflowStatus
response elements are available to provide the respective state and status of a locked image set. You cannot perform other write operations on a locked image set. -
DICOM element constraints are applied to metadata updates. For more information, see DICOM metadata constraints.
-
If an image set metadata update action is not successful, call and review the
message
response element.
The following diagram represents image set metadata being updated in HealthImaging.
![Diagram showing what updating image set metadata looks like in HealthImaging.](/images/healthimaging/latest/devguide/images/image-set-example-update-metadata.png)
To update image set metadata
Choose a tab based on your access preference to AWS HealthImaging.
- CLI
-
- AWS CLI
-
To insert or update an attribute in image set metadata
The following
update-image-set-metadata
code example inserts or updates an attribute in image set metadata.aws medical-imaging update-image-set-metadata \ --datastore-id 12345678901234567890123456789012 \ --image-set-id ea92b0d8838c72a3f25d00d13616f87e \ --latest-version-id 1 \ --update-image-set-metadata-updates file://metadata-updates.json
Contents of
metadata-updates.json
{ "DICOMUpdates": { "updatableAttributes": "eyJTY2hlbWFWZXJzaW9uIjoxLjEsIlBhdGllbnQiOnsiRElDT00iOnsiUGF0aWVudE5hbWUiOiJNWF5NWCJ9fX0=" } }
Note:
updatableAttributes
is a Base64 encoded JSON string. Here is the unencoded JSON string.{"SchemaVersion":1.1,"Patient":{"DICOM":{"PatientName":"MX^MX"}}}
Output:
{ "latestVersionId": "2", "imageSetWorkflowStatus": "UPDATING", "updatedAt": 1680042257.908, "imageSetId": "ea92b0d8838c72a3f25d00d13616f87e", "imageSetState": "LOCKED", "createdAt": 1680027126.436, "datastoreId": "12345678901234567890123456789012" }
To remove an attribute from image set metadata
The following
update-image-set-metadata
code example removes an attribute from image set metadata.aws medical-imaging update-image-set-metadata \ --datastore-id 12345678901234567890123456789012 \ --image-set-id ea92b0d8838c72a3f25d00d13616f87e \ --latest-version-id 1 \ --update-image-set-metadata-updates file://metadata-updates.json
Contents of
metadata-updates.json
{ "DICOMUpdates": { "removableAttributes": "e1NjaGVtYVZlcnNpb246MS4xLFN0dWR5OntESUNPTTp7U3R1ZHlEZXNjcmlwdGlvbjpDSEVTVH19fQo=" } }
Note:
removableAttributes
is a Base64 encoded JSON string. Here is the unencoded JSON string. The key and value must match the attribute to be removed.{"SchemaVersion":1.1,"Study":{"DICOM":{"StudyDescription":"CHEST"}}}
Output:
{ "latestVersionId": "2", "imageSetWorkflowStatus": "UPDATING", "updatedAt": 1680042257.908, "imageSetId": "ea92b0d8838c72a3f25d00d13616f87e", "imageSetState": "LOCKED", "createdAt": 1680027126.436, "datastoreId": "12345678901234567890123456789012" }
To remove an instance from image set metadata
The following
update-image-set-metadata
code example removes an instance from image set metadata.aws medical-imaging update-image-set-metadata \ --datastore-id 12345678901234567890123456789012 \ --image-set-id ea92b0d8838c72a3f25d00d13616f87e \ --latest-version-id 1 \ --update-image-set-metadata-updates file://metadata-updates.json
Contents of
metadata-updates.json
{ "DICOMUpdates": { "removableAttributes": "eezEuMS4xLjEuMS4xLjEyMzQ1LjEyMzQ1Njc4OTAxMi4xMjMuMTIzNDU2Nzg5MDEyMzQuMTp7SW5zdGFuY2VzOnsxLjEuMS4xLjEuMS4xMjM0NS4xMjM0NTY3ODkwMTIuMTIzLjEyMzQ1Njc4OTAxMjM0LjE6e319fX19fQo=" } }
Note:
removableAttributes
is a Base64 encoded JSON string. Here is the unencoded JSON string.{"1.1.1.1.1.1.12345.123456789012.123.12345678901234.1":{"Instances":{"1.1.1.1.1.1.12345.123456789012.123.12345678901234.1":{}}}}}}
Output:
{ "latestVersionId": "2", "imageSetWorkflowStatus": "UPDATING", "updatedAt": 1680042257.908, "imageSetId": "ea92b0d8838c72a3f25d00d13616f87e", "imageSetState": "LOCKED", "createdAt": 1680027126.436, "datastoreId": "12345678901234567890123456789012" }
-
For API details, see UpdateImageSetMetadata
in AWS CLI Command Reference.
-
- Java
-
- SDK for Java 2.x
-
public static void updateMedicalImageSetMetadata(MedicalImagingClient medicalImagingClient, String datastoreId, String imagesetId, String versionId, MetadataUpdates metadataUpdates) { try { UpdateImageSetMetadataRequest updateImageSetMetadataRequest = UpdateImageSetMetadataRequest .builder() .datastoreId(datastoreId) .imageSetId(imagesetId) .latestVersionId(versionId) .updateImageSetMetadataUpdates(metadataUpdates) .build(); UpdateImageSetMetadataResponse response = medicalImagingClient.updateImageSetMetadata(updateImageSetMetadataRequest); System.out.println("The image set metadata was updated" + response); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
Use case #1: Insert or update an attribute.
final String insertAttributes = """ { "SchemaVersion": 1.1, "Study": { "DICOM": { "StudyDescription": "CT CHEST" } } } """; MetadataUpdates metadataInsertUpdates = MetadataUpdates.builder() .dicomUpdates(DICOMUpdates.builder() .updatableAttributes(SdkBytes.fromByteBuffer( ByteBuffer.wrap(insertAttributes .getBytes(StandardCharsets.UTF_8)))) .build()) .build(); updateMedicalImageSetMetadata(medicalImagingClient, datastoreId, imagesetId, versionid, metadataInsertUpdates);
Use case #2: Remove an attribute.
final String removeAttributes = """ { "SchemaVersion": 1.1, "Study": { "DICOM": { "StudyDescription": "CT CHEST" } } } """; MetadataUpdates metadataRemoveUpdates = MetadataUpdates.builder() .dicomUpdates(DICOMUpdates.builder() .removableAttributes(SdkBytes.fromByteBuffer( ByteBuffer.wrap(removeAttributes .getBytes(StandardCharsets.UTF_8)))) .build()) .build(); updateMedicalImageSetMetadata(medicalImagingClient, datastoreId, imagesetId, versionid, metadataRemoveUpdates);
Use case #3: Remove an instance.
final String removeInstance = """ { "SchemaVersion": 1.1, "Study": { "Series": { "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": { "Instances": { "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": {} } } } } } """; MetadataUpdates metadataRemoveUpdates = MetadataUpdates.builder() .dicomUpdates(DICOMUpdates.builder() .removableAttributes(SdkBytes.fromByteBuffer( ByteBuffer.wrap(removeInstance .getBytes(StandardCharsets.UTF_8)))) .build()) .build(); updateMedicalImageSetMetadata(medicalImagingClient, datastoreId, imagesetId, versionid, metadataRemoveUpdates);
-
For API details, see UpdateImageSetMetadata in AWS SDK for Java 2.x API Reference.
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. -
- JavaScript
-
- SDK for JavaScript (v3)
-
import {UpdateImageSetMetadataCommand} from "@aws-sdk/client-medical-imaging"; import {medicalImagingClient} from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The ID of the HealthImaging data store. * @param {string} imageSetId - The ID of the HealthImaging image set. * @param {string} latestVersionId - The ID of the HealthImaging image set version. * @param {{}} updateMetadata - The metadata to update. */ export const updateImageSetMetadata = async (datastoreId = "xxxxxxxxxx", imageSetId = "xxxxxxxxxx", latestVersionId = "1", updateMetadata = '{}') => { const response = await medicalImagingClient.send( new UpdateImageSetMetadataCommand({ datastoreId: datastoreId, imageSetId: imageSetId, latestVersionId: latestVersionId, updateImageSetMetadataUpdates: updateMetadata }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '7966e869-e311-4bff-92ec-56a61d3003ea', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // createdAt: 2023-09-22T14:49:26.427Z, // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // imageSetId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // imageSetState: 'LOCKED', // imageSetWorkflowStatus: 'UPDATING', // latestVersionId: '4', // updatedAt: 2023-09-27T19:41:43.494Z // } return response; };
Use case #1: Insert or update an attribute.
const insertAttributes = JSON.stringify({ "SchemaVersion": 1.1, "Study": { "DICOM": { "StudyDescription": "CT CHEST" } } }); const updateMetadata = { "DICOMUpdates": { "updatableAttributes": new TextEncoder().encode(insertAttributes) } }; await updateImageSetMetadata(datastoreID, imageSetID, versionID, updateMetadata);
Use case #2: Remove an attribute.
// Attribute key and value must match the existing attribute. const remove_attribute = JSON.stringify({ "SchemaVersion": 1.1, "Study": { "DICOM": { "StudyDescription": "CT CHEST" } } }); const updateMetadata = { "DICOMUpdates": { "removableAttributes": new TextEncoder().encode(remove_attribute) } }; await updateImageSetMetadata(datastoreID, imageSetID, versionID, updateMetadata);
Use case #3: Remove an instance.
const remove_instance = JSON.stringify({ "SchemaVersion": 1.1, "Study": { "Series": { "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": { "Instances": { "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": {} } } } } }); const updateMetadata = { "DICOMUpdates": { "removableAttributes": new TextEncoder().encode(remove_instance) } }; await updateImageSetMetadata(datastoreID, imageSetID, versionID, updateMetadata);
-
For API details, see UpdateImageSetMetadata in AWS SDK for JavaScript API Reference.
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. -
- Python
-
- SDK for Python (Boto3)
-
class MedicalImagingWrapper: def __init__(self, health_imaging_client): self.health_imaging_client = health_imaging_client def update_image_set_metadata( self, datastore_id, image_set_id, version_id, metadata ): """ Update the metadata of an image set. :param datastore_id: The ID of the data store. :param image_set_id: The ID of the image set. :param version_id: The ID of the image set version. :param metadata: The image set metadata as a dictionary. For example {"DICOMUpdates": {"updatableAttributes": "{\"SchemaVersion\":1.1,\"Patient\":{\"DICOM\":{\"PatientName\":\"Garcia^Gloria\"}}}"}} :return: The updated image set metadata. """ try: updated_metadata = self.health_imaging_client.update_image_set_metadata( imageSetId=image_set_id, datastoreId=datastore_id, latestVersionId=version_id, updateImageSetMetadataUpdates=metadata, ) except ClientError as err: logger.error( "Couldn't update image set metadata. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return updated_metadata
The following code instantiates the MedicalImagingWrapper object.
client = boto3.client("medical-imaging") medical_imaging_wrapper = MedicalImagingWrapper(client)
Use case #1: Insert or update an attribute.
attributes = """{ "SchemaVersion": 1.1, "Study": { "DICOM": { "StudyDescription": "CT CHEST" } } }""" metadata = {"DICOMUpdates": {"updatableAttributes": attributes}} self.update_image_set_metadata( data_store_id, image_set_id, version_id, metadata )
Use case #2: Remove an attribute.
# Attribute key and value must match the existing attribute. attributes = """{ "SchemaVersion": 1.1, "Study": { "DICOM": { "StudyDescription": "CT CHEST" } } }""" metadata = {"DICOMUpdates": {"removableAttributes": attributes}} self.update_image_set_metadata( data_store_id, image_set_id, version_id, metadata )
Use case #3: Remove an instance.
attributes = """{ "SchemaVersion": 1.1, "Study": { "Series": { "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": { "Instances": { "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": {} } } } } }""" metadata = {"DICOMUpdates": {"removableAttributes": attributes}} self.update_image_set_metadata( data_store_id, image_set_id, version_id, metadata )
-
For API details, see UpdateImageSetMetadata in AWS SDK for Python (Boto3) API Reference.
Note
There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository
. -