web stats
Multiple Comments for Results Question - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 09-13-2018, 02:37 AM
dandan924 dandan924 is offline
What's HL7?
 
Join Date: Mar 2017
Posts: 3
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:

H|\^&|||NUD-57N1||||||||1|20180806094836
P|1||||^|||U||||||||^^^|||||||||
O|1||Sample #^171412|^^^12345|||||||||||Not specified^||||||||||C
C|1|I|111^test||I
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
R|2|^^^pO2^M|155|mmHg|^^^|N||F
----------

The transform code:
--------------------
$co('resultsArray',[]);

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() + ' ';
j++;
}
i++;
$co('resultsArray').push(reslutInfo);
}
Reply With Quote
  #2  
Old 09-13-2018, 07:52 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 435
agermano is on a distinguished road
Default

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.

Code:
$co('resultsArray',[]);

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() + ' ';
	}
	$co('resultsArray').push(resultInfo);
}
Reply With Quote
  #3  
Old 09-13-2018, 08:11 AM
dandan924 dandan924 is offline
What's HL7?
 
Join Date: Mar 2017
Posts: 3
dandan924 is on a distinguished road
Default

Hi agermano,

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

Tags
getsegmentsafter

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 12:15 AM.


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