2016-09-20 22:47:44 +02:00
|
|
|
import { OHIF } from 'meteor/ohif:core';
|
|
|
|
|
|
2016-01-13 16:17:32 +01:00
|
|
|
/**
|
|
|
|
|
* Retrieves metaData for multiple studies at once.
|
|
|
|
|
*
|
2017-02-22 12:00:00 +01:00
|
|
|
* This function calls retrieveStudyMetadata several times, asynchronously,
|
2016-01-13 16:17:32 +01:00
|
|
|
* and waits for all of the results to be returned.
|
|
|
|
|
*
|
|
|
|
|
* @param studyInstanceUids The UIDs of the Studies to be retrieved
|
2017-03-15 22:46:07 +01:00
|
|
|
* @return Promise
|
2016-01-13 16:17:32 +01:00
|
|
|
*/
|
2017-08-16 02:12:32 +02:00
|
|
|
OHIF.studylist.retrieveStudiesMetadata = (studyInstanceUids, seriesInstanceUids, doneCallback, failCallback) => {
|
2016-01-13 16:17:32 +01:00
|
|
|
// Check to make sure studyInstanceUids were actually input
|
|
|
|
|
if (!studyInstanceUids || !studyInstanceUids.length) {
|
|
|
|
|
if (failCallback && typeof failCallback === 'function') {
|
|
|
|
|
failCallback('No studyInstanceUids were input');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-15 22:46:07 +01:00
|
|
|
// Create an empty array to store the Promises for each metaData retrieval call
|
2016-09-26 13:34:26 +02:00
|
|
|
const promises = [];
|
2016-01-13 16:17:32 +01:00
|
|
|
|
|
|
|
|
// 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
|
2017-08-16 02:12:32 +02:00
|
|
|
const promise = OHIF.studylist.retrieveStudyMetadata(studyInstanceUid, seriesInstanceUids);
|
2016-01-13 16:17:32 +01:00
|
|
|
|
|
|
|
|
// Add the current promise to the array of promises
|
2017-02-22 12:00:00 +01:00
|
|
|
promises.push(promise);
|
2016-01-13 16:17:32 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// When all of the promises are complete, this callback runs
|
2017-03-15 22:46:07 +01:00
|
|
|
const promise = Promise.all(promises);
|
|
|
|
|
|
|
|
|
|
// Warn the error on console if some retrieval failed
|
|
|
|
|
promise.catch(error => OHIF.log.warn(error));
|
|
|
|
|
|
|
|
|
|
return promise;
|
2016-09-20 22:47:44 +02:00
|
|
|
};
|