WIP DisplaySetService
This commit is contained in:
1 parent
649216fde4
commit
7a8418f64b
29 files changed
+460
-541
No files matched your search
@@ -1,8 +1,7 @@
|
||||
export default class toolBarManager {
|
||||
constructor(extensionManager, setToolBarLayout) {
|
||||
constructor(extensionManager) {
|
||||
this.buttons = {};
|
||||
this.extensionManager = extensionManager;
|
||||
this.viewModelContextSetToolBarLayout = setToolBarLayout;
|
||||
}
|
||||
|
||||
addButtons(buttons) {
|
||||
@@ -42,6 +41,6 @@ export default class toolBarManager {
|
||||
toolBarLayout.push(toolBarDefinitions);
|
||||
});
|
||||
|
||||
this.viewModelContextSetToolBarLayout(toolBarLayout);
|
||||
// TODO -> Change this to a service. => emit an event to subscribers to update the toolbar layout.
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@ import {
|
||||
addInstancesToStudy,
|
||||
} from './studies/services/wado/studyInstanceHelpers';
|
||||
|
||||
import displaySetManager from './displaySetManager';
|
||||
|
||||
class StudyMetadata {
|
||||
constructor(StudyInstanceUID) {
|
||||
this.StudyInstanceUID = StudyInstanceUID;
|
||||
|
||||
@@ -1,95 +0,0 @@
|
||||
class DisplaySetManager {
|
||||
constructor() {
|
||||
this.displaySets = [];
|
||||
}
|
||||
|
||||
init(extensionManager, SOPClassHandlerIds, viewModelContext) {
|
||||
this.extensionManager = extensionManager;
|
||||
this.SOPClassHandlerIds = SOPClassHandlerIds;
|
||||
|
||||
const {
|
||||
displaySetInstanceUIDs,
|
||||
setDisplaySetInstanceUIDs,
|
||||
} = viewModelContext;
|
||||
|
||||
this.displaySetInstanceUIDs = displaySetInstanceUIDs;
|
||||
this.setDisplaySetInstanceUids = setDisplaySetInstanceUIDs;
|
||||
|
||||
// Reset displaySetInstanceUIDs
|
||||
this.setDisplaySetInstanceUids([]);
|
||||
}
|
||||
|
||||
_addDisplaySets(displaySets) {
|
||||
//const displayInstanceUids = [...this.displaySetInstanceUIDs];
|
||||
|
||||
const addedDisplaySetUids = [];
|
||||
|
||||
displaySets.forEach(displaySet => {
|
||||
this.displaySets.push(displaySet);
|
||||
|
||||
addedDisplaySetUids.push(displaySet.displaySetInstanceUID);
|
||||
});
|
||||
|
||||
return addedDisplaySetUids;
|
||||
}
|
||||
|
||||
getDisplaySetsForSeries = SeriesInstanceUID => {
|
||||
return this.displaySets.filter(
|
||||
displaySet => displaySet.SeriesInstanceUID === SeriesInstanceUID
|
||||
);
|
||||
};
|
||||
|
||||
getDisplaySetByUID = displaySetInstanceUID => {
|
||||
return this.displaySets.find(
|
||||
displaySet => displaySet.displaySetInstanceUID === displaySetInstanceUID
|
||||
);
|
||||
};
|
||||
|
||||
makeDisplaySets = instances => {
|
||||
if (!instances || !instances.length) {
|
||||
throw new Error('No instances were provided.');
|
||||
}
|
||||
|
||||
const instance = instances[0];
|
||||
|
||||
const existingDisplaySets =
|
||||
this.getDisplaySetsForSeries(instance.SeriesInstanceUID) || [];
|
||||
|
||||
const SOPClassHandlerIds = this.SOPClassHandlerIds;
|
||||
|
||||
for (let i = 0; i < SOPClassHandlerIds.length; i++) {
|
||||
const SOPClassHandlerId = SOPClassHandlerIds[i];
|
||||
const handler = this.extensionManager.getModuleEntry(SOPClassHandlerId);
|
||||
|
||||
if (handler.sopClassUids.includes(instance.SOPClassUID)) {
|
||||
let addedDisplaySetUids;
|
||||
|
||||
// Check if displaySets are already created using this SeriesInstanceUID/SOPClassHandler pair.
|
||||
const cachedDisplaySets = existingDisplaySets.filter(
|
||||
displaySet => displaySet.SOPClassHandlerId === SOPClassHandlerId
|
||||
);
|
||||
|
||||
if (cachedDisplaySets.length) {
|
||||
addedDisplaySetUids = cachedDisplaySets.map(
|
||||
displaySet => displaySet.displaySetInstanceUID
|
||||
);
|
||||
} else {
|
||||
const displaySets = handler.getDisplaySetsFromSeries(instances);
|
||||
|
||||
addedDisplaySetUids = this._addDisplaySets(displaySets);
|
||||
}
|
||||
|
||||
this.displaySetInstanceUIDs = [
|
||||
...addedDisplaySetUids,
|
||||
...this.displaySetInstanceUIDs,
|
||||
];
|
||||
|
||||
this.setDisplaySetInstanceUids(this.displaySetInstanceUIDs);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
const displaySetManager = new DisplaySetManager();
|
||||
|
||||
export default displaySetManager;
|
||||
@@ -184,6 +184,7 @@ export default class ExtensionManager {
|
||||
appConfig: this._appConfig,
|
||||
configuration,
|
||||
api: this._api,
|
||||
extensionManager: this,
|
||||
});
|
||||
|
||||
if (!extensionModule) {
|
||||
|
||||
@@ -20,7 +20,6 @@ import studies from './studies/';
|
||||
import ui from './ui';
|
||||
import user from './user.js';
|
||||
import dicomMetadataStore from './dicomMetadataStore';
|
||||
import displaySetManager from './displaySetManager';
|
||||
import ToolBarManager from './ToolBarManager';
|
||||
import { ViewModelProvider, useViewModel } from './ViewModelContext';
|
||||
import {
|
||||
@@ -35,6 +34,7 @@ import {
|
||||
UIModalService,
|
||||
UINotificationService,
|
||||
UIViewportDialogService,
|
||||
DisplaySetService,
|
||||
} from './services';
|
||||
|
||||
import IWebApiDataSource from './DataSources/IWebApiDataSource';
|
||||
@@ -71,10 +71,11 @@ const OHIF = {
|
||||
UIModalService,
|
||||
UINotificationService,
|
||||
UIViewportDialogService,
|
||||
DisplaySetService,
|
||||
MeasurementService,
|
||||
IWebApiDataSource,
|
||||
dicomMetadataStore,
|
||||
displaySetManager,
|
||||
//
|
||||
ToolBarManager,
|
||||
ViewModelProvider,
|
||||
useViewModel,
|
||||
@@ -111,10 +112,10 @@ export {
|
||||
UIModalService,
|
||||
UINotificationService,
|
||||
UIViewportDialogService,
|
||||
DisplaySetService,
|
||||
MeasurementService,
|
||||
IWebApiDataSource,
|
||||
dicomMetadataStore,
|
||||
displaySetManager,
|
||||
ToolBarManager,
|
||||
ViewModelProvider,
|
||||
useViewModel,
|
||||
|
||||
@@ -0,0 +1,173 @@
|
||||
import guid from '../../utils/guid';
|
||||
|
||||
const EVENTS = {
|
||||
DISPLAY_SET_ADDED: 'event::displaySetService:displaySetAdded',
|
||||
};
|
||||
|
||||
const displaySetCache = [];
|
||||
|
||||
export default class DisplaySetService {
|
||||
constructor() {
|
||||
this.displaySets = {};
|
||||
this.EVENTS = EVENTS;
|
||||
this.listeners = {};
|
||||
}
|
||||
|
||||
init(extensionManager, SOPClassHandlerIds) {
|
||||
this.extensionManager = extensionManager;
|
||||
this.SOPClassHandlerIds = SOPClassHandlerIds;
|
||||
this.activeDisplaySets = {};
|
||||
}
|
||||
|
||||
/**
|
||||
* Subscribe to measurement updates.
|
||||
*
|
||||
* @param {string} eventName The name of the event
|
||||
* @param {Function} callback Events callback
|
||||
* @return {Object} Observable object with actions
|
||||
*/
|
||||
subscribe(eventName, callback) {
|
||||
debugger;
|
||||
if (this._isValidEvent(eventName)) {
|
||||
const listenerId = guid();
|
||||
const subscription = { id: listenerId, callback };
|
||||
|
||||
console.info(`displaySetService: Subscribing to '${eventName}'.`);
|
||||
if (Array.isArray(this.listeners[eventName])) {
|
||||
this.listeners[eventName].push(subscription);
|
||||
} else {
|
||||
this.listeners[eventName] = [subscription];
|
||||
}
|
||||
|
||||
return {
|
||||
unsubscribe: () => this._unsubscribe(eventName, listenerId),
|
||||
};
|
||||
} else {
|
||||
throw new Error(`Event ${eventName} not supported.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Unsubscribe to measurement updates.
|
||||
*
|
||||
* @param {string} eventName The name of the event
|
||||
* @param {string} listenerId The listeners id
|
||||
* @return void
|
||||
*/
|
||||
_unsubscribe(eventName, listenerId) {
|
||||
if (!this.listeners[eventName]) {
|
||||
return;
|
||||
}
|
||||
|
||||
const listeners = this.listeners[eventName];
|
||||
if (Array.isArray(listeners)) {
|
||||
this.listeners[eventName] = listeners.filter(
|
||||
({ id }) => id !== listenerId
|
||||
);
|
||||
} else {
|
||||
this.listeners[eventName] = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Broadcasts displaySetService changes.
|
||||
*
|
||||
* @param {string} eventName The event name
|
||||
* @return void
|
||||
*/
|
||||
_broadcastChange(eventName) {
|
||||
const hasListeners = Object.keys(this.listeners).length > 0;
|
||||
const hasCallbacks = Array.isArray(this.listeners[eventName]);
|
||||
|
||||
if (hasListeners && hasCallbacks) {
|
||||
this.listeners[eventName].forEach(listener => {
|
||||
listener.callback(this.activeDisplaySets);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a given displaySetService event is valid.
|
||||
*
|
||||
* @param {string} eventName The name of the event
|
||||
* @return {boolean} Event name validation
|
||||
*/
|
||||
_isValidEvent(eventName) {
|
||||
return Object.values(this.EVENTS).includes(eventName);
|
||||
}
|
||||
|
||||
_addDisplaySetsToCache(displaySets) {
|
||||
displaySets.forEach(displaySet => {
|
||||
displaySetCache.push(displaySet);
|
||||
});
|
||||
}
|
||||
|
||||
_addActiveDisplaySets(displaySets) {
|
||||
const activeDisplaySets = this.activeDisplaySets;
|
||||
|
||||
displaySets.forEach(displaySet => {
|
||||
const { StudyInstanceUID } = displaySet;
|
||||
|
||||
if (!Array.isArray(activeDisplaySets[StudyInstanceUID])) {
|
||||
activeDisplaySets[StudyInstanceUID] = [];
|
||||
}
|
||||
|
||||
activeDisplaySets[StudyInstanceUID].push(displaySet);
|
||||
});
|
||||
|
||||
console.log('DISPLAY_SET_ADDED');
|
||||
console.log(activeDisplaySets);
|
||||
|
||||
this._broadcastChange(EVENTS.DISPLAY_SET_ADDED);
|
||||
}
|
||||
|
||||
getActiveDisplaySets() {
|
||||
return this.activeDisplaySets;
|
||||
}
|
||||
|
||||
getDisplaySetsForSeries = SeriesInstanceUID => {
|
||||
return displaySetCache.filter(
|
||||
displaySet => displaySet.SeriesInstanceUID === SeriesInstanceUID
|
||||
);
|
||||
};
|
||||
|
||||
getDisplaySetByUID = displaySetInstanceUid => {
|
||||
return this.displaySets.find(
|
||||
displaySet => displaySet.displaySetInstanceUid === displaySetInstanceUid
|
||||
);
|
||||
};
|
||||
|
||||
makeDisplaySets = instances => {
|
||||
if (!instances || !instances.length) {
|
||||
throw new Error('No instances were provided.');
|
||||
}
|
||||
|
||||
const instance = instances[0];
|
||||
|
||||
const existingDisplaySets =
|
||||
this.getDisplaySetsForSeries(instance.SeriesInstanceUID) || [];
|
||||
|
||||
const SOPClassHandlerIds = this.SOPClassHandlerIds;
|
||||
|
||||
for (let i = 0; i < SOPClassHandlerIds.length; i++) {
|
||||
const SOPClassHandlerId = SOPClassHandlerIds[i];
|
||||
const handler = this.extensionManager.getModuleEntry(SOPClassHandlerId);
|
||||
|
||||
if (handler.sopClassUids.includes(instance.SOPClassUID)) {
|
||||
// Check if displaySets are already created using this SeriesInstanceUID/SOPClassHandler pair.
|
||||
const cachedDisplaySets = existingDisplaySets.filter(
|
||||
displaySet => displaySet.SOPClassHandlerId === SOPClassHandlerId
|
||||
);
|
||||
|
||||
if (cachedDisplaySets.length) {
|
||||
this._addActiveDisplaySets(cachedDisplaySets);
|
||||
} else {
|
||||
const newDisplaySets = handler.getDisplaySetsFromSeries(instances);
|
||||
|
||||
this._addDisplaySetsToCache(newDisplaySets);
|
||||
this._addActiveDisplaySets(newDisplaySets);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
import DisplaySetService from './DisplaySetService';
|
||||
|
||||
export default {
|
||||
name: 'DisplaySetService',
|
||||
create: ({ configuration = {} }) => {
|
||||
return new DisplaySetService();
|
||||
},
|
||||
};
|
||||
@@ -4,6 +4,7 @@ import UIDialogService from './UIDialogService';
|
||||
import UIModalService from './UIModalService';
|
||||
import UINotificationService from './UINotificationService';
|
||||
import UIViewportDialogService from './UIViewportDialogService';
|
||||
import DisplaySetService from './DisplaySetService';
|
||||
|
||||
export {
|
||||
MeasurementService,
|
||||
@@ -12,4 +13,5 @@ export {
|
||||
UIModalService,
|
||||
UINotificationService,
|
||||
UIViewportDialogService,
|
||||
DisplaySetService,
|
||||
};
|
||||
Reference in new issue
Block a user