web stats
Replace .br tag in OBX-5 - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 08-27-2018, 06:13 AM
Mark Sull Mark Sull is offline
Mirth Newb
 
Join Date: Apr 2018
Location: Ireland
Posts: 24
Mark Sull is on a distinguished road
Default 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)
Reply With Quote
  #2  
Old 08-27-2018, 09:59 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 795
agermano is on a distinguished road
Default

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.
Reply With Quote
  #3  
Old 09-04-2018, 12:01 AM
Mark Sull Mark Sull is offline
Mirth Newb
 
Join Date: Apr 2018
Location: Ireland
Posts: 24
Mark Sull is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 09-04-2018, 12:09 AM
Mark Sull Mark Sull is offline
Mirth Newb
 
Join Date: Apr 2018
Location: Ireland
Posts: 24
Mark Sull is on a distinguished road
Default

Hi Agermano,

Never mind, just found the section.

Ill give your solution a go.

Cheers
Reply With Quote
  #5  
Old 09-04-2018, 01:16 AM
Mark Sull Mark Sull is offline
Mirth Newb
 
Join Date: Apr 2018
Location: Ireland
Posts: 24
Mark Sull is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 09-04-2018, 02:19 AM
AlexNeiva AlexNeiva is offline
Mirth Guru
 
Join Date: Oct 2013
Location: Portugal
Posts: 275
AlexNeiva is on a distinguished road
Default

Hello,


just put this in Preprocessor:

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

it will work.
__________________
Best Regards,
Alex Neiva

Last edited by AlexNeiva; 09-04-2018 at 02:23 AM.
Reply With Quote
  #7  
Old 09-05-2018, 06:02 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 795
agermano is on a distinguished road
Default

My bad, I thought we were working with a Java string in the pre-processor. Thanks for the correction Alex.
Reply With Quote
  #8  
Old 09-11-2018, 06:20 AM
Mark Sull Mark Sull is offline
Mirth Newb
 
Join Date: Apr 2018
Location: Ireland
Posts: 24
Mark Sull is on a distinguished road
Default 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,'~');
Reply With Quote
  #9  
Old 09-11-2018, 09:41 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 795
agermano is on a distinguished road
Default

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\.
Reply With Quote
Reply

Tags
java, replaceall

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


All times are GMT -8. The time now is 04:07 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Mirth Corporation