web stats
Accepting wanted segments instead of deleting the unwanted ones. - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 06-14-2012, 07:14 AM
bob.nwl bob.nwl is offline
What's HL7?
 
Join Date: May 2012
Location: New Albany, IN
Posts: 4
bob.nwl is on a distinguished road
Default Accepting wanted segments instead of deleting the unwanted ones.

Currently my transformer deletes a list of unwanted segments.
delete msg['ZIR'];
delete msg['ZEN'];
delete msg['ZSP'];
Is there a way to keep only the segments that I need without using the static delete so that changes in the source message such as adding another z or IN segment do not affect the channel?

Something along the lines of:

If segment is not MSH, PID PV1 then delete segment.
Reply With Quote
  #2  
Old 06-14-2012, 08:00 AM
cory_cole cory_cole is offline
Mirth Guru
 
Join Date: Mar 2012
Posts: 1,347
cory_cole is on a distinguished road
Default

for each (seg in msg)
{
segName = seg.name().toString();
if(segName != 'PID' && segName != 'MSH' && segName != 'PV1')
{
delete seg;
}
}
Reply With Quote
  #3  
Old 06-18-2012, 12:59 PM
Bostad Bostad is offline
Level 85 Channel Wizard
 
Join Date: Mar 2009
Location: Stratford Ontario
Posts: 712
Bostad is an unknown quantity at this point
Default

If you have a large set of segments you want to keep you could do this:

Code:
var strGoodSeg = 'MSH~PID~PV1~NK1~OBR'  //you get the point right?


for each (seg in msg.children()) {

   var strCurSeg = seg.name();

   if (strGoodSeg.indexOf(strCurSeg) < 0) {     //okay to delete

         delete seg;
 }

}
__________________
I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
http://www.linkedin.com/pub/david-rothbauer/5/923/518
codeismydrug.wordpress.com
hl7coders.wordpress.com

Test all my code suggestions prior to implementation
Reply With Quote
  #4  
Old 12-22-2019, 07:10 PM
robertb1 robertb1 is offline
Mirth Newb
 
Join Date: Aug 2019
Posts: 14
robertb1 is on a distinguished road
Default

Apologies for revitalizing this old thread but I find myself in a similar situation.
I also would like to only keep MSH, PID, NTE, and delete everything else. I tried the code above by Cory Cole and Bostad and it is not working for me.
The delete msg['IN1'] for example works fine but like the author, I want something more robust than the static delete function.
I have tried the code as javascript in both source and destination transformer.
When I send a test message the entire message passes through as if the javascript was not there. (Yes the transformer is checked).

I am on version 3.8.0
Appreciate any tips.
Thank you
Reply With Quote
  #5  
Old 12-23-2019, 10:54 AM
agermano agermano is offline
Mirth Guru
 
Join Date: Apr 2017
Location: Indiana, USA
Posts: 1,106
agermano is on a distinguished road
Default

Here's a different way to do it.

Code:
const segmentsToKeep = new java.util.HashSet(['MSH','PID','NTE']);
var newChildren = new XMLList();
for each (var seg in msg.children()) {
    if (segmentsToKeep.contains(seg.localName())) newChildren += seg;
}
msg.setChildren(newChildren);
Reply With Quote
  #6  
Old 12-24-2019, 07:25 AM
robertb1 robertb1 is offline
Mirth Newb
 
Join Date: Aug 2019
Posts: 14
robertb1 is on a distinguished road
Default

Thank you this one works.
Reply With Quote
Reply

Tags
delete segment, segment

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 08:55 PM.


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