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

feat(MetadataLoading) : enable metadata loading from images #3573

Closed
wants to merge 3 commits into from

Conversation

gpasquie
Copy link

@gpasquie gpasquie commented Aug 1, 2023

Context

The goal of this PR is to allow the MetadataProvider to read the metadata of dicom images directly without making an extra WADO-RS Metadata request to the PACS.
Internaly it uses dataSetCacheManager of dicomImageLoader to access the DICOM dataset. Then dcmjs parse the dataset and add the metadata to the MetadataStore.
This PR allow the DicomJSON source to provide only the image UID + instance number without the need of putting all the image metadata into the final .json.

You can enable or disable this behavior with the variable automaticallyLoadDicomMetadata in the config file.

Changes & Results

Testing

This can be tested using a regular JSON DataSource where only SeriesInstanceUID, StudyInstanceUID, SOPClassUID and InstanceNumber must be present.

Checklist

PR

  • My Pull Request title is descriptive, accurate and follows the
    semantic-release format and guidelines.

Code

  • My code has been well-documented (function documentation, inline comments,
    etc.)

Public Documentation Updates

  • [] The documentation page has been updated as necessary for any public API
    additions or removals.

Tested Environment

  • OS: Windows 10
  • [] Node version:
  • Browser: Chrome 115.0.5790.110, Firefox 115.0.3

blabbe added 3 commits August 1, 2023 16:19
This commit allow OHIF to check when needed if the displaySet are reconstructible.
This allow loading metadata after the initial viewport init and still display the MBR
@netlify
Copy link

netlify bot commented Aug 1, 2023

Deploy Preview for ohif-platform-docs ready!

Name Link
🔨 Latest commit e4b0869
🔍 Latest deploy log https://app.netlify.com/sites/ohif-platform-docs/deploys/64c92d9576621900084be78e
😎 Deploy Preview https://deploy-preview-3573--ohif-platform-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@netlify
Copy link

netlify bot commented Aug 1, 2023

Deploy Preview for ohif-dev ready!

Name Link
🔨 Latest commit e4b0869
🔍 Latest deploy log https://app.netlify.com/sites/ohif-dev/deploys/64c92d95c164df0009a721a9
😎 Deploy Preview https://deploy-preview-3573--ohif-dev.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@sedghi
Copy link
Member

sedghi commented Aug 2, 2023

so this is only for the dicomJSON right? since for the dicomweb there is no extra call to the PACS and the metadata provider already have all the necessary information from the instance call

@gpasquie
Copy link
Author

gpasquie commented Aug 2, 2023

Maybe we missed something in the recent changes, but in the previous versions, OHIF was doing a WADO-RS Metadata request before retrieving the instances, so we thought this could be useful as well for the dicomweb mode, as long as you know the studies, series and instances UIDs.
But in our case, yes, we are mostly interested in reducing the metadata in the JSON datasource. Actually, we are trying to open OHIF from a DICOM Key Object Selection (KOS), which usually does not contain all the images metadata (rows, column, ...).

@sedghi
Copy link
Member

sedghi commented Aug 2, 2023

I see.
We indeed fire a metadata for wadors since that is needed to layout the viewer before the instance call for the dicomweb.
I will review your PR, the immediate thing that comes to my attention is the added dependency of cornerstone and dcmjs into the core

import dicomImageLoader from '@cornerstonejs/dicom-image-loader';
import dcmjs from 'dcmjs';

which ideally should not happen. But I will give my in-depth comments today/tomorrow

Thanks!

@@ -95,6 +95,29 @@ function _getInstanceByImageId(imageId) {
}
}

function _updateInstance(StudyInstanceUID, SeriesInstanceUID, SOPInstanceUID, metadata) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer _updateMetadataForInstance for consistency with next method

Comment on lines +98 to +104
callback: displaySet => {
const {
value: isReconstructable,
missingFrames: missingFrames,
} = isDisplaySetReconstructable(displaySet.instances);

return isReconstructable && missingFrames == 0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think an idea would be to fire and event in the dicomMetadataStore when an instance is updated and maybe recalculate the displaySet.isReconstructable in an event handler?

This will most likely break the dicomweb or if not break would slow it down

Comment on lines +209 to +211
// We need to force this flag to false in case the client wants to load the metadata from the image
// directly with automaticallyLoadDicomMetadata
imageMetadataLoaded: false
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about only make it false if only series/studies/sop UID are provided. For other use cases where we have the full metadata in the JSON this doesn't makes sense to be false and later in the provider it checks and reads again etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you follow the suggestions further in this, then you can figure out when to load appropriately just by which loader it is calling, so there wouldn't be any setting here at all.

Comment on lines +10 to +11
import dicomImageLoader from '@cornerstonejs/dicom-image-loader';
import dcmjs from 'dcmjs';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought these are new dependencies but seems like we already have them although I prefer if we can find a way to not call dicomImageLoader in the provider here, any thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I would suggest is having a lazy load function to call that if it is defined in the metadata, it can be called to replace the metadata with a full load version of it - which then removes the function from the metadata. That way, different providers can provide different versions of the function, some of which might do the dcmjs thing, and others might load JSON metadata, while others might just read bulkdata information which is missing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this

// is set.
// To make your data source compatible with this you'll have to explicitly
// set the instance.imageMetadataLoaded to false
if (this.automaticallyLoadDicomMetadata && (instance.imageMetadataLoaded === false)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I said above, I prefer not to call the dicomImageLoader here, but even with calling it here, I don't think we need a new flag. We can derive the flag status from whether it has all necessary metadata (we should create a schema for that somewhere to validate againts, that also helps people to know what metadata is necessary) and if not we automatically switch to the dicomloader+dcmjs how about that?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wayfarer3130 any thought on where to call the dicomImageLoader + dcmjs other than here? (ideally they should not be here)

Copy link
Member

@sedghi sedghi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see my comments. Thanks again!

@@ -22,6 +22,9 @@ window.config = {
// above, the number of requests can be go a lot higher.
prefetch: 25,
},
// Allow Metadataprovider to parse dicom images as it retrieves it
// Only works with dicom json datasource for now
automaticallyLoadDicomMetadata: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the JSON itself specify this information? That way a JSON can say whether it already has full metadata or not. Something that just specifies SOP UID's would say no, while those that have enough for display might still load it automatically, but not delay processing in order to load it?

@sedghi
Copy link
Member

sedghi commented Aug 14, 2023

can you give this a look please? @moalsad

@moalsad
Copy link

moalsad commented Sep 7, 2023

can you give this a look please? @moalsad

I agree that dicomImageLoader + dcmjs should be placed somewhere else more specific to the (JSON) data source.

@gpasquie
Copy link
Author

Replaced by #3935

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants