Announcement

Collapse
No announcement yet.

Replace .br tag in OBX-5

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

  • Replace .br tag in OBX-5

    Hi All,

    I need to replace each occurrence of a new line '.br' tag in OBX-5 with a tilde symbol '~' as the downstream app cannot work with '.br' tags.

    Source OBX:
    OBX|1|FT|VEL6174853|Macro|test line break\.br\\.br\test line break \.br\\.br\\T\\.br\\.br\/\.br\\.br\\E\\.br\\.br\\S\\.br\\.br\\R\|||N|||F

    Desired OBX output:
    OBX|1|FT|VEL6174853|Macro|test line break~~test line break ~~\T\~~/~~\E\~~\S\~~\R\|||N|||F

    Looking at suggestions on the community it mentions to add the below java script text in the source transformer.

    Code:
    tmpSmsg = tmpSmsg.replaceAll("\r", "\r\n");
    I have amended the the above string to fit my requirements, however, I get the below error after sending it through the source java script transformer.

    Code:
    tmpSmsg = tmpSmsg.replaceAll("\.br\", "~");
    Appreciate the help. I've attached a screenshot the source java script transformer.

    Cheers



    Transformer error
    ERROR MESSAGE: Error evaluating transformer
    com.mirth.connect.server.MirthJavascriptTransforme rException:
    CHANNEL: V Test ORU
    CONNECTOR: sourceConnector
    SCRIPT SOURCE: TRANSFORMER
    SOURCE CODE:
    63:
    64: createSegmentAfter('ORC', msg['PV1']);
    65: msg['ORC']['ORC.1']['ORC.1.1'] = 'RE';
    66: msg['ORC']['ORC.2']['PV1.2.1']= msg['OBR']['OBR.2']['OBR.2.1'].toString()
    67:
    68: tmpSmsg = tmpSmsg.replaceAll("br", "~");
    69: if ('xml' === typeof msg) {
    70: if (msg.hasSimpleContent()) {
    71: msg = msg.toXMLString();
    72: }
    LINE NUMBER: 68
    DETAILS: ReferenceError: "tmpSmsg" is not defined.
    at af841757-a728-4180-b034-4a38a328c0f7:68 (doTransform)
    at af841757-a728-4180-b034-4a38a328c0f7:90 (doScript)
    at af841757-a728-4180-b034-4a38a328c0f7:92
    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(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)

  • #2
    There are a multitude of reasons why what you are trying isn't working in a transformer, but you should be able to do something similar in the pre-processor like this:

    Code:
    return new java.lang.String(message).replaceAll("\\\.br\\", "~");
    Your error was telling you that tmpSmsg was not defined, and therefore, you could not call replaceAll on it. replaceAll is a function for java strings, and can't be called on javascript strings. The first parameter is a regular expression. The backslash and period are special characters in a regex that need to be escaped if meant literally. Finally, in hl7, '~' is usually the field repetition character, so in the transformer, you can't doing a simple string replacement, but must actually create the correct xml structure for a repeating field. This works in the pre-processor because you are dealing with string data at that stage, and it is unaware of the hl7 structure.

    Comment


    • #3
      Hi Agermano,

      Apologies but when you say place in preprocessor, is that not an transformer in the source section on admin mirth? I thought all scripting should be done here. Im not sure where the preprocessor resides.

      Comment


      • #4
        Hi Agermano,

        Never mind, just found the section.

        Ill give your solution a go.

        Cheers

        Comment


        • #5
          Hi Agermano,

          I was able to get the pre-processor to work to a degree. The below script clears the first iteration of the value.

          Code:
          var newMessage = message.replace("\.br\\", '~');
          return newMessage;
          When i try a replace all function it fails for the below error. Any thoughts?

          Code:
          var newMessage = message.replaceAll("\.br\\", '~');
          return newMessage;

          SOURCE CODE:
          47: }
          48: eval('importPackage(' + Packages.java.lang.Class.forName(className).getPac kage().getName() + ')');
          49: }
          50: }
          51: function doScript() {
          52: var newMessage = message.replaceAll("\.br\\", '~');
          53: return newMessage;
          54: }
          LINE NUMBER: 52
          DETAILS: TypeError: Cannot find function replaceAll in object MSH|^~\&|SpeechReport|G2|||20180904075455.4235||OR U^R01^ORU_R01|387718e2-7d62-405c-b5cd-8f364bb73d1d||2.4
          PID|1||EL348177^^^^HOSP||^||19420122000000.0000|M| |||||||||||||||||||||N

          Comment


          • #6
            Hello,


            just put this in Preprocessor:

            Code:
            return message.replace(/\\.br\\/g,'~');

            it will work.
            Last edited by AlexNeiva; 09-04-2018, 02:23 AM.
            Best Regards,
            Alex Neiva

            Comment


            • #7
              My bad, I thought we were working with a Java string in the pre-processor. Thanks for the correction Alex.

              Comment


              • #8
                Correct PART 2

                Thanks for the help guys, that works indeed.

                Do you mind explaining to my a forward slash is required.

                Code:
                return message.replace(/\\.br\\/g,'~');

                Comment


                • #9
                  It has to do with differences between Java and Javascript. Javascript (as do most languages) uses forward slashes to begin and end a regular expression. Java passes the patterns as Strings instead.

                  You could potentially use either one. I just noticed that you removed the part where I explicitly converted message to a java.lang.String. I did this since you were already trying to use the Java syntax. Had you left that part in, it would have worked. The way it was posted by Alex is the correct way to call it on a Javascript string.

                  Also upon review, the solution Alex gave isn't 100% correct because he did not escape the period, so any character would be valid there. For example, his would also split on \pbr\.

                  Comment

                  Working...
                  X