Announcement

Collapse
No announcement yet.

How hard is it to re-order segments?

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

  • How hard is it to re-order segments?

    I have an ADT feed from multiple sites that process through one single interface. Some of the sites are sending the IN1 segment before the DG1 segment. Is there an easy way to re-order those messages to move the DG1 segment to be above the IN1 segment while not impacting the messages that come through correct?

  • #2
    Idea

    Just an idea, have you tried using message outbound templates?

    Comment


    • #3
      This could get you started with re-ordering the segments in the message.

      Code:
      //set the array
      var message_segs = new Array();
      //loop through message to add each segment to the array and delete segment from message
      for each(seg in msg.children())
      {
      	var segi = SerializerFactory.getSerializer('HL7V2').fromXML(seg);
      	message_segs.push(segi);
      	delete msg.children()[seg.childIndex()];
      }
      //loop through array and rebuild message in desired order
      for(i=0;i<message_segs.length;i++)
      {
      	//logger.info('seg: '+message_segs[i].toString().substring(0,3));
      	if(message_segs[i].toString().substring(0,3) == 'MSH')
      	{
      		createSegment('MSH', msg, i);
      		msg['MSH'][i] = message_segs[i].substring(4);
      	}
      	else if(message_segs[i].toString().substring(0,3) == 'EVN')
      	{
      		msg['EVN'][i] = message_segs[i].substring(4);
      	}
      	else if(message_segs[i].toString().substring(0,3) == 'PID')
      	{
      		msg['PID'][i] = message_segs[i].substring(4);
      	}
      }
      Last edited by mcalKno; 10-08-2015, 05:42 AM.

      Comment


      • #4
        That will work. Thanks for the suggestions.

        Comment


        • #5
          Transformer based on the above code...

          Thought I'd share a transformer based on the above code along with some extra help from another thread.

          This is effective, but probably not the most efficient. If you improve upon this code, it'd be cool to re-post the improved code.

          thanks,
          Jack

          Code:
          //Original code, idea taken from: 
          // http://www.mirthcorp.com/community/forums/showthread.php?t=214079
          // Problem:  PAML has a stipulation the NTEs for any given OBR appear AFTER
          // said OBR.  Meidtech places the NTEs between the ORC and OBR.  
          // Solution follows:
          
          var obrs = 0;
          for each (seg in msg..OBR) {
          	obrs++;
          } // need a count of OBX segments
          var msg_segs = new Array();
          var orig_order = new Array();
          var new_order = new Array();
          
          // loop through the message pushing each segment into the array.
          for each(seg in msg.children()) {
          	var serialized = SerializerFactory.getSerializer('HL7V2').fromXML(seg); // get reference
          	msg_segs.push(serialized);
          	orig_order[seg.childIndex()] = (seg.name().toString());
          	// can't delete here, the message childIndex updates correctly with delete...
          }
          // This sucks, better way should be found, but whatever:
          for each(seg in msg.children())
          {
          	delete msg.children()[seg.childIndex()];
          }
          
          // build re-ordering array
          var start = 0;
          var stop = 0;
          for (i=0; i < orig_order.length; i++) {
          	if (orig_order[i] == "ORC") {
          		start = i;
          		new_order[i] = i;
          	} else if (orig_order[i] == "OBR") {
          		if (start > 0) {
          			stop = i;
          		}
          		obrs--;
          	}
          	if (start > 0 && stop == 0) { // Stuff, most often NTEs, between the ORC and OBR
          		if (obrs > 0) {
          			new_order[i+1] = i;
          		} else {
          			new_order[i] = i;
          		}
          	} else if (start > 0 && stop > 0) {
          		new_order[start+1] = i;
          		stop = 0;
          		start = 0;
          	} else if (start == 0 && stop == 0) {
          		new_order[i] = i;
          	} 
          	
          }
          
          // rebuild message to my liking... well, mine and/or PAML's.
          
          var appendedString = '';
          for (i=0; i < new_order.length; i++) {
          	appendedString += msg_segs[new_order[i]] +"\n";
          	//logger.debug(i +" --> " + new_order[i] + "-->" + orig_order[new_order[i]]);
          }
          // This bit found at http://www.mirthcorp.com/community/forums/showthread.php?t=216762
          msg = new XML(SerializerFactory.getSerializer('HL7V2').toXML(appendedString));
          Example Messages - Order Change:
          MSH|^~\&|LAB|NMH|||20170701092951-0600||ORM^O01|5839.1|P|2.3|||AL|NE|
          PID|1||M000123456|M11111|Beam^Jim^J||19230131|F||A I|9876 54th St^^Not so Great Falls^MT^59812||406-123-4567^PRN^PH^^1^406^1234567|||S||V00010040302|543-21-9876|
          PV1|1|I|OB^365^A^NMH|EL|||MILEMARK^Mile^Marker^^^^ ^^XX|||OBG||||SELF|||MILEMARK^Mile^Marker^^^^^^XX| IN||MCD|||||||||||||||||||NMH||ADM|||201707010600|
          ORC|NW|1675085^LAB||070117:R6||N|^^^^^R||201707010 929|
          NTE|1||*TEST NAMERASER|
          NTE|2||*PERFORMING LAB:PAML|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L|||201707010928|||||||||MILEMARK^Mile^M arker^^^^^^XX||00000000||||||LAB|||^^^^^R|
          Becomes
          MSH|^~\&|LAB|NMH|||20170701092951-0600||ORM^O01|5839.1|P|2.3|||AL|NE|
          PID|1||M000123456|M11111|Beam^Jim^J||19230131|F||A I|9876 54th St^^Not so Great Falls^MT^59812||406-123-4567^PRN^PH^^1^406^1234567|||S||V00010040302|543-21-9876|
          PV1|1|I|OB^365^A^NMH|EL|||MILEMARK^Mile^Marker^^^^ ^^XX|||OBG||||SELF|||MILEMARK^Mile^Marker^^^^^^XX| IN||MCD|||||||||||||||||||NMH||ADM|||201707010600|
          ORC|NW|1675085^LAB||070117:R6||N|^^^^^R||201707010 929|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L|||201707010928|||||||||MILEMARK^Mile^M arker^^^^^^XX||00000000||||||LAB|||^^^^^R|
          NTE|1||*TEST NAMERASER|
          NTE|2||*PERFORMING LAB:PAML|
          and it's reasonably tolerable of strange messages:
          MSH|^~\&|LAB|NMH|||20170701092951-0600||ORM^O01|5839.1|P|2.3|||AL|NE|
          PID|1||M000123456|M11111|Beam^Jim^J||19230131|F||A I|9876 54th St^^Not so Great Falls^MT^59812||406-123-4567^PRN^PH^^1^406^1234567|||S||V00010040302|543-21-9876|
          PV1|1|I|OB^365^A^NMH|EL|||MILEMARK^Mile^Marker^^^^ ^^XX|||OBG||||SELF|||MILEMARK^Mile^Marker^^^^^^XX| IN||MCD|||||||||||||||||||NMH||ADM|||201707010600|
          ORC|NW|1675085^LAB||070117:R6||N|^^^^^R||201707010 929|
          NTE|1||*TEST NAMERASER|
          NTE|2||*PERFORMING LAB:PAML|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should go above NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should stay below NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|ORC|NW|1675085^ LAB||070117:R6||N|^^^^^R||201707010929|
          NTE|1||*TEST NAMERASER|
          NTE|2||*PERFORMING LAB:PAML|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should go above NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should stay below NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|
          ORC|NW|1675085^LAB||070117:R6||N|^^^^^R||201707010 929|
          NTE|1||*TEST NAMERASER|
          NTE|2||*PERFORMING LAB:PAML|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should go above NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should stay below NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|
          becomes:

          MSH|^~\&|LAB|NMH|||20170701092951-0600||ORM^O01|5839.1|P|2.3|||AL|NE|
          PID|1||M000123456|M11111|Beam^Jim^J||19230131|F||A I|9876 54th St^^Not so Great Falls^MT^59812||406-123-4567^PRN^PH^^1^406^1234567|||S||V00010040302|543-21-9876|
          PV1|1|I|OB^365^A^NMH|EL|||MILEMARK^Mile^Marker^^^^ ^^XX|||OBG||||SELF|||MILEMARK^Mile^Marker^^^^^^XX| IN||MCD|||||||||||||||||||NMH||ADM|||201707010600|
          ORC|NW|1675085^LAB||070117:R6||N|^^^^^R||201707010 929|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should go above NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|
          NTE|1||*TEST NAMERASER|
          NTE|2||*PERFORMING LAB:PAML|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should stay below NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|ORC|NW|1675085^ LAB||070117:R6||N|^^^^^R||201707010929|
          NTE|1||*TEST NAMERASER|
          NTE|2||*PERFORMING LAB:PAML|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should go above NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should stay below NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|
          ORC|NW|1675085^LAB||070117:R6||N|^^^^^R||201707010 929|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should go above NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|
          NTE|1||*TEST NAMERASER|
          NTE|2||*PERFORMING LAB:PAML|
          OBR|1|1234567^LAB||99999.Z99^MISCELLANEOUS REFERENCE^L^This should stay below NTEs|||201707010928|||||||||MILEMARK^Mile^Marker^^ ^^^^XX||00000000||||||LAB|||^^^^^R|
          Anyway, thanks for posting your code above, thought I'd share my changes.

          Jack
          Last edited by jack.downes; 07-02-2017, 10:18 PM. Reason: Correction.

          Comment


          • #6
            What about when there is more than one segment? I'm trying to move numerous DG1 segments above another segment but the code only moves the one. Any help with this would be greatly appreciated!

            Thanks - Matt

            Comment


            • #7
              a) First you need to create a group of all the DG1 segments combined together and keep it.

              b)Then you can make use of createSegmentAfter, which can be found here on this git

              https://github.com/nextgenhealthcare...nt%20Templates

              to append the DG1 group in step 1 after a specific segment.
              HL7v2.7 Certified Control Specialist!

              Comment

              Working...
              X