Announcement

Collapse
No announcement yet.

Repeating OBX segments with null data

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

  • Repeating OBX segments with null data

    Using the attached sample message, with this JS in a destination transformer step:

    Code:
    var obxi = 0;
    
    while (msg['OBX']['OBX.1']['OBX.1.1'][obxi] != null) {
      logger.info(obxi + ' instance of OBX.5.1 = ' + msg['OBX']['OBX.5']['OBX.5.1'][obxi]);
    obxi++;
    }
    ....is resulting in this in the log:

    0 instance of OBX.5.1 = 279
    1 instance of OBX.5.1 = 265
    2 instance of OBX.5.1 = 41
    3 instance of OBX.5.1 = Test cancelled because triglycerides >250 mg/dL
    4 instance of OBX.5.1 = 15
    5 instance of OBX.5.1 = undefined

    The fourth instance of OBX.5.1 should be null, but we seem to be skipping to the next instance instead, leaving an "undefined" for the last instance. Any ideas what's causing this and how to fix it?

    sample_ORU_R01.txt (877 bytes)

  • #2
    Re:Repeating OBX segments with null data

    Try checking for string length > 0 also.

    Sample code:
    Code:
    var obxi = 0;
    var tempOBX = "";
    
    while (msg['OBX']['OBX.1']['OBX.1.1'][obxi] != null) {
      tempOBX = msg['OBX']['OBX.1']['OBX.1.1'][obxi].toString();
      if (tempOBX.length > 0) {
         logger.info(obxi + ' instance of OBX.5.1 = ' + msg['OBX']['OBX.5']['OBX.5.1'][obxi]);
      } 
    obxi++;
    }
    Hope it helps!

    Comment


    • #3
      Re:Repeating OBX segments with null data

      Checking for string length > 0 did not help, but putting the obxi variable in the right place made it work just right:

      Code:
      logger.info(obxi + ' instance of OBX.5.1 = ' + msg['OBX'][obxi]['OBX.5']['OBX.5.1']);

      Comment

      Working...
      X