* Enable study prefetcher and expose configs * Fix progress for all images * Enable study loading listener * Add new default for displaying progress bar for series * Use events instead of redux to improve performance * Add documentation, resolve issues with different datasets * CR Updates * CR Updates * CR Updates & Resolve issue when activating both stack and study prefetch * Add upward and update display set logic * Add new behavior to prefetching orders * Rollback display set check and activate cache check * Remove prefetch check * Check if displayset has images * Debounce check cache events * Remove usued debounce flags * Ignore prefetching same image * Use new image instead of image rendered * Continue prefetch after cache check * Update prefetch logic after checking cache * Remove log * Update displayset count default to 3 * Update netlify config Co-authored-by: Alireza <ar.sedghi@gmail.com>
94 lines
2.7 KiB
JavaScript
94 lines
2.7 KiB
JavaScript
import React, { useEffect } from 'react';
|
|
import { classes, utils } from '@ohif/core';
|
|
import PropTypes from 'prop-types';
|
|
import cs from 'cornerstone-core';
|
|
|
|
import './StudyPrefetcher.css';
|
|
|
|
const StudyPrefetcher = ({ studies, options }) => {
|
|
useEffect(() => {
|
|
const studyPrefetcher = classes.StudyPrefetcher.getInstance(
|
|
studies,
|
|
options
|
|
);
|
|
const studiesMetadata = studies.map(s =>
|
|
utils.studyMetadataManager.get(s.StudyInstanceUID)
|
|
);
|
|
studyPrefetcher.setStudies(studiesMetadata);
|
|
|
|
const onNewImage = ({ detail }) => {
|
|
/**
|
|
* When images are cached the viewport will load instantly and
|
|
* the display sets will not be available at this point in time.
|
|
*
|
|
* This code add display sets and updates the study prefetcher metadata.
|
|
*/
|
|
const studiesMetadata = studies.map(s => {
|
|
const studyMetadata = utils.studyMetadataManager.get(
|
|
s.StudyInstanceUID
|
|
);
|
|
const displaySets = studyMetadata.getDisplaySets();
|
|
if (!displaySets || displaySets.length < 1) {
|
|
s.displaySets.forEach(ds => studyMetadata.addDisplaySet(ds));
|
|
}
|
|
return studyMetadata;
|
|
});
|
|
studyPrefetcher.setStudies(studiesMetadata);
|
|
|
|
const study = studyPrefetcher.getStudy(detail.image);
|
|
const series = studyPrefetcher.getSeries(study, detail.image);
|
|
const instance = studyPrefetcher.getInstance(series, detail.image);
|
|
|
|
if (study.displaySets && study.displaySets.length > 0) {
|
|
const {
|
|
displaySetInstanceUID,
|
|
} = studyPrefetcher.getDisplaySetBySOPInstanceUID(
|
|
study.displaySets,
|
|
instance
|
|
);
|
|
studyPrefetcher.prefetch(detail.element, displaySetInstanceUID);
|
|
}
|
|
};
|
|
|
|
const onElementEnabled = ({ detail }) => {
|
|
detail.element.addEventListener(cs.EVENTS.NEW_IMAGE, onNewImage);
|
|
};
|
|
|
|
cs.events.addEventListener(cs.EVENTS.ELEMENT_ENABLED, onElementEnabled);
|
|
|
|
return () => {
|
|
cs.events.removeEventListener(
|
|
cs.EVENTS.ELEMENT_ENABLED,
|
|
onElementEnabled
|
|
);
|
|
studyPrefetcher.destroy();
|
|
};
|
|
}, [options, studies]);
|
|
|
|
return null;
|
|
};
|
|
|
|
StudyPrefetcher.propTypes = {
|
|
studies: PropTypes.array.isRequired,
|
|
options: PropTypes.shape({
|
|
enabled: PropTypes.bool,
|
|
order: PropTypes.string,
|
|
displaySetCount: PropTypes.number,
|
|
preventCache: PropTypes.bool,
|
|
prefetchDisplaySetsTimeout: PropTypes.number,
|
|
includeActiveDisplaySet: PropTypes.bool,
|
|
}),
|
|
};
|
|
|
|
StudyPrefetcher.defaultProps = {
|
|
options: {
|
|
order: 'closest',
|
|
displaySetCount: 1,
|
|
preventCache: false,
|
|
prefetchDisplaySetsTimeout: 300,
|
|
includeActiveDisplaySet: false,
|
|
},
|
|
};
|
|
|
|
export default StudyPrefetcher;
|