Questions about LogicModule, and adding custom data source and rules

classic Classic list List threaded Threaded
2 messages Options
Mathias Lin Mathias Lin
Reply | Threaded
Open this post in threaded view
|

Questions about LogicModule, and adding custom data source and rules

I have some questions about the LogicModule:

(1)
Referring to:
http://archive.openmrs.org/wiki/HTML_Form_Entry_Module_HTML_Reference#.3CexcludeIf.3E

What is the difference between a velocityTest and logicTest, besides
the different syntax? Is the one more powerful than the other, or are
they fulfilling different purposes?

(2)
And is there any documentation on the logic operators and syntax for
these tests? I found all operators in the source code under the
org.openmrs.logic.op package, but wondering whether the operators are
somewhere listed/documented (esp. for users setting up html forms).
I found a list of operators at
https://wiki.openmrs.org/display/docs/Logic+Service+Technical+Overview#LogicServiceTechnicalOverview-Supportedoperators,
but it doesn't seem complete (for example: AsOf, In,
GreaterThanEquals, LessThanEquals, Average are not listed there). Also
wondering about the use of brackets. Does it work just similar to JSTL
syntax?


(3)
Referring to:
https://wiki.openmrs.org/display/docs/User-defined+Rules

How to add a custom rule provider?
I want to register a new token, user.roles, for which I would need a
new rule provider, UserDataSource. I want to use logic expressions in
logicTests in the html forms (includeIf, excludeIf tags),
showing/hiding information based on the current user's roles.

How to best deploy such custom data source, or hook it into the
existing system? Would/should it need to be wrapped up as a module, or
just a jar?

How are the custom rules classes to be deployed (i.e. such as the
sample rule classes mentioned on
https://wiki.openmrs.org/display/docs/User-defined+Rules)?
Or would that just needed to be entered into the 'Rule Content' field
under http://demo.openmrs.org/openmrs/module/logic/editRuleDefinition.form?id=1
?

I'm not quite clear whether you write the rule in the OpenMRS Admin
section of the Logic module (i.e. Groovy syntax), or actually write
and compile a java class and deploy it somehow, i.e. a java-class
based rule as described in "Registering a Rule with Logic Service":
https://wiki.openmrs.org/display/docs/Rule+HOWTO


About the existing data sources:
When I look into the existing set of rules in the 1.8.2 demo
(demo.openmrs.org), I see that they're using the PersonDataSource, but
I can't find that class in the source code of the OpenMRS core
anymore, however, browsing on Fisheye, I see that this class existed
up to OpenMRS version 1.5.x, but not beyond.
https://source.openmrs.org/browse/OpenMRS/branches/1.5.x/src/api/org/openmrs/logic/datasource/PersonDataSource.java

Therefore wondering, where has this class gone, or how does 1.8.2 work
without that class, when it's defined as the rule provider in the
logic module configuration though?


I've read the pages in the wiki at
https://wiki.openmrs.org/display/docs/Logic+Service, but above
questions are still open.

_________________________________________

To unsubscribe from OpenMRS Implementers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-implement-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-implement-l]
Mathias LIN
Meta Healthcare Systems Ltd.
20/F Central Tower, 28 Queen's Rd Central, Hong Kong
T +852 8199 9605, M +86 159 0208 1701, Skype: mathias.lin
http://www.metahealthcare.com
Darius Jazayeri-3 Darius Jazayeri-3
Reply | Threaded
Open this post in threaded view
|

Re: Questions about LogicModule, and adding custom data source and rules

Hi Mathias,

I'm going to reply incompletely and quickly (rather than never getting around to replying...) See inline.

On Sun, Apr 29, 2012 at 5:47 AM, Mathias Lin | Meta Healthcare <[hidden email]> wrote:
I have some questions about the LogicModule:

(1)
Referring to:
http://archive.openmrs.org/wiki/HTML_Form_Entry_Module_HTML_Reference#.3CexcludeIf.3E

What is the difference between a velocityTest and logicTest, besides
the different syntax? Is the one more powerful than the other, or are
they fulfilling different purposes?


Different capabilities. The velocity one leverages the same stuff that <lookup expression="..."/> does, and was originally thought of as more of a short-term solution. It is easy to add specific extra functions here if necessary just for HFE. The logic tests depend on the logic module, so as its capabilities are developed, HFE will be able to leverage that.
 
