web stats
Deleting Components in Message - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 11-07-2012, 11:20 AM
ccitrano@tangible.com ccitrano@tangible.com is offline
OBX.3 Kenobi
 
Join Date: Apr 2008
Posts: 122
ccitrano@tangible.com
Default Deleting Components in Message

Hello,

Is there a way to iterate through the components in message and delete them.

In this specific example, I want to iterate through a PID-13 segment and delete all components beyond PID-13.7. I could hardcode it, but sometimes the messages have 14 components other times they have a different value. I am just trying to keep it clean ...


Code:
for(var i=7; i<msg['PID']['PID.13'].length();i++){
	index = 'PID.13.' + i+1;
	delete msg['PID']['PID.13'][index];
}
__________________
Chuck Citrano
ccitrano at tangible.com
[url][/http://www.tangible.comurl]
Reply With Quote
  #2  
Old 11-08-2012, 07:31 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

You've got the right idea; you just need to go one level further when testing the length of the child node list:

Code:
for each (component in msg.PID['PID.13'].children())
	if (parseInt(component.name().toString().substr(7),10) >= 7)
		delete msg.PID['PID.13'][component.name().toString()];
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
Reply With Quote
  #3  
Old 01-31-2013, 08:46 AM
ccitrano@tangible.com ccitrano@tangible.com is offline
OBX.3 Kenobi
 
Join Date: Apr 2008
Posts: 122
ccitrano@tangible.com
Default

Nick,

I'm trying to do this same thing for the NK1 segment which could have repeating segments. I've tried to modify the code to use an iterator but I'm missing something. Can you see what I'm doing wrong ...

Quote:
for(var i=0; i<msg['NK1'].length();i++){
for each (component in msg.NK1[i]['NK1.5'].children()) {
if (parseInt(component.name().toString().substr(7),10 ) > 7)
delete msg.NK1[i]['NK1.5'][component.name().toString()];
}
}
__________________
Chuck Citrano
ccitrano at tangible.com
[url][/http://www.tangible.comurl]
Reply With Quote
  #4  
Old 01-31-2013, 09:36 AM
ccitrano@tangible.com ccitrano@tangible.com is offline
OBX.3 Kenobi
 
Join Date: Apr 2008
Posts: 122
ccitrano@tangible.com
Default

I think I got it ...

Quote:
for each (nk1 in msg..NK1) {
for each (component in nk1['NK1.5'].children()) {
if (parseInt(component.name().toString().substr(6),10 ) > 7)
delete nk1['NK1.5'][component.name().toString()];
}
}
__________________
Chuck Citrano
ccitrano at tangible.com
[url][/http://www.tangible.comurl]
Reply With Quote
  #5  
Old 01-31-2013, 09:43 AM
narupley's Avatar
narupley narupley is online now
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

Quote:
Originally Posted by ccitrano@tangible.com View Post
Nick,

I'm trying to do this same thing for the NK1 segment which could have repeating segments. I've tried to modify the code to use an iterator but I'm missing something. Can you see what I'm doing wrong ...
Your substr call is probably returning an empty string because the length of the component QName is less than 8 (for components 1 through 9 anyway). Slide the starting index back and it should work.
__________________
Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

Nicholas Rupley
Work: 949-237-6069
Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


- How do I foo?
- You just bar.
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 01:33 AM.


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