Add OBX segment AFTER last DG1 segment found -multiple times

Homepage Clovertech Forums Read Only Archives Cloverleaf Tcl Library Add OBX segment AFTER last DG1 segment found -multiple times

  • Creator
    Topic
  • #55375
    Lawrence Nelson
    Participant

    I have a vendor that sends me HL7 ORM messages in the following format

    Lawrence Nelson
    System Architect - MaineHealth IT

Viewing 4 reply threads
  • Author
    Replies
    • #85123
      Jim Kosloskey
      Participant

      First – I don’t think you will need Tcl for this.

      Second – is the layout you show actually what is in your variant(s)?

      If so I don’t think they are correct.

      email me if you would like me to help you and I will work with you off-line.

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

    • #85124
      Lawrence Nelson
      Participant

      The variant – has the OBX in it –

      The message never does.

      The inbound message has an NTE that has to be parsed up into

      a MANY – OBX’s outbound

      I’ve only been successful with getting my Xlate to work by creating a message with a single benign OBX.

      end_prologue

      MSH

      PID

      [ PV1 ]

      [ PD1 ]

      {

        {

           [{ IN1 } ]

           [ IN2 ]

           [ IN3 ]

        }

        [ GT1 ]

      }

      {

        [{ ORC } ]

        [{ NTE } ]

        {

           [{ OBR } ]

           [{ NTE } ]

           [{ DG1 } ]

           [{ OBX } ]

        }

      }

      Lawrence Nelson
      System Architect - MaineHealth IT

    • #85125
      Charlie Bursell
      Participant

      [{ ORC } ] should be just ORC.  It should be required but will not affect your problem.

      “I need a single OBX tacked on AFTER every LAST DG1 per ORC”

      The DG1 is optional.  What if not there?

      Listen to Jim as how to do without Tcl.  If you then really want it done in Tcl, let me know and I will help.

    • #85126
      Charlie Bursell
      Participant

      Changed my mind.  Decided to post code – nothing else going on  ðŸ˜€

      Jim will tell you how to do without Tcl and you can decide which way to go

      Did not test a lot as I don’t have your messages

      ==============================================

      # Set canned OBX segnent to whatever

      set OBX OBX|1||||||.|

      # Split message into segments

      set Segments [split $msg r]

      # Get location of all OBR segments

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

      # Traverse in reverse order so as not to change OBR locations

      foreach loc [lsort -integer -decreasing $obrLoc] {

         # Assume no DG1

         set dg1Loc -1

         # List of all DG1 segments each time

         foreach dg1Loc [lsearch -all -regexp $Segments {^DG1}] {

             # We need DG1 *AFTER* the OBR

             if {$dg1Loc < $loc} {continue}

             # Got one after OBR – bail out

             break

         }

         # No DG1 found – No mod to this OBR loop

         if {$dg1Loc < 0} {continue}

         # Get last one

         # See if multiple DG1 and hget location of last one for the loop

         while {[regexp {^DG1} [lindex $Segments [expr $dg1Loc + 1]]]} {

             incr dg1Loc

         }

         # Incr location so we insert *AFTER* DG1

         incr dg1Loc

         set Segments [linsert $Segments $dg1Loc $OBX]

      }

      msgset $mh [join $segments r]

      return “{CONTINUE $mh}”

    • #85127
      Lawrence Nelson
      Participant

      Thanks Charlie – this is very helpful for the next case I run into something of this nature.

      Jim and I worked through my xlate OBX issues yesterday – and we were able to do away with the TCL preproc in this case. Thanks again to Jim K!

      Lawrence Nelson
      System Architect - MaineHealth IT

Viewing 4 reply threads
  • The forum ‘Tcl Library’ is closed to new topics and replies.

Forum Statistics

Registered Users
5,129
Forums
28
Topics
9,301
Replies
34,447
Topic Tags
288
Empty Topic Tags
10