Announcement

Collapse
No announcement yet.

Link OBX5 using assigned values

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

  • Link OBX5 using assigned values

    Hello Everyone,

    I am working on a feed that has several OBX segments. There are OBX upwards of about 40 OBX segments on each message.

    I need to do the following:
    1. Take all of the OBX with the same values in OBX and add or clump the OBX5 values together.
    2. Take all of the values in OBX 4 and assign the OBX set ID value accordingly.
    3. Delete all of the original OBX segments

    So, for example, suppose below are some of the OBX segments

    OBX|1|NM|1|A|Hi|||||||
    OBX|2|NM|2|B||I|||||||
    OBX|3|NM|1|A|How||||||
    OBX|4|NM|2|B|am|||||||
    OBX|5|NM|1|A|Are||||||
    OBX|6|NM|2|B|Fine|||||
    OBX|7|NM|1|A|You||||||

    The OBX structure should be transformed to the following
    OBX|1|NM|||Hi how are you
    OBX|2|NM|||I am fine


    So basically, each of the OBX that has a value of “1” had the OBX5 values linked together. Likewise, all OBX segments with a value of “2” had the OBX5 linked together...
    And OBX with a value of “A” was assigned a set ID of 1, and "B" set ID of 2.
    And all of the original OBX segments have been removed

    Any help on this will be greatly appreciated

  • #2
    Code:
    var obxGroups = [];
    var newObxList = new XMLList();
    for each (var obx in msg.OBX) {
        seqNo = obx['OBX.3']['OBX.3.1'].toString();
        if (typeof obxGroups[seqNo] == 'undefined') {
            obxGroups[seqNo] = [];
        }
        obxGroups[seqNo].push(obx['OBX.5']['OBX.5.1'].toString());
    }
    
    obxGroups.forEach(function(components,seqNo) {
        newObxList += <OBX>
            <OBX.1>
                <OBX.1.1>{seqNo}</OBX.1.1>
            </OBX.1>
            <OBX.2>
                <OBX.2.1>NM</OBX.2.1>
            </OBX.2>
            <OBX.3/>
            <OBX.4/>
            <OBX.5>
                <OBX.5.1>{components.join(' ')}</OBX.5.1>
            </OBX.5>
        </OBX>;
    });
    
    msg.OBX = newObxList;

    Comment


    • #3
      Thanks agermano. I have been OOO and back now. Will try the code you provided.. and update you.

      Comment


      • #4
        Hey agermano, this works great when OBX3.1 has a numeric value. Can't get it to work for non numeric values in OBX3.1, is there a way to change that?

        Thanks for all of the help, much appreciated.

        Comment


        • #5
          Wouldn't OBX.3.1 have to have a numeric value if you're going to use that to set the OBX.1.1 value of the new segment?

          Can you give another example where this isn't the case and how you want it to be handled?

          Comment

          Working...
          X