[WIP] Moving hanging protocols initialization to OHIF Viewer specific code.

This commit is contained in:
Emanuel F. Oliveira 2017-02-07 17:44:42 -02:00 committed by Eloízio Salgado
parent 7fa581e52b
commit 6cfb4f16eb
5 changed files with 84 additions and 17 deletions

View File

@ -2,12 +2,41 @@ import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
import { Template } from 'meteor/templating';
import { ReactiveDict } from 'meteor/reactive-dict';
import { Tracker } from 'meteor/tracker'
import { OHIF } from 'meteor/ohif:core';
import 'meteor/ohif:cornerstone';
import 'meteor/ohif:viewerbase';
import 'meteor/ohif:metadata';
/**
* 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
const studyMetadataSource = new OHIFStudyMetadataSource();
// Creates Protocol Engine object with required arguments
const ProtocolEngine = new HP.ProtocolEngine(layoutManager, studyMetadataList, [], studyMetadataSource);
// Sets up Hanging Protocol engine
HP.setEngine(ProtocolEngine);
});
};
Meteor.startup(() => {
Session.setDefault('activeViewport', false);
Session.setDefault('leftSidebar', false);
@ -78,12 +107,29 @@ Template.viewer.onCreated(() => {
instance.data.studies.forEach(study => {
study.selected = true;
OHIF.viewer.Studies.insert(study);
OHIF.viewer.StudyMetadataList.insert(studyMetadata);
ViewerData[contentId].studyInstanceUids.push(study.studyInstanceUid);
});
Session.set('ViewerData', ViewerData);
});
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) {
// To run only when ViewerMainRendered dependency has changed.
// because initHangingProtocol can have other reactive components
Tracker.nonreactive(initHangingProtocol);
}
});
});
Template.viewer.events({
'click .js-toggle-studies'() {
const instance = Template.instance();

View File

@ -0,0 +1,16 @@
import { OHIF } from 'meteor/ohif:core';
import 'meteor/ohif:viewerbase';
export class OHIFStudyMetadataSource extends OHIF.viewerbase.StudyMetadataSource {
/**
* Get study metadata for a study with given study InstanceUID
* @param {String} studyInstanceUID Study InstanceUID
*/
getByInstanceUID(studyInstanceUID) {
return new Promise((resolve, reject) => {
getStudyMetadata(studyInstanceUID, resolve, reject);
});
}
}

View File

@ -65,4 +65,5 @@ Package.onUse(function(api) {
// Export the Collections
api.export('StudyListStudies', 'client');
api.export('StudyListSelectedStudies', 'client');
api.export('OHIFStudyMetadataSource', 'client');
});

View File

@ -114,7 +114,11 @@ Template.viewerMain.onRendered(() => {
// Enable hotkeys
hotkeyUtils.enableHotkeys();
Session.set('ViewerMainRendered', Random.id());
Session.set('OHIFViewerMainRendered', {
instance,
date: new Date()
});
});
Template.viewerMain.onDestroyed(() => {

View File

@ -5,25 +5,25 @@ import { OHIFError } from './OHIFError';
*/
export class StudyMetadataSource {
/**
* Get study metadata for a given study info
* @param {Object} studyInfo Study info object
*/
getByStudyInfo(studyInfo) {
/**
* Please override this method on a specialized class.
* Get study metadata for a given study info
* @param {Object} studyInfo Study info object
*/
throw new OHIFError('StudyMetadataSource::getByStudyInfo is not overriden. Please, override it in a specialized class. See OHIFStudyMetadataSource for example');
}
getByStudyInfo(studyInfo) {
/**
* Please override this method on a specialized class.
*/
throw new OHIFError('StudyMetadataSource::getByStudyInfo is not overriden. Please, override it in a specialized class. See OHIFStudyMetadataSource for example');
}
/**
* Get study metadata for a study with given study InstanceUID
* @param {String} studyInstanceUID Study InstanceUID
*/
getByInstanceUID(studyInstanceUID) {
/**
* Please override this method on a specialized class.
* Get study metadata for a study with given study InstanceUID
* @param {String} studyInstanceUID Study InstanceUID
*/
throw new OHIFError('StudyMetadataSource::getByInstanceUID is not overriden. Please, override it in a specialized class. See OHIFStudyMetadataSource for example');
}
getByInstanceUID(studyInstanceUID) {
/**
* Please override this method on a specialized class.
*/
throw new OHIFError('StudyMetadataSource::getByInstanceUID is not overriden. Please, override it in a specialized class. See OHIFStudyMetadataSource for example');
}
}