使用 HealthImaging for Java 2.x 的 SDK 範例 - AWS SDK 程式碼範例

文件 AWS SDK AWS 範例 SDK 儲存庫中有更多可用的 GitHub 範例。

本文為英文版的機器翻譯版本,如內容有任何歧義或不一致之處,概以英文版為準。

使用 HealthImaging for Java 2.x 的 SDK 範例

下列程式碼範例示範如何使用 AWS SDK for Java 2.x with HealthImaging 來執行動作和實作常見案例。

Actions 是大型程式的程式碼摘錄,必須在內容中執行。雖然 動作會示範如何呼叫個別服務函數,但您可以在其相關案例中查看內容中的動作。

案例是程式碼範例,示範如何透過呼叫服務內的多個函數或與其他函數結合來完成特定任務 AWS 服務。

每個範例都包含完整原始程式碼的連結,您可以在其中找到如何在內容中設定和執行程式碼的指示。

動作

下列程式碼範例示範如何使用 CopyImageSet

Java 2.x 的 SDK
/** * 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 詳細資訊,請參閱 CopyImageSet AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 CreateDatastore

Java 2.x 的 SDK
public static String createMedicalImageDatastore(MedicalImagingClient medicalImagingClient, String datastoreName) { try { CreateDatastoreRequest datastoreRequest = CreateDatastoreRequest.builder() .datastoreName(datastoreName) .build(); CreateDatastoreResponse response = medicalImagingClient.createDatastore(datastoreRequest); return response.datastoreId(); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
  • 如需 API 詳細資訊,請參閱 CreateDatastore AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 DeleteDatastore

Java 2.x 的 SDK
public static void deleteMedicalImagingDatastore(MedicalImagingClient medicalImagingClient, String datastoreID) { try { DeleteDatastoreRequest datastoreRequest = DeleteDatastoreRequest.builder() .datastoreId(datastoreID) .build(); medicalImagingClient.deleteDatastore(datastoreRequest); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱 DeleteDatastore AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 DeleteImageSet

Java 2.x 的 SDK
public static void deleteMedicalImageSet(MedicalImagingClient medicalImagingClient, String datastoreId, String imagesetId) { try { DeleteImageSetRequest deleteImageSetRequest = DeleteImageSetRequest.builder() .datastoreId(datastoreId) .imageSetId(imagesetId) .build(); medicalImagingClient.deleteImageSet(deleteImageSetRequest); System.out.println("The image set was deleted."); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱 DeleteImageSet AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 GetDICOMImportJob

Java 2.x 的 SDK
public static DICOMImportJobProperties getDicomImportJob(MedicalImagingClient medicalImagingClient, String datastoreId, String jobId) { try { GetDicomImportJobRequest getDicomImportJobRequest = GetDicomImportJobRequest.builder() .datastoreId(datastoreId) .jobId(jobId) .build(); GetDicomImportJobResponse response = medicalImagingClient.getDICOMImportJob(getDicomImportJobRequest); return response.jobProperties(); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; }
  • 如需 API 詳細資訊,請參閱 Word 參考中的 GetDICOMImport 任務AWS SDK for Java 2.x API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 GetDatastore

Java 2.x 的 SDK
public static DatastoreProperties getMedicalImageDatastore(MedicalImagingClient medicalImagingClient, String datastoreID) { try { GetDatastoreRequest datastoreRequest = GetDatastoreRequest.builder() .datastoreId(datastoreID) .build(); GetDatastoreResponse response = medicalImagingClient.getDatastore(datastoreRequest); return response.datastoreProperties(); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; }
  • 如需 API 詳細資訊,請參閱 GetDatastore AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 GetImageFrame

Java 2.x 的 SDK
public static void getMedicalImageSetFrame(MedicalImagingClient medicalImagingClient, String destinationPath, String datastoreId, String imagesetId, String imageFrameId) { try { GetImageFrameRequest getImageSetMetadataRequest = GetImageFrameRequest.builder() .datastoreId(datastoreId) .imageSetId(imagesetId) .imageFrameInformation(ImageFrameInformation.builder() .imageFrameId(imageFrameId) .build()) .build(); medicalImagingClient.getImageFrame(getImageSetMetadataRequest, FileSystems.getDefault().getPath(destinationPath)); System.out.println("Image frame downloaded to " + destinationPath); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱 GetImageFrame AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 GetImageSet

Java 2.x 的 SDK
public static GetImageSetResponse getMedicalImageSet(MedicalImagingClient medicalImagingClient, String datastoreId, String imagesetId, String versionId) { try { GetImageSetRequest.Builder getImageSetRequestBuilder = GetImageSetRequest.builder() .datastoreId(datastoreId) .imageSetId(imagesetId); if (versionId != null) { getImageSetRequestBuilder = getImageSetRequestBuilder.versionId(versionId); } return medicalImagingClient.getImageSet(getImageSetRequestBuilder.build()); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; }
  • 如需 API 詳細資訊,請參閱 GetImageSet AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 GetImageSetMetadata

Java 2.x 的 SDK
public static void getMedicalImageSetMetadata(MedicalImagingClient medicalImagingClient, String destinationPath, String datastoreId, String imagesetId, String versionId) { try { GetImageSetMetadataRequest.Builder getImageSetMetadataRequestBuilder = GetImageSetMetadataRequest.builder() .datastoreId(datastoreId) .imageSetId(imagesetId); if (versionId != null) { getImageSetMetadataRequestBuilder = getImageSetMetadataRequestBuilder.versionId(versionId); } medicalImagingClient.getImageSetMetadata(getImageSetMetadataRequestBuilder.build(), FileSystems.getDefault().getPath(destinationPath)); System.out.println("Metadata downloaded to " + destinationPath); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 ListDICOMImportJobs

Java 2.x 的 SDK
public static List<DICOMImportJobSummary> listDicomImportJobs(MedicalImagingClient medicalImagingClient, String datastoreId) { try { ListDicomImportJobsRequest listDicomImportJobsRequest = ListDicomImportJobsRequest.builder() .datastoreId(datastoreId) .build(); ListDicomImportJobsResponse response = medicalImagingClient.listDICOMImportJobs(listDicomImportJobsRequest); return response.jobSummaries(); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return new ArrayList<>(); }
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 ListDatastores

Java 2.x 的 SDK
public static List<DatastoreSummary> listMedicalImagingDatastores(MedicalImagingClient medicalImagingClient) { try { ListDatastoresRequest datastoreRequest = ListDatastoresRequest.builder() .build(); ListDatastoresIterable responses = medicalImagingClient.listDatastoresPaginator(datastoreRequest); List<DatastoreSummary> datastoreSummaries = new ArrayList<>(); responses.stream().forEach(response -> datastoreSummaries.addAll(response.datastoreSummaries())); return datastoreSummaries; } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; }
  • 如需 API 詳細資訊,請參閱 ListDatastores AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 ListImageSetVersions

Java 2.x 的 SDK
public static List<ImageSetProperties> listMedicalImageSetVersions(MedicalImagingClient medicalImagingClient, String datastoreId, String imagesetId) { try { ListImageSetVersionsRequest getImageSetRequest = ListImageSetVersionsRequest.builder() .datastoreId(datastoreId) .imageSetId(imagesetId) .build(); ListImageSetVersionsIterable responses = medicalImagingClient .listImageSetVersionsPaginator(getImageSetRequest); List<ImageSetProperties> imageSetProperties = new ArrayList<>(); responses.stream().forEach(response -> imageSetProperties.addAll(response.imageSetPropertiesList())); return imageSetProperties; } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; }
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 ListTagsForResource

Java 2.x 的 SDK
public static ListTagsForResourceResponse listMedicalImagingResourceTags(MedicalImagingClient medicalImagingClient, String resourceArn) { try { ListTagsForResourceRequest listTagsForResourceRequest = ListTagsForResourceRequest.builder() .resourceArn(resourceArn) .build(); return medicalImagingClient.listTagsForResource(listTagsForResourceRequest); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; }
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 SearchImageSets

Java 2.x 的 SDK

用於搜尋映像集的公用程式函數。

public static List<ImageSetsMetadataSummary> searchMedicalImagingImageSets( MedicalImagingClient medicalImagingClient, String datastoreId, SearchCriteria searchCriteria) { try { SearchImageSetsRequest datastoreRequest = SearchImageSetsRequest.builder() .datastoreId(datastoreId) .searchCriteria(searchCriteria) .build(); SearchImageSetsIterable responses = medicalImagingClient .searchImageSetsPaginator(datastoreRequest); List<ImageSetsMetadataSummary> imageSetsMetadataSummaries = new ArrayList<>(); responses.stream().forEach(response -> imageSetsMetadataSummaries .addAll(response.imageSetsMetadataSummaries())); return imageSetsMetadataSummaries; } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; }

使用案例 1:EQUAL 運算子。

List<SearchFilter> searchFilters = Collections.singletonList(SearchFilter.builder() .operator(Operator.EQUAL) .values(SearchByAttributeValue.builder() .dicomPatientId(patientId) .build()) .build()); SearchCriteria searchCriteria = SearchCriteria.builder() .filters(searchFilters) .build(); List<ImageSetsMetadataSummary> imageSetsMetadataSummaries = searchMedicalImagingImageSets( medicalImagingClient, datastoreId, searchCriteria); if (imageSetsMetadataSummaries != null) { System.out.println("The image sets for patient " + patientId + " are:\n" + imageSetsMetadataSummaries); System.out.println(); }

使用案例 #2:使用 BETWEEN 和 Word 的 DICOMStudyTime 運算DICOMStudyDate。

DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd"); searchFilters = Collections.singletonList(SearchFilter.builder() .operator(Operator.BETWEEN) .values(SearchByAttributeValue.builder() .dicomStudyDateAndTime(DICOMStudyDateAndTime.builder() .dicomStudyDate("19990101") .dicomStudyTime("000000.000") .build()) .build(), SearchByAttributeValue.builder() .dicomStudyDateAndTime(DICOMStudyDateAndTime.builder() .dicomStudyDate((LocalDate.now() .format(formatter))) .dicomStudyTime("000000.000") .build()) .build()) .build()); searchCriteria = SearchCriteria.builder() .filters(searchFilters) .build(); imageSetsMetadataSummaries = searchMedicalImagingImageSets(medicalImagingClient, datastoreId, searchCriteria); if (imageSetsMetadataSummaries != null) { System.out.println( "The image sets searched with BETWEEN operator using DICOMStudyDate and DICOMStudyTime are:\n" + imageSetsMetadataSummaries); System.out.println(); }

使用案例 #3:使用 BETWEEN 的 createdAt 運算子。先前持續進行檢查的時間。

searchFilters = Collections.singletonList(SearchFilter.builder() .operator(Operator.BETWEEN) .values(SearchByAttributeValue.builder() .createdAt(Instant.parse("1985-04-12T23:20:50.52Z")) .build(), SearchByAttributeValue.builder() .createdAt(Instant.now()) .build()) .build()); searchCriteria = SearchCriteria.builder() .filters(searchFilters) .build(); imageSetsMetadataSummaries = searchMedicalImagingImageSets(medicalImagingClient, datastoreId, searchCriteria); if (imageSetsMetadataSummaries != null) { System.out.println("The image sets searched with BETWEEN operator using createdAt are:\n " + imageSetsMetadataSummaries); System.out.println(); }

使用案例 #4:DICOMSeriesInstanceUID 上的 EQUAL 運算子和 BETWEEN on updatedAt ,並以 Word on updatedAt 欄位的 ASC 順序排序回應。

Instant startDate = Instant.parse("1985-04-12T23:20:50.52Z"); Instant endDate = Instant.now(); searchFilters = Arrays.asList( SearchFilter.builder() .operator(Operator.EQUAL) .values(SearchByAttributeValue.builder() .dicomSeriesInstanceUID(seriesInstanceUID) .build()) .build(), SearchFilter.builder() .operator(Operator.BETWEEN) .values( SearchByAttributeValue.builder().updatedAt(startDate).build(), SearchByAttributeValue.builder().updatedAt(endDate).build() ).build()); Sort sort = Sort.builder().sortOrder(SortOrder.ASC).sortField(SortField.UPDATED_AT).build(); searchCriteria = SearchCriteria.builder() .filters(searchFilters) .sort(sort) .build(); imageSetsMetadataSummaries = searchMedicalImagingImageSets(medicalImagingClient, datastoreId, searchCriteria); if (imageSetsMetadataSummaries != null) { System.out.println("The image sets searched with EQUAL operator on DICOMSeriesInstanceUID and BETWEEN on updatedAt and sort response\n" + "in ASC order on updatedAt field are:\n " + imageSetsMetadataSummaries); System.out.println(); }
  • 如需 API 詳細資訊,請參閱 SearchImageSets AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 StartDICOMImportJob

Java 2.x 的 SDK
public static String startDicomImportJob(MedicalImagingClient medicalImagingClient, String jobName, String datastoreId, String dataAccessRoleArn, String inputS3Uri, String outputS3Uri) { try { StartDicomImportJobRequest startDicomImportJobRequest = StartDicomImportJobRequest.builder() .jobName(jobName) .datastoreId(datastoreId) .dataAccessRoleArn(dataAccessRoleArn) .inputS3Uri(inputS3Uri) .outputS3Uri(outputS3Uri) .build(); StartDicomImportJobResponse response = medicalImagingClient.startDICOMImportJob(startDicomImportJobRequest); return response.jobId(); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return ""; }
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 TagResource

Java 2.x 的 SDK
public static void tagMedicalImagingResource(MedicalImagingClient medicalImagingClient, String resourceArn, Map<String, String> tags) { try { TagResourceRequest tagResourceRequest = TagResourceRequest.builder() .resourceArn(resourceArn) .tags(tags) .build(); medicalImagingClient.tagResource(tagResourceRequest); System.out.println("Tags have been added to the resource."); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱 TagResource AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 UntagResource

Java 2.x 的 SDK
public static void untagMedicalImagingResource(MedicalImagingClient medicalImagingClient, String resourceArn, Collection<String> tagKeys) { try { UntagResourceRequest untagResourceRequest = UntagResourceRequest.builder() .resourceArn(resourceArn) .tagKeys(tagKeys) .build(); medicalImagingClient.untagResource(untagResourceRequest); System.out.println("Tags have been removed from the resource."); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
  • 如需 API 詳細資訊,請參閱 UntagResource AWS SDK for Java 2.x 參考中的 API

注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何使用 UpdateImageSetMetadata

Java 2.x 的 SDK
/** * Update the metadata of an AWS HealthImaging image set. * * @param medicalImagingClient - The AWS HealthImaging client object. * @param datastoreId - The datastore ID. * @param imageSetId - The image set ID. * @param versionId - The version ID. * @param metadataUpdates - A MetadataUpdates object containing the updates. * @param force - The force flag. * @throws MedicalImagingException - Base exception for all service exceptions thrown by AWS HealthImaging. */ public static void updateMedicalImageSetMetadata(MedicalImagingClient medicalImagingClient, String datastoreId, String imageSetId, String versionId, MetadataUpdates metadataUpdates, boolean force) { try { UpdateImageSetMetadataRequest updateImageSetMetadataRequest = UpdateImageSetMetadataRequest .builder() .datastoreId(datastoreId) .imageSetId(imageSetId) .latestVersionId(versionId) .updateImageSetMetadataUpdates(metadataUpdates) .force(force) .build(); UpdateImageSetMetadataResponse response = medicalImagingClient.updateImageSetMetadata(updateImageSetMetadataRequest); System.out.println("The image set metadata was updated" + response); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); throw e; } }

