Announcement

Collapse
No announcement yet.

Filter with multiple conditions

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Filter with multiple conditions

    I am trying to create a filter that will look to see if a message meets multiple conditions to filter the message or allow it through. The filter needs to look at both the type of Order (OBR 4.2) and the Ordering Physician (OBR 16.1). If both the order type and ordering physician do not equal specific values then it should allow the message through. Right now it is filtering the message if even one of the fields meets the criteria. Here is the javascript that I am using.

    if (( $('OrderType') != "CARDIAC" || $('OrderType') != "ABI" || $('OrderType') != "CARTID" || $('OrderType') != "LEADBIL" || $('OrderType') != "LEADBIX" || $('OrderType') != "LEADIBIL" || $('OrderType') != "LEADILT" || $('OrderType') != "LEADIRT" || $('OrderType') != "LEADLT" || $('OrderType') != "LEADRT" || $('OrderType') != "LEADUBIL" || $('OrderType') != "LEALT" || $('OrderType') != "LEART" || $('OrderType') != "LEVREF") && ($('OrderPhys') != "MIRZU" || $('OrderPhys') != "HARED" || $('OrderPhys') != "HARAC")) {
    return true;
    }

  • #2
    change || to &&

    Comment


    • #3
      Cory is right. Changing all of your ORs to ANDs will fix the problem.

      If you want to use some javascript features and make the code a little easier to manage, you can do something like below. I'd recommend putting the codes in an order that makes them easy to locate.

      PHP Code:
      var orderTypes = [
          
      'CARDIAC',
          
      'ABI',
          
      'CARTID'
      ];

      var 
      orderDocs = [
          
      'MIRZU',
          
      'HARED',
          
      'HARAC'
      ];

      function 
      notEquals(string) {
          return function 
      notEquals(other) { return string != other; };
      }

      return 
      orderTypes.every(notEquals($('OrderType'))) && orderDocs.every(notEquals($('OrderPhys'))); 

      Comment

      Working...
      X