Announcement

Collapse
No announcement yet.

Accepting wanted segments instead of deleting the unwanted ones.

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

  • Accepting wanted segments instead of deleting the unwanted ones.

    Currently my transformer deletes a list of unwanted segments.
    delete msg['ZIR'];
    delete msg['ZEN'];
    delete msg['ZSP'];
    Is there a way to keep only the segments that I need without using the static delete so that changes in the source message such as adding another z or IN segment do not affect the channel?

    Something along the lines of:

    If segment is not MSH, PID PV1 then delete segment.

  • #2
    for each (seg in msg)
    {
    segName = seg.name().toString();
    if(segName != 'PID' && segName != 'MSH' && segName != 'PV1')
    {
    delete seg;
    }
    }

    Comment


    • #3
      If you have a large set of segments you want to keep you could do this:

      Code:
      var strGoodSeg = 'MSH~PID~PV1~NK1~OBR'  //you get the point right?
      
      
      for each (seg in msg.children()) {
      
         var strCurSeg = seg.name();
      
         if (strGoodSeg.indexOf(strCurSeg) < 0) {     //okay to delete
      
               delete seg;
       }
      
      }
      I can be reached through gmail and Google Talk using davidrothbauer at gmail dot com
      http://www.linkedin.com/pub/david-rothbauer/5/923/518
      codeismydrug.wordpress.com
      hl7coders.wordpress.com

      Test all my code suggestions prior to implementation

      Comment


      • #4
        Apologies for revitalizing this old thread but I find myself in a similar situation.
        I also would like to only keep MSH, PID, NTE, and delete everything else. I tried the code above by Cory Cole and Bostad and it is not working for me.
        The delete msg['IN1'] for example works fine but like the author, I want something more robust than the static delete function.
        I have tried the code as javascript in both source and destination transformer.
        When I send a test message the entire message passes through as if the javascript was not there. (Yes the transformer is checked).

        I am on version 3.8.0
        Appreciate any tips.
        Thank you

        Comment


        • #5
          Here's a different way to do it.

          Code:
          const segmentsToKeep = new java.util.HashSet(['MSH','PID','NTE']);
          var newChildren = new XMLList();
          for each (var seg in msg.children()) {
              if (segmentsToKeep.contains(seg.localName())) newChildren += seg;
          }
          msg.setChildren(newChildren);

          Comment


          • #6
            Thank you this one works.

            Comment

            Working...
            X