Files
ohif-viewer/extensions/default/src/DicomWebDataSource/retrieveStudyMetadata.js
T

92 lines
3.0 KiB
JavaScript
Raw Normal View History

import retrieveMetadataFiltered from './utils/retrieveMetadataFiltered.js';
2020-05-12 14:49:32 +02:00
import RetrieveMetadata from './wado/retrieveMetadata.js';
2020-05-11 18:56:46 +02:00
const moduleName = 'RetrieveStudyMetadata';
// Cache for promises. Prevents unnecessary subsequent calls to the server
const StudyMetaDataPromises = new Map();
/**
* Retrieves study metadata.
2020-05-11 18:56:46 +02:00
*
* @param {Object} dicomWebClient The DICOMWebClient instance to be used for series load
2020-05-11 18:56:46 +02:00
* @param {string} StudyInstanceUID The UID of the Study to be retrieved
* @param {boolean} enableStudyLazyLoad Whether the study metadata should be loaded asynchronously.
* @param {Object} [filters] Object containing filters to be applied on retrieve metadata process
* @param {string} [filters.seriesInstanceUID] Series instance uid to filter results against
* @param {array} [filters.SeriesInstanceUIDs] Series instance uids to filter results against
* @param {function} [sortCriteria] Sort criteria function
* @param {function} [sortFunction] Sort function
*
2020-05-11 18:56:46 +02:00
* @returns {Promise} that will be resolved with the metadata or rejected with the error
*/
export function retrieveStudyMetadata(
dicomWebClient,
StudyInstanceUID,
enableStudyLazyLoad,
filters,
sortCriteria,
2023-11-24 10:46:54 -03:00
sortFunction,
dicomWebConfig = {}
2020-05-11 18:56:46 +02: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 (!dicomWebClient) {
throw new Error(`${moduleName}: Required 'dicomWebClient' parameter not provided.`);
2020-05-11 18:56:46 +02:00
}
if (!StudyInstanceUID) {
throw new Error(`${moduleName}: Required 'StudyInstanceUID' parameter not provided.`);
2020-05-11 18:56:46 +02:00
}
2023-11-24 10:46:54 -03:00
const promiseId = `${dicomWebConfig.name}:${StudyInstanceUID}`;
2020-05-11 18:56:46 +02:00
// Already waiting on result? Return cached promise
2023-11-24 10:46:54 -03:00
if (StudyMetaDataPromises.has(promiseId)) {
return StudyMetaDataPromises.get(promiseId);
2020-05-11 18:56:46 +02:00
}
let promise;
if (filters && filters.SeriesInstanceUIDs) {
promise = retrieveMetadataFiltered(
2020-05-11 18:56:46 +02:00
dicomWebClient,
StudyInstanceUID,
enableStudyLazyLoad,
filters,
sortCriteria,
sortFunction
);
} else {
// Create a promise to handle the data retrieval
promise = new Promise((resolve, reject) => {
RetrieveMetadata(
dicomWebClient,
StudyInstanceUID,
enableStudyLazyLoad,
filters,
sortCriteria,
sortFunction
).then(function (data) {
resolve(data);
}, reject);
});
}
2020-05-11 18:56:46 +02:00
// Store the promise in cache
2023-11-24 10:46:54 -03:00
StudyMetaDataPromises.set(promiseId, promise);
2020-05-11 18:56:46 +02: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-05-11 18:56:46 +02:00
*
* @param {String} StudyInstanceUID The UID of the Study to be removed from cache
*/
export function deleteStudyMetadataPromise(StudyInstanceUID) {
if (StudyMetaDataPromises.has(StudyInstanceUID)) {
StudyMetaDataPromises.delete(StudyInstanceUID);
}
}