tcl OBX append

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf tcl OBX append

  • Creator
    Topic
  • #55482
    Lina Patel
    Participant

      Would someone be kind enough to assist with existing tcl code OBX append.

      – 3 new OBX stmts need to be appended to last OBX if exists

      – need to then add text and variable info to each OBX.

      Thank you in advance for your help.

      Lina

    Viewing 23 reply threads
    • Author
      Replies
      • #85482
        Charlie Bursell
        Participant

          Simple enough

          # Get location of all OBX in a list

          set loclist [lsearch -all -regexp $segList {^OBX}]

          set last [lindex $loclist end]

          Now just linsert after the last location.  If last is empty then no OBX

        • #85483
          Lina Patel
          Participant

            Thank you!

            What is good practice to keep count and add the next OBX(x) ID with the linsert command?

          • #85484
            Charlie Bursell
            Participant

              You have location of last OBX.    Get number from it and simply increment for each one added

              To help more you would have to be more specific.   What text, what variables, etc

            • #85485
              Lina Patel
              Participant

                If obx exists, add 3 additional obx segments with correct obx numbering

                If obx(1) exists, add below info

                obx(2)||H|@var1|xx|

                obx(3)||DW|@var2|yy|

                obx(4))|AW|@var3|zz|

              • #85486
                Charlie Bursell
                Participant

                  Try this.

                  I did not do a lot of testing so I may have fat-fingered something.

                  A 15 minute proc  ðŸ˜€

                  I am not married to it.  Modify as you see fit

                • #85487
                  Lina Patel
                  Participant

                    Thanks! Hugh help.

                    Works in most cases except when equal to 4 OBX or more then run into the error below at the end after values are mapped:

                    expected integer but got “^~&”

                  • #85488
                    Charlie Bursell
                    Participant

                      Works fine for me.  I told you I did do a lot of testing or error catching.  I figured I would leave that up to you.

                      I suggest you look at your data.  It looks like you have an OBX with MSH fields.

                      The proc simply pulls from the last OBX.1 field to get the number.  If blank I set to 0 but do not check for invalid data.  As I said “^~&”  is field one of an MSH segment.

                      I tested it with 6 OBX segments and got: (Converted CR to LF to make it readable)

                      MSH|^~&|PSCRIBE|001|RADIS1|001|20080527093606||ORU|20080527093600-2|P|2.3|146968|||||||

                      PID|||000883421||TEST^TESTING^T.||19540507|M||||||||||2626476|222-32-1111|||||||||||

                      PV1||O|2C^2308^0||||02620^THORNE^KEITH|||||||||||O||||||||||||||||||||||||||200805270632|||||||||

                      ORC|RE||||||||||||||||||

                      OBR|1||5155447336|4270001^CATHZ LT HEART PERC|||200805270905|||||||||02620^THORNE^KEITH||||||200805270935|||F|||||||02620^Thorne, M.D.^Keith|02620||||||||||

                      OBX|1|FT|CATHZ LT HEART PERC&BODY||DICTATING PHYSICIAN: Thorne, M.D., Keith  ||||||F|||20080527093534|||

                      OBX|2|FT|CATHZ LT HEART PERC&BODY|| ||||||F|||20080527093534|||

                      OBX|3|FT|CATHZ LT HEART PERC&BODY||DICTATING PHYSICIAN: Thorne, M.D., Keith  ||||||F|||20080527093534|||

                      OBX|4|FT|CATHZ LT HEART PERC&BODY||DICTATING PHYSICIAN: Thorne, M.D., Keith  ||||||F|||20080527093534|||

                      OBX|5|FT|CATHZ LT HEART PERC&BODY|| ||||||F|||20080527093534|||

                      OBX|6|FT|CATHZ LT HEART PERC&BODY|| ||||||F|||20080527093534|||

                      OBX|7||H|var1|xx

                      OBX|8||DW|var2|yy

                      OBX|9|AW|var3|zz

                      NTE|1|FT|CATHZ

                    • #85489
                      Lina Patel
                      Participant

                        Thanks Charlie,

                        As always, appreciate your insight and help.

                        🙂

                      • #85490
                        Lina Patel
                        Participant

                          Works in most cases except when equal to 4 OBX or more then run into the error below at the end after values are mapped:

                          expected integer but got “^~&”

                            while executing

                          “incr OBXnum”

                          Tried setting below in multiple places but did not help.

                          set OBXnum 0

                          This error occurs when there is no OBX segment in message[

                        • #85491
                          Lina Patel
                          Participant

                            Below code works if OBX segment is available.

                            Message errors as OBX number check is encoding characters

                                          # The OBX segs to add

                                          set add1 {

                              }

                                            set add2 {

                              }

                                            set add3 {

                              }

                                            # Parse msg and get last OBX location

                                            set segList [split $msg r]

                                            # Location of last OBX

                                            set loclist [lsearch -all -regexp $segList {^OBX}]

                                            # Location of last OBX set OBXnum to 1

                                            if {$loclist eq “”}  {set OBXnum 1}

                                           

                                            else {

                                            # Get location Of last OBX

                                            set OBXloc [lindex $loclist end]

                                            # Get last OBX and get number – OBX.1

                                            set OBX [split [lindex $segList $OBXloc] $fldSep]

                                     

                                            # Get OBX.1

                                            set OBXnum [lindex $OBX 1]

                              echo “OBXnumelse:” $OBXnum

                                             }

                                         

                                          #Works with one OBX

                                          #

                                           # Get OBX.1

                                            #set OBXnum [lindex $OBX 1]

                                          ##   if {[string trim $OBXnum] eq “”} {set OBXnum 0}

                                           #Works with one OBX- END          

                                         

                                         

                                       if $OBXnum > 1

                                     echo “$OBXnum after:” $OBXnum

                                            # Incrment OBX.1

                                            { incr OBXnum }

                                               

                                             # Set the segments

                                             set first [join [subst $add1] $fldSep]

                                               if $OBXnum > 1   incr OBXnum

                                             set second [join [subst $add2] $fldSep]

                                              if $OBXnum > 1 incr OBXnum

                                             set third [join [subst $add3] $fldSep]

                                   

                                             # Just insert them after last OBX

                                             # The linsert command inserts just before the index so we incr

                                             # OBXloc by one

                                             incr OBXloc

                                                 

                                            set segList [linsert $segList $OBXloc $first $second $third]

                                            set msg [join $segList r]

                                             msgset $mh “$msg”            

                                         lappend dispList “CONTINUE $mh”

                                     }    

                          • #85492
                            Charlie Bursell
                            Participant

                              Somehow OBXnum is getting set to MSH.1 instead of OBX.1.  I cannot see how.  I have run it multiple times here with 4 or more OBX segments without fail.

                              Please send me a copy of the proc.  Perhaps something has changed.  

                              Also, if you make the test message just test data, you could send that.  Please do not send real data

                              You could do a work around like:

                              In the checkMsg proc:

                                   Change

                                    # Just in case

                                     if {[string trim $OBXnum] eq “”} {set OBXnum 0}

                                     To

                                     # Just in case

                                     if {![string is integer -strict $OBXnum]} {set OBXnum 0}

                              However if you are getting an MSH where you should be getting an OBX something else will surely fail

                            • #85493
                              Lina Patel
                              Participant

                                Thank you Charlie!

                                Check above worked for OBXnum

                                Added same check of OBXloc

                                OBX counter will not increment and there is an extra space after last segment and new added OBX (below) segments.

                                RXR|IV|||Med

                                OBX|0||ActWeight||112|kg

                                OBX|0||DosWeight||102|kg

                                OBX|0||Height||189|cm’

                              • #85494
                                Lina Patel
                                Participant

                                  Attached is an example if no obx in message then 3 OBX added after MSH.

                                  If OBX available then works correctly.

                                • #85495
                                  Charlie Bursell
                                  Participant

                                    Looks like you tried to incorporate what I sent you into another proc.  Why do everything inline?  Use subprocs and namespaces foe easier maintenance and trouble shooting.

                                    Note in what I sent you:

                                    # If no OBX simply return 0

                                           if {$locs eq “”} {return 0}

                                    And the messages is continued as is.

                                    When I get time I will look at what you have in more detail.  It is sort of convoluted and not easy to troubleshoot.  I don’t have the databases available.

                                    Do this.  If you still have it, run the proc I sent you originally.  If it runs without error, begin a line by line compare and see what is wrong.  I would strongly suggest you break it into modules.  If you do that most of what I sent will plug into what you have.

                                  • #85496
                                    Lina Patel
                                    Participant

                                      Was not sure how to incorporate the SQL variables component that is why it is one long proc.

                                      Still have your code – will continue to work on this.

                                      Thanks!

                                    • #85497
                                      Lina Patel
                                      Participant

                                        Here is a version with subprocs – no obx and variables need to be passed to the subprocs

                                      • #85498
                                        Lina Patel
                                        Participant

                                          Test data with no obx

                                        • #85499
                                          Charlie Bursell
                                          Participant

                                            Here is my final try at this using namespaces.

                                            You do not need to set ODBC environment with each message.

                                            This assumes each message makes a new connection to DB

                                            I did not use the same ODBC statements as you.  I used some generic subroutines I had.  I did not understand the use of the SQLBindParameter statement which uses PID.18.  It is defined as Input but uses output buffer.

                                            If you still need the Prepare and Bind just change the query routine to use them instead.

                                            Note the queries were all the same except for a code so I made one dynamic query.

                                            I tested a bit using ODBC and a sqlite database but nowhere near the very convoluted queries you have.   But notice I did change the queries so they are readable and maintainable.

                                            If no OBX, message is continued as is.

                                            I put some error checking but not enough.  More would be better

                                            This is a model and not meant as final product.  Change as you see fit.

                                            Good luck with it

                                          • #85500
                                            Lina Patel
                                            Participant

                                              Thanks Charlie – will check it out!

                                              Appreciate all your help.

                                            • #85501
                                              Lina Patel
                                              Participant

                                                Hello,

                                                Have a request to copy pid-2 to pid3 if different for this working tclproc below:

                                              • #85502
                                                Steven Siegfried
                                                Participant

                                                  This code helped me!

                                                • #85503
                                                  Jim Kosloskey
                                                  Participant

                                                    Just FYI.

                                                    Based on the requirements described this coul be done inside an Xlate easily – with no Tcl.

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

                                                  • #85504
                                                    Daniel Murphy
                                                    Participant

                                                      Jim, I am curious as to how to ADD an OBX (or any segment) using Xlate.

                                                      I was trying to figure that out, but ended up writing my own Tcl to handle it. Which doesn’t look like this, but that’s the beauty of programming 🙂

                                                    • #85505
                                                      Jim Kosloskey
                                                      Participant

                                                        Daniel,

                                                        How that is done is to have your own Iteration Counter whch you maintain using Xlate Actions and prepending a $ to the counter name (like $%s99).

                                                        Depending on the circumstances you would keep that in synch with the IB Counter and adjust it when logically necessary. Then use your counter in the OB Address Path in the appropriate location.

                                                        Of course you need to provide the data for the additional segment.

                                                        I cover this in my Xlate ITERATE class. If you would like to discuss this tehnique more email me and we can chat.

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

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