Skip to content

Commit

Permalink
Merge pull request #668 from PaulHax/thumbnail-fail
Browse files Browse the repository at this point in the history
fix(PatientStudyVolumeBrowser): show modality if thumbnail fails
  • Loading branch information
floryst authored Oct 23, 2024
2 parents b649c65 + aae2183 commit 011991c
Showing 1 changed file with 30 additions and 3 deletions.
33 changes: 30 additions & 3 deletions src/components/PatientStudyVolumeBrowser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ function dicomCacheKey(volKey: string) {
return `dicom-${volKey}`;
}
type Thumbnail =
| { kind: 'image'; value: string }
| { kind: 'text'; value: string };
// Assume itkImage type is Uint8Array
function itkImageToURI(itkImage: Image) {
const [width, height] = itkImage.size;
Expand Down Expand Up @@ -116,7 +120,7 @@ export default defineComponent({
// --- thumbnails --- //
const thumbnailCache = reactive<Record<string, string>>({});
const thumbnailCache = reactive<Record<string, Thumbnail>>({});
watch(
volumeKeys,
Expand All @@ -131,7 +135,12 @@ export default defineComponent({
const thumb = await generateDICOMThumbnail(dicomStore, key);
if (thumb !== null) {
const encodedImage = itkImageToURI(thumb);
thumbnailCache[cacheKey] = encodedImage;
thumbnailCache[cacheKey] = { kind: 'image', value: encodedImage };
} else {
thumbnailCache[cacheKey] = {
kind: 'text',
value: dicomStore.volumeInfo[key].Modality,
};
}
} catch (err) {
if (err instanceof Error) {
Expand All @@ -140,6 +149,10 @@ export default defineComponent({
details: `${err}. More details can be found in the developer's console.`,
});
}
thumbnailCache[cacheKey] = {
kind: 'text',
value: dicomStore.volumeInfo[key].Modality,
};
}
});
Expand Down Expand Up @@ -240,7 +253,12 @@ export default defineComponent({
cover
height="150"
width="150"
:src="(thumbnailCache || {})[volume.cacheKey] || ''"
:src="
(thumbnailCache[volume.cacheKey] &&
thumbnailCache[volume.cacheKey].kind === 'image' &&
thumbnailCache[volume.cacheKey].value) ||
''
"
>
<template v-slot:placeholder>
<v-row
Expand All @@ -249,9 +267,18 @@ export default defineComponent({
justify="center"
>
<v-progress-circular
v-if="thumbnailCache[volume.cacheKey] === undefined"
indeterminate
color="grey-lighten-5"
/>
<span
v-else-if="
thumbnailCache[volume.cacheKey] &&
thumbnailCache[volume.cacheKey].kind === 'text'
"
>
{{ thumbnailCache[volume.cacheKey].value }}
</span>
</v-row>
</template>
<persistent-overlay>
Expand Down

0 comments on commit 011991c

Please sign in to comment.