(2)
And is there any documentation on the logic operators and syntax for
these tests? I found all operators in the source code under the
org.openmrs.logic.op package, but wondering whether the operators are
somewhere listed/documented (esp. for users setting up html forms).
I found a list of operators at
https://wiki.openmrs.org/display/docs/Logic+Service+Technical+Overview#LogicServiceTechnicalOverview-Supportedoperators,
but it doesn't seem complete (for example: AsOf, In,
GreaterThanEquals, LessThanEquals, Average are not listed there). Also
wondering about the use of brackets. Does it work just similar to JSTL
syntax?


The logic module is being deprecated as something we bundle in OpenMRS as a "core module". It will continue to exist, and (this is speculation) its ability to let you write sophisticated rules in Arden Syntax will continue to be developed, while the syntax you're referring to (which is indeed incomplete) is unlikely to move forwards.

The strategic replacement for distribution with OpenMRS will be the Calculation module, which we just had a sprint on.
 

(3)
Referring to:
https://wiki.openmrs.org/display/docs/User-defined+Rules

How to add a custom rule provider?
I want to register a new token, user.roles, for which I would need a
new rule provider, UserDataSource. I want to use logic expressions in
logicTests in the html forms (includeIf, excludeIf tags),
showing/hiding information based on the current user's roles.

How to best deploy such custom data source, or hook it into the
existing system? Would/should it need to be wrapped up as a module, or
just a jar?

You should be able to do this by providing it via a module. Depending on whether you want to support a couple of specific queries, or you really want to be able to mix-and-match them, you might consider just writing a couple of rules in Groovy.
 

How are the custom rules classes to be deployed (i.e. such as the
sample rule classes mentioned on
https://wiki.openmrs.org/display/docs/User-defined+Rules)?
Or would that just needed to be entered into the 'Rule Content' field
under http://demo.openmrs.org/openmrs/module/logic/editRuleDefinition.form?id=1
?

I'm not quite clear whether you write the rule in the OpenMRS Admin
section of the Logic module (i.e. Groovy syntax), or actually write
and compile a java class and deploy it somehow, i.e. a java-class
based rule as described in "Registering a Rule with Logic Service":
https://wiki.openmrs.org/display/docs/Rule+HOWTO


Option 1 = Write rules in Java in a module. I have never done this, but they need to implement Rule, and you probably need to also have a "RuleProvider". Win Ribeka may be able to give you more info on this.

Option 2 = (I suggest trying this first) is to write them in Groovy via "Rule Definitions" on your admin page, at the editRuleDefinition.form url you mention. This stores the rule definitions in your database, so if you've got a single implementation, that's fine, but if you want consistent rules to get installed on different servers, this isn't great. Choose Groovy as the language, and put the code in Rule Content. (I recommend groovy over java if you're doing it this way.) The best way to test these out as you develop them is to keep the rule definition editor in one tab, and a Test Logic Expressions page open in another tab, so each time you tweak the rule and save it, you can refresh the other tab and see if it's working.

Option 3 = write data sources, and use these in rules
 

About the existing data sources:
When I look into the existing set of rules in the 1.8.2 demo
(demo.openmrs.org), I see that they're using the PersonDataSource, but
I can't find that class in the source code of the OpenMRS core
anymore, however, browsing on Fisheye, I see that this class existed
up to OpenMRS version 1.5.x, but not beyond.
https://source.openmrs.org/browse/OpenMRS/branches/1.5.x/src/api/org/openmrs/logic/datasource/PersonDataSource.java

Therefore wondering, where has this class gone, or how does 1.8.2 work
without that class, when it's defined as the rule provider in the
logic module configuration though?


It was moved to the Logic Module: http://svn.openmrs.org/openmrs-modules/logic/trunk/
 

I've read the pages in the wiki at
https://wiki.openmrs.org/display/docs/Logic+Service, but above
questions are still open.

The documentation around this is mediocre at best. Please let us know how you end up proceeding, and if you can distill some of what you learn into wiki page edits or comments, that would be wonderful.
 

_________________________________________

To unsubscribe from OpenMRS Implementers' mailing list, send an e-mail to [hidden email] with "SIGNOFF openmrs-implement-l" in the  body (not the subject) of your e-mail.

[mailto:[hidden email]?body=SIGNOFF%20openmrs-implement-l]


[hidden email] from OpenMRS Implementers' mailing list