-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(nifti): pass through DICOM metadata for NIfTI-backed display sets #5970
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
4aa7f30
8a07109
08902ec
1d61e11
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,5 @@ | ||||||||||||||||||||||||||
| import { utils, classes } from '@ohif/core'; | ||||||||||||||||||||||||||
| import { createNiftiImageIdsAndCacheMetadata } from '@cornerstonejs/nifti-volume-loader'; | ||||||||||||||||||||||||||
| import i18n from '@ohif/i18n'; | ||||||||||||||||||||||||||
| import { id } from './id'; | ||||||||||||||||||||||||||
| import getDisplaySetMessages from './getDisplaySetMessages'; | ||||||||||||||||||||||||||
|
|
@@ -14,6 +15,23 @@ const DYNAMIC_VOLUME_LOADER_SCHEME = 'cornerstoneStreamingDynamicImageVolume'; | |||||||||||||||||||||||||
| const sopClassHandlerName = 'stack'; | ||||||||||||||||||||||||||
| let appContext = {}; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const isAbsolutePathOrUrl = value => | ||||||||||||||||||||||||||
| typeof value === 'string' && | ||||||||||||||||||||||||||
| (/^[a-z]+:\/\//i.test(value) || value.startsWith('//') || value.startsWith('/')); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const joinUrl = (baseUrl, path) => { | ||||||||||||||||||||||||||
| if (!baseUrl) { | ||||||||||||||||||||||||||
| return path; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
| return new URL(path, baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`).toString(); | ||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||
| const normalizedBaseUrl = baseUrl.endsWith('/') ? baseUrl : `${baseUrl}/`; | ||||||||||||||||||||||||||
| return `${normalizedBaseUrl}${path.replace(/^\/+/, '')}`; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const getDynamicVolumeInfo = instances => { | ||||||||||||||||||||||||||
| const { extensionManager } = appContext; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
@@ -96,6 +114,14 @@ const makeDisplaySet = (instances, index) => { | |||||||||||||||||||||||||
| // set appropriate attributes to image set... | ||||||||||||||||||||||||||
| const messages = getDisplaySetMessages(instances, isReconstructable, isDynamicVolume); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const { niftiPrivateTagName, niftiBaseUrl } = dataSource.getConfig?.() || {}; | ||||||||||||||||||||||||||
| const niftiPath = niftiPrivateTagName ? instance[niftiPrivateTagName] : undefined; | ||||||||||||||||||||||||||
| let niftiURL; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (typeof niftiPath === 'string' && niftiPath.trim().length > 0) { | ||||||||||||||||||||||||||
| niftiURL = isAbsolutePathOrUrl(niftiPath) ? niftiPath : joinUrl(niftiBaseUrl, niftiPath); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
greptile-apps[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| imageSet.setAttributes({ | ||||||||||||||||||||||||||
| volumeLoaderSchema, | ||||||||||||||||||||||||||
| displaySetInstanceUID: imageSet.uid, // create a local alias for the imageSet UID | ||||||||||||||||||||||||||
|
|
@@ -124,6 +150,43 @@ const makeDisplaySet = (instances, index) => { | |||||||||||||||||||||||||
| FrameOfReferenceUID: instance.FrameOfReferenceUID, | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (niftiURL) { | ||||||||||||||||||||||||||
| // If a downstream integration already exposes a NIfTI URL on the series, | ||||||||||||||||||||||||||
| // pass through the DICOM-derived metadata that a paired loader-side | ||||||||||||||||||||||||||
| // implementation can consume for VOI and series registration. | ||||||||||||||||||||||||||
| const dicomMetadata = { | ||||||||||||||||||||||||||
| Modality: instance.Modality, | ||||||||||||||||||||||||||
| SeriesInstanceUID: instance.SeriesInstanceUID, | ||||||||||||||||||||||||||
| SeriesNumber: instance.SeriesNumber, | ||||||||||||||||||||||||||
| SeriesDescription: instance.SeriesDescription, | ||||||||||||||||||||||||||
| WindowCenter: instance.WindowCenter, | ||||||||||||||||||||||||||
| WindowWidth: instance.WindowWidth, | ||||||||||||||||||||||||||
| VOILUTFunction: instance.VOILUTFunction, | ||||||||||||||||||||||||||
| RescaleSlope: instance.RescaleSlope, | ||||||||||||||||||||||||||
| RescaleIntercept: instance.RescaleIntercept, | ||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| imageSet.setAttributes({ | ||||||||||||||||||||||||||
| niftiURL, | ||||||||||||||||||||||||||
| loadImageIds: async () => { | ||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||
| const loadedImageIds = await createNiftiImageIdsAndCacheMetadata({ | ||||||||||||||||||||||||||
| url: niftiURL, | ||||||||||||||||||||||||||
| dicomMetadata, | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| imageSet.setAttributes({ | ||||||||||||||||||||||||||
| imageIds: loadedImageIds, | ||||||||||||||||||||||||||
| numImageFrames: Array.isArray(loadedImageIds) ? loadedImageIds.length : 0, | ||||||||||||||||||||||||||
| isReconstructable: true, | ||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
|
Comment on lines
+180
to
+184
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't force If 🐛 Proposed fix+ const hasImageIds = Array.isArray(loadedImageIds) && loadedImageIds.length > 0;
+
imageSet.setAttributes({
imageIds: loadedImageIds,
- numImageFrames: Array.isArray(loadedImageIds) ? loadedImageIds.length : 0,
- isReconstructable: true,
+ numImageFrames: hasImageIds ? loadedImageIds.length : 0,
+ isReconstructable: hasImageIds,
});📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||
| console.error('Error loading niftiURL:', error); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||
|
greptile-apps[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| const imageIds = dataSource.getImageIdsForDisplaySet(imageSet); | ||||||||||||||||||||||||||
| let imageId = imageIds[Math.floor(imageIds.length / 2)]; | ||||||||||||||||||||||||||
| let thumbnailInstance = instances[Math.floor(instances.length / 2)]; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.