文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的
本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。
使用 SDK forWord(v3) 的 HealthImaging JavaScript 範例
下列程式碼範例示範如何使用 AWS SDK for JavaScript (v3) with HealthImaging 來執行動作和實作常見案例。
Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然動作會示範如何呼叫個別服務函數,但您可以在相關案例中查看內容中的動作。
案例是程式碼範例,示範如何透過呼叫服務內的多個函數或與其他函數結合,來完成特定任務 AWS 服務。
每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。
開始使用
下列程式碼範例示範如何開始使用 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; };
-
如需 API 詳細資訊,請參閱 ListDatastores AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
動作
下列程式碼範例示範如何使用 CopyImageSet
。
- SDK for JavaScript (v3)
-
用於複製映像集的公用程式函數。
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. * @param {boolean} force - Force the copy action. * @param {[string]} copySubsets - A subset of instance IDs to copy. */ export const copyImageSet = async ( datastoreId = "xxxxxxxxxxx", imageSetId = "xxxxxxxxxxxx", sourceVersionId = "1", destinationImageSetId = "", destinationVersionId = "", force = false, copySubsets = [], ) => { try { const params = { datastoreId: datastoreId, sourceImageSetId: imageSetId, copyImageSetInformation: { sourceImageSet: { latestVersionId: sourceVersionId }, }, force: force, }; if (destinationImageSetId !== "" && destinationVersionId !== "") { params.copyImageSetInformation.destinationImageSet = { imageSetId: destinationImageSetId, latestVersionId: destinationVersionId, }; } if (copySubsets.length > 0) { let copySubsetsJson; copySubsetsJson = { SchemaVersion: 1.1, Study: { Series: { imageSetId: { Instances: {}, }, }, }, }; for (let i = 0; i < copySubsets.length; i++) { copySubsetsJson.Study.Series.imageSetId.Instances[copySubsets[i]] = {}; } params.copyImageSetInformation.dicomCopies = copySubsetsJson; } 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; } catch (err) { console.error(err); } };
複製沒有目的地的影像集。
await copyImageSet( "12345678901234567890123456789012", "12345678901234567890123456789012", "1", );
使用目的地複製映像集。
await copyImageSet( "12345678901234567890123456789012", "12345678901234567890123456789012", "1", "12345678901234567890123456789012", "1", false, );
使用目的地複製影像集的子集,並強制複製。
await copyImageSet( "12345678901234567890123456789012", "12345678901234567890123456789012", "1", "12345678901234567890123456789012", "1", true, ["12345678901234567890123456789012", "11223344556677889900112233445566"], );
-
如需 API 詳細資訊,請參閱 CopyImageSet AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 CreateDatastore AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 DeleteDatastore AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 DeleteImageSet AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 Word 參考中的 GetDICOMImport 任務。 AWS SDK for JavaScript API
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 GetDatastore AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 GetImageFrame AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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 = "", ) => { const 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; };
-
如需 API 詳細資訊,請參閱 GetImageSet AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 GetImageSetMetadata
。
- SDK for JavaScript (v3)
-
公用程式函數,以取得影像集中繼資料。
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; };
取得不含 版本的映像集中繼資料。
try { await getImageSetMetadata( "metadata.json.gzip", "12345678901234567890123456789012", "12345678901234567890123456789012", ); } catch (err) { console.log("Error", err); }
使用 版本取得映像集中繼資料。
try { await getImageSetMetadata( "metadata2.json.gzip", "12345678901234567890123456789012", "12345678901234567890123456789012", "1", ); } catch (err) { console.log("Error", err); }
-
如需 API 詳細資訊,請參閱 GetImageSetMetadata AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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); const 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; };
-
如需 API 詳細資訊,請參閱 Word 參考中的 ListDICOMImport 任務。 AWS SDK for JavaScript API
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 ListDatastores AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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, ); const 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; };
-
如需 API 詳細資訊,請參閱 ListImageSetVersions AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 ListTagsForResource AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 SearchImageSets
。
- SDK for JavaScript (v3)
-
用於搜尋映像集的公用程式函數。
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; };
使用案例 1:EQUAL 運算子。
const datastoreId = "12345678901234567890123456789012"; try { const searchCriteria = { filters: [ { values: [{ DICOMPatientId: "1234567" }], operator: "EQUAL", }, ], }; await searchImageSets(datastoreId, searchCriteria); } catch (err) { console.error(err); }
使用案例 #2:使用 BETWEEN 和 Word 的 DICOMStudyTime 運算DICOMStudyDate。
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); }
使用案例 #3:使用 BETWEEN 的 createdAt 運算子。先前持續進行檢查的時間。
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); }
使用案例 #4:DICOMSeriesInstanceUID 上的 EQUAL 運算子和 BETWEEN on updatedAt ,並以 Word on updatedAt 欄位的 ASC 順序排序回應。
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); }
-
如需 API 詳細資訊,請參閱 SearchImageSets AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 tartDICOMImport 參考中的 SWord 任務。 AWS SDK for JavaScript API
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 TagResource AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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; };
-
如需 API 詳細資訊,請參閱 UntagResource AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何使用 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. * @param {boolean} force - Force the update. */ export const updateImageSetMetadata = async ( datastoreId = "xxxxxxxxxx", imageSetId = "xxxxxxxxxx", latestVersionId = "1", updateMetadata = "{}", force = false, ) => { try { const response = await medicalImagingClient.send( new UpdateImageSetMetadataCommand({ datastoreId: datastoreId, imageSetId: imageSetId, latestVersionId: latestVersionId, updateImageSetMetadataUpdates: updateMetadata, force: force, }), ); 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; } catch (err) { console.error(err); } };
使用案例 #1:插入或更新屬性並強制更新。
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, true, );
使用案例 #2:移除屬性。
// 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, );
使用案例 #3:移除執行個體。
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, );
使用案例 #4:還原至舊版。
const updateMetadata = { revertToVersionId: "1", }; await updateImageSetMetadata( datastoreID, imageSetID, versionID, updateMetadata, );
-
如需 API 詳細資訊,請參閱 UpdateImageSetMetadata AWS SDK for JavaScript 參考中的 API。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
案例
下列程式碼範例示範如何匯入 DICOM 檔案和下載映像影格 in HealthImaging。
實作的結構是工作流程命令列應用程式。
設定 DICOM 匯入的資源。
將 DICOM 檔案匯入資料存放區。
擷取匯入任務的影像集 IDs。
擷取影像集的影像影格 IDs。
下載、解碼和驗證影像影格。
清除資源。
- SDK for JavaScript (v3)
-
index.js - 協調步驟。
import { parseScenarioArgs, Scenario, } from "@aws-doc-sdk-examples/lib/scenario/index.js"; import { saveState, loadState, } from "@aws-doc-sdk-examples/lib/scenario/steps-common.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 "node:url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { parseScenarioArgs(scenarios, { name: "Health Imaging Workflow", description: "Work with DICOM images using an AWS Health Imaging data store.", synopsis: "node index.js --scenario <deploy | demo | destroy> [-h|--help] [-y|--yes] [-v|--verbose]", }); }
deploy-steps.js - 部署資源。
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 - 複製 DICOM 檔案。
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 - 開始匯入資料存放區。
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", default: true, }, ); 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 - 取得映像集 IDs。
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((ids, next) => { return Object.assign({}, ids, { [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 - 取得影像影格 IDs。
import { MedicalImagingClient, GetImageSetMetadataCommand, } from "@aws-sdk/client-medical-imaging"; import { gunzip } from "node:zlib"; import { promisify } from "node: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; }, );
verify-steps.js - 驗證影像影格。AWS HealthImaging Pixel 資料驗證
程式庫已用於驗證。 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", default: true, }, ); 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 - 銷毀資源。
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, }, );
-
如需 API 詳細資訊,請參閱 AWS SDK for JavaScript API 參考中的下列主題。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何標記 a HealthImaging 資料存放區。
- SDK for JavaScript (v3)
-
標記資料存放區。
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); }
標記資源的公用程式函數。
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; };
列出資料存放區的標籤。
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); }
列出資源標籤的公用程式函數。
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; };
取消標記資料存放區。
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); }
用於取消標記資源的公用程式函數。
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; };
-
如需 API 詳細資訊,請參閱 AWS SDK for JavaScript API 參考中的下列主題。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -
下列程式碼範例示範如何標記 a HealthImaging 映像集。
- SDK for JavaScript (v3)
-
標記映像集。
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); }
標記資源的公用程式函數。
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; };
列出映像集的標籤。
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); }
列出資源標籤的公用程式函數。
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; };
取消標記影像集。
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); }
用於取消標記資源的公用程式函數。
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; };
-
如需 API 詳細資訊,請參閱 AWS SDK for JavaScript API 參考中的下列主題。
注意
還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫
中設定和執行。 -