HealthImaging exemples utilisant SDK for JavaScript (v3) - AWS SDK for JavaScript

Le guide de API référence AWS SDK for JavaScript V3 décrit en détail toutes les API opérations de la AWS SDK for JavaScript version 3 (V3).

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

HealthImaging exemples utilisant SDK for JavaScript (v3)

Les exemples de code suivants vous montrent comment effectuer des actions et implémenter des scénarios courants en utilisant le AWS SDK for JavaScript (v3) avec HealthImaging.

Les actions sont des extraits de code de programmes plus larges et doivent être exécutées dans leur contexte. Les actions vous indiquent comment appeler des fonctions de service individuelles, mais vous pouvez les visualiser dans leur contexte dans les scénarios correspondants.

Les scénarios sont des exemples de code qui vous montrent comment accomplir des tâches spécifiques en appelant plusieurs fonctions au sein d'un service ou en les combinant à d'autres Services AWS.

Chaque exemple inclut un lien vers le code source complet, où vous trouverez des instructions sur la façon de configurer et d'exécuter le code en contexte.

Mise en route

Les exemples de code suivants montrent comment commencer à utiliser HealthImaging.

SDKpour 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; };
  • Pour API plus de détails, voir ListDatastoresla section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

Actions

L'exemple de code suivant montre comment utiliserCopyImageSet.

SDKpour JavaScript (v3)

Fonction utilitaire pour copier un ensemble d'images.

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

Copiez un ensemble d'images sans destination.

await copyImageSet( "12345678901234567890123456789012", "12345678901234567890123456789012", "1" );

Copiez un ensemble d'images avec une destination.

await copyImageSet( "12345678901234567890123456789012", "12345678901234567890123456789012", "1", "12345678901234567890123456789012", "1", false, );

Copiez un sous-ensemble d'un ensemble d'images avec une destination et forcez la copie.

await copyImageSet( "12345678901234567890123456789012", "12345678901234567890123456789012", "1", "12345678901234567890123456789012", "1", true, ["12345678901234567890123456789012", "11223344556677889900112233445566"] );
  • Pour API plus de détails, voir CopyImageSetla section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserCreateDatastore.

SDKpour 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; };
  • Pour API plus de détails, voir CreateDatastorela section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserDeleteDatastore.

SDKpour 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; };
  • Pour API plus de détails, voir DeleteDatastorela section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserDeleteImageSet.

SDKpour 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; };
  • Pour API plus de détails, voir DeleteImageSetla section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserGetDICOMImportJob.

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

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserGetDatastore.

SDKpour 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"]; };
  • Pour API plus de détails, voir GetDatastorela section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserGetImageFrame.

SDKpour 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; };
  • Pour API plus de détails, voir GetImageFramela section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserGetImageSet.

SDKpour JavaScript (v3)
import { GetImageSetCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; /** * @param {string} datastoreId - The ID of the data store. * @param {string} imageSetId - The ID of the image set. * @param {string} imageSetVersion - The optional version of the image set. * */ export const getImageSet = async ( datastoreId = "xxxxxxxxxxxxxxx", imageSetId = "xxxxxxxxxxxxxxx", imageSetVersion = "" ) => { let params = { datastoreId: datastoreId, imageSetId: imageSetId }; if (imageSetVersion !== "") { params.imageSetVersion = imageSetVersion; } const response = await medicalImagingClient.send( new GetImageSetCommand(params) ); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '0615c161-410d-4d06-9d8c-6e1241bb0a5a', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // createdAt: 2023-09-22T14:49:26.427Z, // datastoreId: 'xxxxxxxxxxxxxxx', // imageSetArn: 'arn:aws:medical-imaging:us-east-1:xxxxxxxxxx:datastore/xxxxxxxxxxxxxxxxxxxx/imageset/xxxxxxxxxxxxxxxxxxxx', // imageSetId: 'xxxxxxxxxxxxxxx', // imageSetState: 'ACTIVE', // imageSetWorkflowStatus: 'CREATED', // updatedAt: 2023-09-22T14:49:26.427Z, // versionId: '1' // } return response; };
  • Pour API plus de détails, voir GetImageSetla section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserGetImageSetMetadata.

SDKpour JavaScript (v3)

Fonction utilitaire pour obtenir les métadonnées d'un ensemble d'images.

import { GetImageSetMetadataCommand } from "@aws-sdk/client-medical-imaging"; import { medicalImagingClient } from "../libs/medicalImagingClient.js"; import { writeFileSync } from "fs"; /** * @param {string} metadataFileName - The name of the file for the gzipped metadata. * @param {string} datastoreId - The ID of the data store. * @param {string} imagesetId - The ID of the image set. * @param {string} versionID - The optional version ID of the image set. */ export const getImageSetMetadata = async ( metadataFileName = "metadata.json.gzip", datastoreId = "xxxxxxxxxxxxxx", imagesetId = "xxxxxxxxxxxxxx", versionID = "" ) => { const params = { datastoreId: datastoreId, imageSetId: imagesetId }; if (versionID) { params.versionID = versionID; } const response = await medicalImagingClient.send( new GetImageSetMetadataCommand(params) ); const buffer = await response.imageSetMetadataBlob.transformToByteArray(); writeFileSync(metadataFileName, buffer); console.log(response); // { // '$metadata': { // httpStatusCode: 200, // requestId: '5219b274-30ff-4986-8cab-48753de3a599', // extendedRequestId: undefined, // cfId: undefined, // attempts: 1, // totalRetryDelay: 0 // }, // contentType: 'application/json', // contentEncoding: 'gzip', // imageSetMetadataBlob: <ref *1> IncomingMessage {} // } return response; };

Obtenez les métadonnées des ensembles d'images sans version.

try { await getImageSetMetadata( "metadata.json.gzip", "12345678901234567890123456789012", "12345678901234567890123456789012" ); } catch (err) { console.log("Error", err); }

Obtenez les métadonnées des ensembles d'images avec la version.

try { await getImageSetMetadata( "metadata2.json.gzip", "12345678901234567890123456789012", "12345678901234567890123456789012", "1" ); } catch (err) { console.log("Error", err); }
  • Pour API plus de détails, voir GetImageSetMetadatala section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserListDICOMImportJobs.

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

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserListDatastores.

SDKpour 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; };
  • Pour API plus de détails, voir ListDatastoresla section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserListImageSetVersions.

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

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserListTagsForResource.

SDKpour 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; };
  • Pour API plus de détails, voir ListTagsForResourcela section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserSearchImageSets.

SDKpour JavaScript (v3)

Fonction utilitaire permettant de rechercher des ensembles d'images.

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; };

