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

128 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-05-11 18:56:46 +02:00
import RetrieveMetadataLoader from './retrieveMetadataLoader';
2020-05-12 14:49:32 +02:00
//import { sortStudySeries, sortingCriteria } from '../../sortStudy';
import getSeriesInfo from './utils/getSeriesInfo';
2020-05-11 18:56:46 +02:00
/**
* Map seriesList to an array of seriesInstanceUid
* @param {Arrays} seriesList list of Series Instance UIDs
* @returns {Arrays} A list of Series Instance UIDs
*/
function mapStudySeries(seriesList) {
return seriesList.map(series => getSeriesInfo(series).seriesInstanceUid);
}
/**
* Creates an immutable series loader object which loads each series sequentially using the iterator interface
* @param {DICOMWebClient} dicomWebClient The DICOMWebClient instance to be used for series load
* @param {string} studyInstanceUID The Study Instance UID from which series will be loaded
* @param {Array} seriesInstanceUIDList A list of Series Instance UIDs
* @returns {Object} Returns an object which supports loading of instances from each of given Series Instance UID
*/
function makeSeriesAsyncLoader(
client,
studyInstanceUID,
seriesInstanceUIDList
) {
return Object.freeze({
hasNext() {
return seriesInstanceUIDList.length > 0;
},
async next() {
const seriesInstanceUID = seriesInstanceUIDList.shift();
2020-05-12 14:49:32 +02:00
return client.retrieveSeriesMetadata({
2020-05-11 18:56:46 +02:00
studyInstanceUID,
seriesInstanceUID,
});
2020-05-12 14:49:32 +02:00
// return { studyInstanceUID, seriesInstanceUID, sopInstances };
2020-05-11 18:56:46 +02:00
},
});
}
/**
* Class for async load of study metadata.
* It inherits from RetrieveMetadataLoader
*
* It loads the one series and then append to seriesLoader the others to be consumed/loaded
*/
export default class RetrieveMetadataLoaderAsync extends RetrieveMetadataLoader {
/**
* @returns {Array} Array of preLoaders. To be consumed as queue
*/
*getPreLoaders() {
const preLoaders = [];
const {
studyInstanceUID,
filters: { seriesInstanceUID } = {},
client,
} = this;
if (seriesInstanceUID) {
const options = {
studyInstanceUID,
queryParams: { SeriesInstanceUID: seriesInstanceUID },
};
preLoaders.push(client.searchForSeries.bind(client, options));
}
// Fallback preloader
preLoaders.push(client.searchForSeries.bind(client, { studyInstanceUID }));
yield* preLoaders;
}
async preLoad() {
const preLoaders = this.getPreLoaders();
const result = await this.runLoaders(preLoaders);
2020-05-12 14:49:32 +02:00
// const seriesSorted = sortStudySeries(
// result,
// sortingCriteria.seriesSortCriteria.seriesInfoSortingCriteria
// );
//const seriesInstanceUidsMap = mapStudySeries(seriesSorted);
const seriesInstanceUidsMap = mapStudySeries(result);
2020-05-11 18:56:46 +02:00
return seriesInstanceUidsMap;
}
async load(preLoadData) {
const { client, studyInstanceUID } = this;
const seriesAsyncLoader = makeSeriesAsyncLoader(
client,
studyInstanceUID,
preLoadData
);
2020-05-12 14:49:32 +02:00
// const firstSeries = await seriesAsyncLoader.next();
// return {
// sopInstances: firstSeries.sopInstances,
// asyncLoader: seriesAsyncLoader,
// };
2020-05-11 18:56:46 +02:00
2020-05-12 14:49:32 +02:00
const promises = [];
while (seriesAsyncLoader.hasNext()) {
promises.push(seriesAsyncLoader.next());
}
return promises;
// if (asyncLoader.hasNext()) {
2020-05-11 18:56:46 +02:00
}
2020-05-12 14:49:32 +02:00
async posLoad(promises) {
return promises;
// const { client } = this;
// const { sopInstances, asyncLoader } = loadData;
2020-05-11 18:56:46 +02:00
2020-05-12 14:49:32 +02:00
// const study = await createStudyFromSOPInstanceList(server, sopInstances);
2020-05-11 18:56:46 +02:00
2020-05-12 14:49:32 +02:00
// if (asyncLoader.hasNext()) {
// attachSeriesLoader(server, study, asyncLoader);
// }
2020-05-11 18:56:46 +02:00
2020-05-12 14:49:32 +02:00
// return study;
2020-05-11 18:56:46 +02:00
}
}