Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PatientStudyVolumeBrowser): show modality if thumbnail fails #668

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading