web stats
Delete OBX Segments to END - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 10-22-2015, 08:20 AM
nikoli nikoli is offline
OBX.1 Kenobi
 
Join Date: Jan 2013
Posts: 33
nikoli is on a distinguished road
Default Delete OBX Segments to END

I am trying to delete ALL OBX segments in a message from one starting point where defined text is found to the end (All OBX Segments from this one point ... including the found segment, to the end of the message).

Mirth Connect: v3.1.1.7461

This code thus far will delete the segment with the found string, but no segments following this line.


var deleteSeg = false;
for each(seg in msg.children()) {
if(seg.name() == "OBX") {
var strOBXID = seg['OBX.5']['OBX.5.1'].toString();
if(strOBXID.substring(0,26)== "PM******** ORIGINAL REPORT"){
deleteSeg = true;
} else {
deleteSeg = false;
}
}
if(deleteSeg == true ){
var segType = seg.name();
var segCnt = 0;
for(var i=0;i<seg.childIndex();i++){
if(msg.children()[i].name() == seg.name()) {
segCnt++;
}
}
delete msg[segType][segCnt];
}}
Reply With Quote
  #2  
Old 10-23-2015, 03:52 AM
mcalKno mcalKno is offline
 
Join Date: Apr 2015
Location: Pennsylvania
Posts: 247
mcalKno is on a distinguished road
Default

This seems to work. Once the OBX in question is found it records the sequence and then deletes any further OBX segments with a higher sequence ID.

Code:
for each(obx in msg.OBX)
{
	if(obx['OBX.5']['OBX.5.1'].toString().substring(0, 26) == 'PM******** ORIGINAL REPORT')
	{
		var obxCount = obx['OBX.1']['OBX.1.1'];
		delete (msg.children()[obx.childIndex()]);
	}
	else if(obx['OBX.1']['OBX.1.1'].toString() > obxCount)
	{
		delete (msg.children()[obx.childIndex()]);
	}
}
Reply With Quote
  #3  
Old 10-23-2015, 04:52 AM
nikoli nikoli is offline
OBX.1 Kenobi
 
Join Date: Jan 2013
Posts: 33
nikoli is on a distinguished road
Default

This works, but only for the following 5 OBX segments from the deletion point. It deletes the found text and segment at OBX|5| and OBX|6| through OBX|9| as well, but stops there. OBX|10| through OBX|34| remain. I tried stepping through the code to see why it is stopping at this point, but could not find a problem. The first segment that did not delete at OBX|10| is as follows:

OBX|10|FT|93930&BODY^US Bilateral UE Arterial Doppler/Duplex||TECHNIQUE: Axial images of the chest were obtained including sagittal and||||||A|||20151001123352||

Just to be certain, I changed the found text code to be exact for OBX.5.1

if(obx['OBX.5']['OBX.5.1'].toString().substring() == 'PM******** ORIGINAL REPORT ********')

Thanks for the help with this!
Reply With Quote
  #4  
Old 10-23-2015, 04:59 AM
mcalKno mcalKno is offline
 
Join Date: Apr 2015
Location: Pennsylvania
Posts: 247
mcalKno is on a distinguished road
Default

Quote:
Originally Posted by nikoli View Post
This works, but only for the following 5 OBX segments from the deletion point. It deletes the found text and segment at OBX|5| and OBX|6| through OBX|9| as well, but stops there. OBX|10| through OBX|34| remain. I tried stepping through the code to see why it is stopping at this point, but could not find a problem. The first segment that did not delete at OBX|10| is as follows:

OBX|10|FT|93930&BODY^US Bilateral UE Arterial Doppler/Duplex||TECHNIQUE: Axial images of the chest were obtained including sagittal and||||||A|||20151001123352||

Just to be certain, I changed the found text code to be exact for OBX.5.1

if(obx['OBX.5']['OBX.5.1'].toString().substring() == 'PM******** ORIGINAL REPORT ********')

Thanks for the help with this!

try this...

Code:
for each(obx in msg.OBX)
{
	if(obx['OBX.5']['OBX.5.1'].toString().substring(0, 26) == 'PM******** ORIGINAL REPORT')
	{
		var obxCount = obx['OBX.1']['OBX.1.1'];
		delete (msg.children()[obx.childIndex()]);
	}
	else if(parseInt(obx['OBX.1']['OBX.1.1'].toString()) > obxCount)
	{
		delete (msg.children()[obx.childIndex()]);
	}
}
Had to force the string to an Int for the compare

Last edited by mcalKno; 10-23-2015 at 05:02 AM.
Reply With Quote
  #5  
Old 10-23-2015, 05:21 AM
nikoli nikoli is offline
OBX.1 Kenobi
 
Join Date: Jan 2013
Posts: 33
nikoli is on a distinguished road
Default

That did the trick! Thanks again for the help!
Reply With Quote
Reply

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 09:52 AM.


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