4

I am trying to add multiple NTE lines to the end of HL7 messages using Mirth. I can add a single line using for example:

tmp=msg;
msg['NTE']['NTE.1']="1".toString();
msg['NTE']['NTE.3']="Performed at 123 Radiology".toString();

But...

When I want to add a line below that:

msg['NTE']['NTE.1']="2".toString();
msg['NTE']['NTE.3']="123 Radiology Drive STE 100".toString();

I can't just use the tmp=msg because it will simply overwrite the previous line.

In the end I am trying to add something like this to the end of the message:

NTE|1||Test performed at Radiology Imaging
NTE|2||123 Test Road
NTE|3||Chicago, IL 55555

The content is static, I just need to understand how to create each line separately.

user2201142
  • 41
  • 1
  • 1
  • 2

3 Answers3

4

I'm not sure why you need (in this particular example) to assign outbound template to inbound - Mirth will do that for you anyway.

The code to produce the required result may be like this:

var segCount = 0;

createSegment('NTE', msg);
msg['NTE'][segCount]['NTE.1']['NTE.1.1'] = segCount;
msg['NTE'][segCount]['NTE.3']['NTE.3.1'] = "Test performed at Radiology Imaging";

createSegmentAfter('NTE', msg['NTE'][segCount]);
msg['NTE'][++segCount]['NTE.1']['NTE.1.1'] = segCount;
msg['NTE'][segCount]['NTE.3']['NTE.3.1'] = "123 Test Road";

createSegmentAfter('NTE', msg['NTE'][segCount]);
msg['NTE'][++segCount]['NTE.1']['NTE.1.1'] = segCount;
msg['NTE'][segCount]['NTE.3']['NTE.3.1'] = "Chicago, IL 55555";

If you pass the required data as an array, you may loop and simplify this code even further. I left it in this expanded way for clarity.

Shamil
  • 910
  • 4
  • 17
  • If you like the answer, you may also like the "Unofficial Mirth Connect v3.x Developer's Guide" ebook, available to download at - mirthconnect.shamilpublishing.com – Shamil Mar 27 '15 at 22:53
1

You can simply do something like...

var segmentCount = 0;
var nteSegment = createSegment('NTE', msg, segmentCount++);
nteSegment[NTE.1][NTE.1.1] = "1";
nteSegment[NTE.3][NTE.3.1] = "Performed at 123 Radiology".toString();

var nteSegment2 = createSegment('NTE', msg, segmentCount++);
nteSegment2[NTE.1][NTE.1.1] = "2";
nteSegment2[NTE.3][NTE.3.1] = "123 Radiology Drive STE 100".toString();

Or you can create loop and add content from list.

Prashant
  • 31
  • 7
-1

you guys can try out the below solution. It worked for me.

try{
    var NTECOUNTER = 0;
    for each (seg in msg.children()) 
    {
            if (seg.name().toString() == "NTE") 
         {
                    NTECOUNTER++;
            }
    }
    
    var j = NTECOUNTER;
    
    createSegment('NTE', msg, j);
    msg['NTE'][j]['NTE.1']['NTE.1.1'] = 1;
    msg['NTE'][j]['NTE.2']['NTE.2.1'] = "L";
    msg['NTE'][j]['NTE.3']['NTE.3.1'] = "Your comment";
}
catch(err){}