Question
· Oct 9, 2021

How to check repeating segment value in business rule?

Hi,

In the business rule I want to send a message to the business operation if any of OBX:8 (Abnormal Flag) is set.

I tried foreach but could not found desire results. Below is the sample message:

Thanks

Discussion (7)3
Log in or sign up to continue

I will add that I am very grateful to ISC for finally adding this foreach feature to the routing rule functionality (it appears to have become available with 2020.4). I have one quibble, though ... it would be wonderful to be able to exit the loop without returning from the ruleset (i.e. "break"). The current mechanism forces you to loop through all repetitions regardless of the desired condition being met before the final loop iteration is reached.

A design pattern where I might wish to assign a value to a variable and exit the loop when the condition is met (rather than executing a send) is something I can envision doing regularly.

With some help we created a function to loop through a repeating field and verify values against a single string, and a variation against a Lookup Table...

ClassMethod DoesSingleValueExistRepeatingSegmentFields(pHL7Msg As EnsLib.HL7.Message, pSegment As %String, pField As %String, pSubField As %String, pInputValue As %String) As %Boolean

{

   #dim tSeg as EnsLib.HL7.Segment

   set tSegCount = pHL7Msg.SegCountGet()

   set i = 1

   set j = 1

   Set tFound = 0

   //get new values

   set tval=""

   while ((i <= tSegCount) && (tval="")) {

     set tSeg = pHL7Msg.GetSegmentAt(i)

     if (tSeg.Name = pSegment) {

      set pField2 = pField_"(*)"

      set tRepCount = tSeg.GetValueAt(pField2)

      while ((j <= tRepCount) && (tval="")) {

        set tID = tSeg.GetValueAt(pField_"("_j_")"_"."_pSubField)

        if (pInputValue = tID) {

         set tval = 1

        }

       set j = j + 1

      }

     }

     set i = i + 1

   }

   if (tval '= "")

   {

      Q 1

   }

   quit 0

}