Move ohif:metadata into ohif:core

This commit is contained in:
Erik Ziegler committed 2018-12-12 09:11:00 +01:00
1 parent 700fff763c
commit da36c33c70
8 files changed
+22 -72

No files matched your search

@@ -0,0 +1,119 @@
import { Viewerbase } from 'meteor/ohif:viewerbase';
const InstanceMetadata = Viewerbase.metadata.InstanceMetadata;
const DICOMTagDescriptions = Viewerbase.DICOMTagDescriptions;
export class OHIFInstanceMetadata extends InstanceMetadata {
/**
* @param {Object} Instance object.
*/
constructor(data, series, study, uid) {
super(data, uid);
this.init(series, study);
}
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
getTagValue(tagOrProperty, defaultValue, bypassCache) {
// check if this property has been cached...
if (tagOrProperty in this._cache && bypassCache !== true) {
return this._cache[tagOrProperty];
}
const propertyName = OHIFInstanceMetadata.getPropertyName(tagOrProperty);
// 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...
this._cache[tagOrProperty] = rawValue;
return rawValue;
}
return defaultValue;
}
// Override
tagExists(tagOrProperty) {
const propertyName = OHIFInstanceMetadata.getPropertyName(tagOrProperty);
return (propertyName in this._instance || propertyName in this._series || propertyName in this._study);
}
// Override
getImageId(frame, thumbnail) {
// If _imageID is not cached, create it
if (this._imageId === null) {
this._imageId = Viewerbase.getImageId(this.getData(), frame, thumbnail);
}
return this._imageId;
}
/**
* Static methods
*/
// @TODO: The current mapping of standard DICOM property names to local property names is not optimal.
// The inconsistency in property naming makes this function increasingly complex.
// A possible solution to improve this would be adapt retriveMetadata names to use DICOM standard names as in dicomTagDescriptions.js
static getPropertyName(tagOrProperty) {
let propertyName;
const tagInfo = DICOMTagDescriptions.find(tagOrProperty);
if (tagInfo !== void 0) {
// This function tries to translate standard DICOM property names into local naming convention.
propertyName = tagInfo.keyword.replace(/^SOP/, 'sop').replace(/UID$/, 'Uid').replace(/ID$/, 'Id');
propertyName = propertyName.charAt(0).toLowerCase() + propertyName.substr(1);
}
return propertyName;
}
}
@@ -0,0 +1,32 @@
import { Viewerbase } from 'meteor/ohif:viewerbase';
import { OHIFInstanceMetadata } from './OHIFInstanceMetadata';
export class OHIFSeriesMetadata extends Viewerbase.metadata.SeriesMetadata {
/**
* @param {Object} Series object.
*/
constructor(data, study, uid) {
super(data, uid);
this.init(study);
}
init(study) {
const series = this.getData();
// define "_seriesInstanceUID" protected property...
Object.defineProperty(this, '_seriesInstanceUID', {
configurable: false,
enumerable: false,
writable: false,
value: series.seriesInstanceUid
});
// populate internal list of instances...
series.instances.forEach(instance => {
this.addInstance(new OHIFInstanceMetadata(instance, series, study));
});
}
}
@@ -0,0 +1,31 @@
import { Viewerbase } from 'meteor/ohif:viewerbase';
import { OHIFSeriesMetadata } from './OHIFSeriesMetadata';
export class OHIFStudyMetadata extends Viewerbase.metadata.StudyMetadata {
/**
* @param {Object} Study object.
*/
constructor(data, uid) {
super(data, uid);
this.init();
}
init() {
const study = this.getData();
// define "_studyInstanceUID" protected property
Object.defineProperty(this, '_studyInstanceUID', {
configurable: false,
enumerable: false,
writable: false,
value: study.studyInstanceUid
});
// populate internal list of series
study.seriesList.forEach(series => {
this.addSeries(new OHIFSeriesMetadata(series, study));
});
}
}
@@ -0,0 +1,11 @@
import { OHIFStudyMetadata } from './OHIFStudyMetadata';
import { OHIFSeriesMetadata } from './OHIFSeriesMetadata';
import { OHIFInstanceMetadata } from './OHIFInstanceMetadata';
const metadata = {
OHIFStudyMetadata,
OHIFSeriesMetadata,
OHIFInstanceMetadata
}
export default metadata;