Announcement

Collapse
No announcement yet.

Creating a new message from original

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

  • Creating a new message from original

    I have a need to create a new HL7 message for every OBR segment in the original, copying over the original's MSH, PID, ORC segments

    My code looks like this:

    Code:
    function CreateNewORU(inMsg, inOBRGroup)
    {
    
    var outMsg = new XML(<MSG></MSG>);
    
    //keep original segments for MSH, PID, ORC
    outMsg['MSH'] = inMsg['MSH'];
    outMsg['PID'] = inMsg['PID'];
    outMsg['ORC'] = inMsg['ORC'];
    for each(seg in inOBRGroup)
    {
    outMsg.appendChild(seg);
    }
    //return new ADT message
    return outMsg;
    
    }
    My issue is the message comes out wrapped in the <MSG> tags. Is there a way to create a new msg object without using new XML(<MSG></MSG>)?
    Leaving it blank (= new XML()) doesn't work as it won't recognize .appendChild as a valid function.

    Thanks,
    Rut

  • #2
    Not sure my interpretation matches w/your code but you don't have to use <MSG><MSG>. Below is a simple loop that should create a separate HL7 XML for each OBR in an HL7 msg. It'll serialize each message, store it in an array then connector map the first element for the payload. There are various ways but it comes down to personal preference and how you're dispatching each message.
    Code:
    var arrHL7 = []
    for each (obr in msg.OBR) {
      var tmp = <HL7Message/>;
      tmp.appendChild(msg.MSH)
      tmp.appendChild(msg.PID)
      tmp.appendChild(msg.ORC)
      tmp.appendChild(obr)
    
      tmp = SerializerFactory.getSerializer('HL7V2').fromXML(tmp)
      arrHL7.push(tmp)
    }
    $co('HL7V2',arrHL7[0])
    Last edited by jkrebs; 03-25-2021, 10:47 AM. Reason: corrected xml var.

    Comment


    • #3
      That worked perfectly (= new XML(<HL7Message/>)).

      Thanks

      Comment


      • #4
        The purpose of new XML() is to convert a string to an xml object. <HL7Message/> is already an xml object. The following are equivalent:
        Code:
        var tmp = <HL7Message/>;
        var tmp = new XML('<HL7Message/>');

        Comment


        • #5
          There are some other shortcuts you can take here, too. Assuming inOBRGroup is an XMLList (I'm assuming this because it is being used in a for each...in loop,) you can pass the entire list to appendChild, i.e.
          Code:
          // instead of
          for each(seg in inOBRGroup) {
              outMsg.appendChild(seg);
          }
          // for XMLList inOBRGroup you can do
          outMsg.appendChild(inOBRGroup);
          Additionally, if that's the case, you can actually template the entire thing:
          Code:
          function CreateNewORU(inMsg, inOBRGroup) {
            return <HL7Message>
              {inMsg.MSH}
              {inMsh.PID}
              {inMsg.ORC}
              {inOBRGroup}
            </HL7Message>;
          }

          Comment


          • #6
            I have tried this out, is there a way to get the NET's associated with the OBR and make a new message for how every many OBX's?
            Attached Files

            Comment


            • #7
              Post your code attempt please.
              Diridium Technologies, Inc.
              https://diridium.com

              Comment


              • #8
                Should this code be placed in a transformer or other location?
                Code:
                var arrHL7 = [] for each (obr in msg.OBR) { var tmp = <HL7Message/>;
                  tmp.appendChild(msg.MSH)
                  tmp.appendChild(msg.PID)
                  tmp.appendChild(msg.ORC)
                  tmp.appendChild(obr)
                
                  tmp = SerializerFactory.getSerializer('HL7V2').fromXML(t mp)
                  arrHL7.push(tmp)
                }
                $co('HL7V2',arrHL7[0])
                cmc

                Comment

                Working...
                X