Announcement

Collapse
No announcement yet.

Sort/Rearrange OBX segments based on OBX-3 code/name?

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

  • Sort/Rearrange OBX segments based on OBX-3 code/name?

    Hello,

    We are sending result messages to a receiving system that requires OBX segments to be sorted based on orders of the OBX-3 content. Unfortunately our system doesn't generates OBXs in the same order required by the receiving site.

    Has anyone done similar task before? - Sorting OBX segments based on the code or name in OBX-3. For example, if I have three OBXs below:

    OBX|1|ST|13968-3^PENICILLIN
    OBX|2|ST|194-1^CLINDAMYCIN
    OBX|3|ST|525-6^VANCOMYCIN

    And I want to sort them based on their code in OBX-3.1 so the output will be:
    (only consider the value of code before the "-")
    OBX|1|ST|194-1^CLINDAMYCIN
    OBX|2|ST|525-6^VANCOMYCIN
    OBX|3|ST|13968-3^PENICILLIN

    How should I proceed? Any comments/suggestions will be greatly appreciated!

    Jason

  • #2
    var tmpOBX = new Array();
    for each (obx in msg..OBX)//sort OBX
    {
    if (tmpOBX.length == 0)
    {
    tmpOBX.push(obx);
    }
    else
    {
    for(i = 0; i < tmpOBX.length; i++)
    {
    if (tmpOBX[i]['OBX.3']['OBX.3.1'].toString() > obx['OBX.3']['OBX.3.1'].toString())
    {
    tmpOBX.insert(i, obx);
    i = tmpOBX.length; //short circuit if inserted
    }
    if(i == tmpOBX.length - 1)//if last at end of list add to end
    {
    tmpOBX.push(obx);
    }
    }
    }

    for(j = 0; j < tmpOBX.length; j++)//renumber OBXs and replace in msg
    {
    tmpOBX[j]['OBX.1']['OBX.1.1'] = j + 1;
    msg['OBX'][j] = tmpOBX[j];
    }

    Comment


    • #3
      You could use Collections as well:

      Code:
      var obxList = new java.util.ArrayList();
      for each (obx in msg.OBX)
      	obxList.add(obx);
      
      java.util.Collections.sort(obxList,new java.util.Comparator({compare:function(o1, o2) {
      	function getIDValue(node) {
      		var obsId = node['OBX.3']['OBX.3.1'].toString();
      		return parseInt(obsId.substr(0,obsId.indexOf('-')),10);
      	}
      	return getIDValue(o1) - getIDValue(o2);
      }}));
      
      for (var i = 0; i <= obxList.size()-1; i++) {
      	msg.OBX[i] = obxList.get(i);
      	msg.OBX[i]['OBX.1']['OBX.1.1'] = i+1;
      }
      Step 1: JAVA CACHE...DID YOU CLEAR ...wait, ding dong the witch is dead?

      Nicholas Rupley
      Work: 949-237-6069
      Always include what Mirth Connect version you're working with. Also include (if applicable) the code you're using and full stacktraces for errors (use CODE tags). Posting your entire channel is helpful as well; make sure to scrub any PHI/passwords first.


      - How do I foo?
      - You just bar.

      Comment


      • #4
        Cool.

        thanks Cory and narupley!

        Comment


        • #5
          I have a similar issue.

          i need to sort these statements
          i have copied the numbers from OBX.3.1 to OBX.4.1 and would like to order numerically on OBR.4.1

          any help would be much appreciated, in my testing it looks like Java script is sorting by string values, not numerical.


          OBX|10||Statement 20|20|Date: mmddyyyy||||||AS
          OBX|11||Statement 21|21|Time: hh:mm:ss||||||AS
          OBX|12||Statement 22|22|User: N/A||||||AS
          OBX|13||Statement 23|23|Computer: <ComputerName>||||||AS
          OBX|14||Statement 24|24|Description:||||||AS
          OBX|15||Statement 25|25|The Windows Installer service entered the stopped state.||||||AS
          OBX|16||Statement 26|26|For more information, see Help and Support Center at <http://go.microsoft.com/fwlink/events.asp>.||||||AS
          OBX|17||Statement 27|27|||||||AS
          OBX|18||Statement 28|28|larry||||||AS
          OBX|19||Statement 29|29|Seieroe||||||AS
          OBX|20||Statement 30|30|||||||AS
          OBX|21||Statement 31|31|was here today||||||AS
          OBX|22||Statement 1|1|||||||AS
          OBX|23||Statement 2.1|2.1|The system Event log will show that the Windows Installer Service is starting and stopping||||||AS
          OBX|24||Statement 2.2|2.2|automatically.||||||AS
          OBX|25||Statement 3|3|||||||AS
          OBX|26||Statement 4|4|Event Type: Information||||||AS
          OBX|27||Statement 5|5|Event Source: Service Control Manager||||||AS
          OBX|28||Statement 6|6|Event Category: None||||||AS
          OBX|29||Statement 7|7|Event ID: 7035||||||AS
          OBX|30||Statement 8|8|Date: mmddyyyy||||||AS
          Larry aka(Skippy)

          Comment

          Working...
          X