web stats
javascript parser exception - Mirth Community

Go Back   Mirth Community > Mirth Connect > Development

Reply
 
Thread Tools Display Modes
  #1  
Old 11-01-2006, 04:17 PM
kenth kenth is offline
What's HL7?
 
Join Date: Oct 2006
Posts: 5
kenth
Default javascript parser exception

Hi!

I'm currently using version 1.1 of Mirth and having a very frustrating issue.

I'm using a javascript transformer to convert a timestamp into an SQL datetime-friendly format. I have literally copied and pasted the example from another thread ("Best practises - How do I ... ? - DateTime conversion"), changing the message it refers to, and removing the '/' characters from the dobstr:

var dob = msg['PV1']['PV1.45']['TS.1'].text()[0];
var ar = dob.match(/(\d\d\d\d)(\d\d)(\d\d)/);
var dobstr = RegExp.$1 + RegExp.$2 + RegExp.$3;
localMap.put('discharge_date', dobstr);


If I attempt to use this code I get what appears to be a JS parser related exception (see end of post). This is frustrating because I'm (99.9%) sure the code is valid. I'm using a file reader, and that file has a valid PV1 segment, with a discharge date/time: 200209100852

The strange thing is that once the exception appears, it keeps doing so. Even if I comment out all of the code in the above transformer it STILL throws the exception. The only way to get around it is to re-import the channel and try tweaking again.

We are hoping to upgrade to version 1.2 soon - is anyone aware if this will solve the problem? Or have any other solution?

Thanks for your time.

-Kent.



ERROR [32_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='32_destination_1', 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)

Reply With Quote
  #2  
Old 11-01-2006, 09:56 PM
chrisl chrisl is offline
Mirth Employee
 
Join Date: Aug 2006
Posts: 967
chrisl is an unknown quantity at this point
Default Re: javascript parser exception

It appears that this line is the problem:

msg['PV1']['PV1.45']['TS.1'].text()[0];

Make sure you drag this from a sample hl7 message. It is throwing null, presumably on the .text() call on a object that doesn't exist.

Also, make sure to redeploy after every change.

Let us know if that works!
-Chris
__________________
Chris Lang
Reply With Quote
  #3  
Old 11-02-2006, 06:09 AM
albertosaez albertosaez is offline
 
Join Date: Sep 2006
Location: Valladolid, Spain
Posts: 842
albertosaez is an unknown quantity at this point
Default Re: javascript parser exception

You can try a careful aproach

var dob = msg['PV1']['PV1.45']['TS.1'];

if( (dob ==null) || (dob.toString()=='') ) dob='20000101';
else dob=dob.toString();

var ar = dob.match(/(\d\d\d\d)(\d\d)(\d\d)/);
(....)
Reply With Quote
  #4  
Old 11-08-2006, 07:14 PM
kenth kenth is offline
What's HL7?
 
Join Date: Oct 2006
Posts: 5
kenth
Default Re: javascript parser exception

Thanks a lot for your help! Sorry for the late reply - I only work part time.

Anyway, I managed to get things working!!

It seems .text()[0] was not working for me.

(working code at bottom of this post.)

One thing to note is that the parser exception I spoke of seemed to trace back to Mirth_directory/database/mirth.script. After getting the exception once from .text()[0], I simply tried hardcoding a value

localMap.put("discharge_date" = '20010101');

I redeployed, re-ran and again got the parser exception. Even though the above code is clearly correct. This is what mirth.script had compiled:

localMap.put(''discharge_date'', ''20010101);

(missing closing quotes on date)

I then restarted Mirth and re-imported a channel that had not exceptioned, hardcoded the date again, redeployed and ran without issue. This time mirth.script compiled correctly:

localMap.put(''discharge_date'', ''20010101'');

Hope the info is somehow helpful. And thanks for being so quick to respond!

-Kent.


For anyone interested, the following works for me (converting HL7 TS to SQL datetime):

Code:
var admit = msg['PV1']['PV1.44']['TS.1'];

