Replacing switchToTab with routes

This commit is contained in:
Bruno Alves de Faria committed 2017-03-21 10:16:47 -03:00
1 parent 0cf4dbf13f
commit 7718d31a77
46 files changed
+358 -753

No files matched your search

@@ -1,7 +1,7 @@
import { OHIF } from 'meteor/ohif:core';
OHIF.studylist.getSelectedStudies = () => {
return StudyListSelectedStudies.find({}, {
return OHIF.studylist.collections.Studies.find({ selected: true }, {
sort: {
studyDate: 1
}
@@ -1,82 +0,0 @@
import { OHIF } from 'meteor/ohif:core';
import 'meteor/ohif:viewerbase';
// DEPRECATED - use OHIF.studylist.retrieveStudyMetadata instead
// Define the StudyMetaData object. This is used as a cache
// to store study meta data information to prevent unnecessary
// calls to the server
var StudyMetaData = {};
/**
* Retrieves study metadata using a server call, and fires a callback
* when completed.
*
* @params {string} studyInstanceUid The UID of the Study to be retrieved
* @params {function} doneCallback The callback function to be executed when the study retrieval has finished
* @param failCallback The callback function to be executed when the study retrieval has failed
*/
getStudyMetadata = function(studyInstanceUid, doneCallback, failCallback) {
// If the StudyMetaData cache already has data related to this
// studyInstanceUid, then we should fire the doneCallback with this data
// and stop here.
var study = StudyMetaData[studyInstanceUid];
if (study) {
doneCallback(study);
return;
}
console.time('getStudyMetadata');
// If no study metadata is in the cache variable, we need to retrieve it from
// the server with a call.
Meteor.call('GetStudyMetadata', studyInstanceUid, function(error, study) {
console.timeEnd('getStudyMetadata');
if (Meteor.user && Meteor.user()) {
var hipaaEvent = {
eventType: 'viewed',
userId: Meteor.userId(),
userName: Meteor.user().profile.fullName,
collectionName: 'Study',
recordId: studyInstanceUid,
patientId: study.patientId,
patientName: study.patientName
};
HipaaLogger.logEvent(hipaaEvent);
}
if (error) {
OHIF.log.warn(error);
failCallback(error);
return;
}
if (!study) {
throw "GetStudyMetadata: No study data returned from server";
}
// Once we have retrieved the data, we sort the series' by series
// and instance number in ascending order
OHIF.viewerbase.sortStudy(study);
// Updates WADO-RS metaDataManager
OHIF.viewerbase.updateMetaDataManager(study);
// Add additional metadata to our study from the studylist
var studylistStudy = StudyListStudies.findOne({
studyInstanceUid: study.studyInstanceUid
});
if (!studylistStudy) {
// return;
}
$.extend(study, studylistStudy);
// Then we store this data in the cache variable
StudyMetaData[studyInstanceUid] = study;
// Finally, we fire the doneCallback with this study meta data
doneCallback(study);
});
};
@@ -26,8 +26,8 @@ const getStudyPriors = study => {
const patientID = study.getTagValue(PATIENT_ID); // PatientID
const studyDate = study.getTagValue(STUDY_DATE); // StudyDate
// Find prior studies in global StudyListStudies Minimongo collection
const cursor = StudyListStudies.find({
// Find prior studies in global Studies Minimongo collection
const cursor = OHIF.studylist.collections.Studies.find({
patientId: patientID,
studyDate: {
$lt: studyDate
+1 -4
View File
@@ -3,12 +3,9 @@ import './third-party/jquery.twbsPagination.min.js';
import './exportSelectedStudies.js';
import './exportStudies.js';
import './getSelectedStudies.js';
import './getStudyMetadata.js';
import './getStudiesMetadata.js';
import './importStudies.js';
import './openNewTab.js';
import './queryStudies.js';
import './retrieveStudiesMetadata.js';
import './retrieveStudyMetadata.js';
import './studylist.js';
import './switchToTab.js';
import './viewSeriesDetails.js';
@@ -1,27 +0,0 @@
import { Random } from 'meteor/random';
import { OHIF } from 'meteor/ohif:core';
/**
* Opens a new tab in the tabbed studylist environment using
* a given study and new tab title.
*
* @param studyInstanceUid The UID of the Study to be opened
*/
const openNewTab = studyInstanceUid => {
OHIF.log.info('openNewTab');
// Generate a unique ID to represent this tab
// We can't just use the Mongo entry ID because
// then it will change after hot-reloading.
const contentId = Random.id();
// Update the ViewerData global object
ViewerData = window.ViewerData || ViewerData;
ViewerData[contentId] = {
contentId: contentId,
studyInstanceUids: [studyInstanceUid]
};
// Switch to the new tab
switchToTab(contentId);
};
@@ -7,10 +7,9 @@ import { OHIF } from 'meteor/ohif:core';
* and waits for all of the results to be returned.
*
* @param studyInstanceUids The UIDs of the Studies to be retrieved
* @param doneCallback The callback function to be executed when the study retrieval has finished
* @param failCallback The callback function to be executed when the study retrieval has failed
* @return Promise
*/
OHIF.studylist.getStudiesMetadata = (studyInstanceUids, doneCallback, failCallback) => {
OHIF.studylist.retrieveStudiesMetadata = (studyInstanceUids, doneCallback, failCallback) => {
// Check to make sure studyInstanceUids were actually input
if (!studyInstanceUids || !studyInstanceUids.length) {
if (failCallback && typeof failCallback === 'function') {
@@ -20,8 +19,7 @@ OHIF.studylist.getStudiesMetadata = (studyInstanceUids, doneCallback, failCallba
return;
}
// Create an empty array to store the Promises for each metaData
// retrieval call
// Create an empty array to store the Promises for each metaData retrieval call
const promises = [];
// Loop through the array of studyInstanceUids
@@ -35,15 +33,10 @@ OHIF.studylist.getStudiesMetadata = (studyInstanceUids, doneCallback, failCallba
});
// When all of the promises are complete, this callback runs
Promise.all(promises).then(studies => {
// Pass the studies array to the doneCallback, if one exists
if (doneCallback && typeof doneCallback === 'function') {
doneCallback(studies);
}
}).catch(error => {
OHIF.log.warn(error);
if (failCallback && typeof failCallback === 'function') {
failCallback(error);
}
});
const promise = Promise.all(promises);
// Warn the error on console if some retrieval failed
promise.catch(error => OHIF.log.warn(error));
return promise;
};
@@ -62,13 +62,11 @@ OHIF.studylist.retrieveStudyMetadata = studyInstanceUid => {
OHIF.viewerbase.updateMetaDataManager(study);
// Add additional metadata to our study from the studylist
const studylistStudy = StudyListStudies.findOne({
const studylistStudy = OHIF.studylist.collections.Studies.findOne({
studyInstanceUid: study.studyInstanceUid
});
if (!studylistStudy) {
// return;
} else {
if (studylistStudy) {
Object.assign(study, studylistStudy);
}
@@ -1,3 +1,4 @@
import { OHIF } from 'meteor/ohif:core';
import { Viewerbase } from 'meteor/ohif:viewerbase';
// Classes
import { OHIFStudyMetadataSource } from './OHIFStudyMetadataSource';
@@ -11,15 +12,14 @@ StudyList = {
getStudyPriors,
getStudyPriorsMap
},
callbacks: {},
classes: {
OHIFStudyMetadataSource,
OHIFStudySummary
}
};
StudyList.callbacks.dblClickOnStudy = dblClickOnStudy;
StudyList.callbacks.middleClickOnStudy = dblClickOnStudy;
OHIF.studylist.callbacks.dblClickOnStudy = dblClickOnStudy;
OHIF.studylist.callbacks.middleClickOnStudy = dblClickOnStudy;
function dblClickOnStudy(data) {
openNewTab(data.studyInstanceUid);
@@ -1,153 +0,0 @@
import { Blaze } from 'meteor/blaze';
import { Session } from 'meteor/session';
import { jQuery, $ } from 'meteor/jquery';
import { Template } from 'meteor/templating';
import { OHIF } from 'meteor/ohif:core';
/**
* Switches to a new tab in the tabbed studylist container
* This function renders either the StudyList or the Viewer template with new data.
*
* @param contentId The unique ID of the tab to be switched to
*/
switchToTab = function(contentId) {
if (!contentId) {
return;
}
OHIF.log.info('Switching to tab: ' + contentId);
// Clear the cornerstone tool data to sync the measurements with the measurements API
cornerstoneTools.globalImageIdSpecificToolStateManager = cornerstoneTools.newImageIdSpecificToolStateManager();
$('.tab-content .tab-pane').removeClass('active');
if (contentId !== 'studylistTab') {
$('.tab-content .tab-pane#viewerTab').addClass('active');
} else {
$('.tab-content .tab-pane#' + contentId).addClass('active');
}
// Remove any previous Viewers from the DOM
$('.viewerContainer').remove();
$('.studylistContainer').remove();
// Update the 'activeContentId' variable in Session
Session.set('activeContentId', contentId);
// If we are switching to the StudyList tab, reset any CSS styles
// that have been applied to prevent scrolling in the Viewer.
// Then stop here, since nothing needs to be re-rendered.
let container;
if (contentId === 'studylistTab') {
container = $('.tab-content').find('#studylistTab').get(0);
if (!container) {
return;
}
const studylistContainer = document.createElement('div');
studylistContainer.classList.add('studylistContainer');
container.appendChild(studylistContainer);
// Use Blaze to render the StudyListResult Template into the container
Blaze.render(Template.studylistResult, studylistContainer);
document.body.style.overflow = null;
document.body.style.height = null;
document.body.style.minWidth = null;
document.body.style.position = null;
return;
}
// Tab was closed at some point, stop here
ViewerData = window.ViewerData || ViewerData;
if (!ViewerData[contentId]) {
return;
}
container = $('.tab-content').find('#viewerTab').get(0);
container.innerHTML = '';
// Use Blaze to render the Loading Template into the container
// viewStudiesInTab will clear this container
Blaze.renderWithData(Template.loadingText, {}, container);
const studies = ViewerData[contentId].studies;
if (studies) {
// ViewerData already has the meta data (in cases when studylist is launched externally)
viewStudiesInTab(contentId, studies);
} else {
// Use the stored ViewerData global object to retrieve the studyInstanceUid
// related to this tab
const studyInstanceUids = ViewerData[contentId].studyInstanceUids;
// Attempt to retrieve the meta data (it might be cached)
OHIF.studylist.getStudiesMetadata(studyInstanceUids, function(studies) {
viewStudiesInTab(contentId, studies);
});
}
};
const viewStudiesInTab = (contentId, studies) => {
// Tab closed while study data was being retrieved, stop here
if (!ViewerData[contentId]) {
OHIF.log.warn('Tab closed while study data was being retrieved');
return;
}
// Once we have the study data, store it in a structure with
// any other saved data about this tab (e.g. layout structure)
const data = jQuery.extend({}, ViewerData[contentId]);
data.studies = studies;
// TODO: check if this is necessary. Since the typo bug
// was fixed (it was contentid instead of contentId)
data.contentId = contentId;
if (ViewerData[contentId].studies && ViewerData[contentId].studies.length) {
data.studies = ViewerData[contentId].studies;
}
// Add additional metadata to our study from the studylist
data.studies.forEach(study => {
const studylistStudy = StudyListStudies.findOne({
studyInstanceUid: study.studyInstanceUid
});
if (!studylistStudy) {
return;
}
$.extend(study, studylistStudy);
});
// Get tab content container given the contentId string
// If no such container exists, stop here because something is wrong
const container = $('.tab-content').find('#viewerTab').get(0);
// Remove the loading text template that is inside the tab container by default
const viewerContainer = document.createElement('div');
viewerContainer.classList.add('viewerContainer');
container.innerHTML = '';
container.appendChild(viewerContainer);
// Use Blaze to render the Viewer Template into the container
Blaze.renderWithData(Template.viewer, data, viewerContainer);
// Retrieve the DOM element of the viewer
const imageViewer = $('#viewer');
// If it is present in the DOM (it should be), then apply
// styles to prevent page scrolling and overscrolling on mobile devices
if (imageViewer) {
document.body.style.overflow = 'hidden';
document.body.style.height = '100%';
document.body.style.width = '100%';
document.body.style.minWidth = 0;
// Prevent overscroll on mobile devices
document.body.style.position = 'fixed';
}
};