web stats
Multiple Comments for Results Question - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Thread Tools Display Modes
Old 09-13-2018, 03:37 AM
dandan924 dandan924 is offline
What's HL7?
Join Date: Mar 2017
Posts: 4
dandan924 is on a distinguished road
Question Multiple Comments for Results Question

Hi All,

I tried to use the getSegmentsAfter to get the all comments of the results like the following data format.

I want to get the all consecutive Comment ('C') after the first R segment:
for each (c in getSegmentsAfter(msg,msg.R[i],'C',true))

But in fact, I get the Comment from the Order ('O').

I have no idea where is worng. Could you help to check and fix it?

Data Format:

O|1||Sample #^171412|^^^12345|||||||||||Not specified^||||||||||C
R|1|^^^pH^M|7.055||^^^|N||F|||20180806095200|20180 806095200
C|1|I|789^The result has a question||I
C|2|I|476^device error||I

The transform code:

var i = 0;
var j = 0;
for each (R in msg.R){
var reslutInfo = {};

reslutInfo.examName = msg['R'][i]['R.2']['R.2.4'].toString();
reslutInfo.examType = msg['R'][i]['R.4']['R.4.1'].toString();
reslutInfo.examValue = msg['R'][i]['R.3']['R.3.1'].toString();
reslutInfo.examMinValue = msg['R'][i]['R.5']['R.5.1'].toString();
reslutInfo.examMaxValue = msg['R'][i]['R.5']['R.5.2'].toString();

for each (c in getSegmentsAfter(msg,msg.R[i],'C',true)) {

reslutInfo.comment += msg['C'][j]['C.3']['C.3.1'].toString() + '_'+ msg['C'][j]['C.3']['C.3.2'].toString() + ' ';
Reply With Quote
Old 09-13-2018, 08:52 AM
agermano agermano is offline
Mirth Guru
Join Date: Apr 2017
Location: Indiana, USA
Posts: 598
agermano is on a distinguished road

I'm not familiar with that data format, but usually you don't want to mix index variables (i,j) with for each..in or for..in loops. This might work for you.


for each (var R in msg.R){
	var resultInfo = {};

	resultInfo.examName = R['R.2']['R.2.4'].toString();
	resultInfo.examType = R['R.4']['R.4.1'].toString();
	resultInfo.examValue = R['R.3']['R.3.1'].toString();
	resultInfo.examMinValue = R['R.5']['R.5.1'].toString();
	resultInfo.examMaxValue = R['R.5']['R.5.2'].toString();

	resultInfo.comment = '';

	for each (var c in getSegmentsAfter(msg, R, 'C', true)) {
		resultInfo.comment += c['C.3']['C.3.1'].toString() + '_'+ c['C.3']['C.3.2'].toString() + ' ';
Reply With Quote
Old 09-13-2018, 09:11 AM
dandan924 dandan924 is offline
What's HL7?
Join Date: Mar 2017
Posts: 4
dandan924 is on a distinguished road

Hi agermano,

I tried it and it work fine now. Thanks for your help.
Reply With Quote


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:01 PM.

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