Scott Roth · Mar 23, 2021

Using ChildCount from EnsLib.HL7.Message to get repeatable fields

A while back I asked the developer community for a way to loop through repeatable HL7 segments and check them against a Data Lookup table within a Business Rule.

The example I got was the following...

ClassMethod GroupIDExists(pHL7Msg As EnsLib.HL7.Message, pSegment As %String, pField As %String, pLookupTable As %String) As %Boolean
            #dim tSeg as EnsLib.HL7.Segment
            set tSegCount = pHL7Msg.SegCountGet()
            set i = 1
            Set tFound = 0
            //get new values
            set tval=""
            while ((i <= tSegCount) && (tval="")) {
                        set tSeg = pHL7Msg.GetSegmentAt(i)
                        if (tSeg.Name = pSegment) {
                                    set tID = tSeg.GetValueAt(pField)
                                    set tval= ..Lookup(pLookupTable, tID)
                        set i = i + 1 
            if (tval '= "")
                        Q 1 
            quit 0

While this works perfect when you have RGSgrp or a OBXgrp because it is using SegCountGet(), our team is looking to take that a bit further. What if we wanted to loop through OBR.4() and compare it to a Data Lookup table within a Business Rule.

  • Could I go about doing this by using ChildCount() in EnsLib.HL7.Message?
  • Or how would I go about getting the count of a Field within a segment to loop through?



Product version: HealthShare 2018.1
$ZV: Cache for UNIX (IBM AIX for System Power System-64) 2018.1.3 (Build 414U) Mon Oct 28 2019 11:24:02 EDT
1 0 1 67
Log in or sign up to continue


Hi Scott,

You can get the repetition count for a field with the GetValueAt() method:

Set tRepCount = msg.GetValueAt("OBX(3):5(*)")

You can then iterate over the repetitions in a FOR loop:

For tRep = 1:1:tRepCount
    If msg.GetValueAt("OBX(3):5("_tRep_")") = tMatchVal
        // Do stuff