RegSub Question

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf RegSub Question

  • Creator
    Topic
  • #54323
    Jon Melin
    Participant

      Hello,

      I am having an issue getting a regsub to function properly. I’ve used similar code in multiple other spots, especially pre-process. I am trying to simply replace and ampersand (&) with the word and. I’m almost certain this has worked in the past but I can’t seem to get it to this time. I’ve tried with brackets, quotes, without backslash, etc. Any suggestions?

      I would prefer to do this in the xlate since it’s just in one field.

      Code:



      set changed [regsub -all — {&} $xlateInVals {and} newCo]
      set xlateOutVals $newCo

      Thank you,

      Jon

    Viewing 25 reply threads
    • Author
      Replies
      • #80993
        James Cobane
        Participant

          Jon,

          I suspect that the issue is because you are doing it within an Xlate, and because the & is a sub-component separator (I’m assuming you are working on an HL7 message), you are not actually getting the ampersand in xlateInVals; you are likely only getting the individual components.

        • #80994
          Jon Melin
          Participant

            James,

            Good call. I am working with HL7 yes I did notice that when I echoed the result. I just didn’t know why it was doing that but now common sense is kicking in for me and that is why. How would you go about doing it in an Xlate, or would you just create a pre-proc TCL script and be done with it?

            Thank you,

            Jon

          • #80995
            Jim Kosloskey
            Participant

              Once you get to Release 6 you will be able to see the sub-component separator inside the Xlate (that is nice).

              The only real solution to this age old problem s for the source system to stop that from happening.

              Since that is unlikely there are a number of kluges folks have tried but perhaps the next best thing is to use a pre-Xlate proc and go after the field in Tcl – or upgrade to the latest Cloverleaf release.

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

            • #80996
              Jon Melin
              Participant

                Jim,

                I’m on 6.0.1.0, are you taking a newer version than that?

                It still splits it out into two separate fields.

                Thank you,

                Jon

              • #80997
                Jim Kosloskey
                Participant

                  I am on 6.0.0.

                  Are you referencing the field in the Address Path or the component?

                  I will take a look tomorrow at my work.

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

                • #80998
                  Jon Melin
                  Participant

                    Just trying to do this regsub in the Pre Proc section of the Xlate with the Source set as the RXA(0).#17(0).[0] field and the destination set as the RXA(0).#17(0).[0] field. Pretty simple. I could provide a screenshot if that would help. I could write a quick TCL proc to do this but now I’m curious on how to get this to work.

                    Thank you,

                    Jon

                  • #80999
                    James Cobane
                    Participant

                      One option would be to simply ‘join’ the list of xlateInVals values using ” and ” as the separator.

                      Jim Cobane

                      Henry Ford Health

                    • #81000
                      Jon Melin
                      Participant

                        Jim,

                        I had though about that as well. I might play around with my options and see.

                        Thank you,

                        Jon

                      • #81001
                        Jim Kosloskey
                        Participant

                          Jon,

                          Do you have a BULKCOPY involved?

                          If so you need to do a bogus COPY of the field at the field level BEFORE the BULKCOPY (I think the same may be true if PATHCOPY is involved). Apparently BULKCOPY and perhaps PATHCOPY destroy the ability to get at the subcomponent if you attempt after the BULKCOPY/PATHCOPY and don’t do the bogus COPY.

                          Since we rarely use BULKCOPY we have not had this issue.

                          Something like COPY RXA(0).#17(0) –> @stuff.

                          Then you can reference the component with your Pre code (after the BULKCOPY and perhaps PATHCOPY) and the component separator should be there (at least it is with 6.0.0).

                          If the above does not seem to work or you have any questions, please email me because I want to determine if this only works in 6.0.0.

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

                        • #81002
                          Charlie Bursell
                          Participant

                            The ampersand, by default, is used as a replacement character in regexp.

                            The ampersand. & is substituted with the whole regex match but ^ should result in the ampersand itself.

                            Since regexp and regsub uses meta charaters that can be hard to control at times I find it best to use the string map command where possible.

                            For example

                            set newvar [string map

                              $var]
                          • #81003
                            Charlie Bursell
                            Participant

                              Typo in my response.  ^ should read &

                              Sorry bout that  😀

                            • #81004
                              Jon Melin
                              Participant

                                Charlie,

                                When I try a string map I end up getting the first part of the list, no “and” and the rest is blank. Here is what I tried:

                                Code:


                                set test [string map {& and} $xlateInVals]
                                set xlateOutVals $test

                                It looks like I’ll just have to do a pre-proc TCL for this.

                                Thank you,

                                Jon[/code]

                              • #81005
                                Jon Melin
                                Participant

                                  Jim,

                                  I am using a bulkcopy as there are very few minor changes in the xlate.

                                  I tried assigning the value to a variable before the bulkcopy like you suggested and nulled the destination field after the bulkcopy before trying to put the new value in. String map nor regsub seem to work.

                                  It’s odd too that even when I disabled the bulkcopy it still didn’t seem to work.

                                  Thank you,

                                  Jon

                                • #81006
                                  Jim Kosloskey
                                  Participant

                                    Jon,

                                    Please email me and I will work with you off-line on this as this works for me in 6.0.0 and I want to see if it is now ‘broken’ in 6.0.1

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

                                  • #81007
                                    Bob Richardson
                                    Participant

                                      Greetings,

                                      Looks like you need to add the list command to your statement:

                                      set xlateOutVals

                                        This would preserve your two elements here.

                                        As a rule always specify list when setting xlateOutVals.

                                        Hope that fixes it.

                                    • #81008
                                      Jon Melin
                                      Participant

                                        Bob,

                                        I appreciate the input but that didn’t fix the issue.

                                        Thank you,

                                        Jon

                                      • #81009
                                        James Cobane
                                        Participant

                                          I did a simple Xlate that has a BULKCOPY, a COPY of @null to OBR:4.1, and then a copy of OBR:4.1 to OBR:4.1 with a snippet of code:

                                          puts $xlateInVals

                                          set xlateOutVals

                                            ]

                                            puts $xlateOutVals

                                            The incoming value in OBR:4.1 is “Culture, Wound Aerobic & Anaerobic”.

                                            The resulting outbound value in OBR:4.1 is “”Culture, Wound Aerobic and Anaerobic”.  See attached document with screen shot of Xlate, and output of testing tool.

                                            Hope this makes sense.

                                            Jim Cobane

                                            Henry Ford Health

                                          1. #81010
                                            Charlie Bursell
                                            Participant

                                              As bob said both in and out vals are lists and should be treated as such.

                                              set test [string map {& and} [lindex $xlateInVals 0]]

                                              set xlateOutVals

                                                If it still does not work something is weird.  Try this:

                                                echo IN: [lindex $xlateInVals]

                                                set test [string map {& and} [lindex $xlateInVals 0]]

                                                echo OUT:  $test

                                                set xlateOutVals

                                                See what you get.  If you can’t figure it out send it to Jim.  I am sure he will help

                                            • #81011
                                              Charlie Bursell
                                              Participant

                                                Fingers move too fast sometimes  😀

                                                echo IN: [lindex $xlateInVals]

                                                Should be

                                                echo IN: [lindex $xlateInVals 0]

                                              • #81012
                                                Jon Melin
                                                Participant

                                                  I’ve created a Pre-Proc to take care of this in the route but still odd.

                                                  This suggestion still didn’t work even with the bulkcopy completely disabled. Stange issue, I will work with Jim on this to see what the issue might be.

                                                  Thank you for the assistance, it’s greatly appreciated everyone.

                                                  Thank you,

                                                  Jon

                                                • #81013
                                                  Bob Richardson
                                                  Participant

                                                    Jon,

                                                    Suggestion:  copy the entire field to a temporary variable

                                                    and then in your Pre Proc regsub the contents of the temporary variable

                                                    and map that to the output field.

                                                    Don’t forget to set the output as a list:

                                                    set xlateOutVals

                                                      Good luck!

                                                  • #81014
                                                    Jon Melin
                                                    Participant

                                                      Hello,

                                                      I’ve actually done this with a TCL Pre-Proc on the route using the regsub. The issue actually appears to be not the solutions provided (because they all are workable solutions) but how the data is dealt with in Cloverleaf.

                                                      This is true with or without BulkCopy. After some conversation with Jim, it appears this is one of the only situations you want to use xlateInVals without lindex because the list comes inbound as separate list elements (even if you assign it to a variable) without the ampersand intact. So you actually can’t replace or sub it because it’s not there. The join that was suggested works in this care but not if I have fewer or more words to put together. The best way would be to create a for each lindex and put them together with the correct conjunction.  

                                                      I really appreciate all the support with suggestions and they are all valid answers and solutions, it just appears 6.0.1 deals with this differently than 6.0.0 did.

                                                      I’ve attached a screenshot with a couple examples, I hope this clears things up. Let me know if you have any questions.

                                                      Thank you,

                                                      Jon

                                                    • #81015
                                                      Bob Richardson
                                                      Participant

                                                        Jon,

                                                        See your dilemma!  Yes, all the data is converted to list elements.

                                                        Tcl Pre Proc will work here – we have the same problems on 5.8.7.

                                                        Have fun!

                                                      • #81016
                                                        James Cobane
                                                        Participant

                                                          The way I have done these types of scenarios within the Xlate is to do what I did in the sample I provided earlier in this post, but with an added check to see if the list length of xlateInVals is > 1 (i.e.

                                                        • #81017
                                                          Jim Kosloskey
                                                          Participant

                                                            It appears that in 6.0.0 the way this is handled is different.

                                                            Actually what happens in 6.0.0 is the entire component with the sub-component separator in place is presented in xlateInVals so string map or regsub could be used.

                                                            Apparently that is not an intended feature but a bug and thus ‘corrected’ in 6.0.1 and later.

                                                            It would be nice though to have Cloverleaf actually sensitive to those components in the standard which have sub-components allowed and only tokenize those. That would leave those components which do not have sub-components defined as a string of text which then could be more easily handled.

                                                            Heck, if that can be done then why not have the ability to specify escaping following the HL/7 standard should be automatically applied?

                                                            In any case, I have constructed a xltp type Tcl proc which will allow replacing erroneous sub-component separators so this activity can be inside the Xlate instead of in a pre Xlate proc if one chooses.

                                                            If anyone wants the proc and user doc, email me.

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

                                                          • #81018
                                                            Jon Melin
                                                            Participant

                                                              James,

                                                              That is something similar to what I was starting to do before I went the pre-proc TCl route.

                                                              Thank you all again, hopefully this chain will be helpful to others in the future.

                                                              Thank you,

                                                              Jon

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