Announcement

Collapse
No announcement yet.

Using Correct Java Sytax in Mirth via Javascript

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

  • Using Correct Java Sytax in Mirth via Javascript

    I'm using a custom library called aspose.words and I running into some trouble making sure I user the correct java classes and javascript syntax in Mirth to properly using Library via Mirth.

    I need to know how to translate byte[] buffer and ByteArrayInputStream in Mirth, see snippet of code in Java below.

    Mirth Version 3.2


    Code:
    // The document is stored in byte form in the FileContent column.
        // Retrieve these bytes of the first matching record to a new buffer.
        byte[] buffer = resultSet.getBytes("FileContent");
    
        // Wrap the bytes from the buffer into a new ByteArrayInputStream object.
        ByteArrayInputStream newStream = new ByteArrayInputStream(buffer);
    Webservice to the end, Mirth

  • #2
    Please follow the below link for using java code in mirth
    http://www.mirthcorp.com/community/w...ode+from+Mirth

    You need to copy your custom library jar file in mirthconnect/custom-lib folder and then you can create an object of a class :

    Code:
    var object = new Packages.org.example.Class1();
    var object2 = new Packages.org.example.Class1(<param>);

    Comment


    • #3
      Thanks, I do know how to add the jar in the custom lib and access the java package but I wanted to know for these particular java methods below does anyone know how these would look using them in Mirth. These below are part of the default java library.

      // The document is stored in byte form in the FileContent column.
      // Retrieve these bytes of the first matching record to a new buffer.
      byte[] buffer = resultSet.getBytes("FileContent");

      // Wrap the bytes from the buffer into a new ByteArrayInputStream object.
      ByteArrayInputStream newStream = new ByteArrayInputStream(buffer);
      Webservice to the end, Mirth

      Comment


      • #4
        The code is almost the same in JavaScript. Except, you should be using "var", because it's JavaScript. Also you need to invoke Java classes using fully-qualified class names, or import the package first.

        Code:
            // The document is stored in byte form in the FileContent column.
            // Retrieve these bytes of the first matching record to a new buffer.
            var buffer = resultSet.getBytes("FileContent");
        
            // Wrap the bytes from the buffer into a new ByteArrayInputStream object.
            var newStream = new java.io.ByteArrayInputStream(buffer);
        Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

        Nicholas Rupley
        Work: 949-237-6069
        Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


        - How do I foo?
        - You just bar.

        Comment


        • #5
          Thanks narupley, here is my code, I just got this error because I'm working with a Blob data type in SQL. I'm using aspose words library to convert word document from database to a readable format. Looks like when I call getBytes on a blob datatype it is not liking it. I have more code to write but I'm just testing query column that has the binary version of the word document and then using the aspose words library to convert it to readable text.

          LINE NUMBER: 162
          DETAILS: Can't find method javax.sql.rowset.serial.SerialBlob.getBytes().

          importPackage(Packages.com.aspose.words);
          importPackage(java.io);


          Code:
          	var dbConn = DatabaseConnectionFactory.createDatabaseConnection('net.sourceforge.jtds.jdbc.Driver','jdbc:jtds:sqlserver://10.5.18.87:1433/train','sa','amicas2');
          	dbSQL =	"SELECT DOC_TEXT from W_PATIENT_DOC_TEXT "
          	
          	logger.debug ("SQL: " + dbSQL);
          	
          	var dbResult = dbConn.executeCachedQuery(dbSQL);
          	
          
          	while (dbResult.next()) 
          	{
          		var buffer = dbResult.getBlob("DOC_TEXT").getBytes();
          		var newStream = new java.io.ByteArrayInputStream(buffer);
          		var doc = new Document(newStream);
          		logger.debug(doc.toString(SaveFormat.TEXT));
          	}
          	
          	dbResult.close();
          	dbConn.close();
          Webservice to the end, Mirth

          Comment


          • #6
            I don't have this error anymore, after using the primary database source here is the final code. If using Blob type see commented code.


            while (dbResult.next())
            {
            bFound = 1;
            mrisReportFound = 1;
            //var blob = dbResult.getBlob(4);
            //var buffer = blob.getBytes(1,blob.length());
            var buffer = dbResult.getBytes(4);
            var newStream = new java.io.ByteArrayInputStream(buffer);
            var doc = new Document(newStream);
            var wordConverted = doc.toString(SaveFormat.TEXT);
            //var wordConverted = doc.toString(SaveFormat.HTML);

            //BUILD REPORT
            fullReport += wordConverted;
            }
            Webservice to the end, Mirth

            Comment

            Working...
            X