› Clovertech Forums › Read Only Archives › Cloverleaf › Cloverleaf › RegSub Question
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.
set changed [regsub -all — {&} $xlateInVals {and} newCo]
set xlateOutVals $newCo
Thank you,
Jon
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.
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
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.
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
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.
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
One option would be to simply ‘join’ the list of xlateInVals values using ” and ” as the separator.
Jim Cobane
Henry Ford Health
Jim,
I had though about that as well. I might play around with my options and see.
Thank you,
Jon
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.
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
Typo in my response. ^ should read &
Sorry bout that 😀
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:
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]
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
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.
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.
Bob,
I appreciate the input but that didn’t fix the issue.
Thank you,
Jon
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
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
Fingers move too fast sometimes 😀
echo IN: [lindex $xlateInVals]
Should be
echo IN: [lindex $xlateInVals 0]
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
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!
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
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!
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.
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.
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