adding nte to obr

Clovertech Forums Read Only Archives Cloverleaf Tcl Library adding nte to obr

  • Creator
    Topic
  • #55163
    Kevin Crist
    Participant

      I have a tcl proc that will add an NTE segment directly after every OBR. There could be one but there could be many. The info in the NTE is being based of  a table that gets it’s value from the OBX.15. How can i get the NTE after the OBR depending on the corresponding OBX.15 info?

      As is now it adds the NTE after the OBR but all the OBX.15 info is the same so all NTEs are the same.

      Code:

      ######################################################################
      # Name:   perform_site_nte
      # Purpose: This procedure creates a new NTE segment for the message and adds
      #     performing site.
      # UPoC type: tps
      # Args: tps keyedlist containing the following keys:
      #       MODE    run mode (”start”, “run” or “time”)
      #       MSGID   message handle
      #       ARGS    user-supplied arguments:
      #              
      #
      # Returns: tps disposition list:
      #          

      #

      proc perform_site_nte { args } {

         global HciConnName

         keylget args MODE mode               ;# Fetch mode

         set dispList {} ;# Nothing to return
      set OBRFlag “NO”
             set nte “”
       

      set table “poi_performing_site_oru.tbl”

         switch -exact — $mode {
             start {
                 # Perform special init functions
         # N.B.: there may or may not be a MSGID key in args
             }

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

                keylget args MSGID mh
                 set msg [msgget $mh]
                 set fieldsep [crange $msg 3 3]
      set subsep [crange $msg 4 4]
                 set segments [split $msg r]
                 
                 set newmh “”
           

                 # Roll through all segments of the message
                 foreach seg $segments {
                  set segtype [crange $seg 0 2]

              # Pull the fields used to build the header from the appropriate
              # segments.

             switch -exact — $segtype {
                MSH {
       set fieldlist [split $seg |]
       set msh_4 [lindex $fieldlist 3]
      # echo msh_4: $msh_4
       set nte [tbllookup $table $msh_4]
      # echo nte: $nte
      }

      OBR {
      set OBRFlag “YES”
      append newmh $seg r
         set fieldlist [split $seg |]

              set newnte [join [list NTE 1 {} $nte] |]
              append newmh $newnte r
                  }
       

        OBX {
      set fieldlist [split $seg |]
       set obx_15_0 [lindex [split [lindex $fieldlist 15] $subsep] 0]
      #echo obx_15_0: $obx_15_0
       set nte [tbllookup $table $obx_15_0]
      #echo nte: $nte

      }

               default {}
              }  
             
               if {[cequal $OBRFlag “YES”]} {
                  set OBRFlag “NO”
               } else {
                  append newmh $seg r
               }
                   
               }

      #regsub command looks for 2 carriage returns at the end of the message and
      #replaces it with one.    
      #regsub -all {x0dx0d} $newmh x0d newmh

               msgset $mh $newmh
               lappend dispList “CONTINUE $mh”

             }

             time {
                 # Timer-based processing
         # N.B.: there may or may not be a MSGID key in args
             }
             
             shutdown {
         # Doing some clean-up work
           }
         }

         return $dispList
      }

    Viewing 13 reply threads
    • Author
      Replies
      • #84391
        Kevin Crist
        Participant

          For some reason the first NTE always shows up as NTE|1|  

          Cant figure why it does that.

        • #84392
          David Barr
          Participant

            Kevin Crist wrote:

            For some reason the first NTE always shows up as NTE|1|

          • #84393
            Kevin Crist
            Participant

              Thanks for the reply David, I thought that and flipped them with no luck. If there are multiple OBRs it works correctly.

            • #84394
              David Barr
              Participant

                It looks to me like your message processing logic is wrong. It goes something like this:

                set nte variable to blank

                receive MSH

                append MSH to message

                receive PID

                append PID to message

                receive OBR

                append OBR #1 to message

                append NTE with blank nte variable to message

                receive OBX

                append OBX #1 to message

                store value for OBX/OBR #1 in nte

                receive OBR segment

                append OBR #2 to message

                append NTE with nte data for OBX #1 to message

                receive OBX segment

                append OBX #2 to message

                store value for OBX/OBR #2 in nte (never placed in message)

                I’d have to see what your messages look like, but maybe you need to put the NTE right before the OBX segment so that it has data from the correct OBX.

              • #84395
                Kevin Crist
                Participant

                  I think putting the nte in front of the obx would be OK.

                • #84396
                  Charlie Bursell
                  Participant

                    I am also confused here.  Why do you set the nte variable based on the MSH *AND* the OBR?

                    It looks to me like you are trying to build an NTE segment when you find the OBR.  Part of the NTE segment should be values found in the OBX.  However in normal messages the OBR comes *BEFORE* the OBX.

                    What if more than one OBX between OBR segments?

                    A lot of unanswered questions plus you are making the algorithm much too difficult.  It could easily be done without building a new message by using lsearch and traversing in a reverse order.

                    Let us know if you can clarify or perhaps it is me that is confused.  That does happen  ðŸ˜€

                  • #84397
                    Kevin Crist
                    Participant

                      I am trying to piece together a proc so i think some of that may be my issue.

                      Here is before:

                      OBR

                      OBX

                      OBX

                      OBX

                      OBR

                      OBX

                      OBR

                      OBX

                      Here is after:

                      OBR

                      NTE

                      OBX

                      OBX

                      OBX

                      OBR

                      NTE

                      OBX

                      OBR

                      NTE

                      OBX

                    • #84398
                      Charlie Bursell
                      Participant

                        Why get MSH.4?  Do you always use the data from the first OBX to build NTE?

                        What if OBX.15 is empty?

                        Qestions, questions, questions  ðŸ˜€

                      • #84399
                        Kevin Crist
                        Participant

                          Sorry, forgot about that. They wanted IF MSH.4 = to a table value then use that but they have since changed their mind. It is now if MSH.3 = MIC then we only use one certain performing site in all the NTEs.

                          i asked about the OBX.15 being empty and got crickets.

                        • #84400
                          Charlie Bursell
                          Participant

                            It may have to be modified after you get some of your questions answered but this should give you an idea

                            run {

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

                                       keylget args MSGID mh

                                       set msg [msgget $mh]

                                       set fieldsep [crange $msg 3 3]

                                       set subsep [crange $msg 4 4]

                                       set segments [split $msg r]

                                       # Build base NTE

                                       set BASE

                                         # First get MSH.3 value

                                         set msh3 [lindex [split [lindex $segments 0] $fieldsep] 2]

                                         # If MSH.3 = MIC then only use one certain performing site in all the NTEs

                                         set fixedSite “”

                                         if {$msh3 eq “MIC”} { set fixedSite “FIXED” }

                                         # Traverse all OBR segments in reverse order

                                         foreach OBRloc [lsort -integer -decreasing

                                                 [lsearch -all -regexp $segments {^OBR}]] {

                                             # If MSH.3 not equal MIC get NTE.3 from First OBX after OBR

                                             # Else use the “fixed site”

                                             # Assume OBR is followed by OBX

                                             # First get base NTE

                                             set NTE $BASE

                                             # Get next location after OBR

                                             set plusOne [expr $OBRloc + 1]

                                             if {$fixedSite eq “”} {

                                                 set OBX [split [lindex #segments $plusOne] $fieldsep]

                                                 # Get OBX.15.1 and do table lookup.  If field is empty

                                                 # table will return default value

                                                 set fld [lindex [split [lindex $OBX 15] $subsep] 0]

                                                 lappend NTE [tbllookup $table $fld]

                                             } else {

                                                 # Just use Fixed Site

                                                 lappend NTE $fixedSite

                                             }

                                             # Put NTE in segments list

                                             set segments [linsert $segments $plusOne [join $NTE $fieldsep]]

                                         }

                                         # Output modified message

                                         msgset $mh [join $segments r]

                                         return “{CONTINUE $mh}”

                                     }

                          • #84401
                            Kevin Crist
                            Participant

                              Thanks Charlie. That works for most but apparently there are some that are formatted differently, that have something like below: where the NTEs currently in place have different values. When the proc goes to add the NTE after the OBR it is blank, is this because it is assuming the an OBX is following the OBR, which is what i was told.

                              OBR

                              NTE

                              NTE

                              NTE

                              NTE

                              NTE

                              NTE

                              OBX

                              NTE

                              NTE

                              NTE

                              NTE

                              OBX

                              NTE

                              NTE

                              NTE

                              NTE

                            • #84402

                              This would be much easier in an Xlate. Xlates are designed to provide easy access to HL7 formats. Just saying.

                              -- Max Drown (Infor)

                            • #84403
                              Kevin Crist
                              Participant

                                i agree. This is going on a route to 7 different downstream systems that are raw at the moment.

                                Thanks.

                              • #84404
                                Charlie Bursell
                                Participant

                                  Kevin:

                                  I was just trying to deal with what you had.  As I said, many unanswered questions remain: What if no OBX, multiple OBX, OBX.15 empty, etc.?

                                  As Max said this could also be done in Xlate.  Simply define an OB variant that looks exactly like the IB then add an optional NTE after each OBR.

                                  In the Xlate, iterate over the OBR/OBX group and have IF statements to determine how and if the NTE will be populated.

                                  However, IMHO, which may be biased, when I have something rather complicated and arcane I prefer to do it in Tcl most of the time.  I can then fully document at the top of the script exactly what I am doing and why.  Remember, over 65% of your time will be in maintenance and others may have to modify what you have done.  In fact a year later I may not even remember what I did and why.   I realize you can also comment in Xlate but I feel the comments are easily read at the top of a Tcl script.

                                  If you, like most people, are just going to implement with no regard to comments, then it makes no difference  ðŸ˜€

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