Skip to content

454 refactored Encoding/Decoding logic to expose DICOM encoding mappings for consumption - #455

Closed
luissantosHCIT wants to merge 59 commits into
dcmjs-org:masterfrom
luissantosHCIT:454_incorrect_decoding_of_iso_ir_100
Closed

luissantosHCIT wants to merge 59 commits into
dcmjs-org:masterfrom
luissantosHCIT:454_incorrect_decoding_of_iso_ir_100

Conversation

@luissantosHCIT

Copy link
Copy Markdown
Contributor

Fixes #454.

Although, I did not find any bugs with dcmjs, some of the tooling in the library could be better exposed for consumption in other projects. I focus on exposing the DICOM buffer decoding here given an initial SpecificCharacterSet. If translation is not necessary, a few convenience methods are provided to set the correct encoder or decoder on demand.

This is a code cleanup / reorganization kind of PR.

Jest tests passed.
I did not add any new tests since there is coverage from the current tests and the one class I added is trivial.

Luis M. Santos added 6 commits August 19, 2025 09:00
…the same logic can be used elsewhere and hopefully it is clearer. Functionality should remain the same.
…used by BufferStream but also can be used elsewhere.

Added export of new DicomBufferCODEC class.
@netlify

netlify Bot commented Aug 19, 2025 •

Copy link
Copy Markdown

✅ Deploy Preview for dcmjs2 ready!

Name Link
🔨 Latest commit f44ed90
🔍 Latest deploy log https://app.netlify.com/projects/dcmjs2/deploys/6a02200a67d0fc0008dfe681
😎 Deploy Preview https://deploy-preview-455--dcmjs2.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 project configuration.

@luissantosHCIT

Copy link
Copy Markdown
Contributor Author

@pieper I went ahead and did some cleanup based on your comments in #454. In terms of the other issue (#373), I do not do anything here other than change the location of the logic in question which I partially move lower in the abstraction hierarchy. However, if I get some time in the near future and no one has addressed it, I might take a stab. I think that the reasonable approach is to find the specific character set at the level of the tree in the header and use that for that level only. That can get a bit complex than I have time at the moment and I will need to consult the standard for other potential cases.

@pieper
pieper requested a review from wayfarer3130 August 19, 2025 19:39
@pieper

pieper commented Aug 19, 2025

Copy link
Copy Markdown
Collaborator

From a quick look I think the PR looks good 👍

I'd like another set of eyes on it though, so hopefully @wayfarer3130 can take a look too.

@luissantosHCIT

Copy link
Copy Markdown
Contributor Author

@wayfarer3130 checking in if there is anything you think I should improve on in this PR. No rush, I know you have been very helpful in other PRs and very busy. I am just helping keep this PR in people's minds in case there is a chance to merge. Thank you!

Comment thread src/DicomMetaDictionary.js Resolved
Comment thread src/DicomMetaDictionary.js Resolved
Comment thread src/DicomMessage.js Resolved
Comment thread src/BufferStream.js Resolved
luissantosHCIT and others added 15 commits March 6, 2026 13:40
Signed-off-by: Luis M. Santos <[email protected]>
…y changing the stream decoder.

Signed-off-by: Luis M. Santos <[email protected]>
… sure it is clear that regardless of encoding we reset it to utf-8 after setting up the internal buffer stream for decoding.

chore added unit tests to make sure future changes to this logic clearly shows that we expect one encoding.

Signed-off-by: Luis M. Santos <[email protected]>
…er and decoder sides use the same default encoding.

Signed-off-by: Luis M. Santos <[email protected]>
… to .has() since constants were converted to Sets, and cleaned up some vars into lets and consts.

Signed-off-by: Luis M. Santos <[email protected]>
@pieper

pieper commented Mar 16, 2026

Copy link
Copy Markdown
Collaborator

Looks like a couple remaining check issues.

I'm thinking someone should try building OHIF or other projects off this branch for some testing. I wonder if we should add that as a build check on PRs to get a netlify hosted test version or similar.

@luissantosHCIT

Copy link
Copy Markdown
Contributor Author

Looks like a couple remaining check issues.

I'm thinking someone should try building OHIF or other projects off this branch for some testing. I wonder if we should add that as a build check on PRs to get a netlify hosted test version or similar.

I was going to do that after the merge, but you are right.

I will do that now instead in my OHIF PR branch to see if there are issues I will need to address.

@wayfarer3130

Copy link
Copy Markdown
Contributor

Looks like a couple remaining check issues.
I'm thinking someone should try building OHIF or other projects off this branch for some testing. I wonder if we should add that as a build check on PRs to get a netlify hosted test version or similar.

I was going to do that after the merge, but you are right.

I will do that now instead in my OHIF PR branch to see if there are issues I will need to address.

There is a change just being worked on right now in CS3D that allows building OHIF previews/running tests and running the OHIF PR tests with a just built CS3D version - it would be very nice to have the same sort of thing.

The OHIF side works well now, but the CS3D side isn't quite there yet.

@luissantosHCIT

Copy link
Copy Markdown
Contributor Author

A few updates from my side:

  • I cleared up the reported unused imports.
  • I found I was using a much newer version of node and that is why I was not getting errors when running the test suites, but I was able to replicate the errors now. I am addressing the errors now.
  • Modifying the package.json to include "dcmjs": "https://github.com/luissantosHCIT/dcmjs.git#454_incorrect_decoding_of_iso_ir_100" in every workspace generates module not found errors after running yarn install. Do I need to do something else to temporarily switch to use this branch to test the OHIF Viewer? @wayfarer3130

…file and turned it into a Map.

