web stats
msg .. OBX or multiple segments or hierarchy - Mirth Community

Go Back   Mirth Community > Mirth Connect > Support

Reply
 
Thread Tools Display Modes
  #1  
Old 04-12-2012, 11:50 AM
jmjiru jmjiru is offline
Mirth Newb
 
Join Date: Mar 2012
Posts: 10
jmjiru is on a distinguished road
Default msg .. OBX or multiple segments or hierarchy

Hi all,
I noticed in some posts that when people for showing how to iterate over multiple segments, they used this (msg..OBX) as part of their code. I'm still very new to Mirth and HL7 so I was wondering why that format and not (msg.OBX)? Also I am still trying to understand the hierarchy that Mirth uses for HL7. Is this correct: messageObject is the whole message which Mirth uses msg as the global; so I could use "for each (segment in msg.children)" but could I use "for each (field in msg.children.child)"? I know that the hierarchy is segment/field/component/subcomponent but what comes after msg.children.child or is that even legal code? Well it must be legal because I'm not getting errors. My brain is starting to smoke so I will go now
Thanks for any help.
Reply With Quote
  #2  
Old 04-13-2012, 05:18 AM
narupley's Avatar
narupley narupley is offline
Mirth Employee
 
Join Date: Oct 2010
Posts: 4,543
narupley is on a distinguished road
Default

Quote:
Originally Posted by jmjiru View Post
Hi all,
I noticed in some posts that when people for showing how to iterate over multiple segments, they used this (msg..OBX) as part of their code. I'm still very new to Mirth and HL7 so I was wondering why that format and not (msg.OBX)?
Don't worry, I had that question at first too. It's actually an E4X thing: "node.elementname" returns an XMLList of all children of node with the QName "elementname". On the other hand, "node..elementname" returns an XMLList of all descendants of node with the QName "elementname". Say you had the following XML:

Code:
<message>
	<result>test0</result>
	<level1>
		<result>test1</result>
		<level2>
			<result>test2</result>
			<level3>
				<result>test3</result>
			</level3>
		</level2>
	</level1>
</message>
In Mirth, if you referenced msg.result, you would get:

Code:
<result>test0</result>
However, if you referenced msg..result, you would get:

Code:
<result>test0</result>
<result>test1</result>
<result>test2</result>
<result>test3</result>
In most cases, it's probably safer to stick with the single dot notation rather than the double dot. For example, if you're working with CCDs and you wanted to get the OID of a particular node, you would want to reference node.id.@root and not node..id.@root.

In most cases here on the forums, people work with HL7 2.x and no strict parser. So, both "msg.OBX" and "msg..OBX" do exactly the same thing, since all segments of an HL7 message are direct children of the root node. However, if you use the strict parser, then all segments are not direct children of the root node, so that descendants syntax may come into play, depending on what you're trying to do.

Quote:
Originally Posted by jmjiru View Post
Also I am still trying to understand the hierarchy that Mirth uses for HL7. Is this correct: messageObject is the whole message which Mirth uses msg as the global; so I could use "for each (segment in msg.children)" but could I use "for each (field in msg.children.child)"? I know that the hierarchy is segment/field/component/subcomponent but what comes after msg.children.child or is that even legal code? Well it must be legal because I'm not getting errors. My brain is starting to smoke so I will go now
Thanks for any help.
messageObject is the current MessageObject associated with a message; there's a separate instance for each connector. In the postprocessor, messageObject always refers to that of the Source connector.

The variable msg is an E4X XML object representation of the raw data of a connector. So, all E4X properties and methods apply. You can use "for each (seg in msg.children())" to iterate through each child of the root node. The child(index) method returns the child of a node at a specified index. So technically, instead of msg.MSH or msg['MSH'], you could also use msg.child(0). If you want to reference a field of a segment, realize that now you're just going another level deeper, that's all. So to get all instances of PID.3 (assuming you have field repetition parsing turned on), you would do "for each (field in msg.PID['PID.3'])".
Reply With Quote
Reply

Tags
global map, hl7 messages, msg, multiple segments

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 -7. The time now is 06:50 AM.


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