Announcement

Collapse
No announcement yet.

Multiple DG1 Segments into a database

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

  • Multiple DG1 Segments into a database

    Currently, I have an inbound LLP reader writing out to a mysql database containing a good deal of the information about the message. In certain messages I have, (like the multiple insurance case) I would like to insert all of those segments into a database. Of course, i wont be knowing how many segments I will be receiving.

    I have tried the following in the main SQL statement, but I dont think it likes multiple statements and while loops there. Im not sure.
    Code:
    var i = 0;
    while(msg['DG1']['DG1.4'][i] != null)
    {
    Insert into ...
    }
    I was going to try and hack together something inside the transformer using the database connection that can be made there, but I also had problems as well.

    Code:
    var driver = "com.mysql.jdbc.Driver";
    var address = "jdbc:mysql://localhost/rawhl7;";
    var username = "user"; 
    var password = "password"; 
    var i = 0;
    var patientID = msg['PID']['PID.3']['CX.1'];
    
    var dbConn = DatabaseConnectionFactory.createDatabaseConnection(driver,address,username,password);
    while(msg['DG1']['DG1.4'][i] != null)
    {
    
    var complaintNumber = msg['DG1']['DG1.1'][i];
    var complaint = msg['DG1']['DG1.4'][i];
    var expression = "INSERT IGNORE INTO a08_complaints values (DEFAULT, '" + patientID + "', '" + complaintNumber + "', '" + complaint + "';";  
    var result = dbConn.executeCachedQuery(expression);
    result.close();
    i++;
    }
    
    dbConn.close();
    Regardless of whether i have something as complex as that in the transformer... or something as simple as the following which i just did to see what is making the transformer fail. Apparently it doesnt like anything at all but the most basic msg['DG1']['DG1.1'] type entry.

    Code:
    return (msg['DG1']['DG1.1']);
    I get a gigantic transformer error.

    ERROR [3_destination_1.dispatcher.1] org.mule.impl.DefaultExceptionStrategy:
    ************************************************** ******************************
    Message : syntax error (<cmd>#1) (org.mozilla.javascript.EvaluatorException)
    Type : org.mule.umo.transformer.TransformerException
    Code : 64999
    Transformer : Transformer{name=&#039;3_destination_1&#039;, returnClass=false, returnClass=false, sourceTypes=[]}
    JavaDoc : http://mule.codehaus.org/docs/apidoc...Exception.html
    ************************************************** ******************************
    Exception stack is:
    1. syntax error (<cmd>#1) (org.mozilla.javascript.EvaluatorException)
    org.mozilla.javascript.DefaultErrorReporter:95 (null)
    2. syntax error (<cmd>#1) (org.mozilla.javascript.EvaluatorException) (org.mule.umo.transformer.TransformerException)
    com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer:66 (http://mule.codehaus.org/docs/apidoc...Exception.html)
    ************************************************** ******************************
    Root Exception stack trace:
    org.mozilla.javascript.EvaluatorException: syntax error (<cmd>#1)
    at org.mozilla.javascript.DefaultErrorReporter.runtim eError(DefaultErrorReporter.java:95)
    at org.mozilla.javascript.DefaultErrorReporter.error( DefaultErrorReporter.java:82)
    at org.mozilla.javascript.Parser.addError(Parser.java :122)
    at org.mozilla.javascript.Parser.reportError(Parser.j ava:128)
    at org.mozilla.javascript.Parser.primaryExpr(Parser.j ava:2013)
    at org.mozilla.javascript.Parser.memberExpr(Parser.ja va:1640)
    at org.mozilla.javascript.Parser.unaryExpr(Parser.jav a:1503)
    at org.mozilla.javascript.Parser.mulExpr(Parser.java: 1432)
    at org.mozilla.javascript.Parser.addExpr(Parser.java: 1413)
    at org.mozilla.javascript.Parser.shiftExpr(Parser.jav a:1393)
    at org.mozilla.javascript.Parser.relExpr(Parser.java: 1367)
    at org.mozilla.javascript.Parser.eqExpr(Parser.java:1 323)
    at org.mozilla.javascript.Parser.bitAndExpr(Parser.ja va:1312)
    at org.mozilla.javascript.Parser.bitXorExpr(Parser.ja va:1301)
    at org.mozilla.javascript.Parser.bitOrExpr(Parser.jav a:1290)
    at org.mozilla.javascript.Parser.andExpr(Parser.java: 1278)
    at org.mozilla.javascript.Parser.orExpr(Parser.java:1 266)
    at org.mozilla.javascript.Parser.condExpr(Parser.java :1249)
    at org.mozilla.javascript.Parser.assignExpr(Parser.ja va:1231)
    at org.mozilla.javascript.Parser.argumentList(Parser. java:1595)
    at org.mozilla.javascript.Parser.memberExprTail(Parse r.java:1728)
    at org.mozilla.javascript.Parser.memberExpr(Parser.ja va:1643)
    at org.mozilla.javascript.Parser.unaryExpr(Parser.jav a:1503)
    at org.mozilla.javascript.Parser.mulExpr(Parser.java: 1432)
    at org.mozilla.javascript.Parser.addExpr(Parser.java: 1413)
    at org.mozilla.javascript.Parser.shiftExpr(Parser.jav a:1393)
    at org.mozilla.javascript.Parser.relExpr(Parser.java: 1367)
    at org.mozilla.javascript.Parser.eqExpr(Parser.java:1 323)
    at org.mozilla.javascript.Parser.bitAndExpr(Parser.ja va:1312)
    at org.mozilla.javascript.Parser.bitXorExpr(Parser.ja va:1301)
    at org.mozilla.javascript.Parser.bitOrExpr(Parser.jav a:1290)
    at org.mozilla.javascript.Parser.andExpr(Parser.java: 1278)
    at org.mozilla.javascript.Parser.orExpr(Parser.java:1 266)
    at org.mozilla.javascript.Parser.condExpr(Parser.java :1249)
    at org.mozilla.javascript.Parser.assignExpr(Parser.ja va:1231)
    at org.mozilla.javascript.Parser.expr(Parser.java:122 0)
    at org.mozilla.javascript.Parser.statementHelper(Pars er.java:1107)
    at org.mozilla.javascript.Parser.statement(Parser.jav a:619)
    at org.mozilla.javascript.Parser.parseFunctionBody(Pa rser.java:413)
    at org.mozilla.javascript.Parser.function(Parser.java :519)
    at org.mozilla.javascript.Parser.parse(Parser.java:34 4)
    at org.mozilla.javascript.Parser.parse(Parser.java:28 9)
    at org.mozilla.javascript.Context.compileImpl(Context .java:2190)
    at org.mozilla.javascript.Context.compileString(Conte xt.java:1284)
    at org.mozilla.javascript.Context.compileString(Conte xt.java:1273)
    at org.mozilla.javascript.Context.evaluateString(Cont ext.java:1129)
    at com.webreach.mirth.server.mule.transformers.JavaSc riptTransformer.doTransform(JavaScriptTransformer. java:58)
    at org.mule.transformers.AbstractTransformer.transfor m(AbstractTransformer.java:197)
    at org.mule.impl.MuleEvent.getTransformedMessage(Mule Event.java:251)
    at org.mule.providers.jdbc.JdbcMessageDispatcher.doDi spatch(JdbcMessageDispatcher.java:88)
    at org.mule.providers.AbstractMessageDispatcher$Worke r.run(AbstractMessageDispatcher.java:257)
    at org.mule.impl.work.WorkerContext.run(WorkerContext .java:290)
    at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.runTask(ThreadPoolExecutor. java:650)
    at edu.emory.mathcs.backport.java.util.concurrent.Thr eadPoolExecutor$Worker.run(ThreadPoolExecutor.java :675)
    at java.lang.Thread.run(Unknown Source)

    ************************************************** ******************************
    Can somebody help me figure out what may be wrong here? Thank you very much.

    Justin

  • #2
    My issue resolved!

    Okay.... So i spent a little more time and realized that the transformer is the incorrect place to be doing all of those. So, moving my code to the filter got me to a whole bunch of errors. Anyway, after resolving those i figured I would post the code to help anybody else out who would like to do the same.

    Basically, it takes all the ADT^A08 messages and places them into their own table & symptoms table.

    Code:
    if(msg[&#039;MSH&#039;][&#039;MSH.9&#039;][&#039;CM_MSG.1&#039;] == "ADT" && msg[&#039;MSH&#039;][&#039;MSH.9&#039;][&#039;CM_MSG.2&#039;] == "A08") {
    var driver = "com.mysql.jdbc.Driver";
    var address = "jdbc:mysql://localhost/rawhl7";
    var username = "username"; 
    var password = "password"; 
    var i = 0;
    var patientID = msg[&#039;PID&#039;][&#039;PID.3&#039;][&#039;CX.1&#039;];
    var dbConn = DatabaseConnectionFactory.createDatabaseConnection(driver,address,username,password);
    
    while(msg[&#039;DG1&#039;][&#039;DG1.4&#039;][i] != null) {
    var complaintNumber = msg[&#039;DG1&#039;][&#039;DG1.1&#039;][i];
    var complaint = msg[&#039;DG1&#039;][&#039;DG1.4&#039;][i];
    var expression = "INSERT IGNORE INTO a08_complaints values (DEFAULT, &#039;" + patientID + "&#039;, &#039;" + complaintNumber + "&#039;, &#039;" + complaint + "&#039;);";  
    var result = dbConn.executeUpdate(expression);
    i = i + 1;
    }
    dbConn.close();
    }
    
    return msg[&#039;MSH&#039;][&#039;MSH.9&#039;][&#039;CM_MSG.1&#039;] == "ADT" && msg[&#039;MSH&#039;][&#039;MSH.9&#039;][&#039;CM_MSG.2&#039;] == "A08";

    Comment


    • #3
      Re: Multiple DG1 Segments into a database

      Thank you for your in-dept analysis and the code! Glad you got it working.


      A few tips:
      * Your first design was correct (database call in the transformer)


      Ideally you would include a simple filter that checks the message type:

      Code:
      if(msg[&#039;MSH&#039;][&#039;MSH.9&#039;][&#039;CM_MSG.1&#039;] == "ADT" && msg[&#039;MSH&#039;][&#039;MSH.9&#039;][&#039;CM_MSG.2&#039;] == "A08") {
      return true;
      }else{
      return false;
      }
      Then your transformer would include a Javascript step that has the rest of your code.

      * We are hoping to include the ability to use more complex templating in the JDBC sql statement on the destination endpoint, such that you would not have to perform your JDBC logic inside of the actual Javascript, but rather use the mapping steps to build your loop. This is scheduled for our 1.3 release.
      Chris Lang

      Comment


      • #4
        Hi Chris,
        I try to code in Mirth wiki lib mapping multiple seg to a database,
        http://www.mirthcorp.com/community/w...+to+a+Database
        however, i been getting error when processing the multiple segment messages.
        it says msg not defined.

        [I]
        [2016-02-25 10:13:02,921] ERROR (com.mirth.connect.connectors.jdbc.DatabaseDispatc herScript:152): Error evaluating Database Writer (Database Writer "RepeatSegments" on channel adba08a9-ca51-4aa3-921a-29013d7f4ae5).
        com.mirth.connect.server.MirthJavascriptTransforme rException: CHANNEL:
        LIS OrdersCONNECTOR:
        RepeatSegmentsSOURCE CODE:
        48: var VisitNo = $('VisitNo');49: var UID = $('UID');50: 51: var i = 0;52: 53: while(msg['OBR']['OBR.4']['OBR.4.2'][i] != null) {54: var Orders= msg['OBR']['OBR.4']['OBR.4.2'];55: var expression = "INSERT IGNORE INTO LIS_Orders values (DEFAULT, '" + NRIC + "', '" + VisitNo + "', '" + UID + "', '" + Orders + "');";56: var result = dbConn.executeUpdate(expression);57: LINE NUMBER:
        53DETAILS:
        ReferenceError: "msg" is not defined.
        at b3845d44-e2e8-416a-ad90-44566ee2112c:53 (doScript)
        at b3845d44-e2e8-416a-ad90-44566ee2112c:69
        at com.mirth.connect.server.util.javascript.JavaScrip tUtil.executeScript(JavaScriptUtil.java:527)
        at com.mirth.connect.connectors.jdbc.DatabaseDispatch erScript$DatabaseDispatcherTask.call(DatabaseDispa tcherScript.java:120)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker( Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run (Unknown Source)
        at java.lang.Thread.run(Unknown Source)


        how do i resole this?

        Comment

        Working...
        X