This topic contains 0 replies, has 1 voice, and was last updated by  lev 8 years, 4 months ago.

Filter messages by multiple values from the message itself.

  • Recently a customer asked what would be right way to filter messages if he needs to filter them by combination of multiple values taken from different Fields across given message Segments.

    So I expanded a little our well know example from page http://help.interfaceware.com/kb/filter-out-messages.

    Here, we will use Lua lists and other handy things to make the code reasonably maintainable and easily scalable to any number of values to compare.

    
    local Filter_1 = {'a','b','MESA_ADT','c'}
    local Filter_2 = {'XYZ_ADMITTING','d','e','f'}
    
    function main(myData)  
       local In = hl7.parse{vmd = 'matchAll.vmd', data = myData }
       local L = {
          MakeLookup(Filter_1),
          MakeLookup(Filter_2)
       }
       local P = {
          In.MSH[3][1]:nodeValue(),
          In.MSH[4][1]:nodeValue()
       }   
       local function push_valid()  
          local push = {}      
          for i =1,#L do
             push[i] = false
             if L[i](P[i]) then
                push[i] = true   
             end
          end
          
          if not MakeLookup(push)(false) then 
             return true 
          end
       end  
       if push_valid() then 
          queue.push{data=myData} 
       end
    end
    
    function MakeLookup(T)
       local L = {}
       for i=1, #T do
          L[T[i]] = true
       end
       return function(V) return L[(V)] end
    end
    

    The above code assumes two values to filter by.

    If you need to filter by 3 values, then add in three places:
    – add line local Filter_3 = {}
    – add MakeLookup(Filter_3) declaration to list ‘L’
    – add to list ‘P’ source Segment/Field to take the 3rd value from, e.g. In.MSH[4][1]:nodeValue()

    That’s it.

    Translator project for impatient is attached below.
    Have fun and feel free to modify as you please, this is only example.

    Attachments:
    You must be logged in to view attached files.

You must be logged in to reply to this topic.