Creating a new message based on each OBR

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf Creating a new message based on each OBR

  • Creator
    Topic
  • #54925
    Jawad Chaudhry
    Participant

      I need help with a tcl script to create a new message based on each ORU and the OBX that follows that ORU. For example:

      ORU |a||||

      OBX |a||||||

      ORU |b|||||

      OBX |b||||

      new message 1:

      ORU |a|||||

      OBX |a|||||

      new message 2:

      ORU |b||||||

      OBX |b||||||

    Viewing 5 reply threads
    • Author
      Replies
      • #83472
        Charlie Bursell
        Participant

          I know Jim K. will figure out some way to do this in Xlate  ðŸ˜€

          What is the entire message configuration>  Are the ORU/OBX pairs the last segments?  It would be much easier if they were.  Can we also assume that each OBR will always be followed by one OBX?  Any algorithm must be based on valid assumptions

          Assume you know how to do the first part with the HL7 split, etc.

          # We will always KILL the original message

          set dispList

            # Find first OBR and make a message header there

            set obxLoc [lsearch -regexp $segList {^OBR}]

            # all upto but not including first OBR

            incr obxLoc -1

            set baseHL7 [lrange $segList 0 $obrLoc]

            # Now just loop through and grab

            foreach loc [lsearch -all -regexp {^OBR}] {

                 

                set OBR [lindex $segList $loc]

                set OBX [lindex $segList [expr $loc + 1]]

                # New message.  Do not forget CR at the end

                set newMsg [lappend dispList $OBR $OBX “”]

                set nmh [msgcopy $mh]

                msgset $nmh [join $newMsg r]

                lappend dispList “CONTINUE $nmh”]

            }

            return $dispList

            The above is off the top of my head so there may be some fat-fingered  mistakes.

            It is based on the assumptions I made above.  If not true we would need to know complete message structure and modify code

        • #83473
          Jawad Chaudhry
          Participant

            thanks for the reply!

            So the message could have many OBX’s with each OBR. I dont know if that matters.

            I am getting confused on the foreach statement. It keeps putting out multple OBR’s and multple OBX’s  This is what I used based on what you gave me:

            foreach segment $segmentlist {

            set newobr [lsearch -glob -regexp $segmentlist ^OBR]

                set OBR [lindex $segmentlist $newobr]

                set OBX [lindex $segmentlist [expr $newobr + 1]]

            puts $OBR

            }

            When I print out the OBR for example, it prints out only the first one multple times. I need it to pring each of the ones i have in the message. this is what its doing based on above code:

            OBR|1|367718|4050310755|PXCBC1^Parexel Complete Blood Count w/Different|||201512170459|||||||201512170541||||||||201512170550||HEMEH|F||^^^^^R|||||AUTO

            OBR|1|367718|4050310755|PXCBC1^Parexel Complete Blood Count w/Different|||201512170459|||||||201512170541||||||||201512170550||HEMEH|F||^^^^^R|||||AUTO

            Its doing this multple times.

          • #83474
            Charlie Bursell
            Participant

              I should have know I would fat-finger it if I did not test  ðŸ˜³

              Here is as it should be.  Modified to handle multiple OBX segments after the OBR.  It still assumes the OBR/OBX segments are last in the message

              I did test it    ðŸ™‚

                     run {

                         # Message handle

                         keylget args MSGID mh

                         # Get msg and split into a list of segs

                         set msg [msgget $mh]

                         set segList [split $msg r]

                         # We will always KILL the original message

                         set dispList

                           # Find first OBR and make a message header there

                           set obrLoc [lsearch -regexp $segList {^OBR}]

                           # All upto but not including first OBR

                           incr obrLoc -1

                           set baseHL7 [lrange $segList 0 $obrLoc]

                           # Now just loop through and grab OBR/OBX

                           foreach loc [lsearch -all -regexp $segList {^OBR}] {

                               # Get OBR segment

                               set OBR [lindex $segList $loc]

                               # Start building new message

                               set newMsg [lappend baseHL7 $OBR]

                               # Possible multiple OBX

                               # See how many OBX segments follow

                               set OBXloc $loc; incr OBXloc

                               # First segment following OBR

                               set OBX [lindex $segList $OBXloc]

                               # While we have OBX segments, append to new message

                               while {[regexp — {^OBX} $OBX]} {

                                   # Add OBX

                                   set newMsg [lappend newMsg $OBX]

                                   # Get next and check for OBX

                                   incr OBXloc

                                   set OBX [lindex $segList $OBXloc]

                               }

                               # Do not forget CR at the end

                               set newMsg [lappend newMsg “”]

                               # New message

                               set nmh [msgcopy $mh]

                               msgset $nmh [join $newMsg r]

                               lappend dispList “CONTINUE $nmh”

                           }

                           # Send them on

                           return $dispList

                       }

            • #83475
              Jim Kosloskey
              Participant

                This certainly could be done in an Xlate – but as I recall Medstar does not use Xlates.

                email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

              • #83476
                David Coffey
                Participant

                  You may wish to add a modification to the MSH Control ID,  Some systems will drop messages where the control id of the current message matches the previous.

                • #83477
                  Christopher Wells
                  Participant

                    Thanks for posting this solution.  It helped me out with a coding issue I was having when creating multiple OB messages from one IB. I was getting an ‘Invalid MSI index -1’ error.  Bottom line, I was not killing the original message.

                    Christopher Wells

                Viewing 5 reply threads
                • The forum ‘Cloverleaf’ is closed to new topics and replies.