Announcement

Collapse
No announcement yet.

Convert DICOM to XML with BasicDicomObject

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Convert DICOM to XML with BasicDicomObject

    Hello everyone,

    I wrote a script to query a ModalityWorklist from within Mirth 3.4.X
    Each result I get from the worklist is put into an array.
    So each element of this array belongs to the class BasicDicomObject

    I checked this with the getRoot() method. My DICOM object is ok.

    So I tried to convert into the default XML:
    Code:
    for (i = 0; i < resultArray.length; i++) {
    
    	dicom = resultArray[i].getRoot()
    	finaldcm = SerializerFactory.getSerializer('DICOM').toXML(dicom);
    but I get this error:
    Transformer error
    ERROR MESSAGE: Error evaluating transformer
    com.mirth.connect.server.MirthJavascriptTransforme rException:
    CHANNEL: DCM Worklist Query
    CONNECTOR: Destination 1
    SCRIPT SOURCE: TRANSFORMER
    SOURCE CODE:
    1033: for (i = 0; i < resultArray.length; i++) {
    1034:
    1035: dicom = resultArray[i].getRoot()
    1036: //logger.info(dicom)
    1037: logger.info('dicom: ' + typeof(dicom) + '\r\n' + dicom)
    1038: finaldcm = SerializerFactory.getSerializer('DICOM').toXML(dic om);
    1039:
    1040: //dcmba = new String(DICOMUtil.dicomObjectToByteArray(dicom) )
    1041: //finaldcm = SerializerFactory.getSerializer('DICOM').toXML(dcm ba);
    1042:
    LINE NUMBER: 1038
    DETAILS: Wrapped com.mirth.connect.donkey.model.message.MessageSeri alizerException: Error converting DICOM to XML
    at ff5541b9-52cc-4a6b-8f98-10ddb72b67d0:1038 (doTransform)
    at ff5541b9-52cc-4a6b-8f98-10ddb72b67d0:1070 (doScript)
    at ff5541b9-52cc-4a6b-8f98-10ddb72b67d0:1072
    at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:154)
    at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:119)
    at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
    at java.util.concurrent.FutureTask.run(FutureTask.jav a:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: com.mirth.connect.donkey.model.message.MessageSeri alizerException: Error converting DICOM to XML
    at com.mirth.connect.plugins.datatypes.dicom.DICOMSer ializer.toXML(DICOMSerializer.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mozilla.javascript.MemberBox.invoke(MemberBox. java:126)
    at org.mozilla.javascript.NativeJavaMethod.call(Nativ eJavaMethod.java:225)
    at org.mozilla.javascript.Interpreter.interpretLoop(I nterpreter.java:1479)
    at org.mozilla.javascript.Interpreter.interpret(Inter preter.java:815)
    at org.mozilla.javascript.InterpretedFunction.call(In terpretedFunction.java:109)
    at org.mozilla.javascript.ContextFactory.doTopCall(Co ntextFactory.java:393)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(Scr iptRuntime.java:3280)
    at org.mozilla.javascript.InterpretedFunction.exec(In terpretedFunction.java:120)
    at com.mirth.connect.server.util.javascript.JavaScrip tTask.executeScript(JavaScriptTask.java:142)
    at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:143)
    ... 6 more
    Caused by: org.dcm4che2.io.DicomCodingException: Not a DICOM Stream
    at org.dcm4che2.io.DicomInputStream.guessTransferSynt ax(DicomInputStream.java:288)
    at org.dcm4che2.io.DicomInputStream.<init>(DicomInput Stream.java:150)
    at com.mirth.connect.plugins.datatypes.dicom.DICOMSer ializer.toXML(DICOMSerializer.java:152)
    ... 20 more
    So according to this I need an InputStream, so I've setup a DicomInputStream. I converted the DICOM Object to a ByteArray and so on ...

    Code:
    for (i = 0; i < resultArray.length; i++) {
    
    	dicom = resultArray[i].getRoot()
    	dcmba = new String(DICOMUtil.dicomObjectToByteArray(dicom) )
    
    	jis = new java.io.InputStream(dcmba)
    	bis = java.io.BufferedInputStream(jis)
    	dis = new org.dcm4che2.io.DicomInputStream(bis)
    	finaldcm = SerializerFactory.getSerializer('DICOM').toXML(dis);
    
    }
    I am not quite sure about the "new String()" method but without this it errors already when converting from DICOM to ByteArray. This code works... somehow.

    Anyway, even with InputStreams and bytearray, I still get this error:
    Transformer error
    ERROR MESSAGE: Error evaluating transformer
    com.mirth.connect.server.MirthJavascriptTransforme rException:
    CHANNEL: DCM Worklist Query
    CONNECTOR: Destination 1
    SCRIPT SOURCE: TRANSFORMER
    SOURCE CODE:
    1041: //finaldcm = SerializerFactory.getSerializer('DICOM').toXML(dcm ba);
    1042:
    1043: jis = new java.io.InputStream(dcmba)
    1044: bis = java.io.BufferedInputStream(jis)
    1045: dis = new org.dcm4che2.io.DicomInputStream(bis)
    1046: finaldcm = SerializerFactory.getSerializer('DICOM').toXML(dis );
    1047:
    1048: }
    1049: if ('xml' === typeof msg) {
    1050: if (msg.hasSimpleContent()) {
    LINE NUMBER: 1046
    DETAILS: Wrapped com.mirth.connect.donkey.model.message.MessageSeri alizerException: Error converting DICOM to XML
    at 896bff53-9a36-4dd3-935a-d9c3a2199010:1046 (doTransform)
    at 896bff53-9a36-4dd3-935a-d9c3a2199010:1070 (doScript)
    at 896bff53-9a36-4dd3-935a-d9c3a2199010:1072
    at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:154)
    at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:119)
    at com.mirth.connect.server.util.javascript.JavaScrip tTask.call(JavaScriptTask.java:113)
    at java.util.concurrent.FutureTask.run(FutureTask.jav a:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker( ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
    Caused by: com.mirth.connect.donkey.model.message.MessageSeri alizerException: Error converting DICOM to XML
    at com.mirth.connect.plugins.datatypes.dicom.DICOMSer ializer.toXML(DICOMSerializer.java:193)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.mozilla.javascript.MemberBox.invoke(MemberBox. java:126)
    at org.mozilla.javascript.NativeJavaMethod.call(Nativ eJavaMethod.java:225)
    at org.mozilla.javascript.Interpreter.interpretLoop(I nterpreter.java:1479)
    at org.mozilla.javascript.Interpreter.interpret(Inter preter.java:815)
    at org.mozilla.javascript.InterpretedFunction.call(In terpretedFunction.java:109)
    at org.mozilla.javascript.ContextFactory.doTopCall(Co ntextFactory.java:393)
    at org.mozilla.javascript.ScriptRuntime.doTopCall(Scr iptRuntime.java:3280)
    at org.mozilla.javascript.InterpretedFunction.exec(In terpretedFunction.java:120)
    at com.mirth.connect.server.util.javascript.JavaScrip tTask.executeScript(JavaScriptTask.java:142)
    at com.mirth.connect.server.transformers.JavaScriptFi lterTransformer$FilterTransformerTask.doCall(JavaS criptFilterTransformer.java:143)
    ... 6 more
    Caused by: org.dcm4che2.io.DicomCodingException: Not a DICOM Stream
    at org.dcm4che2.io.DicomInputStream.guessTransferSynt ax(DicomInputStream.java:288)
    at org.dcm4che2.io.DicomInputStream.<init>(DicomInput Stream.java:150)
    at com.mirth.connect.plugins.datatypes.dicom.DICOMSer ializer.toXML(DICOMSerializer.java:152)
    ... 20 more
    any ideas?

  • #2
    I just reworked my code and also used Output instead of Input Streams.
    Anyway, no luck.
    Code:
    for (i = 0; i < resultArray.length; i++) {
    
    	dicom = resultArray[i].getRoot()
    	byteArray = new DICOMUtil.dicomObjectToByteArray(dicom)
    	
    	fos = new java.io.ByteArrayOutputStream()
    	bos = new java.io.BufferedOutputStream(fos)
    	dos = new org.dcm4che2.io.DicomOutputStream(bos)
    	dos.write(byteArray)
    
    	logger.info(byteArray)
    	logger.info(dos)
    
    	SerializerFactory.getSerializer('DICOM').toXML(dos);
    	
    	dos.close()
    	bos.close()
    	fos.close()
    }

    EDIT:
    I tried to do something redundant. In the next code I used the DICOMUtil to convert my DICOM Object into a ByteArray and back into a DICOM object.
    Code:
    for (i = 0; i < resultArray.length; i++) {
    
    	dicom = resultArray[i].getRoot()
    	byteArray = new DICOMUtil.dicomObjectToByteArray(dicom)
    	dcm = new DICOMUtil.byteArrayToDicomObject(byteArray)
    	SerializerFactory.getSerializer('DICOM').toXML(dcm);
    
    }
    it fails,

    1039: dcm = new DICOMUtil.byteArrayToDicomObject(byteArray)
    1040: //logger.info(dcm)
    1041: SerializerFactory.getSerializer('DICOM').toXML(dcm );
    1042:
    1043: }
    LINE NUMBER: 1039
    DETAILS: Can't find method com.mirth.connect.server.userutil.DICOMUtil.byteAr rayToDicomObject([B).
    it looks again like the "java vs JS string error" but maybe I am completely wrong anyway.
    Last edited by gkittlaus; 09-28-2016, 05:26 AM.

    Comment


    • #3
      can you help me?

      Hello,

      I am pretty new to mirth and saw the your posting.I hold the belief that you are capble of solving my problem.And I hope that you can help me.
      I want to convert DICOM to XML with mirth,however,I don't know the concrete steps,can you show me?

      Comment

      Working...
      X