使用案例 #1:插入或更新屬性。

final String insertAttributes = """ { "SchemaVersion": 1.1, "Study": { "DICOM": { "StudyDescription": "CT CHEST" } } } """; MetadataUpdates metadataInsertUpdates = MetadataUpdates.builder() .dicomUpdates(DICOMUpdates.builder() .updatableAttributes(SdkBytes.fromByteBuffer( ByteBuffer.wrap(insertAttributes .getBytes(StandardCharsets.UTF_8)))) .build()) .build(); updateMedicalImageSetMetadata(medicalImagingClient, datastoreId, imagesetId, versionid, metadataInsertUpdates, force);

使用案例 #2:移除屬性。

final String removeAttributes = """ { "SchemaVersion": 1.1, "Study": { "DICOM": { "StudyDescription": "CT CHEST" } } } """; MetadataUpdates metadataRemoveUpdates = MetadataUpdates.builder() .dicomUpdates(DICOMUpdates.builder() .removableAttributes(SdkBytes.fromByteBuffer( ByteBuffer.wrap(removeAttributes .getBytes(StandardCharsets.UTF_8)))) .build()) .build(); updateMedicalImageSetMetadata(medicalImagingClient, datastoreId, imagesetId, versionid, metadataRemoveUpdates, force);

使用案例 #3:移除執行個體。

