web stats
Changing XML Tag Names with Field and Component Descriptions - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 02-06-2014, 07:51 AM
marke marke is offline
Mirth Newb
 
Join Date: Jan 2013
Posts: 20
marke is on a distinguished road
Cool Changing XML Tag Names with Field and Component Descriptions

Hello, I am using MirthConnect 3.0, and it appears that my Javascript cannot recognize:
-- getSegmentorCompositeFieldDescription
-- getCompositeFieldDescriptionWithSegment
I'm trying to rename the XML tags using code I found on another post: http://www.mirthcorp.com/community/f...ead.php?t=6988

Any suggestions are greatly appreciated!

Here is the code:
--------------------------------------------------------
importPackage(com.mirth.connect.model.hl7v2);

String.prototype.escape = function() {return (this+'').replace(/[\s\/<>']/g,'');};

tmp = msg.copy();

for each (seg in tmp.children())

for each (field in seg.children()) {
if (field.name())
field.setName(Component.getSegmentorCompositeField Description(field.name().toString(),false).escape( ));

for each (component in field.children()){
logger.info(component.name())
if (component.name())
component.setName(Component.getCompositeFieldDescr iptionWithSegment(component.name().toString(),fals e).escape());
}
}

Thank you

Last edited by marke; 02-06-2014 at 07:56 AM. Reason: added reference to post
Reply With Quote
  #2  
Old 02-06-2014, 08:23 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

That should still work in 3.x. However, there are a couple tweaks I would make to the code to ensure it works for all types of messages:

Code:
importPackage(com.mirth.connect.model.hl7v2);
String.prototype.escape = function() {return (this+'').replace(/[\s\/<>',]/g,'')};

for each (seg in msg.children()) {
	for each (field in seg.children()) {
		if (field.name()) {
			field.setName(Component.getSegmentorCompositeFieldDescription(field.name().toString(),false).escape() || field.name());
		}

		for each (component in field.children()) {
			if (component.name()) {
				component.setName(Component.getCompositeFieldDescriptionWithSegment(component.name().toString(),false).escape() || 'Value');
			}
		}
	}
}
Replace msg with tmp if necessary. I'll also attach an example channel.
Attached Files
File Type: xml Example - Use HL7v2 Descriptions in XML.xml (13.1 KB, 53 views)
__________________
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 02-06-2014, 09:25 AM
marke marke is offline
Mirth Newb
 
Join Date: Jan 2013
Posts: 20
marke is on a distinguished road
Default

Man this is awesome - thank you!
Regarding the output of the [Example - Use HL7v2 Descriptions in XML] channel shown below - is there a way to replace the tags for:
<MSH.12.2.1> thru <MSH.12.2.9> ? Or have we hit the limits!

Output:
--------------------------------------------
-<VersionID>
<VersionID>2.6</VersionID>
-<InternationalizationCode>
<MSH.12.2.1>VersionID_InternationalizationCode_Ide ntifier</MSH.12.2.1>
<MSH.12.2.2>VersionID_InternationalizationCode_Tex t</MSH.12.2.2>
<MSH.12.2.3>VersionID_InternationalizationCode_Nam eOfCodingSystem</MSH.12.2.3>
<MSH.12.2.4>VersionID_InternationalizationCode_Alt ernateIdentifier</MSH.12.2.4>
<MSH.12.2.5>VersionID_InternationalizationCode_Alt ernateText</MSH.12.2.5>
<MSH.12.2.6>VersionID_InternationalizationCode_Nam eOfAlternateCodingSystem</MSH.12.2.6>
<MSH.12.2.7>VersionID_InternationalizationCode_Cod ingSystemVersionID</MSH.12.2.7>
<MSH.12.2.8>VersionID_InternationalizationCode_Alt ernateCodingSystemVersionID</MSH.12.2.8>
<MSH.12.2.9>VersionID_InternationalizationCode_Ori ginalText</MSH.12.2.9>
</InternationalizationCode>
Reply With Quote
  #4  
Old 02-06-2014, 10:42 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 7,126
narupley is on a distinguished road
Default

Unfortunately yeah, the reference XML just doesn't currently go down to the subcomponent level. However, you can always manually override the tag names yourself.
__________________
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

Tags
rename, xml, xml tags

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 10:13 PM.


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