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

[dicom-dump] Add json output format #440

Merged
merged 11 commits into from
Aug 13, 2024
Merged

Conversation

naterichman
Copy link
Contributor

Add flag to output in dicom json format

Copy link
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

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

Great initiative, thank you! Some inline suggestions follow.

For transparency, I intend to throw a new patch release of the project soon, which will not include these new PRs, but after 0.6.3 we can start reviewing greater changes towards 0.7.

dump/src/lib.rs Outdated Show resolved Hide resolved
dump/src/main.rs Outdated Show resolved Hide resolved
@Enet4 Enet4 added enhancement A-tool Area: tooling C-dump Crate: dicom-dump labels Feb 24, 2024
naterichman and others added 3 commits February 24, 2024 10:49
* Change option from output to format
* Pretty print to writer instead of to string
@Enet4
Copy link
Owner

Enet4 commented Feb 24, 2024

So I took the liberty of continuing with this pull request:

  • rebased it to the latest upstream revision
  • updated the doc comment for DumpFormat::Json
  • ensured that dumping as JSON also works for regular (non-file) DICOM objects
  • added a test for dumping a small DICOM object as JSON
  • feature-gated deriving EnumValue on DumpFormat (only works with Cargo feature "cli")

Alas, this might have hit a very weird bug in Rust, because it started raising absurd errors in another crate. I might need to look for advice with members of the Rust team on how to diagnose this.

@naterichman
Copy link
Contributor Author

Thanks for working on this, sorry I've been AWOL, my day job has been very busy! Just checking, is there anything I can do here to help? I still plan on working on my other PR as well

@Enet4
Copy link
Owner

Enet4 commented Mar 1, 2024

Thank you for the heads-up. I managed to get things sorted out in this PR. I suspect at this point that the dependency changes may have introduced trait implementations which ambiguated the != comparison between message IDs in dicom-echoscu, leading to the unrelated error. So no more interventions should be required here, I'll just be some final testing before merging.

I would certainly be grateful if you did another iteration on #437, so we can complete that one as well.

@Enet4
Copy link
Owner

Enet4 commented Mar 10, 2024

Further testing shows that the tool chokes a bit on files with encapsulated pixel data, whereas it would be nicer if it just ignored the pixel data with a warning. I suspect that this would complicate the implementation though.

@naterichman
Copy link
Contributor Author

Sorry for the delay on this one, kinda forgot about it! I added a simple serializer for PixelDataFragments which splits it up into the offset table and the fragments. LMK your thoughts. I thought about just ignoring the PixelData, but I realized that would make the behavior inconsistent with the text output. Would be pretty easy to just ignore it if you think thats better, lmk

Copy link
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

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

Thank you for your commitment to this PR. I left some feedback inline.

let offset_table = self.inner().offset_table();
let fragments = self.inner().fragments();
let mut map = serializer.serialize_map(Some(2))?;
map.serialize_entry("Offset Table", offset_table)?;
Copy link
Owner

Choose a reason for hiding this comment

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

I have mixed feelings about this. :) It may be interesting for encapsulated pixel data serialization to be supported in some way, but it may also be surprising for this to exist as a non-standard extension provided specifically by this implementation.

I think we'd be able to serve both worlds if we did the following in this order:

  1. At dicom-dump, we can check whether Pixel Data is encapsulated, raise a warning that it will be ignored, and remove it from the dataset before the dump.
  2. Later on, we can make it possible to provide parameters to the serialization process, so that the decision of whether to serialize encapsulated pixel data or not can be explicitly stated by the API user or the dicom-dump user.
    • IIRC we don't quite have a way to do this yet. Intuitively I would make this a field of DicomJson, but since it is defined as a single item tuple, adding new fields is likely breaking change (which could probably be mitigated through some tricker, but a breaking change nevertheless).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I left the serialize implementation for PixelFragmentSequence for when/if we do want to support that, but I can remove if you don't want unused code

Copy link
Owner

@Enet4 Enet4 left a comment

Choose a reason for hiding this comment

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

This seems to be in good order now. Thanks! 👍

@Enet4 Enet4 merged commit 4ae7ebb into Enet4:master Aug 13, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tool Area: tooling C-dump Crate: dicom-dump enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants