2017-01-19 20:00:34 +01:00
|
|
|
import { Meteor } from 'meteor/meteor';
|
|
|
|
|
import { Session } from 'meteor/session';
|
|
|
|
|
import { Template } from 'meteor/templating';
|
|
|
|
|
import { ReactiveDict } from 'meteor/reactive-dict';
|
2017-02-07 20:44:42 +01:00
|
|
|
import { Tracker } from 'meteor/tracker'
|
2017-01-19 20:00:34 +01:00
|
|
|
|
2016-07-12 20:37:53 +02:00
|
|
|
import { OHIF } from 'meteor/ohif:core';
|
2017-01-24 17:35:56 +01:00
|
|
|
import 'meteor/ohif:cornerstone';
|
2017-01-16 22:29:49 +01:00
|
|
|
import 'meteor/ohif:viewerbase';
|
|
|
|
|
import 'meteor/ohif:metadata';
|
2016-07-23 15:56:36 +02:00
|
|
|
|
2017-02-07 20:44:42 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Inits OHIF Hanging Protocol's onReady.
|
|
|
|
|
* It waits for OHIF Hanging Protocol to be ready to instantiate the ProtocolEngine
|
|
|
|
|
* Hanging Protocol will use OHIF LayoutManager to render viewports properly
|
|
|
|
|
*/
|
|
|
|
|
const initHangingProtocol = () => {
|
|
|
|
|
// When Hanging Protocol is ready
|
|
|
|
|
HP.ProtocolStore.onReady(() => {
|
|
|
|
|
|
|
|
|
|
// Gets all StudyMetadata objects: necessary for Hanging Protocol to access study metadata
|
|
|
|
|
const studyMetadataList = OHIF.viewer.StudyMetadataList.all();
|
|
|
|
|
|
|
|
|
|
// Caches Layout Manager: Hanging Protocol uses it for layout management according to current protocol
|
|
|
|
|
const layoutManager = OHIF.viewerbase.layoutManager;
|
|
|
|
|
|
|
|
|
|
// Instantiate StudyMetadataSource: necessary for Hanging Protocol to get study metadata
|
2017-02-07 21:08:48 +01:00
|
|
|
const studyMetadataSource = new StudyList.classes.OHIFStudyMetadataSource();
|
2017-02-07 20:44:42 +01:00
|
|
|
|
2017-02-10 15:54:22 +01:00
|
|
|
// Get prior studies map
|
|
|
|
|
const studyPriorsMap = StudyList.functions.getStudyPriorsMap(studyMetadataList);
|
|
|
|
|
|
2017-02-07 20:44:42 +01:00
|
|
|
// Creates Protocol Engine object with required arguments
|
2017-02-10 15:54:22 +01:00
|
|
|
const ProtocolEngine = new HP.ProtocolEngine(layoutManager, studyMetadataList, studyPriorsMap, studyMetadataSource);
|
2017-02-07 20:44:42 +01:00
|
|
|
|
|
|
|
|
// Sets up Hanging Protocol engine
|
|
|
|
|
HP.setEngine(ProtocolEngine);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2017-01-19 20:00:34 +01:00
|
|
|
Meteor.startup(() => {
|
|
|
|
|
Session.setDefault('activeViewport', false);
|
|
|
|
|
Session.setDefault('leftSidebar', false);
|
|
|
|
|
Session.setDefault('rightSidebar', false);
|
|
|
|
|
|
|
|
|
|
OHIF.viewer = OHIF.viewer || {};
|
|
|
|
|
OHIF.viewer.defaultTool = 'wwwc';
|
|
|
|
|
OHIF.viewer.refLinesEnabled = true;
|
|
|
|
|
OHIF.viewer.cine = {
|
|
|
|
|
framesPerSecond: 24,
|
|
|
|
|
loop: true
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const viewportUtils = OHIF.viewerbase.viewportUtils;
|
|
|
|
|
|
|
|
|
|
OHIF.viewer.functionList = {
|
|
|
|
|
toggleCineDialog: viewportUtils.toggleCineDialog,
|
|
|
|
|
toggleCinePlay: viewportUtils.toggleCinePlay,
|
|
|
|
|
clearTools: viewportUtils.clearTools,
|
|
|
|
|
resetViewport: viewportUtils.resetViewport,
|
|
|
|
|
invert: viewportUtils.invert
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
OHIF.viewer.stackImagePositionOffsetSynchronizer = new OHIF.viewerbase.StackImagePositionOffsetSynchronizer();
|
2017-02-22 12:00:00 +01:00
|
|
|
|
2017-01-24 17:35:56 +01:00
|
|
|
// Create the synchronizer used to update reference lines
|
|
|
|
|
OHIF.viewer.updateImageSynchronizer = new cornerstoneTools.Synchronizer('CornerstoneNewImage', cornerstoneTools.updateImageSynchronizer);
|
|
|
|
|
|
|
|
|
|
OHIF.viewer.metadataProvider = OHIF.cornerstone.metadataProvider;
|
|
|
|
|
|
|
|
|
|
// Metadata configuration
|
|
|
|
|
const metadataProvider = OHIF.viewer.metadataProvider;
|
|
|
|
|
cornerstoneTools.metaData.addProvider(metadataProvider.provider.bind(metadataProvider));
|
2017-01-19 20:00:34 +01:00
|
|
|
});
|
|
|
|
|
|
2016-07-22 14:26:29 +02:00
|
|
|
|
|
|
|
|
Template.viewer.onCreated(() => {
|
|
|
|
|
const instance = Template.instance();
|
|
|
|
|
|
|
|
|
|
instance.data.state = new ReactiveDict();
|
|
|
|
|
instance.data.state.set('leftSidebar', Session.get('leftSidebar'));
|
|
|
|
|
instance.data.state.set('rightSidebar', Session.get('rightSidebar'));
|
2016-05-07 08:58:46 +02:00
|
|
|
|
2016-07-22 14:26:29 +02:00
|
|
|
const contentId = instance.data.contentId;
|
2016-07-12 20:37:53 +02:00
|
|
|
|
2016-07-23 20:11:01 +02:00
|
|
|
if (ViewerData[contentId] && ViewerData[contentId].loadedSeriesData) {
|
2016-09-20 22:47:44 +02:00
|
|
|
OHIF.log.info('Reloading previous loadedSeriesData');
|
2015-10-30 12:21:59 +01:00
|
|
|
OHIF.viewer.loadedSeriesData = ViewerData[contentId].loadedSeriesData;
|
2015-10-23 14:08:51 +02:00
|
|
|
} else {
|
2016-09-20 22:47:44 +02:00
|
|
|
OHIF.log.info('Setting default ViewerData');
|
2015-10-30 12:21:59 +01:00
|
|
|
OHIF.viewer.loadedSeriesData = {};
|
2016-07-23 20:11:01 +02:00
|
|
|
ViewerData[contentId] = {};
|
2015-10-30 12:21:59 +01:00
|
|
|
ViewerData[contentId].loadedSeriesData = OHIF.viewer.loadedSeriesData;
|
|
|
|
|
|
|
|
|
|
// Update the viewer data object
|
|
|
|
|
ViewerData[contentId].viewportColumns = 1;
|
|
|
|
|
ViewerData[contentId].viewportRows = 1;
|
|
|
|
|
ViewerData[contentId].activeViewport = 0;
|
2015-10-23 14:08:51 +02:00
|
|
|
}
|
|
|
|
|
|
2015-10-30 12:21:59 +01:00
|
|
|
Session.set('activeViewport', ViewerData[contentId].activeViewport || 0);
|
|
|
|
|
|
2017-01-17 20:32:42 +01:00
|
|
|
// @TypeSafeStudies
|
2017-02-07 23:09:02 +01:00
|
|
|
// Clears OHIF.viewer.Studies collection
|
2017-01-17 20:32:42 +01:00
|
|
|
OHIF.viewer.Studies.removeAll();
|
2016-07-12 20:37:53 +02:00
|
|
|
|
2017-02-07 23:09:02 +01:00
|
|
|
// @TypeSafeStudies
|
|
|
|
|
// Clears OHIF.viewer.StudyMetadataList collection
|
|
|
|
|
OHIF.viewer.StudyMetadataList.removeAll();
|
|
|
|
|
|
2016-08-04 10:42:34 +02:00
|
|
|
ViewerData[contentId].studyInstanceUids = [];
|
2016-07-22 14:26:29 +02:00
|
|
|
instance.data.studies.forEach(study => {
|
2017-02-07 21:47:39 +01:00
|
|
|
const studyMetadata = new OHIF.metadata.StudyMetadata(study);
|
|
|
|
|
const displaySets = OHIF.viewerbase.sortingManager.getDisplaySets(studyMetadata);
|
|
|
|
|
|
|
|
|
|
studyMetadata.setDisplaySets(displaySets);
|
|
|
|
|
|
2015-11-17 18:17:51 +01:00
|
|
|
study.selected = true;
|
2017-02-07 21:47:39 +01:00
|
|
|
study.displaySets = displaySets;
|
2017-01-17 20:32:42 +01:00
|
|
|
OHIF.viewer.Studies.insert(study);
|
2017-02-07 20:44:42 +01:00
|
|
|
OHIF.viewer.StudyMetadataList.insert(studyMetadata);
|
2016-08-04 10:42:34 +02:00
|
|
|
ViewerData[contentId].studyInstanceUids.push(study.studyInstanceUid);
|
2015-11-17 18:17:51 +01:00
|
|
|
});
|
2016-08-04 10:42:34 +02:00
|
|
|
|
|
|
|
|
Session.set('ViewerData', ViewerData);
|
2015-10-23 14:08:51 +02:00
|
|
|
});
|
|
|
|
|
|
2017-02-07 20:44:42 +01:00
|
|
|
Template.viewer.onRendered(function() {
|
|
|
|
|
|
|
|
|
|
this.autorun(function() {
|
|
|
|
|
// To make sure ohif viewerMain is rendered before initializing Hanging Protocols
|
|
|
|
|
const isOHIFViewerMainRendered = Session.get('OHIFViewerMainRendered');
|
|
|
|
|
|
|
|
|
|
// To avoid first run
|
|
|
|
|
if (isOHIFViewerMainRendered) {
|
2017-02-10 15:54:22 +01:00
|
|
|
// To run only when OHIFViewerMainRendered dependency has changed.
|
2017-02-07 20:44:42 +01:00
|
|
|
// because initHangingProtocol can have other reactive components
|
|
|
|
|
Tracker.nonreactive(initHangingProtocol);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
2016-07-22 14:26:29 +02:00
|
|
|
Template.viewer.events({
|
|
|
|
|
'click .js-toggle-studies'() {
|
|
|
|
|
const instance = Template.instance();
|
|
|
|
|
const current = instance.data.state.get('leftSidebar');
|
|
|
|
|
instance.data.state.set('leftSidebar', !current);
|
|
|
|
|
},
|
|
|
|
|
'click .js-toggle-protocol-editor'() {
|
|
|
|
|
const instance = Template.instance();
|
|
|
|
|
const current = instance.data.state.get('rightSidebar');
|
|
|
|
|
instance.data.state.set('rightSidebar', !current);
|
|
|
|
|
},
|
2016-08-24 13:49:41 +02:00
|
|
|
});
|