web stats
OBX Segment parsing - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 03-16-2018, 07:17 AM
tkurian tkurian is offline
Mirth Newb
 
Join Date: Jan 2018
Posts: 11
tkurian is on a distinguished road
Default OBX Segment parsing

I have these OBX Segements and I'm using Mirth 3.5.1

OBX|1|ST|||John Doe was admitted to Hospital , Event Type: In-Patient
OBX|2|ST|||Company Name^
OBX|3|CE|R52^Pain, unspecified^I10||diagnosis^R52^Stuff in here^I10^^F
OBX|4|CE|S90.811A^Abrasion, right foot, initial encounter^I10||diagnosis^S90.811^Stuff in Here^I10^^F

And I have run this code but for some reason it doesn't run the if statement when it equals CE can someone see what I'm doing wrong here in this javascript transformer step?

var obxText = '';

try{
for each (seg in msg.children()) {
if (seg.name().toString() == "OBX") {
if(msg['OBX']['OBX.2']['OBX.2.1'].toString() == 'CE'){
logger.info('CE');
obxText = obxText + 'Diagnosis Code: ' + msg['OBX']['OBX.3']['OBX.3.1'].toString() + 'Diagnosis: ' + msg['OBX']['OBX.3']['OBX.3.2'].toString();

}
else{
obxText = obxText + seg['OBX.5']['OBX.5.1'].toString();
}

}
}
}
catch(e){
logger.error(e);
}

globalChannelMap.put('OBXValues', obxText);
Reply With Quote
  #2  
Old 03-16-2018, 07:56 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 898
agermano is on a distinguished road
Default

msg['OBX'] will give you the list of msg.children() where name == 'OBX'. You have to make sure you're using your loop variable consistently. You did it correctly in the else clause.

Also, not sure what your purpose is for storing the value in the globalChannelMap, but that is not thread safe, won't survive a server reboot, and won't be visible in the message viewer. If you're just keeping it to use later in the same message (e.g. in another transformer step, your destination connector properties, another destination, or the post-processor,) use the channelMap instead.

Code:
var obxText = '';

try{
	for each (seg in msg['OBX']) {
		if(seg['OBX.2']['OBX.2.1'].toString() == 'CE'){
			logger.info('CE');
			obxText = obxText + 'Diagnosis Code: ' + seg['OBX.3']['OBX.3.1'].toString() + 'Diagnosis: ' + seg['OBX.3']['OBX.3.2'].toString();
		}
		else{
			obxText = obxText + seg['OBX.5']['OBX.5.1'].toString();
		}
	}
}
catch(e){
	logger.error(e);
}

globalChannelMap.put('OBXValues', obxText);

Last edited by agermano; 03-16-2018 at 09:22 AM. Reason: fix typo
Reply With Quote
  #3  
Old 03-16-2018, 09:00 AM
tkurian tkurian is offline
Mirth Newb
 
Join Date: Jan 2018
Posts: 11
tkurian is on a distinguished road
Default

Thank you this worked great the only comment is that there is no period msg.['OBX']) it should be just msg['OBX'])
Reply With Quote
  #4  
Old 03-16-2018, 09:44 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 898
agermano is on a distinguished road
Default

Quote:
Originally Posted by tkurian View Post
Thank you this worked great the only comment is that there is no period msg.['OBX']) it should be just msg['OBX'])
Oops I fixed it. I had it right in the comment, just not in the code.
Reply With Quote
Reply

Tags
obx, parse repeating fields

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 07:45 PM.


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