fix thumbnail persistence

This commit is contained in:
dannyrb 2020-05-22 14:31:51 -04:00
parent 23a94251fc
commit 4a390bfb66
3 changed files with 59 additions and 60 deletions

View File

@ -48,11 +48,28 @@ function PanelStudyBrowser({
StudyInstanceUIDs.forEach(sid => fetchStudiesForPatient(sid));
}, [StudyInstanceUIDs, getStudiesForPatientByStudyInstanceUID]);
// ~~ Initial Thumbnails
useEffect(() => {
const currentDisplaySets = DisplaySetService.activeDisplaySets || [];
currentDisplaySets.forEach(async dSet => {
const newImageSrcEntry = {};
const displaySet = DisplaySetService.getDisplaySetByUID(
dSet.displaySetInstanceUID
);
const imageIds = dataSource.getImageIdsForDisplaySet(displaySet);
const imageId = imageIds[Math.floor(imageIds.length / 2)];
// When the image arrives, render it and store the result in the thumbnailImgSrcMap
newImageSrcEntry[dSet.displaySetInstanceUID] = await getImageSrc(imageId);
setThumbnailImageSrcMap(prevState => {
return { ...prevState, ...newImageSrcEntry };
});
});
}, []);
// ~~ displaySets
useEffect(() => {
// TODO: Deep copy? Or By IDs?
// TODO: May need to be mapped to a different shape?
// TODO: Iterate over `studyDisplayList` and map these for all studies in list?
// TODO: Are we sure `activeDisplaySets` will always be accurate?
const currentDisplaySets = DisplaySetService.activeDisplaySets || [];
const mappedDisplaySets = _mapDisplaySets(
currentDisplaySets,
@ -62,48 +79,48 @@ function PanelStudyBrowser({
setDisplaySets(mappedDisplaySets);
}, [thumbnailImageSrcMap]);
async function handleDisplaySetsAdded(newDisplaySets) {
console.warn('~~ handleDisplaySetsAdded');
// First, launch requests for a thumbnail for the new display sets
newDisplaySets.forEach(async dset => {
const newImageSrcEntry = {};
const imageIds = dataSource.getImageIdsForDisplaySet(dset);
const imageId = imageIds[Math.floor(imageIds.length / 2)];
// When the image arrives, render it and store the result in the thumbnailImgSrcMap
newImageSrcEntry[dset.displaySetInstanceUID] = await getImageSrc(imageId);
console.log(`setting thumbnail for ${imageId}`);
setThumbnailImageSrcMap(prevState => {
return {...prevState, ...newImageSrcEntry}
});
});
}
// ~~ subscriptions --> displaySets
useEffect(() => {
const subscriptions = [
DisplaySetService.subscribe(
DisplaySetService.EVENTS.DISPLAY_SETS_ADDED,
handleDisplaySetsAdded
),
// TODO: Should this event indicate batch/series/study?
// Naming feels odd, and result is non-obvious
// Will this always contain _all_ displaySets we care about?
DisplaySetService.subscribe(
DisplaySetService.EVENTS.DISPLAY_SETS_CHANGED,
changedDisplaySets => {
const mappedDisplaySets = _mapDisplaySets(
changedDisplaySets,
thumbnailImageSrcMap
// DISPLAY_SETS_ADDED returns an array of DisplaySets that were added
const SubscriptionDisplaySetsAdded = DisplaySetService.subscribe(
DisplaySetService.EVENTS.DISPLAY_SETS_ADDED,
newDisplaySets => {
newDisplaySets.forEach(async dSet => {
const newImageSrcEntry = {};
const displaySet = DisplaySetService.getDisplaySetByUID(
dSet.displaySetInstanceUID
);
const imageIds = dataSource.getImageIdsForDisplaySet(displaySet);
const imageId = imageIds[Math.floor(imageIds.length / 2)];
setDisplaySets(mappedDisplaySets);
}
),
];
// When the image arrives, render it and store the result in the thumbnailImgSrcMap
newImageSrcEntry[dSet.displaySetInstanceUID] = await getImageSrc(
imageId
);
setThumbnailImageSrcMap(prevState => {
return { ...prevState, ...newImageSrcEntry };
});
});
}
);
// TODO: Will this always hold _all_ the displaySets we care about?
// DISPLAY_SETS_CHANGED returns `DisplaySerService.activeDisplaySets`
const SubscriptionDisplaySetsChanged = DisplaySetService.subscribe(
DisplaySetService.EVENTS.DISPLAY_SETS_CHANGED,
changedDisplaySets => {
const mappedDisplaySets = _mapDisplaySets(
changedDisplaySets,
thumbnailImageSrcMap
);
setDisplaySets(mappedDisplaySets);
}
);
return () => {
subscriptions.forEach(sub => sub.unsubscribe);
SubscriptionDisplaySetsAdded.unsubscribe();
SubscriptionDisplaySetsChanged.unsubscribe();
};
}, []);
@ -132,6 +149,7 @@ function PanelStudyBrowser({
PanelStudyBrowser.propTypes = {
DisplaySetService: PropTypes.shape({
EVENTS: PropTypes.object.isRequired,
getDisplaySetByUID: PropTypes.func.isRequired,
hasDisplaySetsForStudy: PropTypes.func.isRequired,
subscribe: PropTypes.func.isRequired,
}).isRequired,
@ -189,6 +207,7 @@ function _mapDisplaySets(displaySets, thumbnailImageSrcMap) {
});
}
/**
*
* @param {string[]} primaryStudyInstanceUIDs

View File

@ -9,14 +9,6 @@ function requestDisplaySetCreationForStudy(
}
dataSource.retrieveSeriesMetadata({ StudyInstanceUID });
// 1. Update DICOMStore
// 2. DICOMStore shoots out events
// 3. IFF instance is in study/series that is "active" (being viewed?), displaySet is created?
// 4. IFF not, just store is updated
// 5. IFF active studies change, splitting logic is refired?
// DisplaySetService.makeDisplaySets
}
export default requestDisplaySetCreationForStudy;

View File

@ -87,23 +87,11 @@ export default function ModeRoute({
// Add SOPClassHandlers to a new SOPClassManager.
DisplaySetService.init(extensionManager, sopClassHandlers);
const queryParams = location.search;
console.log('queryParams: ', queryParams);
// Call the data source to start building the view model?
// TODO: This should be called on subscription to DicomMetadataStore?
// dataSource.retrieve.series.metadata(
// queryParams,
// DisplaySetService.makeDisplaySets
// );
// TODO: This should be baked into core, not manuel?
// DisplaySetService would wire this up?
DicomMetadataStore.subscribe(
DicomMetadataStore.EVENTS.INSTANCES_ADDED,
({ StudyInstanceUID, SeriesInstanceUID }) => {
console.warn(`INSTANCES_ADDED::\nStudy:${StudyInstanceUID}\nSeries:${SeriesInstanceUID}`);
const seriesMetadata = DicomMetadataStore.getSeries(
StudyInstanceUID,
SeriesInstanceUID