how do i get the "children" segments?

199 views
Skip to first unread message

Derick Bailey

unread,
Apr 19, 2011, 12:54:21 PM4/19/11
to ruby...@googlegroups.com
I have an HL7 doc with several OBR segments. each OBR has multiple OBX segments that are associated to it. How do I get the child OBX segments, for a given OBR segment?

  -Derick

-- 
-----------------------
END OF LINE

Jimmy Dee

unread,
Apr 19, 2011, 1:04:27 PM4/19/11
to ruby...@googlegroups.com
There is a method HL7::Message::Segment#children that returns a collection of all child segments associated with a particular segment. If you call HL7::Message::Segment::OBR#children, you'll potentially get SPM segments as well as OBX segments, but you can easily filter those out:

  obx_children = obr_segment.children.select { |s| s.is_a? HL7::Message::Segment::OBX }

Derick Bailey

unread,
Apr 19, 2011, 2:25:30 PM4/19/11
to ruby...@googlegroups.com
do the child segments have to be in a specific order? or is there any other criteria by which the code knows what is / is not a child?

here's the gist of what i'm doing:

obr = msg[:OBR].select{|seg| ... some critieria to get the right OBR}.first
obx = obr.children.select{ |seg| ... more criteria to get the right obx}

but when i run this, obr.children comes back as empty.

my file has OBR / OBX data.  here's a sample of the data i'm using:

OBR|14|...|
OBX|1|...|
OBX|2|...|
OBX|3|...|
OBR|15|...|
OBX|1|...|

my code is looking for OBR 14, and finding it. i'm getting the correct OBR segment back... but no children for it.

any ideas?

  -derick

-- 
-----------------------
END OF LINE

Derick Bailey

unread,
Apr 19, 2011, 6:08:36 PM4/19/11
to ruby...@googlegroups.com
found the problem... windows line endings in the hl7 file. here's how i fixed it:

raw_data = open(file).readlines
data = raw_data.map{|seg| seg.strip!}.join("\r")
msg = HL7::Message.new(data)

and from there, my code works fine and the children and parsed correctly.

  -derick

-- 
-----------------------
END OF LINE

Reply all
Reply to author
Forward
0 new messages