Cas d'utilisation #1 : EQUAL opérateur.

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

Cas d'utilisation #2 : BETWEEN opérateur utilisant DICOMStudyDate etDICOMStudyTime.

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

Cas d'utilisation #3 : utilisation par l'BETWEENopérateurcreatedAt. Les études temporelles étaient auparavant poursuivies.

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

Cas d'utilisation #4 : EQUAL opérateur BETWEEN activé DICOMSeriesInstanceUID updatedAt et réponse triée par ASC ordre sur le updatedAt terrain.

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); }
  • Pour API plus de détails, voir SearchImageSetsla section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserStartDICOMImportJob.

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

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserTagResource.

SDKpour 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; };
  • Pour API plus de détails, voir TagResourcela section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserUntagResource.

SDKpour 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; };
  • Pour API plus de détails, voir UntagResourcela section AWS SDK for JavaScript APIRéférence.

Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment utiliserUpdateImageSetMetadata.

SDKpour 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); } };

Cas d'utilisation #1 : Insérer ou mettre à jour un attribut et forcer la mise à jour.

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

Cas d'utilisation #2 : Supprimer un attribut.

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

Cas d'utilisation #3 : Supprimer une instance.

const remove_instance = JSON.stringify({ "SchemaVersion": 1.1, "Study": { "Series": { "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": { "Instances": { "1.1.1.1.1.1.12345.123456789012.123.12345678901234.1": {} } } } } }); const updateMetadata = { "DICOMUpdates": { "removableAttributes": new TextEncoder().encode(remove_instance) } }; await updateImageSetMetadata(datastoreID, imageSetID, versionID, updateMetadata);

Cas d'utilisation #4 : Revenir à une version antérieure.

const updateMetadata = { "revertToVersionId": "1" }; await updateImageSetMetadata(datastoreID, imageSetID, versionID, updateMetadata);
Note

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

Scénarios

L'exemple de code suivant montre comment importer des DICOM fichiers et télécharger des cadres d'image dans HealthImaging.

L'implémentation est structurée comme une application de ligne de commande de flux de travail.

  • Configurez les ressources pour une DICOM importation.

  • Importez DICOM des fichiers dans un magasin de données.

  • Récupérez l'ensemble d'images IDs pour la tâche d'importation.

  • Récupérez le cadre d'image IDs pour les ensembles d'images.

  • Téléchargez, décodez et vérifiez les cadres d'image.

  • Nettoyez les ressources.

SDKpour JavaScript (v3)

index.js- Orchestrez les étapes.

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 "url"; if (process.argv[1] === fileURLToPath(import.meta.url)) { parseScenarioArgs(scenarios); }

deploy-steps.js- Déployez des ressources.

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- Copiez DICOM des fichiers.

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- Lancez l'importation dans la banque de données.

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- Obtenez un ensemble d'imagesIDs.

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

image-frame-steps.js- Obtenez un cadre d'imageIDs.

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

verify-steps.js- Vérifiez les cadres d'image. La bibliothèque AWS HealthImaging Pixel Data Verification a été utilisée pour la vérification.

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- Détruisez des ressources.

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

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment étiqueter un magasin de HealthImaging données.

SDKpour JavaScript (v3)

Pour étiqueter un magasin de données.

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

Fonction utilitaire permettant de baliser une ressource.

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; };

Pour répertorier les balises d'un magasin de données.

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

Fonction utilitaire permettant de répertorier les balises d'une ressource.

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; };

Pour supprimer le balisage d'un magasin de données.

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

Fonction utilitaire permettant de détaguer une ressource.

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

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.

L'exemple de code suivant montre comment baliser un ensemble HealthImaging d'images.

SDKpour JavaScript (v3)

Pour baliser un ensemble d'images.

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

Fonction utilitaire permettant de baliser une ressource.

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; };

Pour répertorier les balises d'un ensemble d'images.

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

Fonction utilitaire permettant de répertorier les balises d'une ressource.

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; };

Pour annuler le balisage d'un ensemble d'images.

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

Fonction utilitaire permettant de détaguer une ressource.

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

Il y en a plus à ce sujet GitHub. Trouvez l’exemple complet et découvrez comment le configurer et l’exécuter dans le référentiel d’exemples de code AWS.