From 4c84961d4c34fc3d5372c5c8409ededafbd9f374 Mon Sep 17 00:00:00 2001 From: "Emanuel F. Oliveira" Date: Tue, 7 Feb 2017 20:40:54 -0200 Subject: [PATCH] Fixed displaySet search inside protocolEngine --- .../client/protocolEngine.js | 12 ++------ .../client/lib/classes/ImageSet.js | 29 +++++++++++++++---- .../lib/classes/metadata/StudyMetadata.js | 15 ++++++++++ 3 files changed, 42 insertions(+), 14 deletions(-) diff --git a/Packages/ohif-hanging-protocols/client/protocolEngine.js b/Packages/ohif-hanging-protocols/client/protocolEngine.js index bafeff517..0498e5938 100644 --- a/Packages/ohif-hanging-protocols/client/protocolEngine.js +++ b/Packages/ohif-hanging-protocols/client/protocolEngine.js @@ -500,19 +500,13 @@ HP.ProtocolEngine = class ProtocolEngine { } }; - // Filter imageSet function: filter by InstanceUid - const filterImageSetFn = (imageSet, sopInstanceUid) => { - // @TODO: remove getData() here - const found = imageSet.getData().sopInstanceUid === instance.sopInstanceUid; - return found; - }; - // Find the displaySet - const displaySet = study.getDisplaySets().find(ds => ds.images.filter(imageSet => filterImageSetFn)); + const currentSOPInstanceUID = instance.getSOPInstanceUID(); + const displaySet = study.findDisplaySet(displaySet => displaySet.images.find(image => image.getSOPInstanceUID() === currentSOPInstanceUID)); // If the instance was found, set the displaySet ID if (displaySet) { - imageDetails.displaySetInstanceUid = displaySet.displaySetInstanceUid; + imageDetails.displaySetInstanceUid = displaySet.getUID(); imageDetails.imageId = instance.getImageId(); } diff --git a/Packages/ohif-viewerbase/client/lib/classes/ImageSet.js b/Packages/ohif-viewerbase/client/lib/classes/ImageSet.js index 86cab9da8..75d98f1be 100644 --- a/Packages/ohif-viewerbase/client/lib/classes/ImageSet.js +++ b/Packages/ohif-viewerbase/client/lib/classes/ImageSet.js @@ -1,4 +1,7 @@ import { Random } from 'meteor/random'; +import { OHIFError } from './OHIFError'; + +const OBJECT = 'object'; /** * This class defines an ImageSet object which will be used across the viewer. This object represents @@ -11,13 +14,29 @@ export class ImageSet { constructor(images) { if (Array.isArray(images) !== true) { - throw new TypeError('ImageSet expects an array of images...'); + throw new OHIFError('ImageSet expects an array of images...'); } - // Main ImageSet attributes - this.images = images; // Array of images - this.uid = Random.id(); // Unique ID of the instance + // @property "images" + Object.defineProperty(this, 'images', { + enumerable: false, + configurable: false, + writable: false, + value: images + }); + // @property "uid" + Object.defineProperty(this, 'uid', { + enumerable: false, + configurable: false, + writable: false, + value: Random.id() // Unique ID of the instance + }); + + } + + getUID() { + return this.uid; } setAttribute(attribute, value) { @@ -29,7 +48,7 @@ export class ImageSet { } setAttributes(attributes) { - if (typeof attributes === 'object' && attributes !== null) { + if (typeof attributes === OBJECT && attributes !== null) { const imageSet = this, hasOwn = Object.prototype.hasOwnProperty; for (let attribute in attributes) { if (hasOwn.call(attributes, attribute)) { diff --git a/Packages/ohif-viewerbase/client/lib/classes/metadata/StudyMetadata.js b/Packages/ohif-viewerbase/client/lib/classes/metadata/StudyMetadata.js index 460d65d63..5bee98df7 100644 --- a/Packages/ohif-viewerbase/client/lib/classes/metadata/StudyMetadata.js +++ b/Packages/ohif-viewerbase/client/lib/classes/metadata/StudyMetadata.js @@ -89,6 +89,21 @@ export class StudyMetadata extends Metadata { } } + /** + * Search the associated display sets using the supplied callback as criteria. The callback is passed + * two arguments: display set (a ImageSet instance) and index (the integer + * index of the display set within the current study) + * @param {function} callback The callback function which will be invoked for each display set instance. + * @returns {undefined} Nothing is returned. + */ + findDisplaySet(callback) { + if (Metadata.isValidCallback(callback)) { + return this._displaySets.find((displaySet, index) => { + return callback.call(null, displaySet, index); + }); + } + } + /** * Returns the StudyInstanceUID of the current study. */