HealthImaging examples using SDK for JavaScript (v3) - Amazon SDK for JavaScript
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

The Amazon SDK for JavaScript V3 API Reference Guide describes in detail all the API operations for the Amazon SDK for JavaScript version 3 (V3).

HealthImaging examples using SDK for JavaScript (v3)

The following code examples show you how to perform actions and implement common scenarios by using the Amazon SDK for JavaScript (v3) with HealthImaging.

Actions are code excerpts from larger programs and must be run in context. While actions show you how to call individual service functions, you can see actions in context in their related scenarios and cross-service examples.

Scenarios are code examples that show you how to accomplish a specific task by calling multiple functions within the same service.

Each example includes a link to GitHub, where you can find instructions on how to set up and run the code in context.

Get started

The following code examples show how to get started using HealthImaging.

SDK for JavaScript (v3)
import { ListDatastoresCommand, MedicalImagingClient, } from "@aws-sdk/client-medical-imaging"; // When no region or credentials are provided, the SDK will use the // region and credentials from the local AWS config. const client = new MedicalImagingClient({}); export const helloMedicalImaging = async () => { const command = new ListDatastoresCommand({}); const { datastoreSummaries } = await client.send(command); console.log("Datastores: "); console.log(datastoreSummaries.map((item) => item.datastoreName).join("\n")); return datastoreSummaries; };
  • For API details, see ListDatastores in Amazon 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 Amazon Code Examples Repository.

Actions

The following code example shows how to use CopyImageSet.

SDK for JavaScript (v3)

Utility function to copy an image set.

import { CopyImageSetCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The ID of the data store. * @param {string} imageSetId - The source image set ID. * @param {string} sourceVersionId - The source version ID. * @param {string} destinationImageSetId - The optional ID of the destination image set. * @param {string} destinationVersionId - The optional version ID of the destination image set. */ export const copyImageSet = async ( datastoreId = "xxxxxxxxxxx", imageSetId = "xxxxxxxxxxxx", sourceVersionId = "1", destinationImageSetId = "", destinationVersionId = "" ) => { const params = { datastoreId: datastoreId, sourceImageSetId: imageSetId, copyImageSetInformation: { sourceImageSet: { latestVersionId: sourceVersionId }, }, }; if (destinationImageSetId !== "" && destinationVersionId !== "") { params.copyImageSetInformation.destinationImageSet = { imageSetId: destinationImageSetId, latestVersionId: destinationVersionId, }; } const response = await medicalImagingClient.send( new CopyImageSetCommand(params) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: 'd9b219ce-cc48-4a44-a5b2-c5c3068f1ee8', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // datastoreId: 'xxxxxxxxxxxxxx', // destinationImageSetProperties: { // createdAt: 2023-09-27T19:46:21.824Z, // imageSetArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxxxx:datastore/xxxxxxxxxxxxx/imageset/xxxxxxxxxxxxxxxxxxx', // imageSetId: 'xxxxxxxxxxxxxxx', // imageSetState: 'LOCKED', // imageSetWorkflowStatus: 'COPYING', // latestVersionId: '1', // updatedAt: 2023-09-27T19:46:21.824Z // }, // sourceImageSetProperties: { // createdAt: 2023-09-22T14:49:26.427Z, // imageSetArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxxxx:datastore/xxxxxxxxxxxxx/imageset/xxxxxxxxxxxxxxxx', // imageSetId: 'xxxxxxxxxxxxxxxx', // imageSetState: 'LOCKED', // imageSetWorkflowStatus: 'COPYING_WITH_READ_ONLY_ACCESS', // latestVersionId: '4', // updatedAt: 2023-09-27T19:46:21.824Z // } // } return response; };

Copy an image set without a destination.

try { await copyImageSet( "12345678901234567890123456789012", "12345678901234567890123456789012", "1" ); } catch (err) { console.error(err); }

Copy an image set with a destination.

try { await copyImageSet( "12345678901234567890123456789012", "12345678901234567890123456789012", "4", "12345678901234567890123456789012", "1" ); } catch (err) { console.error(err); }
  • For API details, see CopyImageSet in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use CreateDatastore.

SDK for JavaScript (v3)
import { CreateDatastoreCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreName - The name of the data store to create. */ export const createDatastore = async (datastoreName = "DATASTORE_NAME") => { const response = await medicalImagingClient.send( new CreateDatastoreCommand({ datastoreName: datastoreName }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: 'a71cd65f-2382-49bf-b682-f9209d8d399b', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // datastoreStatus: 'CREATING' // } return response; };
  • For API details, see CreateDatastore in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use DeleteDatastore.

SDK for JavaScript (v3)
import { DeleteDatastoreCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The ID of the data store to delete. */ export const deleteDatastore = async (datastoreId = "DATASTORE_ID") => { const response = await medicalImagingClient.send( new DeleteDatastoreCommand({ datastoreId }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: 'f5beb409-678d-48c9-9173-9a001ee1ebb1', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // datastoreStatus: 'DELETING' // } return response; };
  • For API details, see DeleteDatastore in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use DeleteImageSet.

SDK for JavaScript (v3)
import { DeleteImageSetCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The data store ID. * @param {string} imageSetId - The image set ID. */ export const deleteImageSet = async ( datastoreId = "xxxxxxxxxxxxxxxx", imageSetId = "xxxxxxxxxxxxxxxx" ) => { const response = await medicalImagingClient.send( new DeleteImageSetCommand({ datastoreId: datastoreId, imageSetId: imageSetId, }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '6267bbd2-eaa5-4a50-8ee8-8fddf535cf73', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // datastoreId: 'xxxxxxxxxxxxxxxx', // imageSetId: 'xxxxxxxxxxxxxxx', // imageSetState: 'LOCKED', // imageSetWorkflowStatus: 'DELETING' // } return response; };
  • For API details, see DeleteImageSet in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use GetDICOMImportJob.

SDK for JavaScript (v3)
import { GetDICOMImportJobCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The ID of the data store. * @param {string} jobId - The ID of the import job. */ export const getDICOMImportJob = async ( datastoreId = "xxxxxxxxxxxxxxxxxxxx", jobId = "xxxxxxxxxxxxxxxxxxxx" ) => { const response = await medicalImagingClient.send( new GetDICOMImportJobCommand({ datastoreId: datastoreId, jobId: jobId }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: 'a2637936-78ea-44e7-98b8-7a87d95dfaee', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // jobProperties: { // dataAccessRoleArn: 'arn:aws:iam::xxxxxxxxxxxx:role/dicom_import', // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxx', // endedAt: 2023-09-19T17:29:21.753Z, // inputS3Uri: 's3://healthimaging-source/CTStudy/', // jobId: ''xxxxxxxxxxxxxxxxxxxxxxxxx'', // jobName: 'job_1', // jobStatus: 'COMPLETED', // outputS3Uri: 's3://health-imaging-dest/ouput_ct/'xxxxxxxxxxxxxxxxxxxxxxxxx'-DicomImport-'xxxxxxxxxxxxxxxxxxxxxxxxx'/', // submittedAt: 2023-09-19T17:27:25.143Z // } // } return response; };
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

The following code example shows how to use GetDatastore.

SDK for JavaScript (v3)
import { GetDatastoreCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreID - The ID of the data store. */ export const getDatastore = async (datastoreID = "DATASTORE_ID") => { const response = await medicalImagingClient.send( new GetDatastoreCommand({ datastoreId: datastoreID }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '55ea7d2e-222c-4a6a-871e-4f591f40cadb', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // datastoreProperties: { // createdAt: 2023-08-04T18:50:36.239Z, // datastoreArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxx:datastore/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // datastoreName: 'my_datastore', // datastoreStatus: 'ACTIVE', // updatedAt: 2023-08-04T18:50:36.239Z // } // } return response["datastoreProperties"]; };
  • For API details, see GetDatastore in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use GetImageFrame.

SDK for JavaScript (v3)
import { GetImageFrameCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} imageFrameFileName - The name of the file for the HTJ2K-encoded image frame. * @param {string} datastoreID - The data store's ID. * @param {string} imageSetID - The image set's ID. * @param {string} imageFrameID - The image frame's ID. */ export const getImageFrame = async ( imageFrameFileName = "image.jph", datastoreID = "DATASTORE_ID", imageSetID = "IMAGE_SET_ID", imageFrameID = "IMAGE_FRAME_ID" ) => { const response = await medicalImagingClient.send( new GetImageFrameCommand({ datastoreId: datastoreID, imageSetId: imageSetID, imageFrameInformation: { imageFrameId: imageFrameID }, }) ); const buffer = await response.imageFrameBlob.transformToByteArray(); writeFileSync(imageFrameFileName, buffer); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: 'e4ab42a5-25a3-4377-873f-374ecf4380e1', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // contentType: 'application/octet-stream', // imageFrameBlob: <ref *1> IncomingMessage {} // } return response; };
  • For API details, see GetImageFrame in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use GetImageSet.

SDK for JavaScript (v3)
import { GetImageSetCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The ID of the data store. * @param {string} imageSetId - The ID of the image set. * @param {string} imageSetVersion - The optional version of the image set. * */ export const getImageSet = async ( datastoreId = "xxxxxxxxxxxxxxx", imageSetId = "xxxxxxxxxxxxxxx", imageSetVersion = "" ) => { let params = { datastoreId: datastoreId, imageSetId: imageSetId }; if (imageSetVersion !== "") { params.imageSetVersion = imageSetVersion; } const response = await medicalImagingClient.send( new GetImageSetCommand(params) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '0615c161-410d-4d06-9d8c-6e1241bb0a5a', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // createdAt: 2023-09-22T14:49:26.427Z, // datastoreId: 'xxxxxxxxxxxxxxx', // imageSetArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxxx:datastore/xxxxxxxxxxxxxxxxxxxx/imageset/xxxxxxxxxxxxxxxxxxxx', // imageSetId: 'xxxxxxxxxxxxxxx', // imageSetState: 'ACTIVE', // imageSetWorkflowStatus: 'CREATED', // updatedAt: 2023-09-22T14:49:26.427Z, // versionId: '1' // } return response; };
  • For API details, see GetImageSet in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use GetImageSetMetadata.

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 "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); }
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

The following code example shows how to use ListDICOMImportJobs.

SDK for JavaScript (v3)
import { paginateListDICOMImportJobs } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The ID of the data store. */ export const listDICOMImportJobs = async ( datastoreId = "xxxxxxxxxxxxxxxxxx" ) => { const paginatorConfig = { client: medicalImagingClient, pageSize: 50, }; const commandParams = { datastoreId: datastoreId }; const paginator = paginateListDICOMImportJobs(paginatorConfig, commandParams); let jobSummaries = []; for await (const page of paginator) { // Each page contains a list of `jobSummaries`. The list is truncated if is larger than `pageSize`. jobSummaries.push(...page["jobSummaries"]); console.log(page); } // { // '$metadata': { // httpStatusCode: 200, // requestId: '3c20c66e-0797-446a-a1d8-91b742fd15a0', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // jobSummaries: [ // { // dataAccessRoleArn: 'arn:aws:iam::xxxxxxxxxxxx:role/dicom_import', // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxx', // endedAt: 2023-09-22T14:49:51.351Z, // jobId: 'xxxxxxxxxxxxxxxxxxxxxxxxx', // jobName: 'test-1', // jobStatus: 'COMPLETED', // submittedAt: 2023-09-22T14:48:45.767Z // } // ]} return jobSummaries; };
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

The following code example shows how to use ListDatastores.

SDK for JavaScript (v3)
import { paginateListDatastores } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; export const listDatastores = async () => { const paginatorConfig = { client: medicalImagingClient, pageSize: 50, }; const commandParams = {}; const paginator = paginateListDatastores(paginatorConfig, commandParams); /** * @type {import("@aws-sdk/client-medical-imaging").DatastoreSummary[]} */ const datastoreSummaries = []; for await (const page of paginator) { // Each page contains a list of `jobSummaries`. The list is truncated if is larger than `pageSize`. datastoreSummaries.push(...page["datastoreSummaries"]); console.log(page); } // { // '$metadata': { // httpStatusCode: 200, // requestId: '6aa99231-d9c2-4716-a46e-edb830116fa3', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // datastoreSummaries: [ // { // createdAt: 2023-08-04T18:49:54.429Z, // datastoreArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxx:datastore/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // datastoreName: 'my_datastore', // datastoreStatus: 'ACTIVE', // updatedAt: 2023-08-04T18:49:54.429Z // } // ... // ] // } return datastoreSummaries; };
  • For API details, see ListDatastores in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use ListImageSetVersions.

SDK for JavaScript (v3)
import { paginateListImageSetVersions } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The ID of the data store. * @param {string} imageSetId - The ID of the image set. */ export const listImageSetVersions = async ( datastoreId = "xxxxxxxxxxxx", imageSetId = "xxxxxxxxxxxx" ) => { const paginatorConfig = { client: medicalImagingClient, pageSize: 50, }; const commandParams = { datastoreId, imageSetId }; const paginator = paginateListImageSetVersions( paginatorConfig, commandParams ); let imageSetPropertiesList = []; for await (const page of paginator) { // Each page contains a list of `jobSummaries`. The list is truncated if is larger than `pageSize`. imageSetPropertiesList.push(...page["imageSetPropertiesList"]); console.log(page); } // { // '$metadata': { // httpStatusCode: 200, // requestId: '74590b37-a002-4827-83f2-3c590279c742', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // imageSetPropertiesList: [ // { // ImageSetWorkflowStatus: 'CREATED', // createdAt: 2023-09-22T14:49:26.427Z, // imageSetId: 'xxxxxxxxxxxxxxxxxxxxxxx', // imageSetState: 'ACTIVE', // versionId: '1' // }] // } return imageSetPropertiesList; };
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

The following code example shows how to use ListTagsForResource.

SDK for JavaScript (v3)
import { ListTagsForResourceCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. */ export const listTagsForResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:abc:datastore/def/imageset/ghi" ) => { const response = await medicalImagingClient.send( new ListTagsForResourceCommand({ resourceArn: resourceArn }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '008fc6d3-abec-4870-a155-20fa3631e645', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // tags: { Deployment: 'Development' } // } return response; };
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

The following code example shows how to use SearchImageSets.

SDK for JavaScript (v3)

The utility function for searching image sets.

import {paginateSearchImageSets} from "@aws-sdk/client-medical-imaging"; import {medicalImagingClient} from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The data store's ID. * @param { import('@aws-sdk/client-medical-imaging').SearchFilter[] } filters - The search criteria filters. * @param { import('@aws-sdk/client-medical-imaging').Sort } sort - The search criteria sort. */ export const searchImageSets = async ( datastoreId = "xxxxxxxx", searchCriteria = {} ) => { const paginatorConfig = { client: medicalImagingClient, pageSize: 50, }; const commandParams = { datastoreId: datastoreId, searchCriteria: searchCriteria, }; const paginator = paginateSearchImageSets(paginatorConfig, commandParams); const imageSetsMetadataSummaries = []; for await (const page of paginator) { // Each page contains a list of `jobSummaries`. The list is truncated if is larger than `pageSize`. imageSetsMetadataSummaries.push(...page["imageSetsMetadataSummaries"]); console.log(page); } // { // '$metadata': { // httpStatusCode: 200, // requestId: 'f009ea9c-84ca-4749-b5b6-7164f00a5ada', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // imageSetsMetadataSummaries: [ // { // DICOMTags: [Object], // createdAt: "2023-09-19T16:59:40.551Z", // imageSetId: '7f75e1b5c0f40eac2b24cf712f485f50', // updatedAt: "2023-09-19T16:59:40.551Z", // version: 1 // }] // } return imageSetsMetadataSummaries; };

Use case #1: EQUAL operator.

const datastoreId = "12345678901234567890123456789012"; try { const searchCriteria = { filters: [ { values: [{DICOMPatientId: "1234567"}], operator: "EQUAL", }, ] }; await searchImageSets(datastoreId, searchCriteria); } catch (err) { console.error(err); }

Use case #2: BETWEEN operator using DICOMStudyDate and DICOMStudyTime.

const datastoreId = "12345678901234567890123456789012"; try { const searchCriteria = { filters: [ { values: [ { DICOMStudyDateAndTime: { DICOMStudyDate: "19900101", DICOMStudyTime: "000000", }, }, { DICOMStudyDateAndTime: { DICOMStudyDate: "20230901", DICOMStudyTime: "000000", }, }, ], operator: "BETWEEN", }, ] }; await searchImageSets(datastoreId, searchCriteria); } catch (err) { console.error(err); }

Use case #3: BETWEEN operator using createdAt. Time studies were previously persisted.

const datastoreId = "12345678901234567890123456789012"; try { const searchCriteria = { filters: [ { values: [ {createdAt: new Date("1985-04-12T23:20:50.52Z")}, {createdAt: new Date()}, ], operator: "BETWEEN", }, ] }; await searchImageSets(datastoreId, searchCriteria); } catch (err) { console.error(err); }

Use case #4: EQUAL operator on DICOMSeriesInstanceUID and BETWEEN on updatedAt and sort response in ASC order on updatedAt field.

const datastoreId = "12345678901234567890123456789012"; try { const searchCriteria = { filters: [ { values: [ {updatedAt: new Date("1985-04-12T23:20:50.52Z")}, {updatedAt: new Date()}, ], operator: "BETWEEN", }, { values: [ {DICOMSeriesInstanceUID: "1.1.123.123456.1.12.1.1234567890.1234.12345678.123"}, ], operator: "EQUAL", }, ], sort: { sortOrder: "ASC", sortField: "updatedAt", } }; await searchImageSets(datastoreId, searchCriteria); } catch (err) { console.error(err); }
  • For API details, see SearchImageSets in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use StartDICOMImportJob.

SDK for JavaScript (v3)
import { StartDICOMImportJobCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} jobName - The name of the import job. * @param {string} datastoreId - The ID of the data store. * @param {string} dataAccessRoleArn - The Amazon Resource Name (ARN) of the role that grants permission. * @param {string} inputS3Uri - The URI of the S3 bucket containing the input files. * @param {string} outputS3Uri - The URI of the S3 bucket where the output files are stored. */ export const startDicomImportJob = async ( jobName = "test-1", datastoreId = "12345678901234567890123456789012", dataAccessRoleArn = "arn:aws:iam::xxxxxxxxxxxx:role/ImportJobDataAccessRole", inputS3Uri = "s3://medical-imaging-dicom-input/dicom_input/", outputS3Uri = "s3://medical-imaging-output/job_output/" ) => { const response = await medicalImagingClient.send( new StartDICOMImportJobCommand({ jobName: jobName, datastoreId: datastoreId, dataAccessRoleArn: dataAccessRoleArn, inputS3Uri: inputS3Uri, outputS3Uri: outputS3Uri, }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '6e81d191-d46b-4e48-a08a-cdcc7e11eb79', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // datastoreId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // jobId: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx', // jobStatus: 'SUBMITTED', // submittedAt: 2023-09-22T14:48:45.767Z // } return response; };
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

The following code example shows how to use TagResource.

SDK for JavaScript (v3)
import { TagResourceCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. * @param {Record<string,string>} tags - The tags to add to the resource as JSON. * - For example: {"Deployment" : "Development"} */ export const tagResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:xxxxxx:datastore/xxxxx/imageset/xxx", tags = {} ) => { const response = await medicalImagingClient.send( new TagResourceCommand({ resourceArn: resourceArn, tags: tags }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 204, // requestId: '8a6de9a3-ec8e-47ef-8643-473518b19d45', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // } // } return response; };
  • For API details, see TagResource in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use UntagResource.

SDK for JavaScript (v3)
import { UntagResourceCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. * @param {string[]} tagKeys - The keys of the tags to remove. */ export const untagResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:xxxxxx:datastore/xxxxx/imageset/xxx", tagKeys = [] ) => { const response = await medicalImagingClient.send( new UntagResourceCommand({ resourceArn: resourceArn, tagKeys: tagKeys }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 204, // requestId: '8a6de9a3-ec8e-47ef-8643-473518b19d45', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // } // } return response; };
  • For API details, see UntagResource in Amazon 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 Amazon Code Examples Repository.

The following code example shows how to use UpdateImageSetMetadata.

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);
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

Scenarios

The following code example shows how to import DICOM files and download image frames in HealthImaging.

The implementation is structured as a workflow command-line application.

  • Set up resources for a DICOM import.

  • Import DICOM files into a data store.

  • Retrieve the image set IDs for the import job.

  • Retrieve the image frame IDs for the image sets.

  • Download, decode and verify the image frames.

  • Clean up resources.

SDK for JavaScript (v3)

index.js - Orchestrate steps.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { parseScenarioArgs, Scenario, } from "@aws-doc-sdk-examples/lib/scenario/index.js"; import { loadState, saveState } from "./state-steps.js"; import { createStack, deployStack, getAccountId, getDatastoreName, getStackName, outputState, waitForStackCreation, } from "./deploy-steps.js"; import { doCopy, selectDataset, copyDataset, outputCopiedObjects, } from "./dataset-steps.js"; import { doImport, outputImportJobStatus, startDICOMImport, waitForImportJobCompletion, } from "./import-steps.js"; import { getManifestFile, outputImageSetIds, parseManifestFile, } from "./image-set-steps.js"; import { getImageSetMetadata, outputImageFrameIds, } from "./image-frame-steps.js"; import { decodeAndVerifyImages, doVerify } from "./verify-steps.js"; import { confirmCleanup, deleteImageSets, deleteStack, } from "./clean-up-steps.js"; const context = {}; const scenarios = { deploy: new Scenario( "Deploy Resources", [ deployStack, getStackName, getDatastoreName, getAccountId, createStack, waitForStackCreation, outputState, saveState, ], context, ), demo: new Scenario( "Run Demo", [ loadState, doCopy, selectDataset, copyDataset, outputCopiedObjects, doImport, startDICOMImport, waitForImportJobCompletion, outputImportJobStatus, getManifestFile, parseManifestFile, outputImageSetIds, getImageSetMetadata, outputImageFrameIds, doVerify, decodeAndVerifyImages, saveState, ], context, ), destroy: new Scenario( "Clean Up Resources", [loadState, confirmCleanup, deleteImageSets, deleteStack], context, ), }; // Call function if run directly import { fileURLToPath } from "url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { parseScenarioArgs(scenarios); }

deploy-steps.js - Deploy resources.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import fs from "node:fs/promises"; import path from "node:path"; import { CloudFormationClient, CreateStackCommand, DescribeStacksCommand, } from "@aws-sdk/client-cloudformation"; import { STSClient, GetCallerIdentityCommand } from "@aws-sdk/client-sts"; import { ScenarioAction, ScenarioInput, ScenarioOutput, } from "@aws-doc-sdk-examples/lib/scenario/index.js"; import { retry } from "@aws-doc-sdk-examples/lib/utils/util-timers.js"; const cfnClient = new CloudFormationClient({}); const stsClient = new STSClient({}); const __dirname = path.dirname(new URL(import.meta.url).pathname); const cfnTemplatePath = path.join( __dirname, "../../../../../workflows/healthimaging_image_sets/resources/cfn_template.yaml", ); export const deployStack = new ScenarioInput( "deployStack", "Do you want to deploy the CloudFormation stack?", { type: "confirm" }, ); export const getStackName = new ScenarioInput( "getStackName", "Enter a name for the CloudFormation stack:", { type: "input", skipWhen: (/** @type {{}} */ state) => !state.deployStack }, ); export const getDatastoreName = new ScenarioInput( "getDatastoreName", "Enter a name for the HealthImaging datastore:", { type: "input", skipWhen: (/** @type {{}} */ state) => !state.deployStack }, ); export const getAccountId = new ScenarioAction( "getAccountId", async (/** @type {{}} */ state) => { const command = new GetCallerIdentityCommand({}); const response = await stsClient.send(command); state.accountId = response.Account; }, { skipWhen: (/** @type {{}} */ state) => !state.deployStack, }, ); export const createStack = new ScenarioAction( "createStack", async (/** @type {{}} */ state) => { const stackName = state.getStackName; const datastoreName = state.getDatastoreName; const accountId = state.accountId; const command = new CreateStackCommand({ StackName: stackName, TemplateBody: await fs.readFile(cfnTemplatePath, "utf8"), Capabilities: ["CAPABILITY_IAM"], Parameters: [ { ParameterKey: "datastoreName", ParameterValue: datastoreName, }, { ParameterKey: "userAccountID", ParameterValue: accountId, }, ], }); const response = await cfnClient.send(command); state.stackId = response.StackId; }, { skipWhen: (/** @type {{}} */ state) => !state.deployStack }, ); export const waitForStackCreation = new ScenarioAction( "waitForStackCreation", async (/** @type {{}} */ state) => { const command = new DescribeStacksCommand({ StackName: state.stackId, }); await retry({ intervalInMs: 10000, maxRetries: 60 }, async () => { const response = await cfnClient.send(command); const stack = response.Stacks?.find( (s) => s.StackName == state.getStackName, ); if (!stack || stack.StackStatus === "CREATE_IN_PROGRESS") { throw new Error("Stack creation is still in progress"); } if (stack.StackStatus === "CREATE_COMPLETE") { state.stackOutputs = stack.Outputs?.reduce((acc, output) => { acc[output.OutputKey] = output.OutputValue; return acc; }, {}); } else { throw new Error( `Stack creation failed with status: ${stack.StackStatus}`, ); } }); }, { skipWhen: (/** @type {{}} */ state) => !state.deployStack, }, ); export const outputState = new ScenarioOutput( "outputState", (/** @type {{}} */ state) => { /** * @type {{ stackOutputs: { DatastoreID: string, BucketName: string, RoleArn: string }}} */ const { stackOutputs } = state; return `Stack creation completed. Output values: Datastore ID: ${stackOutputs?.DatastoreID} Bucket Name: ${stackOutputs?.BucketName} Role ARN: ${stackOutputs?.RoleArn} `; }, { skipWhen: (/** @type {{}} */ state) => !state.deployStack }, );

dataset-steps.js - Copy DICOM files.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { S3Client, CopyObjectCommand, ListObjectsV2Command, } from "@aws-sdk/client-s3"; import { ScenarioAction, ScenarioInput, ScenarioOutput, } from "@aws-doc-sdk-examples/lib/scenario/index.js"; const s3Client = new S3Client({}); const datasetOptions = [ { name: "CT of chest (2 images)", value: "00029d25-fb18-4d42-aaa5-a0897d1ac8f7", }, { name: "CT of pelvis (57 images)", value: "00025d30-ef8f-4135-a35a-d83eff264fc1", }, { name: "MRI of head (192 images)", value: "0002d261-8a5d-4e63-8e2e-0cbfac87b904", }, { name: "MRI of breast (92 images)", value: "0002dd07-0b7f-4a68-a655-44461ca34096", }, ]; /** * @typedef {{ stackOutputs: { * BucketName: string, * DatastoreID: string, * doCopy: boolean * }}} State */ export const selectDataset = new ScenarioInput( "selectDataset", (state) => { if (!state.doCopy) { process.exit(0); } return "Select a DICOM dataset to import:"; }, { type: "select", choices: datasetOptions, }, ); export const doCopy = new ScenarioInput( "doCopy", "Do you want to copy images from the public dataset into your bucket?", { type: "confirm", }, ); export const copyDataset = new ScenarioAction( "copyDataset", async (/** @type { State } */ state) => { const inputBucket = state.stackOutputs.BucketName; const inputPrefix = `input/`; const selectedDatasetId = state.selectDataset; const sourceBucket = "idc-open-data"; const sourcePrefix = `${selectedDatasetId}`; const listObjectsCommand = new ListObjectsV2Command({ Bucket: sourceBucket, Prefix: sourcePrefix, }); const objects = await s3Client.send(listObjectsCommand); const copyPromises = objects.Contents.map((object) => { const sourceKey = object.Key; const destinationKey = `${inputPrefix}${sourceKey .split("/") .slice(1) .join("/")}`; const copyCommand = new CopyObjectCommand({ Bucket: inputBucket, CopySource: `/${sourceBucket}/${sourceKey}`, Key: destinationKey, }); return s3Client.send(copyCommand); }); const results = await Promise.all(copyPromises); state.copiedObjects = results.length; }, ); export const outputCopiedObjects = new ScenarioOutput( "outputCopiedObjects", (state) => `${state.copiedObjects} DICOM files were copied.`, );

import-steps.js - Start import into datastore.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { MedicalImagingClient, StartDICOMImportJobCommand, GetDICOMImportJobCommand, } from "@aws-sdk/client-medical-imaging"; import { ScenarioAction, ScenarioOutput, ScenarioInput, } from "@aws-doc-sdk-examples/lib/scenario/index.js"; import { retry } from "@aws-doc-sdk-examples/lib/utils/util-timers.js"; /** * @typedef {{ stackOutputs: { * BucketName: string, * DatastoreID: string, * RoleArn: string * }}} State */ export const doImport = new ScenarioInput( "doImport", "Do you want to import DICOM images into your datastore?", { type: "confirm", }, ); export const startDICOMImport = new ScenarioAction( "startDICOMImport", async (/** @type {State} */ state) => { if (!state.doImport) { process.exit(0); } const medicalImagingClient = new MedicalImagingClient({}); const inputS3Uri = `s3://${state.stackOutputs.BucketName}/input/`; const outputS3Uri = `s3://${state.stackOutputs.BucketName}/output/`; const command = new StartDICOMImportJobCommand({ dataAccessRoleArn: state.stackOutputs.RoleArn, datastoreId: state.stackOutputs.DatastoreID, inputS3Uri, outputS3Uri, }); const response = await medicalImagingClient.send(command); state.importJobId = response.jobId; }, ); export const waitForImportJobCompletion = new ScenarioAction( "waitForImportJobCompletion", async (/** @type {State} */ state) => { const medicalImagingClient = new MedicalImagingClient({}); const command = new GetDICOMImportJobCommand({ datastoreId: state.stackOutputs.DatastoreID, jobId: state.importJobId, }); await retry({ intervalInMs: 10000, maxRetries: 60 }, async () => { const response = await medicalImagingClient.send(command); const jobStatus = response.jobProperties?.jobStatus; if (!jobStatus || jobStatus === "IN_PROGRESS") { throw new Error("Import job is still in progress"); } if (jobStatus === "COMPLETED") { state.importJobOutputS3Uri = response.jobProperties.outputS3Uri; } else { throw new Error(`Import job failed with status: ${jobStatus}`); } }); }, ); export const outputImportJobStatus = new ScenarioOutput( "outputImportJobStatus", (state) => `DICOM import job completed. Output location: ${state.importJobOutputS3Uri}`, );

image-set-steps.js - Get image set IDs.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3"; import { ScenarioAction, ScenarioOutput, } from "@aws-doc-sdk-examples/lib/scenario/index.js"; /** * @typedef {{ stackOutputs: { * BucketName: string, * DatastoreID: string, * RoleArn: string * }, importJobId: string, * importJobOutputS3Uri: string, * imageSetIds: string[], * manifestContent: { jobSummary: { imageSetsSummary: { imageSetId: string }[] } } * }} State */ const s3Client = new S3Client({}); export const getManifestFile = new ScenarioAction( "getManifestFile", async (/** @type {State} */ state) => { const bucket = state.stackOutputs.BucketName; const prefix = `output/${state.stackOutputs.DatastoreID}-DicomImport-${state.importJobId}/`; const key = `${prefix}job-output-manifest.json`; const command = new GetObjectCommand({ Bucket: bucket, Key: key, }); const response = await s3Client.send(command); const manifestContent = await response.Body.transformToString(); state.manifestContent = JSON.parse(manifestContent); }, ); export const parseManifestFile = new ScenarioAction( "parseManifestFile", (/** @type {State} */ state) => { const imageSetIds = state.manifestContent.jobSummary.imageSetsSummary.reduce( (imageSetIds, next) => { return { ...imageSetIds, [next.imageSetId]: next.imageSetId }; }, {}, ); state.imageSetIds = Object.keys(imageSetIds); }, ); export const outputImageSetIds = new ScenarioOutput( "outputImageSetIds", (/** @type {State} */ state) => `The image sets created by this import job are: \n${state.imageSetIds .map((id) => `Image set: ${id}`) .join("\n")}`, );

image-frame-steps.js - Get image frame IDs.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { MedicalImagingClient, GetImageSetMetadataCommand, } from "@aws-sdk/client-medical-imaging"; import { gunzip } from "zlib"; import { promisify } from "util"; import { ScenarioAction, ScenarioOutput, } from "@aws-doc-sdk-examples/lib/scenario/index.js"; const gunzipAsync = promisify(gunzip); /** * @typedef {Object} DICOMValueRepresentation * @property {string} name * @property {string} type * @property {string} value */ /** * @typedef {Object} ImageFrameInformation * @property {string} ID * @property {Array<{ Checksum: number, Height: number, Width: number }>} PixelDataChecksumFromBaseToFullResolution * @property {number} MinPixelValue * @property {number} MaxPixelValue * @property {number} FrameSizeInBytes */ /** * @typedef {Object} DICOMMetadata * @property {Object} DICOM * @property {DICOMValueRepresentation[]} DICOMVRs * @property {ImageFrameInformation[]} ImageFrames */ /** * @typedef {Object} Series * @property {{ [key: string]: DICOMMetadata }} Instances */ /** * @typedef {Object} Study * @property {Object} DICOM * @property {Series[]} Series */ /** * @typedef {Object} Patient * @property {Object} DICOM */ /** * @typedef {{ * SchemaVersion: string, * DatastoreID: string, * ImageSetID: string, * Patient: Patient, * Study: Study * }} ImageSetMetadata */ /** * @typedef {{ stackOutputs: { * BucketName: string, * DatastoreID: string, * RoleArn: string * }, imageSetIds: string[] }} State */ const medicalImagingClient = new MedicalImagingClient({}); export const getImageSetMetadata = new ScenarioAction( "getImageSetMetadata", async (/** @type {State} */ state) => { const outputMetadata = []; for (const imageSetId of state.imageSetIds) { const command = new GetImageSetMetadataCommand({ datastoreId: state.stackOutputs.DatastoreID, imageSetId, }); const response = await medicalImagingClient.send(command); const compressedMetadataBlob = await response.imageSetMetadataBlob.transformToByteArray(); const decompressedMetadata = await gunzipAsync(compressedMetadataBlob); const imageSetMetadata = JSON.parse(decompressedMetadata.toString()); outputMetadata.push(imageSetMetadata); } state.imageSetMetadata = outputMetadata; }, ); export const outputImageFrameIds = new ScenarioOutput( "outputImageFrameIds", (/** @type {State & { imageSetMetadata: ImageSetMetadata[] }} */ state) => { let output = ""; for (const metadata of state.imageSetMetadata) { const imageSetId = metadata.ImageSetID; /** @type {DICOMMetadata[]} */ const instances = Object.values(metadata.Study.Series).flatMap( (series) => { return Object.values(series.Instances); }, ); const imageFrameIds = instances.flatMap((instance) => instance.ImageFrames.map((frame) => frame.ID), ); output += `Image set ID: ${imageSetId}\nImage frame IDs:\n${imageFrameIds.join( "\n", )}\n\n`; } return output; }, { slow: false }, );

verify-steps.js - Verify image frames. The Amazon HealthImaging Pixel Data Verification library was used for verification.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { spawn } from "node:child_process"; import { ScenarioAction, ScenarioInput, } from "@aws-doc-sdk-examples/lib/scenario/index.js"; /** * @typedef {Object} DICOMValueRepresentation * @property {string} name * @property {string} type * @property {string} value */ /** * @typedef {Object} ImageFrameInformation * @property {string} ID * @property {Array<{ Checksum: number, Height: number, Width: number }>} PixelDataChecksumFromBaseToFullResolution * @property {number} MinPixelValue * @property {number} MaxPixelValue * @property {number} FrameSizeInBytes */ /** * @typedef {Object} DICOMMetadata * @property {Object} DICOM * @property {DICOMValueRepresentation[]} DICOMVRs * @property {ImageFrameInformation[]} ImageFrames */ /** * @typedef {Object} Series * @property {{ [key: string]: DICOMMetadata }} Instances */ /** * @typedef {Object} Study * @property {Object} DICOM * @property {Series[]} Series */ /** * @typedef {Object} Patient * @property {Object} DICOM */ /** * @typedef {{ * SchemaVersion: string, * DatastoreID: string, * ImageSetID: string, * Patient: Patient, * Study: Study * }} ImageSetMetadata */ /** * @typedef {{ stackOutputs: { * BucketName: string, * DatastoreID: string, * RoleArn: string * }, imageSetMetadata: ImageSetMetadata[] }} State */ export const doVerify = new ScenarioInput( "doVerify", "Do you want to verify the imported images?", { type: "confirm", }, ); export const decodeAndVerifyImages = new ScenarioAction( "decodeAndVerifyImages", async (/** @type {State} */ state) => { if (!state.doVerify) { process.exit(0); } const verificationTool = "./pixel-data-verification/index.js"; for (const metadata of state.imageSetMetadata) { const datastoreId = state.stackOutputs.DatastoreID; const imageSetId = metadata.ImageSetID; for (const [seriesInstanceUid, series] of Object.entries( metadata.Study.Series, )) { for (const [sopInstanceUid, _] of Object.entries(series.Instances)) { console.log( `Verifying image set ${imageSetId} with series ${seriesInstanceUid} and sop ${sopInstanceUid}`, ); const child = spawn( "node", [ verificationTool, datastoreId, imageSetId, seriesInstanceUid, sopInstanceUid, ], { stdio: "inherit" }, ); await new Promise((resolve, reject) => { child.on("exit", (code) => { if (code === 0) { resolve(); } else { reject( new Error( `Verification tool exited with code ${code} for image set ${imageSetId}`, ), ); } }); }); } } } }, );

clean-up-steps.js - Destroy resources.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { CloudFormationClient, DeleteStackCommand, } from "@aws-sdk/client-cloudformation"; import { MedicalImagingClient, DeleteImageSetCommand, } from "@aws-sdk/client-medical-imaging"; import { ScenarioAction, ScenarioInput, } from "@aws-doc-sdk-examples/lib/scenario/index.js"; /** * @typedef {Object} DICOMValueRepresentation * @property {string} name * @property {string} type * @property {string} value */ /** * @typedef {Object} ImageFrameInformation * @property {string} ID * @property {Array<{ Checksum: number, Height: number, Width: number }>} PixelDataChecksumFromBaseToFullResolution * @property {number} MinPixelValue * @property {number} MaxPixelValue * @property {number} FrameSizeInBytes */ /** * @typedef {Object} DICOMMetadata * @property {Object} DICOM * @property {DICOMValueRepresentation[]} DICOMVRs * @property {ImageFrameInformation[]} ImageFrames */ /** * @typedef {Object} Series * @property {{ [key: string]: DICOMMetadata }} Instances */ /** * @typedef {Object} Study * @property {Object} DICOM * @property {Series[]} Series */ /** * @typedef {Object} Patient * @property {Object} DICOM */ /** * @typedef {{ * SchemaVersion: string, * DatastoreID: string, * ImageSetID: string, * Patient: Patient, * Study: Study * }} ImageSetMetadata */ /** * @typedef {{ stackOutputs: { * BucketName: string, * DatastoreID: string, * RoleArn: string * }, imageSetMetadata: ImageSetMetadata[] }} State */ const cfnClient = new CloudFormationClient({}); const medicalImagingClient = new MedicalImagingClient({}); export const confirmCleanup = new ScenarioInput( "confirmCleanup", "Do you want to delete the created resources?", { type: "confirm" }, ); export const deleteImageSets = new ScenarioAction( "deleteImageSets", async (/** @type {State} */ state) => { const datastoreId = state.stackOutputs.DatastoreID; for (const metadata of state.imageSetMetadata) { const command = new DeleteImageSetCommand({ datastoreId, imageSetId: metadata.ImageSetID, }); try { await medicalImagingClient.send(command); console.log(`Successfully deleted image set ${metadata.ImageSetID}`); } catch (e) { if (e instanceof Error) { if (e.name === "ConflictException") { console.log(`Image set ${metadata.ImageSetID} already deleted`); } } } } }, { skipWhen: (/** @type {{}} */ state) => !state.confirmCleanup, }, ); export const deleteStack = new ScenarioAction( "deleteStack", async (/** @type {State} */ state) => { const stackName = state.getStackName; const command = new DeleteStackCommand({ StackName: stackName, }); await cfnClient.send(command); console.log(`Stack ${stackName} deletion initiated`); }, { skipWhen: (/** @type {{}} */ state) => !state.confirmCleanup, }, );
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

The following code example shows how to tag a HealthImaging data store.

SDK for JavaScript (v3)

To tag a data store.

try { const datastoreArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012"; const tags = { Deployment: "Development", }; await tagResource(datastoreArn, tags); } catch (e) { console.log(e); }

The utility function for tagging a resource.

import { TagResourceCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. * @param {Record<string,string>} tags - The tags to add to the resource as JSON. * - For example: {"Deployment" : "Development"} */ export const tagResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:xxxxxx:datastore/xxxxx/imageset/xxx", tags = {} ) => { const response = await medicalImagingClient.send( new TagResourceCommand({ resourceArn: resourceArn, tags: tags }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 204, // requestId: '8a6de9a3-ec8e-47ef-8643-473518b19d45', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // } // } return response; };

To list tags for a data store.

try { const datastoreArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012"; const { tags } = await listTagsForResource(datastoreArn); console.log(tags); } catch (e) { console.log(e); }

The utility function for listing a resource's tags.

import { ListTagsForResourceCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. */ export const listTagsForResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:abc:datastore/def/imageset/ghi" ) => { const response = await medicalImagingClient.send( new ListTagsForResourceCommand({ resourceArn: resourceArn }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '008fc6d3-abec-4870-a155-20fa3631e645', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // tags: { Deployment: 'Development' } // } return response; };

To untag a data store.

try { const datastoreArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012"; const keys = ["Deployment"]; await untagResource(datastoreArn, keys); } catch (e) { console.log(e); }

The utility function for untagging a resource.

import { UntagResourceCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. * @param {string[]} tagKeys - The keys of the tags to remove. */ export const untagResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:xxxxxx:datastore/xxxxx/imageset/xxx", tagKeys = [] ) => { const response = await medicalImagingClient.send( new UntagResourceCommand({ resourceArn: resourceArn, tagKeys: tagKeys }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 204, // requestId: '8a6de9a3-ec8e-47ef-8643-473518b19d45', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // } // } return response; };
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.

The following code example shows how to tag a HealthImaging image set.

SDK for JavaScript (v3)

To tag an image set.

try { const imagesetArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012/imageset/12345678901234567890123456789012"; const tags = { Deployment: "Development", }; await tagResource(imagesetArn, tags); } catch (e) { console.log(e); }

The utility function for tagging a resource.

import { TagResourceCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. * @param {Record<string,string>} tags - The tags to add to the resource as JSON. * - For example: {"Deployment" : "Development"} */ export const tagResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:xxxxxx:datastore/xxxxx/imageset/xxx", tags = {} ) => { const response = await medicalImagingClient.send( new TagResourceCommand({ resourceArn: resourceArn, tags: tags }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 204, // requestId: '8a6de9a3-ec8e-47ef-8643-473518b19d45', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // } // } return response; };

To list tags for an image set.

try { const imagesetArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012/imageset/12345678901234567890123456789012"; const { tags } = await listTagsForResource(imagesetArn); console.log(tags); } catch (e) { console.log(e); }

The utility function for listing a resource's tags.

import { ListTagsForResourceCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. */ export const listTagsForResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:abc:datastore/def/imageset/ghi" ) => { const response = await medicalImagingClient.send( new ListTagsForResourceCommand({ resourceArn: resourceArn }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '008fc6d3-abec-4870-a155-20fa3631e645', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // tags: { Deployment: 'Development' } // } return response; };

To untag an image set.

try { const imagesetArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012/imageset/12345678901234567890123456789012"; const keys = ["Deployment"]; await untagResource(imagesetArn, keys); } catch (e) { console.log(e); }

The utility function for untagging a resource.

import { UntagResourceCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} resourceArn - The Amazon Resource Name (ARN) for the data store or image set. * @param {string[]} tagKeys - The keys of the tags to remove. */ export const untagResource = async ( resourceArn = "arn:aws:medical-imaging:us-east-1:xxxxxx:datastore/xxxxx/imageset/xxx", tagKeys = [] ) => { const response = await medicalImagingClient.send( new UntagResourceCommand({ resourceArn: resourceArn, tagKeys: tagKeys }) ); console.log(response); // { // '$metadata': { // httpStatusCode: 204, // requestId: '8a6de9a3-ec8e-47ef-8643-473518b19d45', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // } // } return response; };
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the Amazon Code Examples Repository.