Announcement

Collapse
No announcement yet.

Rearrange OBX sections in ORU based on Addendums

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

  • Rearrange OBX sections in ORU based on Addendums

    Hi everyone. Any help with this would be appreciated. We are trying to rearrange the OBX section of an HL7 ORU message based on the following:

    If no addendum leave original report as is

    If 1 addendum move the addendum section to be on top of the original report.

    If 2 addendums move addendum 2 on top of addendum 1 which is on top of the original report.

    If 3 addendums move addendum 3 on top of addendum 2, on top of 1, on top of original report.....you get the idea.

    Basically latest dications/addendums on top.

    Here is the message we need to transform. Below that is what we am trying to accomplish. Thanks for taking a peek, I realize this is a bit complicated (or at least seems to be as we try to make it do what we want it to do!)

    ORIGINAL REPORT:

    OBX|1||||TEST REPORT||||||F|||20160225215226||123456
    OBX|2||||||||||F|||20160225215226||123456
    OBX|3||||IMPRESSION:||||||F|||20160225215226||1234 56
    OBX|4||||Test impression.||||||F|||20160225215226||123456
    OBX|5||||||||||F|||20160225215226||123456
    OBX|6||||This report was electronically signed by:||||||F|||20160225215226||123456
    OBX|7||||||||||F|||20160225215226||123456
    OBX|8||||Rad Test MD||||||F|||20160225215226||123456
    OBX|9||||||||||F|||20160225215226||123456
    OBX|10||||||||||F|||20160225215226||123456
    OBX|11||||ADDENDUM:||||||F|||20160225215226||12345 6
    OBX|12||||||||||F|||20160225215226||123456
    OBX|13||||Test Addendum 1 notes||||||F|||20160225215226||123456
    OBX|14||||||||||F|||20160225215226||123456
    OBX|15||||This report was electronically signed by:||||||F|||20160225215226||123456
    OBX|16||||||||||F|||20160225215226||123456
    OBX|17||||Rad Test MD||||||F|||20160225215226||123456
    OBX|18||||||||||F|||20160225215226||123456
    OBX|19||||ADDENDUM:||||||F|||20160225215226||12345 6
    OBX|20||||||||||F|||20160225215226||123456
    OBX|21||||Test Addendum 2 notes||||||F|||20160225215226||123456
    OBX|22||||||||||F|||20160225215226||123456
    OBX|23||||This report was electronically signed by:||||||F|||20160225215226||123456
    OBX|24||||||||||F|||20160225215226||123456
    OBX|25||||Rad Test MD||||||F|||20160225215226||123456
    OBX|26||||||||||F|||20160225215226||123456
    OBX|27||||ADDENDUM:||||||F|||20160225215226||12345 6
    OBX|28||||||||||F|||20160225215226||123456
    OBX|29||||Test Addendum 3 notes||||||F|||20160225215226||123456
    OBX|30||||||||||F|||20160225215226||123456
    OBX|31||||This report was electronically signed by:||||||F|||20160225215226||123456
    OBX|32||||||||||F|||20160225215226||123456
    OBX|33||||Rad Test MD||||||F|||20160225215226||123456
    OBX|34||||||||||F|||20160225215226||123456



    GOAL:

    OBX|1||||ADDENDUM:||||||F|||20160225215226||123456
    OBX|2||||||||||F|||20160225215226||123456
    OBX|3||||Test Addendum 1 notes||||||F|||20160225215226||123456
    OBX|4||||||||||F|||20160225215226||123456
    OBX|5||||This report was electronically signed by:||||||F|||20160225215226||123456
    OBX|6||||||||||F|||20160225215226||123456
    OBX|7||||Rad Test MD||||||F|||20160225215226||123456
    OBX|8||||||||||F|||20160225215226||123456
    OBX|9||||ADDENDUM:||||||F|||20160225215226||123456
    OBX|10||||||||||F|||20160225215226||123456
    OBX|11||||Test Addendum 2 notes||||||F|||20160225215226||123456
    OBX|12||||||||||F|||20160225215226||123456
    OBX|13||||This report was electronically signed by:||||||F|||20160225215226||123456
    OBX|14||||||||||F|||20160225215226||123456
    OBX|15||||Rad Test MD||||||F|||20160225215226||123456
    OBX|16||||||||||F|||20160225215226||123456
    OBX|17||||ADDENDUM:||||||F|||20160225215226||12345 6
    OBX|18||||||||||F|||20160225215226||123456
    OBX|19||||Test Addendum 3 notes||||||F|||20160225215226||123456
    OBX|20||||||||||F|||20160225215226||123456
    OBX|21||||This report was electronically signed by:||||||F|||20160225215226||123456
    OBX|22||||||||||F|||20160225215226||123456
    OBX|23||||Rad Test MD||||||F|||20160225215226||123456
    OBX|24||||||||||F|||20160225215226||123456
    OBX|25||||TEST REPORT||||||F|||20160225215226||123456
    OBX|26||||||||||F|||20160225215226||123456
    OBX|27||||IMPRESSION:||||||F|||20160225215226||123 456
    OBX|28||||Test impression.||||||F|||20160225215226||123456
    OBX|29||||||||||F|||20160225215226||123456
    OBX|30||||This report was electronically signed by:||||||F|||20160225215226||123456
    OBX|31||||||||||F|||20160225215226||123456
    OBX|32||||Rad Test MD||||||F|||20160225215226||123456
    OBX|33||||||||||F|||20160225215226||123456
    OBX|34||||||||||F|||20160225215226||123456

  • #2
    Based on your example I guess the easiest solution would be to cut OBX.1 to OBX.10 and append it to the end of the report, am I right?

    Or is it that you have
    • test report
    • impression
    • addendum1
    • addendum2
    • addendum3


    and need to reverse the order of the addendum-section
    • addendum3
    • addendum2
    • addendum1
    • test report
    • impression


    ?

    Comment


    • #3
      Thanks for the reply! Everything from "TEST REPORT" until the first addendum is the original report. Then there are 3 addendums. Usually there will be 1 however I need to code to check if there are more than 1 and arrange exactly as you showed in the bottom of your reply.
      Last edited by Jaypell22; 02-26-2016, 07:10 AM.

      Comment


      • #4
        try this:

        my approach is to cut out parts of the report an rearrange them as needed. maybe not the most elegant solution but it works

        Code:
        arObx = new Array();
        found = false;
        
        for each (obx in msg..OBX) {
        	if ((obx['OBX.5']['OBX.5.1'].toString() != 'ADDENDUM:') && (!found)) {
        		arObx.push(obx)
        		delete msg.children()[obx.childIndex()]
        	}
        	else if (obx['OBX.5']['OBX.5.1'].toString() == 'ADDENDUM:') {
        		found = true;
        	}
        }
        
        arIndexTemp = new Array();
        i=0;
        for each (obx in msg..OBX) {
        	if (obx['OBX.5']['OBX.5.1'].toString() == 'ADDENDUM:') {
        		arIndexTemp.push(i)
        	}
        	i++
        }
        
        //reversing order of array
        arIndexAddendum = arIndexTemp.reverse()
        arObxAddendum = new Array();
        
        // Reading Addendum Blocks from Bottom(!) to Top(!)
        for (i=0; i<arIndexAddendum.length; i++) {
        
        	lastIndex = msg['OBX'].length()
        	for (j=arIndexAddendum[i];j<lastIndex;j++) {
        		arObxAddendum.push(msg['OBX'][j])
        	}
        	
        	// Deleting Addendum Report
        	for (j=lastIndex;j>=arIndexAddendum[i];j--) {
        		logger.debug("j: " + j);
        		delete msg['OBX'][j]
        	}
        }
        
        //Appending Addendum Reports to msg
        for (i=0; i<arObxAddendum.length; i++)
        {
        	msg.appendChild(arObxAddendum[i])
        }
        
        //Appending Original Report to msg
        for (i=0; i<arObx.length; i++)
        {
        	msg.appendChild(arObx[i])
        }
        
        // recreate OBX Counter
        var ObxCounter=1;
        for each (obx in msg..OBX) {
        	obx['OBX.1']['OBX.1.1'] = ObxCounter;
        	ObxCounter++;
        }

        Comment

        Working...
        X