diff --git a/Packages/ohif-hanging-protocols/client/protocolEngine.js b/Packages/ohif-hanging-protocols/client/protocolEngine.js index 0498e5938..a76d69605 100644 --- a/Packages/ohif-hanging-protocols/client/protocolEngine.js +++ b/Packages/ohif-hanging-protocols/client/protocolEngine.js @@ -308,10 +308,11 @@ HP.ProtocolEngine = class ProtocolEngine { * @returns {any|*} The number of available prior studies with the same patientId */ getNumberOfAvailablePriors(study) { - var studies = StudyListStudies.find({ - patientId: study.patientId, + const instance = study.getFirstInstance(); + const studies = StudyListStudies.find({ + patientId: instance.getRawValue('x00100020'), // PatientID, studyDate: { - $lt: study.studyDate + $lt: instance.getRawValue('x00080020') // StudyDate } }); diff --git a/Packages/ohif-metadata/client/OHIFInstanceMetadata.js b/Packages/ohif-metadata/client/OHIFInstanceMetadata.js index 27f8d83ef..08578ee7b 100644 --- a/Packages/ohif-metadata/client/OHIFInstanceMetadata.js +++ b/Packages/ohif-metadata/client/OHIFInstanceMetadata.js @@ -7,16 +7,47 @@ export class OHIFInstanceMetadata extends InstanceMetadata { /** * @param {Object} Instance object. */ - constructor(data) { + constructor(data, series, study) { super(data); - this._cache = Object.create(null); // Object with null prototype for fast and safe lookups... - this.init(); + this.init(series, study); } - init() { - const data = this.getData(); - // set protected property... - this._sopInstanceUID = data.sopInstanceUid; + init(series, study) { + const instance = this.getData(); + + // Initialize Private Properties + Object.defineProperties(this, { + _sopInstanceUID: { + configurable: false, + enumerable: false, + writable: false, + value: instance.sopInstanceUid + }, + _study: { + configurable: false, + enumerable: false, + writable: false, + value: study + }, + _series: { + configurable: false, + enumerable: false, + writable: false, + value: series + }, + _instance: { + configurable: false, + enumerable: false, + writable: false, + value: instance + }, + _cache: { + configurable: false, + enumerable: false, + writable: false, + value: Object.create(null) + } + }); } // Override @@ -28,8 +59,16 @@ export class OHIFInstanceMetadata extends InstanceMetadata { } const propertyName = OHIFInstanceMetadata.getPropertyName(tagOrProperty); - const data = this.getData(); - const rawValue = data[propertyName]; + + // Search property value in the whole study metadata chain... + let rawValue; + if (propertyName in this._instance) { + rawValue = this._instance[propertyName]; + } else if (propertyName in this._series) { + rawValue = this._series[propertyName]; + } else if (propertyName in this._study) { + rawValue = this._study[propertyName]; + } if (rawValue !== void 0) { // if rawValue value is not undefined, cache result... @@ -44,9 +83,7 @@ export class OHIFInstanceMetadata extends InstanceMetadata { tagExists(tagOrProperty) { const propertyName = OHIFInstanceMetadata.getPropertyName(tagOrProperty); - const data = this.getData(); - - return (propertyName in data); + return (propertyName in this._instance || propertyName in this._series || propertyName in this._study); } // Override @@ -72,7 +109,7 @@ export class OHIFInstanceMetadata extends InstanceMetadata { if (tagInfo.propertyName !== null) { // This function tries to translate standard DICOM property names into local naming convention. - propertyName = tagInfo.propertyName.replace(/^SOP/, 'sop').replace(/UID$/, 'Uid'); + propertyName = tagInfo.propertyName.replace(/^SOP/, 'sop').replace(/UID$/, 'Uid').replace(/ID$/, 'Id'); propertyName = propertyName.charAt(0).toLowerCase() + propertyName.substr(1); } diff --git a/Packages/ohif-metadata/client/OHIFSeriesMetadata.js b/Packages/ohif-metadata/client/OHIFSeriesMetadata.js index 81f322a0e..1b4de4bab 100644 --- a/Packages/ohif-metadata/client/OHIFSeriesMetadata.js +++ b/Packages/ohif-metadata/client/OHIFSeriesMetadata.js @@ -6,19 +6,25 @@ export class OHIFSeriesMetadata extends Viewerbase.metadata.SeriesMetadata { /** * @param {Object} Series object. */ - constructor(data) { + constructor(data, study) { super(data); - this.init(); + this.init(study); } - init() { - const data = this.getData(); + init(study) { + const series = this.getData(); + + // define "_seriesInstanceUID" protected property... + Object.defineProperty(this, '_seriesInstanceUID', { + configurable: false, + enumerable: false, + writable: false, + value: series.seriesInstanceUid + }); - // set protected property... - this._seriesInstanceUID = data.seriesInstanceUid; // populate internal list of instances... - data.instances.forEach(instance => { - this.addInstance(new OHIFInstanceMetadata(instance)); + series.instances.forEach(instance => { + this.addInstance(new OHIFInstanceMetadata(instance, series, study)); }); } diff --git a/Packages/ohif-metadata/client/OHIFStudyMetadata.js b/Packages/ohif-metadata/client/OHIFStudyMetadata.js index 8899e6914..1bd1ce2a8 100644 --- a/Packages/ohif-metadata/client/OHIFStudyMetadata.js +++ b/Packages/ohif-metadata/client/OHIFStudyMetadata.js @@ -12,13 +12,19 @@ export class OHIFStudyMetadata extends Viewerbase.metadata.StudyMetadata { } init() { - const data = this.getData(); + const study = this.getData(); + + // define "_studyInstanceUID" protected property... + Object.defineProperty(this, '_studyInstanceUID', { + configurable: false, + enumerable: false, + writable: false, + value: study.studyInstanceUid + }); - // set protected property... - this._studyInstanceUID = data.studyInstanceUid; // populate internal list of series... - data.seriesList.forEach(series => { - this.addSeries(new OHIFSeriesMetadata(series)); + study.seriesList.forEach(series => { + this.addSeries(new OHIFSeriesMetadata(series, study)); }); } diff --git a/Packages/ohif-viewerbase/client/lib/classes/metadata/InstanceMetadata.js b/Packages/ohif-viewerbase/client/lib/classes/metadata/InstanceMetadata.js index 5076526a7..86e270d52 100644 --- a/Packages/ohif-viewerbase/client/lib/classes/metadata/InstanceMetadata.js +++ b/Packages/ohif-viewerbase/client/lib/classes/metadata/InstanceMetadata.js @@ -11,8 +11,21 @@ export class InstanceMetadata extends Metadata { constructor(data) { super(data); - this._sopInstanceUID = null; - this._imageId = null; + // Initialize Private Properties + Object.defineProperties(this, { + _sopInstanceUID: { + configurable: true, // configurable so that it can be redefined in sub-classes... + enumerable: false, + writable: true, + value: null + }, + _imageId: { + configurable: true, // configurable so that it can be redefined in sub-classes... + enumerable: false, + writable: true, + value: null + } + }); // Initialize Public Properties this._definePublicProperties(); } diff --git a/Packages/ohif-viewerbase/client/lib/classes/metadata/Metadata.js b/Packages/ohif-viewerbase/client/lib/classes/metadata/Metadata.js index 0be4a707e..8cac78f4d 100644 --- a/Packages/ohif-viewerbase/client/lib/classes/metadata/Metadata.js +++ b/Packages/ohif-viewerbase/client/lib/classes/metadata/Metadata.js @@ -6,6 +6,7 @@ const STRING = 'string'; const NUMBER = 'number'; const FUNCTION = 'function'; +const OBJECT = 'object'; export class Metadata { @@ -14,7 +15,14 @@ export class Metadata { */ constructor(data) { - this._data = data; + // Define the main "_data" private property as an immutable property. + // IMPORTANT: This property can only be set during instance construction. + Object.defineProperty(this, '_data', { + configurable: false, + enumerable: false, + writable: false, + value: data + }); } getData() { @@ -24,7 +32,7 @@ export class Metadata { getDataProperty(propertyName) { let propertyValue; const _data = this._data; - if (_data instanceof Object || typeof _data === 'object' && _data !== null) { + if (_data instanceof Object || typeof _data === OBJECT && _data !== null) { propertyValue = _data[propertyName]; } return propertyValue; diff --git a/Packages/ohif-viewerbase/client/lib/classes/metadata/SeriesMetadata.js b/Packages/ohif-viewerbase/client/lib/classes/metadata/SeriesMetadata.js index 453a5ef78..d2f561a10 100644 --- a/Packages/ohif-viewerbase/client/lib/classes/metadata/SeriesMetadata.js +++ b/Packages/ohif-viewerbase/client/lib/classes/metadata/SeriesMetadata.js @@ -5,8 +5,21 @@ export class SeriesMetadata extends Metadata { constructor(data) { super(data); - this._seriesInstanceUID = null; - this._instances = []; // InstanceMetadata[] + // Initialize Private Properties + Object.defineProperties(this, { + _seriesInstanceUID: { + configurable: true, // configurable so that it can be redefined in sub-classes... + enumerable: false, + writable: true, + value: null + }, + _instances: { + configurable: false, + enumerable: false, + writable: false, + value: [] + } + }); // Initialize Public Properties this._definePublicProperties(); } diff --git a/Packages/ohif-viewerbase/client/lib/classes/metadata/StudyMetadata.js b/Packages/ohif-viewerbase/client/lib/classes/metadata/StudyMetadata.js index 5bee98df7..3726921cd 100644 --- a/Packages/ohif-viewerbase/client/lib/classes/metadata/StudyMetadata.js +++ b/Packages/ohif-viewerbase/client/lib/classes/metadata/StudyMetadata.js @@ -6,9 +6,27 @@ export class StudyMetadata extends Metadata { constructor(data) { super(data); - this._studyInstanceUID = null; - this._series = []; // SeriesMetadata[] - this._displaySets = []; + // Initialize Private Properties + Object.defineProperties(this, { + __studyInstanceUID: { + configurable: true, // configurable so that it can be redefined in sub-classes... + enumerable: false, + writable: true, + value: null + }, + _series: { + configurable: false, + enumerable: false, + writable: false, + value: [] + }, + _displaySets: { + configurable: false, + enumerable: false, + writable: false, + value: [] + } + }); // Initialize Public Properties this._definePublicProperties(); }