2019-08-13 15:36:46 -04:00
|
|
|
import log from '../log.js';
|
|
|
|
|
import { retrieveStudyMetadata } from './retrieveStudyMetadata';
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves metaData for multiple studies at once.
|
|
|
|
|
*
|
|
|
|
|
* This function calls retrieveStudyMetadata several times, asynchronously,
|
|
|
|
|
* and waits for all of the results to be returned.
|
|
|
|
|
*
|
2019-11-05 18:48:44 -03:00
|
|
|
* @param {Object} server Object with server configuration parameters
|
2020-03-09 19:03:23 +00:00
|
|
|
* @param {Array} studyInstanceUIDs The UIDs of the Studies to be retrieved
|
2019-11-05 18:48:44 -03:00
|
|
|
* @param {Object} [filters] - Object containing filters to be applied on retrieve metadata process
|
|
|
|
|
* @param {string} [filter.seriesInstanceUID] - series instance uid to filter results against
|
|
|
|
|
* @returns {Promise} that will be resolved with the metadata or rejected with the error
|
2019-08-13 15:36:46 -04:00
|
|
|
*/
|
|
|
|
|
export default function retrieveStudiesMetadata(
|
|
|
|
|
server,
|
2020-03-09 19:03:23 +00:00
|
|
|
studyInstanceUIDs,
|
2019-11-05 18:48:44 -03:00
|
|
|
filters
|
2019-08-13 15:36:46 -04:00
|
|
|
) {
|
|
|
|
|
// Create an empty array to store the Promises for each metaData retrieval call
|
|
|
|
|
const promises = [];
|
|
|
|
|
|
2020-03-09 19:03:23 +00:00
|
|
|
// Loop through the array of studyInstanceUIDs
|
|
|
|
|
studyInstanceUIDs.forEach(function(StudyInstanceUID) {
|
2019-08-13 15:36:46 -04:00
|
|
|
// Send the call and resolve or reject the related promise based on its outcome
|
2020-03-09 19:03:23 +00:00
|
|
|
const promise = retrieveStudyMetadata(server, StudyInstanceUID, filters);
|
2019-08-13 15:36:46 -04:00
|
|
|
|
|
|
|
|
// 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 => log.warn(error));
|
|
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
}
|