final String removeInstance = """ { "SchemaVersion": 1.1, "Study": { "Series": { "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": { "Instances": { "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": {} } } } } } """; MetadataUpdates metadataRemoveUpdates = MetadataUpdates.builder() .dicomUpdates(DICOMUpdates.builder() .removableAttributes(SdkBytes.fromByteBuffer( ByteBuffer.wrap(removeInstance .getBytes(StandardCharsets.UTF_8)))) .build()) .build(); updateMedicalImageSetMetadata(medicalImagingClient, datastoreId, imagesetId, versionid, metadataRemoveUpdates, force);

使用案例 #4:還原至先前的版本。

// In this case, revert to previous version. String revertVersionId = Integer.toString(Integer.parseInt(versionid) - 1); MetadataUpdates metadataRemoveUpdates = MetadataUpdates.builder() .revertToVersionId(revertVersionId) .build(); updateMedicalImageSetMetadata(medicalImagingClient, datastoreId, imagesetId, versionid, metadataRemoveUpdates, force);
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

案例

下列程式碼範例示範如何標記 a HealthImaging 資料存放區。

Java 2.x 的 SDK

標記資料存放區。

final String datastoreArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012"; TagResource.tagMedicalImagingResource(medicalImagingClient, datastoreArn, ImmutableMap.of("Deployment", "Development"));

