Possible to check jxpath variables?

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?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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:

 concat(/details/companyName,substring(concat(/details/lastName,',',/details/firstName),0,number(not(/details/companyName))*string-length(concat(/details/lastName,',',/details/firstName))+1))  

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.:

 openvpms:var("patient.name", "!! no current patient !!") 

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

Syndicate content