PreXlate TCL Proc to Modify 1 Piece of an OBR 2.5.1 Variant

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf PreXlate TCL Proc to Modify 1 Piece of an OBR 2.5.1 Variant

  • Creator
    Topic
  • #54810
    Karen May
    Participant

      Hi All.  

      I’m working on a proc to determine the LAB Section ID for OBR.24 and I have two issues and a brain freeze.   😳

      Issue 1:  I’ve got something amiss with curly braces.

      Issue 2:  I haven’t been able to put the segments back together with the new OBR.  

      The code is below.. Yep I’m aware that I’ve commented out several lines. Just trying to step through the code.  Any help appreciated.. Thanks..!!

      ######################################################################

      # Name: preXLT_DetermineDEPT

      # Purpose: TPS proc used to take the accession number from a LAB

      # report and break it apart to determine the SECTION ID

      #             and populate OBR.24.  Can be removed when Meditech

      # adds department to OBR.24 per request. E

      # UPoC type: tps

      # Args: tps keyedlist containing the following keys:

      #       MODE    run mode (“start”, “run” or “time”)

      #       MSGID   message handle

      #       ARGS    None                    

      #

      # Returns: Message with LAB Section ID in OBR.24

      ######################################################################

      proc preXLT_DetermineDEPT { args } {

         global HciConnName

         keylget args MODE mode ;# Fetch Mode

         switch -exact — $mode {

             start {}

             run {

         # run mode always has a MSGID; fetch and process it

                 keylget args MSGID mh       ;# Get message handle

                 set msg [msgget $mh]       ;# Get a copy of the message

         set segs [split $msg r] ;# Split the message into segments

                 set fldSep [string index $msg 3] ;# Field Separator

                 set subSep [string index $msg 4] ;# Sub-Field Separator

         # Set variables for later use

         set Dept “”

         set Delim “:”

         # Get the OBR Segment and Determine what the Lab Section

                 # LOOP through the message and modify each OBR segment.

                 foreach OBR [lsearch -all -inline -regexp $segs {^OBR}] {  

                  set OBRflds [split $OBR $fldSep] ;# Field List

                  set OBR3 [lindex $OBRflds 3] ;# Accession Number

          set FldList [split $OBR3 $Delim] ;# Split on a delimeter of “:”

          set Prefix [lindex $FldList 0] ;# Get Data before the “:”

          set Suffix [lindex $FldList 1] ;# Get Data after the “:”

          set Suf1 [string range $Suffix 0 1] ;# Get the first two bytes of Suffix

          set OBR24 [lindex $FldList 24] ;# Get the OBR24 field for later

      # echo “OBR is $OBR”

      # echo “OBRflds are $OBRflds”

      echo “OBR3 is $OBR3”

      echo “Prefix is $Prefix”

                     if { [string length $Prefix] < 3 } { ;# if only 2 digits; it's MICRO   set Dept MIC   ;# Set OBR24 to “MIC”                 } else {        if { [string match $Suf1 “BB”] } { ;# if it’s ‘BB’, its Blood Bank                   set Dept BBK ;# Set OBR24 to “BBK”   } else {   set Dept LAB   ;# Everthing else is General LAB   }                     set OBRflds [lreplace $OBRflds 24 24 $Dept] ;# Put the updated value back in OBR.24                   set OBR [join $OBRflds $fldSep] ;# Put the OBR segment back together   } ;# End foreach Loop                  echo “New Dept is $Dept”  #echo “OBR24 is $OBR24”                  echo “Modified OBR segment: $OBR” }                                msgset $mh [join $segs r] ;# Create a new message            return “{CONTINUE $mh}”        } time {}        #shutdown {}        #default {}        } # return $dispList    } }

    Viewing 5 reply threads
    • Author
      Replies
      • #83088
        Robert Kersemakers
        Participant

          Hi Karen,

          Had a quick glance.

          1: looks like the final, closing curly brace is the culprit. Just delete it.

          2: You need to put back the newly created OBR ($OBR) into the list containing all segments ($seg). So after you put the OBR segment back together, you have to ‘lvarpop’ this OBR back into $segs. Problem however is: you don’t know where, at what index of $seg, you need to put it back. This is because you use a ‘foreach’ with an inline ‘lsearch’. And someone correct me if I’m wrong, but this way there is no ‘index’ telling you which OBR segment you are currently processing. Or before putting back the OBR into $segs, you would have to do another ‘lsearch’ for this specific OBR, but you would have to have a field in this OBR uniquely identifying the OBR.

          If it were for me, I would just ‘foreach’ through all the elements of $seg. Inside the foreach have a counter ($counter) keeping track of which segment you are currently processing. Then use an ‘if’ to determine if it’s an OBR you need to process; if so, create the new OBR and then

          Code:

          lvarpop segs $counter $OBR


          The rest should work: you put back your $segs into a message and process it.

          Zuyderland Medisch Centrum; Heerlen/Sittard; The Netherlands

        • #83089
          Karen May
          Participant

            Thanks for your reply Robert.  I had found that last brace item.  Given that I have to replace OBR.24 in ALL OBR segs, your suggestion to set a counter to keep track of where the proc is at each encounter is a prudent one.. I’ll give it a try.

          • #83090
            Jim Kosloskey
            Participant

              Since this is pre Xlate why not just use an xltp type proc inside the Xlate for the one field?

              After all the Xlate has already parsed the message for you and will put it back together.

              Unless I am missing something (that is entirely possible) don’t you just want to work on the one field in each OBR?

              email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.

            • #83091
              Karen May
              Participant

                Thanks Jim.. The reason I’ve gone the tps route is to avoid overhead in the engine.  I originally set it up as a tcl frag inside the xlate and that worked out just fine untl we realized that Meditech is sending in three different formats requiring three different translations.  I could still do it that way… It would be a whole lot quicker as I know I’ve got the 2.5.1 iterations working as expected via the xlate.

                We’ve asked Meditech to modify their output to include the section ID in OBR.24 but it takes a while for them to do anything.  Thought it might be a little cleaner to stack a couple of procs pre-xlate to 1.  Determine section ID and then 2. A second proc using an ARG to Continue or Kill based on that.  Then once Meditech does their thing… the first proc can be removed/retired.  Another wrinkle that just got thrown at us is that a fair number of the OBX’s have to be turned into NTE’s based on the data type in OBX1.  Yeesshh.. They’re makin me nuts..!

                Hope that helps..  Based on the above.. how would you attack it.?

                Still futzing with the lvarpop syntax.. Haven’t used it before..  

                Thanks again.. Karen

              • #83092
                Jim Kosloskey
                Participant

                  Personally I would do all (not sure about the filtering) in Xlates and use Tcl to extend the Xlates – as you can see this is likely to expand even more if a detailed analysis of all of the needs have not been done.

                  email: jim.kosloskey@jim-kosloskey.com 30+ years Cloverleaf, 60 years IT – old fart.

                • #83093
                  Karen May
                  Participant

                    Thanks Jim..

                    The only way to do filtering (I’ve already got a tps proc working) is based on the SectionID in OBR.24 which at present, comes in blank.. hence the other proc move to the preXlate stack.  I’ll play with this more and see what I can come up with.

                    Karen

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