Appointment reminder macro
Submitted by dadmin on Thu, 06/11/2014 - 13:47
I am trying to build a macro that, when you have an appointment selected on the Workflow|Scheduling screen, can be used to generate the text for an SMS message to the customer reminding them of their appointment.
My current macro expression is:
concat('Please be reminded that your vet appointment is today at ',date:formatTime(openvpms:get(.,"startTime"), "short"),'. Note we are fully booked today so please arrive on time. Thank you.')
The above (and several other things I tried) all gave expression error.
Is what I want to do possible - if so what is the correct expression.
Regards, Tim G
Re: Appointment reminder macro
Looks OK. Whats in the error logs?
Re: Appointment reminder macro
Humm - maybe a clue in the full log (before I just looked in the short log). It shows:
06 Nov 2014 15:49:52,867 WARN LookupMacros,http-8080-1:209 - org.openvpms.macro.MacroException: Failed to evaluate expression='concat('Please be reminded that your vet appointment is today at ',date:formatTime(openvpms:get(.,"startTime"), "short"),' . Note we are fully booked today so please arrive on time. Thank you.')' for macro=zzta org.openvpms.macro.MacroException: Failed to evaluate expression='concat('Please be reminded that your vet appointment is today at ',date:formatTime(openvpms:get(.,"startTime"), "short"),' . Note we are fully booked today so please arrive on time. Thank you.')' for macro=zzta at org.openvpms.macro.impl.AbstractExpressionMacroRunner.evaluate(AbstractExpressionMacroRunner.java:59) at org.openvpms.macro.impl.ExpressionMacroRunner.run(ExpressionMacroRunner.java:48) at org.openvpms.macro.impl.MacroContext.run(MacroContext.java:138) at org.openvpms.macro.impl.LookupMacros.runAll(LookupMacros.java:206) at org.openvpms.web.component.property.StringPropertyTransformer.apply(StringPropertyTransformer.java:165) at org.openvpms.web.component.bound.TextComponentBinder.setProperty(TextComponentBinder.java:121) at org.openvpms.web.component.bound.Binder.setProperty(Binder.java:93) ..... lots more stuff then Caused by: org.apache.commons.jxpath.JXPathInvalidAccessException: Cannot invoke public static java.lang.Object org.openvpms.component.business.service.archetype.ArchetypeServiceFunctions.get(java.lang.Object,java.lang.String); java.lang.Object cannot be cast to org.openvpms.component.system.common.util.PropertySet at org.apache.commons.jxpath.functions.MethodFunction.invoke(MethodFunction.java:99) at org.apache.commons.jxpath.ri.compiler.ExtensionFunction.computeValue(ExtensionFunction.java:102) at org.apache.commons.jxpath.ri.compiler.ExtensionFunction.compute(ExtensionFunction.java:84) at org.apache.commons.jxpath.ri.compiler.ExtensionFunction.computeValue(ExtensionFunction.java:92) at org.apache.commons.jxpath.ri.compiler.ExtensionFunction.compute(ExtensionFunction.java:84) at org.apache.commons.jxpath.ri.compiler.CoreFunction.functionConcat(CoreFunction.java:528) at org.apache.commons.jxpath.ri.compiler.CoreFunction.computeValue(CoreFunction.java:263) at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:353) at org.apache.commons.jxpath.ri.JXPathContextReferenceImpl.getValue(JXPathContextReferenceImpl.java:313) at org.openvpms.macro.impl.AbstractExpressionMacroRunner.evaluate(AbstractExpressionMacroRunner.java:55) ... 52 more Caused by: java.lang.ClassCastException: java.lang.Object cannot be cast to org.openvpms.component.system.common.util.PropertySet at org.openvpms.component.business.service.archetype.ArchetypeServiceFunctions.get(ArchetypeServiceFunctions.java:95) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.apache.commons.jxpath.functions.MethodFunction.invoke(MethodFunction.java:93) ... 61 more
If I write the expression as:
concat('Please be reminded that your vet appointment is today at ',date:formatTime(java.util.Date.new(), "short"),' . Note we are fully booked today so please arrive on time. Thank you.')
it works.
So I thought - perhaps I have to cast the start time - so I adjusted the expression to
concat('Please be reminded that your vet appointment is today at ',date:formatTime((java.util.Date)openvpms:get(.,"startTime"), "short"),' . Note we are fully booked today so please arrive on time. Thank you.')
but still no good - now the log shows:
Caused by: org.apache.commons.jxpath.JXPathInvalidSyntaxException: Invalid XPath: 'concat(\'Please be reminded that your vet appointment is today at \',date:formatTime((java.util.Date)openvpms:get(.,\"startTime\"), \"short\"),\' . Note we are fully booked today so please arrive on time. Thank you.\')'
so it evidently does not like the (java.util.Date) cast.
I am out of ideas. Regards, Tim G
Re: Appointment reminder macro
This is not supported. The problem you are having is due to:
openvpms:get(.,"startTime")
The '.' refers to the context object, which must be an IMObject with a startTime node. In the SMS editor, there is no context object.
To support this, the selected appointment would need to be exposed as a variable, i.e. $appointment.
Re: Appointment reminder macro
Humm - OK - I had a quick look at MacroVariables.java and it appear quite straight forward to add both $appointment and (say) $task - I really need to get comfortable with IntelliJ so I playwith source mods and test them.
Do you mind if I put in a jira to add $appointment and $task?
I can keep the practice happy with a macro where they supply the time - ie they enter say @smsr 3.30pm and it generates the text "Vet appointment reminder: We are fully booked today so we would appreciate you arriving on time. Your appointment is at 3.30pm"
Regards, Tim G
Re: Appointment reminder macro
Go ahead.
Re: Appointment reminder macro
Done - see https://openvpms.atlassian.net/browse/OVPMS-1536
Regards, Tim G