rbeckman-nextgen / test-mc3

0 stars 0 forks source link

DICOM data type cannot parse files with certain control characters in tags #3021

Open rbeckman-nextgen opened 4 years ago

rbeckman-nextgen commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

Workaround till ticket is resolved.

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

rbeckman-nextgen commented 4 years ago

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