Question Christine Nyamu · May 12, 2023

HOW TO SEARCH IF A STRING EXISTS IN A LOOKUP TABLE

Hello,

I am quite new to the InterSystems world. I have one of my OBX 5 fields having this value "blood work was done<>tested positive for anemia<>tested negative for hepatitis". I have a lookup table "AnemiaResults" with a key of TESTED POSITIVE FOR ANEMIA. My issue is that since OBX 5 has other characters/text  (and OBX is a repeating segment) , I am unable to use the Exists function. Any idea how to tackle this? Any assistance will be greatly appreciated. 

Product version: IRIS 2021.2

Comments

Cristiano Silva · May 12, 2023

Hi @Christine Nyamu 

Use $Piece function to get the value of a delimited string. In you specific case:

Set value = $Piece(obxValue, "<>", 2)

I assumed that the variable obxValue was set before in the code.

Note if the in the obx segment the value change the order like, "TESTED POSITIVE FOR ANEMIA<>BLOOD WORK WAS DONE<>TESTED NEGATIVE FOR HEPATITIS", the above sample code will fail

0
Christine Nyamu  May 12, 2023 to Cristiano Silva

Thanks for your reply. Will try it out 

Edited to add:

Would Set value = $Piece(obxValue, "<>", *) work?

0
Christine Nyamu  May 12, 2023 to Cristiano Silva

The challenge is that the text does not follow any particular order :-(

0
Alex Woodhead · May 13, 2023

Hi Christine,

Please consider if the following snippet may be helpful.

Includes some common checks to prevent invalid lookup

Class Test.Fun Extends Ens.Rule.FunctionSet{ClassMethod ExistsAny(pTable As %String = "", pValue As %String = "", pDelimiter As %String = "<>") As %Boolean [ Final ]{  Quit:""=pTable 0  Quit:""=pValue 0  Quit:""=pDelimiter 0  Set result=0// Use Length Function to count delimited fields. Always one or more
  Set len=$Length(pValue,pDelimiter)  For i=1:1:len {    Set key=$Piece(pValue,pDelimiter,i)    // strip white space at front and end    Set key=$ZSTRIP(key,"<>W")    // Avoid empty string for key lookup    Continue:""=key    // make uppercase for case insensitive search    Set key=$ZCVT(key,"U")    If $Data(^Ens.LookupTable(pTable,key)) {      Set result=1      Quit    }  }  Return result}
} 
0
Yone Moreno  May 15, 2023 to Alex Woodhead

Thanks for your reply Alex Woodhead. You seem to offer a very complete solution and handle some special cases, such as whitespace removal and case insensitive searches.

0
Christine Nyamu  May 15, 2023 to Alex Woodhead

Hi @Alex Woodhead 

At which point do we actually specify the lookup table we are searching against in the function? In my case, the table is AnemiaResults 

0
Alex Woodhead  May 15, 2023 to Christine Nyamu

In Routing Rule context, the newly projected function ExistsAny is applied.

The first argument is the LookupTable name from method signature.

An example expression:

1=(ExistsAny("AnemiaResults",Document.[OBX:5]))

0