AWS 文档 AWS SDK示例 GitHub 存储库中还有更多SDK示例
本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
与 AWS SDK或CopyImageSet
一起使用 CLI
以下代码示例演示如何使用 CopyImageSet
。
- CLI
-
- AWS CLI
-
例 1:复制没有目标的影像集。
以下
copy-image-set
示例为没有目标的影像集创建副本。aws medical-imaging copy-image-set \ --datastore-id
12345678901234567890123456789012
\ --source-image-set-idea92b0d8838c72a3f25d00d13616f87e
\ --copy-image-set-information '{"sourceImageSet": {"latestVersionId": "1" } }
'输出:
{ "destinationImageSetProperties": { "latestVersionId": "2", "imageSetWorkflowStatus": "COPYING", "updatedAt": 1680042357.432, "imageSetId": "b9a06fef182a5f992842f77f8e0868e5", "imageSetState": "LOCKED", "createdAt": 1680042357.432 }, "sourceImageSetProperties": { "latestVersionId": "1", "imageSetWorkflowStatus": "COPYING_WITH_READ_ONLY_ACCESS", "updatedAt": 1680042357.432, "imageSetId": "ea92b0d8838c72a3f25d00d13616f87e", "imageSetState": "LOCKED", "createdAt": 1680027126.436 }, "datastoreId": "12345678901234567890123456789012" }
例 2:复制带有目标的影像集。
以下
copy-image-set
示例创建带有目标的影像集的副本。aws medical-imaging copy-image-set \ --datastore-id
12345678901234567890123456789012
\ --source-image-set-idea92b0d8838c72a3f25d00d13616f87e
\ --copy-image-set-information '{"sourceImageSet": {"latestVersionId": "1" }, "destinationImageSet": { "imageSetId": "b9a06fef182a5f992842f77f8e0868e5", "latestVersionId": "1"} }
'输出:
{ "destinationImageSetProperties": { "latestVersionId": "2", "imageSetWorkflowStatus": "COPYING", "updatedAt": 1680042505.135, "imageSetId": "b9a06fef182a5f992842f77f8e0868e5", "imageSetState": "LOCKED", "createdAt": 1680042357.432 }, "sourceImageSetProperties": { "latestVersionId": "1", "imageSetWorkflowStatus": "COPYING_WITH_READ_ONLY_ACCESS", "updatedAt": 1680042505.135, "imageSetId": "ea92b0d8838c72a3f25d00d13616f87e", "imageSetState": "LOCKED", "createdAt": 1680027126.436 }, "datastoreId": "12345678901234567890123456789012" }
示例 3:将实例子集从源图像集复制到目标影像集。
以下
copy-image-set
示例将一个DICOM实例从源图像集复制到目标影像集。提供力参数是为了覆盖 “患者”、“研究” 和 “系列” 级别属性中的不一致之处。aws medical-imaging copy-image-set \ --datastore-id
12345678901234567890123456789012
\ --source-image-set-idea92b0d8838c72a3f25d00d13616f87e
\ --copy-image-set-information '{"sourceImageSet": {"latestVersionId": "1","DICOMCopies": {"copiableAttributes": "{\"SchemaVersion\":\"1.1\",\"Study\":{\"Series\":{\"1.3.6.1.4.1.5962.99.1.3673257865.2104868982.1369432891697.3666.0\":{\"Instances\":{\"1.3.6.1.4.1.5962.99.1.3673257865.2104868982.1369432891697.3669.0\":{}}}}}}"}},"destinationImageSet": {"imageSetId": "b9eb50d8ee682eb9fcf4acbf92f62bb7","latestVersionId": "1"}}
' \ --force输出:
{ "destinationImageSetProperties": { "latestVersionId": "2", "imageSetWorkflowStatus": "COPYING", "updatedAt": 1680042505.135, "imageSetId": "b9eb50d8ee682eb9fcf4acbf92f62bb7", "imageSetState": "LOCKED", "createdAt": 1680042357.432 }, "sourceImageSetProperties": { "latestVersionId": "1", "imageSetWorkflowStatus": "COPYING_WITH_READ_ONLY_ACCESS", "updatedAt": 1680042505.135, "imageSetId": "ea92b0d8838c72a3f25d00d13616f87e", "imageSetState": "LOCKED", "createdAt": 1680027126.436 }, "datastoreId": "12345678901234567890123456789012" }
有关更多信息,请参阅《AWS HealthImaging 开发者指南》中的复制图像集。
-
有关API详细信息,请参阅 “CopyImageSet AWS CLI
命令参考”。
-
- Java
-
- SDK适用于 Java 2.x
-
/** * Copy an AWS HealthImaging image set. * * @param medicalImagingClient - The AWS HealthImaging client object. * @param datastoreId - The datastore ID. * @param imageSetId - The image set ID. * @param latestVersionId - The version ID. * @param destinationImageSetId - The optional destination image set ID, ignored if null. * @param destinationVersionId - The optional destination version ID, ignored if null. * @param force - The force flag. * @param subsets - The optional subsets to copy, ignored if null. * @return - The image set ID of the copy. * @throws MedicalImagingException - Base exception for all service exceptions thrown by AWS HealthImaging. */ public static String copyMedicalImageSet(MedicalImagingClient medicalImagingClient, String datastoreId, String imageSetId, String latestVersionId, String destinationImageSetId, String destinationVersionId, boolean force, Vector<String> subsets) { try { CopySourceImageSetInformation.Builder copySourceImageSetInformation = CopySourceImageSetInformation.builder() .latestVersionId(latestVersionId); // Optionally copy a subset of image instances. if (subsets != null) { String subsetInstanceToCopy = getCopiableAttributesJSON(imageSetId, subsets); copySourceImageSetInformation.dicomCopies(MetadataCopies.builder() .copiableAttributes(subsetInstanceToCopy) .build()); } CopyImageSetInformation.Builder copyImageSetBuilder = CopyImageSetInformation.builder() .sourceImageSet(copySourceImageSetInformation.build()); // Optionally designate a destination image set. if (destinationImageSetId != null) { copyImageSetBuilder = copyImageSetBuilder.destinationImageSet(CopyDestinationImageSet.builder() .imageSetId(destinationImageSetId) .latestVersionId(destinationVersionId) .build()); } CopyImageSetRequest copyImageSetRequest = CopyImageSetRequest.builder() .datastoreId(datastoreId) .sourceImageSetId(imageSetId) .copyImageSetInformation(copyImageSetBuilder.build()) .force(force) .build(); CopyImageSetResponse response = medicalImagingClient.copyImageSet(copyImageSetRequest); return response.destinationImageSetProperties().imageSetId(); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); throw e; } }
用于创建可复制属性的实用函数。
/** * Create a JSON string of copiable image instances. * * @param imageSetId - The image set ID. * @param subsets - The subsets to copy. * @return A JSON string of copiable image instances. */ private static String getCopiableAttributesJSON(String imageSetId, Vector<String> subsets) { StringBuilder subsetInstanceToCopy = new StringBuilder( """ { "SchemaVersion": 1.1, "Study": { "Series": { " """ ); subsetInstanceToCopy.append(imageSetId); subsetInstanceToCopy.append( """ ": { "Instances": { """ ); for (String subset : subsets) { subsetInstanceToCopy.append('"' + subset + "\": {},"); } subsetInstanceToCopy.deleteCharAt(subsetInstanceToCopy.length() - 1); subsetInstanceToCopy.append(""" } } } } } """); return subsetInstanceToCopy.toString(); }
-
有关API详细信息,请参阅 “AWS SDK for Java 2.x API参考 CopyImageSet” 中的。
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 -
- JavaScript
-
- SDK对于 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详细信息,请参阅 “AWS SDK for JavaScript API参考 CopyImageSet” 中的。
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 -
- Python
-
- SDK适用于 Python (Boto3)
-
用于复制映像集的实用程序函数。
class MedicalImagingWrapper: def __init__(self, health_imaging_client): self.health_imaging_client = health_imaging_client def copy_image_set( self, datastore_id, image_set_id, version_id, destination_image_set_id=None, destination_version_id=None, force=False, subsets=[], ): """ Copy an image set. :param datastore_id: The ID of the data store. :param image_set_id: The ID of the image set. :param version_id: The ID of the image set version. :param destination_image_set_id: The ID of the optional destination image set. :param destination_version_id: The ID of the optional destination image set version. :param force: Force the copy. :param subsets: The optional subsets to copy. For example: ["12345678901234567890123456789012"]. :return: The copied image set ID. """ try: copy_image_set_information = { "sourceImageSet": {"latestVersionId": version_id} } if destination_image_set_id and destination_version_id: copy_image_set_information["destinationImageSet"] = { "imageSetId": destination_image_set_id, "latestVersionId": destination_version_id, } if len(subsets) > 0: copySubsetsJson = { "SchemaVersion": "1.1", "Study": {"Series": {"imageSetId": {"Instances": {}}}}, } for subset in subsets: copySubsetsJson["Study"]["Series"]["imageSetId"]["Instances"][ subset ] = {} copy_image_set_information["sourceImageSet"]["DICOMCopies"] = { "copiableAttributes": json.dumps(copySubsetsJson) } copy_results = self.health_imaging_client.copy_image_set( datastoreId=datastore_id, sourceImageSetId=image_set_id, copyImageSetInformation=copy_image_set_information, force=force, ) except ClientError as err: logger.error( "Couldn't copy image set. Here's why: %s: %s", err.response["Error"]["Code"], err.response["Error"]["Message"], ) raise else: return copy_results["destinationImageSetProperties"]["imageSetId"]
复制没有目标的映像集。
copy_image_set_information = { "sourceImageSet": {"latestVersionId": version_id} } copy_results = self.health_imaging_client.copy_image_set( datastoreId=datastore_id, sourceImageSetId=image_set_id, copyImageSetInformation=copy_image_set_information, force=force, )
复制带有目标的映像集。
copy_image_set_information = { "sourceImageSet": {"latestVersionId": version_id} } if destination_image_set_id and destination_version_id: copy_image_set_information["destinationImageSet"] = { "imageSetId": destination_image_set_id, "latestVersionId": destination_version_id, } copy_results = self.health_imaging_client.copy_image_set( datastoreId=datastore_id, sourceImageSetId=image_set_id, copyImageSetInformation=copy_image_set_information, force=force, )
复制影像集的子集。
copy_image_set_information = { "sourceImageSet": {"latestVersionId": version_id} } if len(subsets) > 0: copySubsetsJson = { "SchemaVersion": "1.1", "Study": {"Series": {"imageSetId": {"Instances": {}}}}, } for subset in subsets: copySubsetsJson["Study"]["Series"]["imageSetId"]["Instances"][ subset ] = {} copy_image_set_information["sourceImageSet"]["DICOMCopies"] = { "copiableAttributes": json.dumps(copySubsetsJson) } copy_results = self.health_imaging_client.copy_image_set( datastoreId=datastore_id, sourceImageSetId=image_set_id, copyImageSetInformation=copy_image_set_information, force=force, )
以下代码实例化对象。 MedicalImagingWrapper
client = boto3.client("medical-imaging") medical_imaging_wrapper = MedicalImagingWrapper(client)
-
有关API详细信息,请参阅CopyImageSet中的 AWS SDKPython (Boto3) API 参考。
注意
还有更多相关信息 GitHub。查找完整示例,学习如何在 AWS 代码示例存储库
中进行设置和运行。 -