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
|
|
|
|
|
* @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
|
|
|
|
|
*/
|
2016-09-26 13:34:26 +02:00
|
|
|
OHIF.studylist.getStudiesMetadata = (studyInstanceUids, 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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 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-02-22 12:00:00 +01:00
|
|
|
const promise = OHIF.studylist.retrieveStudyMetadata(studyInstanceUid);
|
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-02-22 12:00:00 +01:00
|
|
|
Promise.all(promises).then(studies => {
|
2016-01-13 16:17:32 +01:00
|
|
|
// Pass the studies array to the doneCallback, if one exists
|
|
|
|
|
if (doneCallback && typeof doneCallback === 'function') {
|
|
|
|
|
doneCallback(studies);
|
|
|
|
|
}
|
2017-02-22 12:00:00 +01:00
|
|
|
}).catch(error => {
|
2016-09-20 22:47:44 +02:00
|
|
|
OHIF.log.warn(error);
|
2016-01-13 16:17:32 +01:00
|
|
|
if (failCallback && typeof failCallback === 'function') {
|
|
|
|
|
failCallback(error);
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-09-20 22:47:44 +02:00
|
|
|
};
|