Improving new study browser and moving studies services to ohif:studies

This commit is contained in:
Bruno Alves de Faria committed 2017-10-25 22:09:08 -02:00
1 parent 0b51a53976
commit eb372bed03
54 files changed
+560 -495

No files matched your search

@@ -36,7 +36,7 @@ Template.seriesDetailsTable.onRendered(() => {
// Get series list for the study
_.map(studies, (selectedStudy, index) => {
studies[index].seriesList = [];
OHIF.studylist.retrieveStudyMetadata(study => {
OHIF.studies.retrieveStudyMetadata(study => {
// Set series list
studies[index].seriesList = study.seriesList;
studies[index].displaySeriesLoadingText = false;
@@ -13,7 +13,7 @@ export class OHIFStudyMetadataSource extends OHIF.viewerbase.StudyMetadataSource
* @return {Promise} A Promise object
*/
getByInstanceUID(studyInstanceUID) {
return OHIF.studylist.retrieveStudyMetadata(studyInstanceUID);
return OHIF.studies.retrieveStudyMetadata(studyInstanceUID);
}
/**
@@ -12,7 +12,7 @@ queryStudies = function(studiesToQuery, options) {
const promises = [];
studiesToQuery.forEach(studyToQuery => {
const promise = OHIF.studylist.retrieveStudyMetadata(studyToQuery.studyInstanceUid);
const promise = OHIF.studies.retrieveStudyMetadata(studyToQuery.studyInstanceUid);
promise.then(study => {
studiesQueried++;
notify({
@@ -1,42 +1,12 @@
import { OHIF } from 'meteor/ohif:core';
const note = 'OHIF.studylist.retrieveStudiesMetadata is deprecated.';
const instructions = 'Please use OHIF.studies.retrieveStudiesMetadata instead.';
/**
* Retrieves metaData for multiple studies at once.
*
* This function calls retrieveStudyMetadata several times, asynchronously,
* and waits for all of the results to be returned.
*
* @param studyInstanceUids The UIDs of the Studies to be retrieved
* @return Promise
* @deprecated Please use OHIF.studies.retrieveStudiesMetadata instead
*/
OHIF.studylist.retrieveStudiesMetadata = (studyInstanceUids, seriesInstanceUids, doneCallback, failCallback) => {
// // Check to make sure studyInstanceUids were actually input
// if (!studyInstanceUids || !studyInstanceUids.length) {
// if (failCallback && typeof failCallback === 'function') {
// failCallback('No studyInstanceUids were input');
// }
//
// return;
// }
// Create an empty array to store the Promises for each metaData retrieval call
const promises = [];
// Loop through the array of studyInstanceUids
studyInstanceUids.forEach(function(studyInstanceUid) {
// Send the call, and attach doneCallbacks and failCallbacks
// which can resolve or reject the related promise based on its outcome
const promise = OHIF.studylist.retrieveStudyMetadata(studyInstanceUid, seriesInstanceUids);
// Add the current promise to the array of promises
promises.push(promise);
});
// When all of the promises are complete, this callback runs
const promise = Promise.all(promises);
// Warn the error on console if some retrieval failed
promise.catch(error => OHIF.log.warn(error));
return promise;
OHIF.studylist.retrieveStudiesMetadata = function() {
OHIF.log.warn(`${note}\n${instructions}`);
OHIF.studies.retrieveStudiesMetadata.apply(this, arguments);
};
@@ -1,110 +1,12 @@
import { Meteor } from 'meteor/meteor';
import { OHIF } from 'meteor/ohif:core';
import 'meteor/ohif:viewerbase';
// Define the StudyMetaDataPromises object. This is used as a cache to store study meta data
// promises and prevent unnecessary subsequent calls to the server
const StudyMetaDataPromises = new Map();
const note = 'OHIF.studylist.retrieveStudyMetadata is deprecated.';
const instructions = 'Please use OHIF.studies.retrieveStudyMetadata instead.';
/**
* Retrieves study metadata using a server call
*
* @param {String} studyInstanceUid The UID of the Study to be retrieved
* @returns {Promise} that will be resolved with the metadata or rejected with the error
* @deprecated Please use OHIF.studies.retrieveStudyMetadata instead
*/
OHIF.studylist.retrieveStudyMetadata = (studyInstanceUid, seriesInstanceUids) => {
// @TODO: Whenever a study metadata request has failed, its related promise will be rejected once and for all
// and further requests for that metadata will always fail. On failure, we probably need to remove the
// corresponding promise from the "StudyMetaDataPromises" map...
// If the StudyMetaDataPromises cache already has a pending or resolved promise related to the
// given studyInstanceUid, then that promise is returned
if (StudyMetaDataPromises.has(studyInstanceUid)) {
return StudyMetaDataPromises.get(studyInstanceUid);
}
console.time('retrieveStudyMetadata');
// Create a promise to handle the data retrieval
const promise = new Promise((resolve, reject) => {
// 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('retrieveStudyMetadata');
if (error) {
const errorType = error.error;
let errorMessage = '';
if (errorType === 'server-connection-error') {
errorMessage = 'There was an error connecting to the DICOM server, please verify if it is up and running.'
} else if (errorType === 'server-internal-error') {
errorMessage = `There was an internal error with the DICOM server getting metadeta for ${studyInstanceUid}`;
} else {
errorMessage = `For some reason we could not retrieve the study\'s metadata for ${studyInstanceUid}.`;
}
OHIF.log.error(errorMessage);
OHIF.log.error(error.stack);
reject(`GetStudyMetadata: ${errorMessage}`);
return;
}
// Filter series if seriesInstanceUid exists
if (seriesInstanceUids && seriesInstanceUids.length) {
study.seriesList = study.seriesList.filter(series => seriesInstanceUids.indexOf(series.seriesInstanceUid) > -1);
}
if (!study) {
reject(`GetStudyMetadata: No study data returned from server: ${studyInstanceUid}`);
return;
}
if (window.HipaaLogger && Meteor.user && Meteor.user()) {
window.HipaaLogger.logEvent({
eventType: 'viewed',
userId: Meteor.userId(),
userName: Meteor.user().profile.fullName,
collectionName: 'Study',
recordId: studyInstanceUid,
patientId: study.patientId,
patientName: study.patientName
});
}
// Once the data was retrieved, the series are sorted by series and instance number
OHIF.viewerbase.sortStudy(study);
// Updates WADO-RS metaDataManager
OHIF.viewerbase.updateMetaDataManager(study);
// Add additional metadata to our study from the studylist
const studylistStudy = OHIF.studylist.collections.Studies.findOne({
studyInstanceUid: study.studyInstanceUid,
'seriesList.seriesInstanceUid': '123456',
});
if (studylistStudy) {
Object.assign(study, studylistStudy);
}
// Transform the study in a StudyMetadata object
const studyMetadata = new OHIF.metadata.StudyMetadata(study);
// Add the display sets to the study
study.displaySets = OHIF.viewerbase.sortingManager.getDisplaySets(studyMetadata);
study.displaySets.forEach(displaySet => {
OHIF.viewerbase.stackManager.makeAndAddStack(study, displaySet);
});
// Resolve the promise with the final study metadata object
resolve(study);
});
});
// Store the promise in cache
StudyMetaDataPromises.set(studyInstanceUid, promise);
return promise;
OHIF.studylist.retrieveStudyMetadata = function() {
OHIF.log.warn(`${note}\n${instructions}`);
OHIF.studies.retrieveStudyMetadata.apply(this, arguments);
};