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

How to stop DObject.read from setting some tags to nil? #76

Open
vas1468 opened this issue Sep 25, 2018 · 6 comments
Open

How to stop DObject.read from setting some tags to nil? #76

vas1468 opened this issue Sep 25, 2018 · 6 comments

Comments

@vas1468
Copy link

vas1468 commented Sep 25, 2018

I noticed that just by reading a dicom file,

dcm = DObject.read("some_file.dcm")

is setting some tags like (PatientID, StudyInstanceUID, SeriesInstanceUID) to nil.

There is any way to stop that and read all of the tags without removing any?

I do not want any anonymization or tags removal, just to replace PatientID, keep all other tags as they are and save to a different file.

Is this possible?

Environment:
Ruby 1.9.3
dicom 0.9.6

@dicom
Copy link
Owner

dicom commented Sep 25, 2018

If you want to just change the Patient's ID, then you can achieve that like this:

dcm = DObject.read("some_file.dcm")
dcm["0010,0020"].value = "12345"
dcm.write("new_file.dcm")

Hope that helps.

Best regards,
Chris

@vas1468
Copy link
Author

vas1468 commented Sep 25, 2018

Thanks for the quick reply Chris, I appreciate that.

If you want to just change the Patient's ID, then you can achieve that like this:

dcm = DObject.read("some_file.dcm")
dcm["0010,0020"].value = "12345"
dcm.write("new_file.dcm")

Hope that helps.

Best regards,
Chris

Thats Correct, but other tag elements like StudyInstanceUID become nil. I have used exactly the same code you have suggested above.

It looks like private tags are getting removed on DObject.read, there is such thing?

I can provide the file before and the file after if that helps.

Thanks in advance,
Vasos.

@dicom
Copy link
Owner

dicom commented Sep 26, 2018

Hmm, this is not expected. I am very surprised if this is the case. Any other tags (including private) should be left alone when this is performed.

Please provide your before and after example, so I can have a look at it.

Best regards,
Chris

@vas1468
Copy link
Author

vas1468 commented Sep 26, 2018

I was surprised as well. So the only code i executed after our discussion is:

dcm = DObject.read("1eb65c4a-059e-4518-be65-efe48063450d.dcm")
dcm.write("new_file.dcm")

The file size reduced from 1.7 MB to 852 bytes.
Archive.zip

Environment:
Ruby 1.9.3
dicom 0.9.6

Once again I appreciate your help :) Thanks.

@dicom
Copy link
Owner

dicom commented Sep 26, 2018

Thanks for supplying the file in question.

I understand now what is going on.

This DICOM file is actually invalid. It contains tags which have odd length (0010,0020 Patient ID and 0020,000D Study Instance UID). If you study the log, ruby-dicom will inform you that it failed reading the file because of this. With ruby-dicom 0.9.8, I get the following output:

W, [2018-09-26T12:32:04.527989 #1492]  WARN -- DICOM: Encountered a Data Element (0010,0020) with an invalid (odd) value length.
E, [2018-09-26T12:32:04.527989 #1492] ERROR -- DICOM: Parsing a Data Element has failed. This is likely caused by an inv alid DICOM encoding.

I would complain about this to the software responsible for outputting this DICOM file. From tag 0002,0013, the name of this software seems to be:
DWV_0.25.0-beta
(perhaps a good reason why its saying beta....)

That being said, it is possible ruby-dicom should still be able to parse this file, and I will look into that. Still though, this would not be a problem if the source software encoded this file properly.

Best regards,
Chris

@vas1468
Copy link
Author

vas1468 commented Sep 26, 2018

Amazingly I missed this on the log yeah.

DICOM: Parsing a Data Element has failed. This is likely caused by an invalid DICOM encoding. DICOM: Failed to parse this string as DICOM.

Seems like the initial parsing and encoding happening on js from that library is wrong yeah. :(

Thanks again

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

No branches or pull requests

2 participants