Possible to check jxpath variables?
Submitted by Guest on Sun, 16/06/2013 - 15:59
If you look at the bottom lines of http://www.openvpms.org/documentation/csh/1.7/customer/sms you will see that I have suggested a macro expression for generating the text for SMS reminders, and the caveat that it will not expand if there is no current patient.
Is it possible to check if $patient is valid?
Re: Possible to check jxpath variables?
I don't believe so no. One way to do it would be to introduce a function which can detect the existence of a variable. If the variable is undefined, what do you want to be able to do?
Re: Possible to check jxpath variables?
Tim A - see http://www.openvpms.org/documentation/csh/1.7/customer/sms for background.
It would be neat for the smsr macro to expand to "smsr - !! no current patient !!" if there wasn't one.
Looking at the definition of the name node for party.customerperson it has the expression:
and this returns the company name if there is one, else surname,firstName. It does this using the fact that number(not(/details/companyName)) returns 1 if there is no company name, else 0.
Hence if number(not($patient)) would return 1 if there was no current patient, or 0 if there was, one could modify the smsr macro expand to "smsr - !! no current patient !!" if there wasn't one.
By the way, does the above expression imply that one can use the full xpath 1.0 set of functions? Currently the only one I have mentioned in the CSH pages is concat.
Regards, Tim G
Re: Possible to check jxpath variables?
If a variable is missing, JXPath throws an exception, aborting evaluation of the expression.
There would need to be a conditional function developed that evaluates a variable if it exists, else returns the result of another expression.
E.g.:
JXPath only supports XPath 1.0, hence the need for the conditional via substring workaround used in party.customerperson (known as Becker's Method I believe).
I think it supports the full set of XPath 1.0 functions.
-Tim A
Re: Possible to check jxpath variables?
If we had a staff idle coders wondering what to do, this would be a neat enhancement, but we don't so let's leave it. [The CSH page warns that the macro will not expand if there is no current patient.]
Re full set of XPath 1. functions - I have just had a play (using the Test function of Admin|Org|Work List View) and they work happily. I will add to the CSH pages.
Regards, Tim G