Announcement

Collapse
No announcement yet.

Issue with parsing OBX value

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

  • Issue with parsing OBX value

    We need to reject the result if any of the OBX 5 contains either '***' or '<>'. The no of OBX are random. There are no error message and the result is making it to destination. i have below code for it in my transformer i also tried to use in Filter but same result.

    Code:
    for(var a=0; a<msg['OBX'].length();a++ ){
    	if (msg['OBX'][a]['OBX.5']['OBX.5.1'].toString() != '***' && msg['OBX'][a]['OBX.5']['OBX.5.1'].toString() != '<>')
    	return true;
    	{
    	return false;
    }
    }
    This is the sample message i use

    MSH|^~\&|TEST|TEST|||20110529130917-04:00||ORU^R30^ORU-R30|1|P|2.6
    PID|1|12349|123||E^A^B^III||19610615|M|||2222 HOMESTREET^^GREENSBORO^NC^27401-1020|GL|(555) 555-2004|(555)555-2004||S||PATID12345001^2^M10^ADT1^AN^A
    ORC|NW|1234
    PV1|1|I|2000^2012^01||||004777^ATTEND^AARON^A^titl e|||||||1||||||||||||||||||||||||||||||20070110230 0|200701102300
    OBX|1||^HCT^LN||<10|%PCV|||||F|||||APOC3214|||2011 0529130917-04:00|MIX
    OBX|2||41651-1^GLU^LN||28|mg/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|3||^BUN^LN||139|mg/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|4||^CREA^LN||15.5|mg/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|5||^NA^LN||100|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|6||^K^LN||2.1|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|7||^CL^LN||76|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|8||^TCO2^LN||11|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|9||^ANGAP^LN||16|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|10||^ICA^LN||<>|mmol/L|||||F|||||APOC3214|||20110529130917-04:00|MIX
    OBX|11||^HB^LN||123|g/dL|||||F|||||APOC3214|||20110529130917-04:00|MIX
    NTE|1|||Sample Type=MIX||20110529130917-04:00
    NTE|2|||CPB=Yes||20110529130917-04:00
    NTE|3|||DSN=314237||20110529130917-04:00
    NTE|4|||HCT=LOW||20110529130917-04:00


    I also tried below code but same result no error and result is processed instead of reject

    Code:
    for(var Y=0; Y<msg['OBX'].length();Y++ ){
    	var OBXVal= msg['OBX'][Y]['OBX.5'].toString();
    	if (OBXVal == '***'  && OBXVal == '<>')
    	return false;
    	{
    	return true;
    }
    }

  • #2
    Hi,

    '&&' is a logical AND. Use '||' for an OR.

    I'm wondering if Mirth won't escape '<' to '&lt;' and '>' to '&gt;' as HL7 messages get parsed into XML.
    Tom

    Comment


    • #3
      You're missing the 'else' keyword before the block after your 'if' statement in both samples, however, you also can't return true in your loop or it will short circuit the loop after the first OBX and not check the rest. After you know that none of the OBX segments cause the message to reject, then it is safe to return true.

      Filtering must be done in a filter. Returning false from a transformer won't have the desired effect.

      It's not incorrect to loop with an index variable like you are doing, but there is a cleaner way to do it.

      Code:
      for each (obx5_1 in msg['OBX']['OBX.5']['OBX.5.1']) {
        if (obx5_1.toString().match(/^<>|\*\*\*$/))
          return false;
      }
      return true;
      This uses a regular expression to check that it matches exactly to '<>' or '***'. As aTom pointed out, you need to use a logical OR when checking for the false condition. It can never be both at the same time, so your AND will always be false.

      If you change the regular expression from /^<>|\*\*\*$/ to /<>|\*\*\*/, it will check for those character sequences anywhere in the string, even if it starts with spaces or has other characters following them.

      Mirth uses Mozilla Rhino as it's Javascript engine. Rhino uses a now depricated (but very useful) standard called e4x for processing XML. Your HL7 is represented by e4x xml objects in your filters/transformers. Here are a couple of resources for working with e4x:

      https://developer.mozilla.org/en-US/...g_XML_with_E4X

      https://wso2.com/project/mashup/0.2/...uickstart.html

      Comment


      • #4
        I like agermano's solution since it's short and sweet and uses reg expressions.

        Try something like this in your JavaScript type in Edit Filter and not in your Edit Transformer only if the value is *** or <> in OBX.5.1

        Code:
        // Initialize variable
        var suppress 
        
        // Loop through all the OBXs.
        for ( var a=0; a < msg['OBX'].length(); a++ )
        {
        	// Check for values in OBX and set suppress to yes if condition is met.
        	if (msg['OBX'][a]['OBX.5']['OBX.5.1'].toString() == '***' || msg['OBX'][a]['OBX.5']['OBX.5.1'].toString() == '<>')
        	{
        		//set the value for the variable
        		 suppress = 'yes';
        	} 
        }
        
        // if supress is yes then it will cause the message to be filtered.
        // else the message will get sent.
        if (suppress == 'yes') {
        	return false
        } else {
        	return true
        }
        Last edited by austina; 03-16-2018, 07:13 AM.

        Comment


        • #5
          Originally posted by aTom View Post
          I'm wondering if Mirth won't escape '<' to '&lt;' and '>' to '&gt;' as HL7 messages get parsed into XML.
          You're safe when calling toString().

          Code:
          js> x = <xml/>
          
          js> x.lt = '<'
          <
          js> x.lt.toString()
          <
          js> x.lt.toXMLString()
          <lt>&lt;</lt>

          Comment


          • #6
            Thank you all for your help. I am fairly new to mirth and programming so still trying to catch up. you guys are so helpful cant say how much thankful i am. @agermano thanks a lot for detailed explanation with link for further details. As a newcomer it really helps a lot to learn.

            Comment


            • #7
              My filter is working with manual coding but i upgraded my mirth to 3.6.1 and they have iterator function which i tried to use but some reason its not filtering the data if its *** can someone explain me why may be i am missing something very basic. I am really new to scripting/programming so sorry if its a dumb question but i really want to understand whats wrong with my iterator



              my manual code looks like below:

              Code:
              for ( var b=0; b < msg['OBX'].length(); b++ )
              {
              	// Check for values in OBX and set suppress to yes if condition is met.
              	var OBXValue = msg['OBX'][b]['OBX.5']['OBX.5.1'].toString();
              	if (OBXValue == '***')
              	{
              		//set the value for the variable
              		reject = true;
              		break;
              	}
              }
              
              if (reject == false) 
              { return true;} else 
              { return false; }
              the code generated by iterator looks like below:

              Code:
              var _iterator_flag_0 = false;
              for (var b = 0; b < getArrayOrXmlLength(msg['OBX']); b++) {
                  if (
                      (function() {
                          if (msg['OBX'][b]['OBX.5']['OBX.5.1'].toString() != '***') {
                              return true;
                          }
                          return false;
                      }() == true)
                  ) {
                      _iterator_flag_0 = true;
                      break;
                  }
              
              }
              return _iterator_flag_0;

              Comment


              • #8
                I think you just need to change your iterator to accept if All are true instead of At least one.

                Comment


                • #9
                  Actually its already set to At lease one only.

                  Comment

                  Working...
                  X