|
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface LogicService
The Logic Service provides a mechanism for both registering and consuming business logic in the form of logic rules. Rules may be run against a single patient or a set of patients. Rules are registered under a unique string token. Later evaluation and/or retrieval of the rule is done through the token. Tokens can be tagged with any number of string word/phrases to simplify organization and lookup of tokens. Data source results can be obtained directly by using a token in the form @foo.bar, where foo is the logic data source name and bar is the key for that data source. For example, the token @person.gender is a direct reference to the gender key of the person logic data source.
Patient myPatient = Context.getPatientService().getPatient(123);
LogicService logicService = Context.getLogicService();
Result result = logicService.eval(myPatient, "HIV POSITIVE");
if (result.toBoolean()) {
// patient is HIV positive
}
Results can be derived with specific criteria as well. For example, to fetch
the maximum CD4 count within the past six months:
Result result = logicService.eval(myPatient, new LogicCriteria("CD4 COUNT")
.within(Duration.months(6)).max();
or within 6 months of 11-November-2006:
Date targetDate = new GregorianCalendar(2006, 11, 11).getTime();
Result result = logicService.eval(myPatient, new LogicCriteria("CD4 COUNT")
.asOf(targetDate).within(Duration.months(6)).max();
Rule,
LogicCriteria,
LogicDataSource| Method Summary | |
|---|---|
void |
addRule(java.lang.String token,
Rule rule)
Registers a new rule with the logic service. |
void |
addRule(java.lang.String token,
java.lang.String[] tags,
Rule rule)
Registers a new rule with the logic service, associating the tags with the given token |
void |
addTokenTag(java.lang.String token,
java.lang.String tag)
Adds a tag to the given token. |
java.util.Map<LogicCriteria,java.util.Map<java.lang.Integer,Result>> |
eval(Cohort who,
java.util.List<LogicCriteria> criterias)
Evaluates a collection of queries for a set of patients |
java.util.Map<java.lang.Integer,Result> |
eval(Cohort who,
LogicCriteria criteria)
Evaluates a query over a list of patients |
java.util.Map<java.lang.Integer,Result> |
eval(Cohort who,
LogicCriteria criteria,
java.util.Map<java.lang.String,java.lang.Object> parameters)
Evaluates a query over a list of patients |
java.util.Map<java.lang.Integer,Result> |
eval(Cohort who,
java.lang.String token)
Evaluates a query over a list of patients |
java.util.Map<java.lang.Integer,Result> |
eval(Cohort who,
java.lang.String token,
java.util.Map<java.lang.String,java.lang.Object> parameters)
Evaluates a query over a list of patients |
Result |
eval(Patient who,
LogicCriteria criteria)
Evaluates a query for a given patient |
Result |
eval(Patient who,
LogicCriteria criteria,
java.util.Map<java.lang.String,java.lang.Object> parameters)
Evaluates a query for a given patient |
Result |
eval(Patient who,
java.lang.String token)
Evaluates a rule for a given patient, given the token for the rule. |
Result |
eval(Patient who,
java.lang.String token,
java.util.Map<java.lang.String,java.lang.Object> parameters)
Evaluates a rule for a given patient, given a token and parameters for the rule. |
java.util.Set<java.lang.String> |
findTags(java.lang.String partialTag)
Performs a partial match search for token tags among all known tokens. |
java.util.Set<java.lang.String> |
findToken(java.lang.String token)
Fetch all known (registered) tokens matching a given string |
Result.Datatype |
getDefaultDatatype(java.lang.String token)
Fetches the default datatype this token will return when fed to an eval() call. |
LogicDataSource |
getLogicDataSource(java.lang.String name)
Get a logic data source by name |
java.util.Map<java.lang.String,LogicDataSource> |
getLogicDataSources()
Get all registered logic data sources |
java.util.Set<RuleParameterInfo> |
getParameterList(java.lang.String token)
Fetches the parameters expected by a given rule |
Rule |
getRule(java.lang.String token)
Gets the rule registered under a given token |
java.util.Collection<java.lang.String> |
getTagsByToken(java.lang.String token)
Gets all tags associated with this token. |
java.util.Set<java.lang.String> |
getTokens()
Fetch all known (registered) tokens |
java.util.Set<java.lang.String> |
getTokensByTag(java.lang.String tag)
Gets all tokens associated with this tag. |
void |
registerLogicDataSource(java.lang.String name,
LogicDataSource logicDataSource)
Adds a data source to the logic service. |
void |
removeLogicDataSource(java.lang.String name)
Remove a logic data source by name |
void |
removeRule(java.lang.String token)
Removes a rule from the logic service |
void |
removeTokenTag(java.lang.String token,
java.lang.String tag)
Removes a token's previously assigned tag. |
void |
setLogicDataSources(java.util.Map<java.lang.String,LogicDataSource> logicDataSources)
Adds the given logic data sources to the list of current data sources on this logic service |
void |
updateRule(java.lang.String token,
Rule rule)
Update a rule that has previously been registered |
| Method Detail |
|---|
java.util.Set<java.lang.String> getTokens()
java.util.Set<java.lang.String> findToken(java.lang.String token)
token - full or partial token name
void addRule(java.lang.String token,
Rule rule)
throws LogicException
token - the lookup key ("token") for this rulerule - new rule to be registered
LogicExceptionRule
void addRule(java.lang.String token,
java.lang.String[] tags,
Rule rule)
throws LogicException
token - the unique lookup key ("token") for this ruletags - words or phrases associated with this token (do not need to
be unique)rule - new rule to be registered
LogicException
Rule getRule(java.lang.String token)
throws LogicException
token - lookup key ("token") under which the rule is registered
LogicException - if no rule by that name is found
void updateRule(java.lang.String token,
Rule rule)
throws LogicException
token - lookup key ("token") for the rule to be updatedrule - new version of rule (replaces existing rule)
LogicException
void removeRule(java.lang.String token)
throws LogicException
token - lookup key ("token") under which rule to be removed is
registered
LogicException
Result eval(Patient who,
java.lang.String token)
throws LogicException
who - patient for whom the rule is to be calculatedtoken - lookup key for rule to be calculated
LogicException
Result eval(Patient who,
java.lang.String token,
java.util.Map<java.lang.String,java.lang.Object> parameters)
throws LogicException
who - patient for whom the rule is to be calculatedtoken - lookup key for rule to be calculatedparameters - parameters to be passed to the rule
LogicException
Result eval(Patient who,
LogicCriteria criteria)
throws LogicException
who - patient for whom the query is to be runcriteria - question to be answered (along with the token) for the
given patient
LogicException
Result eval(Patient who,
LogicCriteria criteria,
java.util.Map<java.lang.String,java.lang.Object> parameters)
throws LogicException
who - patient for whom the query is to be runcriteria - question to be answered (along with the token) for the
given patientargs - arguments to be passed to the rule
LogicException
java.util.Map<java.lang.Integer,Result> eval(Cohort who,
java.lang.String token)
throws LogicException
who - patients for whom the query is to be runtoken - concept to be looked up for each patient
LogicException
java.util.Map<java.lang.Integer,Result> eval(Cohort who,
java.lang.String token,
java.util.Map<java.lang.String,java.lang.Object> parameters)
throws LogicException
who - patients for whom the query is to be runtoken - concept to be looked up for each patientparameters - parameters to be passed to the rule
LogicException
java.util.Map<java.lang.Integer,Result> eval(Cohort who,
LogicCriteria criteria)
throws LogicException
who - patients for whom the query is to be runcriteria - question to be answered (along with the token) for each
patient
LogicException
java.util.Map<java.lang.Integer,Result> eval(Cohort who,
LogicCriteria criteria,
java.util.Map<java.lang.String,java.lang.Object> parameters)
throws LogicException
who - patients for whom the query is to runcriteria - question to be answered (along with the token) for each
patientparameters - arguments to be passed to the rule
LogicException
java.util.Map<LogicCriteria,java.util.Map<java.lang.Integer,Result>> eval(Cohort who,
java.util.List<LogicCriteria> criterias)
throws LogicException
who - patients for whom the queries are to be runtokens - tokens to be calculatedcriterias - parallel list of criteria to be applied for each token
LogicException
void addTokenTag(java.lang.String token,
java.lang.String tag)
token - tag -
void removeTokenTag(java.lang.String token,
java.lang.String tag)
token - tag - java.util.Collection<java.lang.String> getTagsByToken(java.lang.String token)
token - token to look up by
java.util.Set<java.lang.String> getTokensByTag(java.lang.String tag)
tag - tag to look up by
java.util.Set<java.lang.String> findTags(java.lang.String partialTag)
partialTag - partial match string
Result.Datatype getDefaultDatatype(java.lang.String token)
token - token to look the datatype up for
java.util.Set<RuleParameterInfo> getParameterList(java.lang.String token)
void registerLogicDataSource(java.lang.String name,
LogicDataSource logicDataSource)
throws LogicException
name - name for the data sourcelogicDataSource - the data source
LogicExceptionjava.util.Map<java.lang.String,LogicDataSource> getLogicDataSources()
void setLogicDataSources(java.util.Map<java.lang.String,LogicDataSource> logicDataSources)
throws LogicException
logicDataSources -
LogicExceptionLogicDataSource getLogicDataSource(java.lang.String name)
name - name of the desired logic data source
null
if there is no data source registered under the given name (must
be an exact match)void removeLogicDataSource(java.lang.String name)
name - name of the logic data source to be unregistered
|
OpenMRS-trunk | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||