標記資源的公用程式函數。

public static void tagMedicalImagingResource(MedicalImagingClient medicalImagingClient, String resourceArn, Map<String, String> tags) { try { TagResourceRequest tagResourceRequest = TagResourceRequest.builder() .resourceArn(resourceArn) .tags(tags) .build(); medicalImagingClient.tagResource(tagResourceRequest); System.out.println("Tags have been added to the resource."); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }

列出資料存放區的標籤。

final String datastoreArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012"; ListTagsForResourceResponse result = ListTagsForResource.listMedicalImagingResourceTags( medicalImagingClient, datastoreArn); if (result != null) { System.out.println("Tags for resource: " + result.tags()); }

列出資源標籤的公用程式函數。

public static ListTagsForResourceResponse listMedicalImagingResourceTags(MedicalImagingClient medicalImagingClient, String resourceArn) { try { ListTagsForResourceRequest listTagsForResourceRequest = ListTagsForResourceRequest.builder() .resourceArn(resourceArn) .build(); return medicalImagingClient.listTagsForResource(listTagsForResourceRequest); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; }

取消標記資料存放區。

final String datastoreArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012"; UntagResource.untagMedicalImagingResource(medicalImagingClient, datastoreArn, Collections.singletonList("Deployment"));

用於取消標記資源的公用程式函數。

public static void untagMedicalImagingResource(MedicalImagingClient medicalImagingClient, String resourceArn, Collection<String> tagKeys) { try { UntagResourceRequest untagResourceRequest = UntagResourceRequest.builder() .resourceArn(resourceArn) .tagKeys(tagKeys) .build(); medicalImagingClient.untagResource(untagResourceRequest); System.out.println("Tags have been removed from the resource."); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。

下列程式碼範例示範如何標記 a HealthImaging 映像集。

Java 2.x 的 SDK

標記映像集。

final String imageSetArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012/imageset/12345678901234567890123456789012"; TagResource.tagMedicalImagingResource(medicalImagingClient, imageSetArn, ImmutableMap.of("Deployment", "Development"));

標記資源的公用程式函數。

public static void tagMedicalImagingResource(MedicalImagingClient medicalImagingClient, String resourceArn, Map<String, String> tags) { try { TagResourceRequest tagResourceRequest = TagResourceRequest.builder() .resourceArn(resourceArn) .tags(tags) .build(); medicalImagingClient.tagResource(tagResourceRequest); System.out.println("Tags have been added to the resource."); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }

列出映像集的標籤。

final String imageSetArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012/imageset/12345678901234567890123456789012"; ListTagsForResourceResponse result = ListTagsForResource.listMedicalImagingResourceTags( medicalImagingClient, imageSetArn); if (result != null) { System.out.println("Tags for resource: " + result.tags()); }

列出資源標籤的公用程式函數。

public static ListTagsForResourceResponse listMedicalImagingResourceTags(MedicalImagingClient medicalImagingClient, String resourceArn) { try { ListTagsForResourceRequest listTagsForResourceRequest = ListTagsForResourceRequest.builder() .resourceArn(resourceArn) .build(); return medicalImagingClient.listTagsForResource(listTagsForResourceRequest); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } return null; }

取消標記影像集。

final String imageSetArn = "arn:aws:medical-imaging:us-east-1:123456789012:datastore/12345678901234567890123456789012/imageset/12345678901234567890123456789012"; UntagResource.untagMedicalImagingResource(medicalImagingClient, imageSetArn, Collections.singletonList("Deployment"));

用於取消標記資源的公用程式函數。

public static void untagMedicalImagingResource(MedicalImagingClient medicalImagingClient, String resourceArn, Collection<String> tagKeys) { try { UntagResourceRequest untagResourceRequest = UntagResourceRequest.builder() .resourceArn(resourceArn) .tagKeys(tagKeys) .build(); medicalImagingClient.untagResource(untagResourceRequest); System.out.println("Tags have been removed from the resource."); } catch (MedicalImagingException e) { System.err.println(e.awsErrorDetails().errorMessage()); System.exit(1); } }
注意

還有更多 on GitHub。尋找完整範例,並了解如何在 AWS 程式碼範例儲存庫中設定和執行。