Signed-off-by: Luis M. Santos <[email protected]>
…adjusted its usage in normalizers.

Signed-off-by: Luis M. Santos <[email protected]>
@luissantosHCIT

Copy link
Copy Markdown
Contributor Author

Assuming I did not miss an unused import, all that is left is for me to figure out how to make OHIF accept my branch in package.json.

@luissantosHCIT

Copy link
Copy Markdown
Contributor Author

Nvm, I figured it out. I needed to import from my local project directory instead from github because the repo lacks a copy of the built bundle by default. Oops.

I am currently testing the viewer using my built copy of dcmjs.

@luissantosHCIT

luissantosHCIT commented Mar 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Tests done with my OHIF branch pointing to this dcmjs branch:

  • All unit tests
  • Cypress E2E tests
  • Manual opening of cases
  • Manual navigation
  • Manual review of one of the Cypress tests

The Cypress tests showed an error. This error was present regardless of which version of dcmjs was in use. The error did not occur when I manually navigated to the case and opened it following the test's steps.

Screenshot From 2026-03-18 13-02-57

My conclusion is that the dcmjs changes here do not affect the OHIF side. Do try yourselves in case I missed a way to force bugs out of this dcmjs repo from the OHIF Viewer.

@pieper @wayfarer3130

@fedorov

fedorov commented Mar 19, 2026

Copy link
Copy Markdown
Collaborator

@igoroctaviano do you want to take a look at this - mostly to make sure this does not negatively affect functionality important for IDC?

@igoroctaviano

Copy link
Copy Markdown
Collaborator

@igoroctaviano do you want to take a look at this - mostly to make sure this does not negatively affect functionality important for IDC?

From static analysis alone of the code, for dicom-microscopy-viewer, ohif fork and slim looks like this does not introduce compatibility problems. Residual risk is behavioral, like string decoding for certain character sets, but I ran slim/dmv/ohif linked here, and it seems fine..

@luissantosHCIT

Copy link
Copy Markdown
Contributor Author

@pieper Just a small poke to ask if there is anything else needed to merge this change.
Thank you!

@pieper

pieper commented May 11, 2026

Copy link
Copy Markdown
Collaborator

Sorry for the delays @luissantosHCIT - I've become a bit gunshy in merging. This one's a lot to parse, especially with all the formatting and other small changes that make it hard to see the big picture. I kind of wish those were a separate PR but that may just be extra work at this point.

Looks like it's now got a conflict with the main branch.

Assuming that gets resolved it sounds like Igor is okay so maybe @wayfarer3130 can chime in if all his issues got resolved.

@luissantosHCIT

Copy link
Copy Markdown
Contributor Author

Sorry for the delays @luissantosHCIT - I've become a bit gunshy in merging. This one's a lot to parse, especially with all the formatting and other small changes that make it hard to see the big picture. I kind of wish those were a separate PR but that may just be extra work at this point.

Looks like it's now got a conflict with the main branch.

Assuming that gets resolved it sounds like Igor is okay so maybe @wayfarer3130 can chime in if all his issues got resolved.

I completely understand. This is a foundational project that affects many people!

Let me see what the conflict is and resolve it for you.

I am just making sure that the PR does not get forgotten if it can be merged since at some point I might just forget about it as well. Haha.

@luissantosHCIT

Copy link
Copy Markdown
Contributor Author

Looks like in this PR I had moved the VR constants to their own location for usage in multiple sources but main had the pre-PR change. I kept my change here since we handle the refactor here.

This reminds me of the VR refactor/clean up I was trying to do a while back and which I forked into its own ticket. I am currently working on optimizing my Rust-based HL7 interface toolkit so I will not get to finish that work (#480) for some time now. If it sits without progress for a year, feel free to ask me to close it or you can close it yourself at that point.

I agree about keeping the PRs simpler moving forward. I prefer to reach "checkpoints" in a complex objective myself. I will try to improve on where to draw the line on changes and break the PRs further.

@luissantosHCIT

Copy link
Copy Markdown
Contributor Author

I have not been able to be on top of this feature due to business development, financials, unemployment, & my own project.

What do I need to do to get my PR accepted now that I have found a week for development?

I would like to get credit for the hours I put on this PR and re-assess what follow up PRs are needed to reach an ideal state.

@wayfarer3130 @pieper

@wayfarer3130

Copy link
Copy Markdown
Contributor

Thank you, @luissantosHCIT, for this work and for your patience during the long review. Your ideas are now in #650, on the 1.0 branch. You are co-author of each commit in #650.

#650 takes these ideas from this PR:

  • The buffer stream constructors take an options object, with little endian as the default. The 0.x form still works.
  • The charset table can be extended. registerCharacterSet adds a term with a decode function and an encode function. The writer now encodes text in the declared SpecificCharacterSet.
  • The VR lists have one copy. Vrs and registerVr replace the separate lists. The SOP class list uses the same pattern (SopClasses, registerSopClass).

#650 does not take the DicomTextTranscode class. The 1.0 branch already has a charset module (packages/core/src/charset/) that does this work.

The SR text problem of #454 has a different cause. BufferStream.more() gives each sequence item a new latin1 decoder. #520 and #609 fix that cause.

We will close this PR when #650 is ready.

🤖 Generated with Claude Code

@wayfarer3130

Copy link
Copy Markdown
Contributor

@luissantosHCIT - I've merged an equivalent change against the 1.0 beta branch, so I'm closing this PR.

@github-project-automation github-project-automation Bot moved this from Todo to Done in dcmjs roadmap Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Wrong decoding from ISO 2022 IR 100 to ISO IR 192 (UTF-8)?

5 participants