Announcement

Collapse
No announcement yet.

How to throw Exception in Javascript

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

  • How to throw Exception in Javascript

    Dear All,

    How to handle the exception using javascript?

    If Patient Name is not there in ADT message I need to throw Exception and I need not Process that message.

    I am using Mirth 1.5

    Regards
    Raghavendra

  • #2
    Re:How to throw Exception in Javascript

    Use the filter to validate and reject messages before they even get to the transformer.
    Brendan Haverlock | Mirth Software Engineer | Mirth Corporation

    Comment


    • #3
      Re:How to throw Exception in Javascript

      Thanks for the Help.Is it possible to show this message as Error.

      Comment


      • #4
        Is it possible to show message as Error when filter false?
        And move File to Error-Directory?
        Last edited by Calle_2007; 03-21-2012, 06:09 AM.

        Comment


        • #5
          Originally posted by Calle_2007 View Post
          Is it possible to show message as Error when filter false?
          And move File to Error-Directory?
          I think I've answered this same question before... maybe. You can throw an exception from your filter, which will update the message status and channel statistics accordingly. If instead you want the message to process through successfully, but the status in the database and the channel stats to reflect an error, you can do those updates manually in the postprocessor for example; search the forums for the relevant code on how to do that...

          However, I suppose this sort of defeats the purpose of a filter... generally it's there so that you can avoid processing a message for the purpose of not throwing an error. *shrugs*
          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


          • #6
            Originally posted by narupley View Post
            I think I've answered this same question before...
            The thread narupley is referring to is:
            Force message to Error.

            Originally posted by Calle_2007 View Post
            Is it possible to show message as Error when filter false?
            I opened a suggestion of improvement:
            [#MIRTH-2063] Choose the status of the message.

            If you have the same need, you can vote for it, and then wait for the experts to choose whether to implement it or not .
            Last edited by DBE; 03-28-2012, 07:15 AM.

            Comment


            • #7
              There are a few ways you can do this.

              I would recommend against throwing an error as you may miss it in the error log.

              Here's how I would do it:

              For all cases this would be done at the filter.

              Method #1a:

              If there won't be tons of these I'd go with email alerts. You need to make sure you have an SMTP server associated in your Mirth settings.

              Code:
              if (message == good) {
              
                return true;
              
              }  else {
              
              var smtpConn = SMTPConnectionFactory.createSMTPConnection();
              
              var body = 'The code ' + strOBX + ' was not found in the OBX table.\n';
              body = body + 'Please do not respond to this message.';
              
              smtpConn.send('user1.hpha.ca', '[email protected]', '[email protected]', 'No Mapping for Code in OBX Table', body);
              
              return false;
              
              
              
              }
              #1 b is an email sent using the Mirth alerts

              In your filter replace the email stuff with

              Code:
              alerts.sendAlert('message');
              You'd then set up an alert for this channel in the Mirth Alerts window.


              Method #2: File Drop

              In your destination filter you'd have

              Code:
              if (message == good) {
              
                 return true; 
              } else {
              
                return false;
              
              }
              Create a second destination as a file drop and reverse the true/false (so it will filter if its good and go if its not).

              In your file writer I'd create a file name that is the formatted date and set the append flag to true. (This gives you one file a day).

              You can write a minimum dataset by mapping say patient name and account (or whatever you need) to the channelMap and replace your encodedData in the file writer with those values.

              The third method would be to send the bad message to a completely different channel (why you'd want to do this I don't know, but I thought of it so I'm including it)

              Code:
              router.routeMessage(channelName, 'message', useQueue);
              If I need to refer to a channel from another one I add the channel name to global channel map by putting this in the monitored channel's deploy script.

              [/code]var channelName = Packages.com.mirth.connect.server.controllers.Chan nelController.getInstance().getDeployedChannelById (channelId).getName();

              globalMap.put('thischannel_id',channelId);
              globalMap.put('thischannel_name',channelName);

              //substitute some meaningful name for 'thischannel'

              [/code]


              I know I just threw a lot of info at you, let us know if you need any further assistance
              I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
              http://www.linkedin.com/pub/david-rothbauer/5/923/518
              codeismydrug.wordpress.com
              hl7coders.wordpress.com

              Test all my code suggestions prior to implementation

              Comment

              Working...
              X