2019-08-13 15:36:46 -04:00
|
|
|
import RetrieveMetadata from './services/wado/retrieveMetadata.js';
|
|
|
|
|
|
2019-09-23 15:05:26 +02:00
|
|
|
const moduleName = 'RetrieveStudyMetadata';
|
2019-08-13 15:36:46 -04:00
|
|
|
// Cache for promises. Prevents unnecessary subsequent calls to the server
|
|
|
|
|
const StudyMetaDataPromises = new Map();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Retrieves study metadata
|
|
|
|
|
*
|
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 {string} StudyInstanceUID The UID of the Study 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
|
2019-08-13 15:36:46 -04:00
|
|
|
* @returns {Promise} that will be resolved with the metadata or rejected with the error
|
|
|
|
|
*/
|
2020-03-09 19:03:23 +00:00
|
|
|
export function retrieveStudyMetadata(server, StudyInstanceUID, filters) {
|
2019-08-13 15:36:46 -04:00
|
|
|
// @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 (!server) {
|
2019-09-23 15:05:26 +02:00
|
|
|
throw new Error(`${moduleName}: Required 'server' parameter not provided.`);
|
2019-08-13 15:36:46 -04:00
|
|
|
}
|
2020-03-09 19:03:23 +00:00
|
|
|
if (!StudyInstanceUID) {
|
2019-08-13 15:36:46 -04:00
|
|
|
throw new Error(
|
2020-03-09 19:03:23 +00:00
|
|
|
`${moduleName}: Required 'StudyInstanceUID' parameter not provided.`
|
2019-08-13 15:36:46 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Already waiting on result? Return cached promise
|
2020-03-09 19:03:23 +00:00
|
|
|
if (StudyMetaDataPromises.has(StudyInstanceUID)) {
|
|
|
|
|
return StudyMetaDataPromises.get(StudyInstanceUID);
|
2019-08-13 15:36:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a promise to handle the data retrieval
|
|
|
|
|
const promise = new Promise((resolve, reject) => {
|
2020-03-09 19:03:23 +00:00
|
|
|
RetrieveMetadata(server, StudyInstanceUID, filters).then(function(data) {
|
2019-08-13 15:36:46 -04:00
|
|
|
resolve(data);
|
|
|
|
|
}, reject);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Store the promise in cache
|
2020-03-09 19:03:23 +00:00
|
|
|
StudyMetaDataPromises.set(StudyInstanceUID, promise);
|
2019-08-13 15:36:46 -04:00
|
|
|
|
|
|
|
|
return promise;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Delete the cached study metadata retrieval promise to ensure that the browser will
|
|
|
|
|
* re-retrieve the study metadata when it is next requested
|
|
|
|
|
*
|
2020-03-09 19:03:23 +00:00
|
|
|
* @param {String} StudyInstanceUID The UID of the Study to be removed from cache
|
2019-08-13 15:36:46 -04:00
|
|
|
*
|
|
|
|
|
*/
|
2020-03-09 19:03:23 +00:00
|
|
|
export function deleteStudyMetadataPromise(StudyInstanceUID) {
|
|
|
|
|
if (StudyMetaDataPromises.has(StudyInstanceUID)) {
|
|
|
|
|
StudyMetaDataPromises.delete(StudyInstanceUID);
|
2019-08-13 15:36:46 -04:00
|
|
|
}
|
|
|
|
|
}
|