if( (admit == null) || (admit.toString() == '') ) 
    admit = '';
else 
    admit = admit.toString();

var ar = admit.match(/(\d\d\d\d)(\d\d)(\d\d)(\d\d)?(\d\d)?(\d\d)?/);
if( ar == null )
{
    //match to the SQL default
    admit = '19000101';
    admit.match(/(\d\d\d\d)(\d\d)(\d\d)(\d\d)?(\d\d)?(\d\d)?/);
}
var admitstr = RegExp.$1 + RegExp.$2 + RegExp.$3;
if( (RegExp.$4 != null ) && (RegExp.$4 != '') )
{
    //RegExp.$4 indicates if optional hour was given. 
    if( (RegExp.$5 != null ) && (RegExp.$5 != '') )
        admitstr += ' ' + RegExp.$4 + ':' + RegExp.$5;
    else
        admitstr += ' ' + RegExp.$4 + ':00';
}
if( (RegExp.$6 != null ) && (RegExp.$6 != '') )
        admitstr += ':' + RegExp.$6;

localMap.put('admit_date', admitstr);
Reply With Quote
  #5  
Old 11-08-2006, 08:14 PM
chrisl chrisl is offline
Mirth Employee
 
Join Date: Aug 2006
Posts: 967
chrisl is an unknown quantity at this point
Default Re: javascript parser exception

Very interesting about the mirth.script issue. Thanks for posting your fix! Can you upload this to the File Repository? I'm sure others would find it helpful.

Also, 1.2 completely changes the JS compilation/etc so this issue should be resolved.

-Chris
__________________
Chris Lang
Reply With Quote
  #6  
Old 11-09-2006, 07:04 AM
nshaik nshaik is offline
Mirth Guru
 
Join Date: Sep 2006
Posts: 302
nshaik
Default Re: javascript parser exception

This worked for getting patient appointments in mm/dd/yyyy HH:MM format (SIU S12 message).

========================
Mirth v1.1, SQL Server 2000 SP3

Database updates done using the "Workaround to call a stored procedure from Mirth".

http://www.mirthproject.org/index.ph...d=26&Itemid=43
========================

// Appt. start datetime
if (msg['SCH']['SCH.11']['TQ.4']['TS.1'].text()[0] != null) {
// Get appt. date in mm/dd/yyyy HH:MM format
var apptStart = msg['SCH']['SCH.11']['TQ.4']['TS.1'].text()[0];
var arStart = apptStart.match(/(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)/);
tempStartDate = RegExp.$2 + '/' + RegExp.$3 + '/' + RegExp.$1 + ' ' + RegExp.$4 + ':' + RegExp.$5;
tempStartDate = "'" + tempStartDate + "'";
}
Reply With Quote
  #7  
Old 11-14-2006, 06:05 PM
kenth kenth is offline
What's HL7?
 
Join Date: Oct 2006
Posts: 5
kenth
Default Re: javascript parser exception

Thanks Chris. Will upgrade to 1.2 shortly.

I have submitted "PV1 Tranformer (including sql datetimes)" to the File Repository, in the Transformers section.

Cheers - Kent.
Reply With Quote
  #8  
Old 11-15-2006, 07:51 PM
chrisl chrisl is offline
Mirth Employee
 
Join Date: Aug 2006
Posts: 967
chrisl is an unknown quantity at this point
Default Re: javascript parser exception

Thanks for the submission, we have approved and published it.

-Chris
__________________
Chris Lang
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to throw Exception in Javascript rkedilaya Support 6 03-29-2012 10:59 AM
SQL Parser question Bostad Support 3 03-18-2009 08:54 AM
Caught exception in Exception Strategy maqboolp Support 5 12-16-2008 09:02 AM
New hl7 parser gliptak General Discussion 1 03-25-2007 12:26 AM
Getting exception using JavaScript replace nshaik Development 1 09-14-2006 04:41 PM


All times are GMT -7. The time now is 10:18 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Mirth Corporation