There are more AWS SDK examples available in the AWS Doc SDK Examples
Use GetImageSetMetadata
with an AWS SDK or CLI
The following code examples show how to use GetImageSetMetadata
.
Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:
- C++
-
- SDK for C++
-
Utility function to get image set metadata.
//! Routine which gets a HealthImaging image set's metadata. /*! \param dataStoreID: The HealthImaging data store ID. \param imageSetID: The HealthImaging image set ID. \param versionID: The HealthImaging image set version ID, ignored if empty. \param outputFilePath: The path where the metadata will be stored as gzipped json. \param clientConfig: Aws client configuration. \\return bool: Function succeeded. */ bool AwsDoc::Medical_Imaging::getImageSetMetadata(const Aws::String &dataStoreID, const Aws::String &imageSetID, const Aws::String &versionID, const Aws::String &outputFilePath, const Aws::Client::ClientConfiguration &clientConfig) { Aws::MedicalImaging::Model::GetImageSetMetadataRequest request; request.SetDatastoreId(dataStoreID); request.SetImageSetId(imageSetID); if (!versionID.empty()) { request.SetVersionId(versionID); } Aws::MedicalImaging::MedicalImagingClient client(clientConfig); Aws::MedicalImaging::Model::GetImageSetMetadataOutcome outcome = client.GetImageSetMetadata( request); if (outcome.IsSuccess()) { std::ofstream file(outputFilePath, std::ios::binary); auto &metadata = outcome.GetResult().GetImageSetMetadataBlob(); file << metadata.rdbuf(); } else { std::cerr << "Failed to get image set metadata: " << outcome.GetError().GetMessage() << std::endl; } return outcome.IsSuccess(); }
Get image set metadata without version.
if (AwsDoc::Medical_Imaging::getImageSetMetadata(dataStoreID, imageSetID, "", outputFilePath, clientConfig)) { std::cout << "Successfully retrieved image set metadata." << std::endl; std::cout << "Metadata stored in: " << outputFilePath << std::endl; }
Get image set metadata with version.
if (AwsDoc::Medical_Imaging::getImageSetMetadata(dataStoreID, imageSetID, versionID, outputFilePath, clientConfig)) { std::cout << "Successfully retrieved image set metadata." << std::endl; std::cout << "Metadata stored in: " << outputFilePath << std::endl; }
-
For API details, see GetImageSetMetadata in AWS SDK for C++ 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
. -
- CLI
-
- AWS CLI
-
Example 1: To get image set metadata without version
The following
get-image-set-metadata
code example gets metadata for an image set without specifying a version.Note:
outfile
is a required parameteraws medical-imaging get-image-set-metadata \ --datastore-id
12345678901234567890123456789012
\ --image-set-idea92b0d8838c72a3f25d00d13616f87e
\studymetadata.json.gz
The returned metadata is compressed with gzip and stored in the studymetadata.json.gz file. To view the contents of the returned JSON object, you must first decompress it.
Output:
{ "contentType": "application/json", "contentEncoding": "gzip" }
Example 2: To get image set metadata with version
The following
get-image-set-metadata
code example gets metadata for an image set with a specified version.Note:
outfile
is a required parameteraws medical-imaging get-image-set-metadata \ --datastore-id
12345678901234567890123456789012
\ --image-set-idea92b0d8838c72a3f25d00d13616f87e
\ --version-id1
\studymetadata.json.gz
The returned metadata is compressed with gzip and stored in the studymetadata.json.gz file. To view the contents of the returned JSON object, you must first decompress it.
Output:
{ "contentType": "application/json", "contentEncoding": "gzip" }
For more information, see Getting image set metadata in the AWS HealthImaging Developer Guide.
-
For API details, see GetImageSetMetadata
in AWS CLI Command Reference.
-
- Java
-
- SDK for Java 2.x
-
public static void getMedicalImageSetMetadata(MedicalImagingClient medicalImagingClient, String destinationPath, String datastoreId, String imagesetId, String versionId) { try { GetImageSetMetadataRequest.Builder getImageSetMetadataRequestBuilder = GetImageSetMetadataRequest.builder() .datastoreId(datastoreId) .imageSetId(imagesetId); if (versionId != null) { getImageSetMetadataRequestBuilder = getImageSetMetadataRequestBuilder.versionId(versionId); } medicalImagingClient.getImageSetMetadata(getImageSetMetadataRequestBuilder.build(), FileSystems.getDefault().getPath(destinationPath)); System.out.println("Metadata downloaded to " + destinationPath); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
-
For API details, see GetImageSetMetadata 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)
-
Utility function to get image set metadata.
import { GetImageSetMetadataCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; import { writeFileSync } from "node:fs"; /** * @param {string} metadataFileName - The name of the file for the gzipped metadata. * @param {string} datastoreId - The ID of the data store. * @param {string} imagesetId - The ID of the image set. * @param {string} versionID - The optional version ID of the image set. */ export const getImageSetMetadata = async ( metadataFileName = "metadata.json.gzip", datastoreId = "xxxxxxxxxxxxxx", imagesetId = "xxxxxxxxxxxxxx", versionID = "", ) => { const params = { datastoreId: datastoreId, imageSetId: imagesetId }; if (versionID) { params.versionID = versionID; } const response = await medicalImagingClient.send( new GetImageSetMetadataCommand(params), ); const buffer = await response.imageSetMetadataBlob.transformToByteArray(); writeFileSync(metadataFileName, buffer); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '5219b274-30ff-4986-8cab-48753de3a599', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // contentType: 'application/json', // contentEncoding: 'gzip', // imageSetMetadataBlob: <ref *1> IncomingMessage {} // } return response; };
Get image set metadata without version.
try { await getImageSetMetadata( "metadata.json.gzip", "12345678901234567890123456789012", "12345678901234567890123456789012", ); } catch (err) { console.log("Error", err); }
Get image set metadata with version.
try { await getImageSetMetadata( "metadata2.json.gzip", "12345678901234567890123456789012", "12345678901234567890123456789012", "1", ); } catch (err) { console.log("Error", err); }
-
For API details, see GetImageSetMetadata 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)
-
Utility function to get image set metadata.
class MedicalImagingWrapper: def __init__(self, health_imaging_client): self.health_imaging_client = health_imaging_client def get_image_set_metadata( self, metadata_file, datastore_id, image_set_id, version_id=None ): """ Get the metadata of an image set. :param metadata_file: The file to store the JSON gzipped metadata. :param datastore_id: The ID of the data store. :param image_set_id: The ID of the image set. :param version_id: The version of the image set. """ try: if version_id: image_set_metadata = self.health_imaging_client.get_image_set_metadata( imageSetId=image_set_id, datastoreId=datastore_id, versionId=version_id, ) else: image_set_metadata = self.health_imaging_client.get_image_set_metadata( imageSetId=image_set_id, datastoreId=datastore_id ) print(image_set_metadata) with open(metadata_file, "wb") as f: for chunk in image_set_metadata["imageSetMetadataBlob"].iter_chunks(): if chunk: f.write(chunk) except ClientError as err: logger.error( "Couldn't get image metadata. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise
Get image set metadata without version.
image_set_metadata = self.health_imaging_client.get_image_set_metadata( imageSetId=image_set_id, datastoreId=datastore_id )
Get image set metadata with version.
image_set_metadata = self.health_imaging_client.get_image_set_metadata( imageSetId=image_set_id, datastoreId=datastore_id, versionId=version_id, )
The following code instantiates the MedicalImagingWrapper object.
client = boto3.client("medical-imaging") medical_imaging_wrapper = MedicalImagingWrapper(client)
-
For API details, see GetImageSetMetadata 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
. -