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 data type cannot parse files with certain control characters in tags #3041

Open
rbeckman-nextgen opened this issue May 11, 2020 · 5 comments

Comments

@rbeckman-nextgen
Copy link
Collaborator

@rbeckman-nextgen rbeckman-nextgen commented May 11, 2020

If a DICOM file contains control characters that are invalid for XML (other than pixel data that should already have been taken out by the attachment handler), and the channel has an active transformer, serialization will fail:

[2014-01-21 09:41:41,881] ERROR (Server:146): [Fatal Error] :1:709: Character reference "&#1" is an invalid XML character. [2014-01-21 09:41:41,882] ERROR (com.mirth.connect.model.converters.DocumentSerializer:112): org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 709; Character reference "&#1" is an invalid XML character.

We're currently using SAX to parse the DICOM data to and from XML, and it doesn't allow those invalid characters. We could use XPP instead, but then we'd probably have to recreate the ContentHandlerAdapter from dcm4che that is being used with SAX, and we'd be creating technically invalid XML anyway so that's not really a good option. Maybe a better option is to add a custom ContentHandler that can detect invalid characters and encode to Base64 automatically. Might not be feasible since SAX streams the character data, not sure.

Imported Issue. Original Details:
Jira Issue Key: MIRTH-3127
Reporter: narupley
Created: 2014-01-21T09:57:14.000-0800

@rbeckman-nextgen rbeckman-nextgen added this to the Future Planned milestone May 11, 2020
@rbeckman-nextgen
Copy link
Collaborator Author

@rbeckman-nextgen rbeckman-nextgen commented May 11, 2020

Attaching sample DICOM message to reproduce the issue with.

Imported Comment. Original Details:
Author: narupley
Created: 2014-01-21T09:57:54.000-0800

@rbeckman-nextgen
Copy link
Collaborator Author

@rbeckman-nextgen rbeckman-nextgen commented May 11, 2020

*This has performance issues but does work to avoid the main issue above. *

As a workaround for 3.5.2. 3.6.x and later should be able to use Addis' fix below via his attachment channel XML.

  1. Set all of your data types to RAW
  2. If you need to edit tags or get tags, you can use the dcm4che API along with all these other methods: https://www.dcm4che.org/docs/dcm4che-2.0.16-apidocs/org/dcm4che2/data/DicomObject.html

Example:
var dcmObj = DICOMUtil.byteArrayToDicomObject(FileUtil.decode(msg), false);
dcmObj.putString(0x61690010,org.dcm4che2.data.VR.LO,'your text here');
msg = FileUtil.encode(DICOMUtil.dicomObjectToByteArray(dcmObj));

  1. Set your template to either raw (if no changes) or transformed if you are making changes. This should allow you to do anything you need to do with the dcm4che API that you would normally be able to do with the Mirth API.

Imported Comment. Original Details:
Author: brianda
Created: 2019-01-13T21:37:18.000-0800

@rbeckman-nextgen
Copy link
Collaborator Author

@rbeckman-nextgen rbeckman-nextgen commented May 11, 2020

For those still looking for workaround.
Added DICOM raw channel example where edits are done via dcm4che API. - see attachments section.

Imported Comment. Original Details:
Author: addis144
Created: 2019-01-22T17:52:04.000-0800

@rbeckman-nextgen
Copy link
Collaborator Author

@rbeckman-nextgen rbeckman-nextgen commented May 11, 2020

Workaround till ticket is resolved.

Imported Comment. Original Details:
Author: addis144
Created: 2019-01-22T17:52:49.000-0800

@rbeckman-nextgen
Copy link
Collaborator Author

@rbeckman-nextgen rbeckman-nextgen commented May 11, 2020

My example is much slower because it is not using attachments. Addis's example channel is a much better workaround.

Imported Comment. Original Details:
Author: brianda
Created: 2019-01-23T13:23:16.000-0800

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

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.