Fixed displaySet search inside protocolEngine

This commit is contained in:
Emanuel F. Oliveira 2017-02-07 20:40:54 -02:00 committed by Eloízio Salgado
parent f96a37e1bc
commit 4c84961d4c
3 changed files with 42 additions and 14 deletions

View File

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

View File

@ -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)) {

View File

@ -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.
*/