|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
@Transactional 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:
Calendar calendar = Calendar.getInstance(); calendar.set(2006, 11, 11); Date targetDate = calendar.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 expression)
Evaluates a query over a list of patients |
java.util.Map<java.lang.Integer,Result> |
eval(Cohort who,
java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> parameters)
Evaluates a query over a list of patients |
Result |
eval(java.lang.Integer patientId,
LogicCriteria criteria)
Evaluates a query for a given patient |
Result |
eval(java.lang.Integer patientId,
LogicCriteria criteria,
java.util.Map<java.lang.String,java.lang.Object> parameters)
Evaluates a query for a given patient |
java.util.Map<LogicCriteria,Result> |
eval(java.lang.Integer patientId,
java.util.Map<java.lang.String,java.lang.Object> parameters,
LogicCriteria... criteria)
Evaluates multiple LogicCriteria for a single patient. |
java.util.Map<java.lang.String,Result> |
eval(java.lang.Integer patientId,
java.util.Map<java.lang.String,java.lang.Object> parameters,
java.lang.String... expressions)
Evaluates multiple logic expressions for a single patient. |
Result |
eval(java.lang.Integer patientId,
java.lang.String expression)
Evaluates a rule for a given patient, given the token for the rule. |
Result |
eval(java.lang.Integer patientId,
java.lang.String expression,
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. |
Result |
eval(Patient who,
LogicCriteria criteria)
Deprecated. use eval(Integer, LogicCriteria) |
Result |
eval(Patient who,
LogicCriteria criteria,
java.util.Map<java.lang.String,java.lang.Object> parameters)
Deprecated. use eval(Integer, LogicCriteria, Map) |
Result |
eval(Patient who,
java.lang.String expression)
Deprecated. use eval(Integer, String) |
Result |
eval(Patient who,
java.lang.String expression,
java.util.Map<java.lang.String,java.lang.Object> parameters)
Deprecated. use eval(Integer, String, Map) |
java.util.Set<java.lang.String> |
findTags(java.lang.String partialTag)
Deprecated. use getTags(String) |
java.util.Set<java.lang.String> |
findToken(java.lang.String token)
Deprecated. use getTokens(String) |
java.util.List<java.lang.String> |
getAllTokens()
Fetch all known (registered) tokens |
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.List<java.lang.String> |
getTags(java.lang.String partialTag)
Performs a partial match search for token tags among all known tokens. |
java.util.Collection<java.lang.String> |
getTagsByToken(java.lang.String token)
Deprecated. use getTokenTags(String) |
java.util.Set<java.lang.String> |
getTokens()
Deprecated. use getAllTokens() |
java.util.List<java.lang.String> |
getTokens(java.lang.String partialToken)
Fetch all known (registered) tokens matching a given string |
java.util.Set<java.lang.String> |
getTokensByTag(java.lang.String tag)
Deprecated. use getTokensWithTag(String) |
java.util.List<java.lang.String> |
getTokensWithTag(java.lang.String tag)
Gets all tokens associated with this tag. |
java.util.Set<java.lang.String> |
getTokenTags(java.lang.String token)
Gets all tags associated with this token. |
LogicCriteria |
parse(java.lang.String criteria)
Parse a criteria String to create a new LogicCriteria. |
LogicCriteria |
parseString(java.lang.String inStr)
Deprecated. use parse(String) |
void |
registerLogicDataSource(java.lang.String name,
LogicDataSource logicDataSource)
Deprecated. data sources are now auto-registered via Spring (since Logic module version 0.5) |
void |
removeLogicDataSource(java.lang.String name)
Deprecated. data sources are now auto-registered via Spring (since Logic module version 0.5) |
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)
Deprecated. data sources are now auto-registered via Spring (since Logic module version 0.5) |
void |
updateRule(java.lang.String token,
Rule rule)
Update a rule that has previously been registered |
Method Detail |
---|
@Deprecated java.util.Set<java.lang.String> getTokens()
getAllTokens()
java.util.List<java.lang.String> getAllTokens()
@Deprecated java.util.Set<java.lang.String> findToken(java.lang.String token)
getTokens(String)
token
- full or partial token name
java.util.List<java.lang.String> getTokens(java.lang.String partialToken)
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
LogicException
Rule
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 foundvoid 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(java.lang.Integer patientId, java.lang.String expression) throws LogicException
patientId
- patient for whom the rule is to be calculatedexpression
- expression to be parsed and evaluated
LogicException
#parse(String)}
Result eval(java.lang.Integer patientId, java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> parameters) throws LogicException
patientId
- patient for whom the rule is to be calculatedexpression
- expression to be parsed and evaluatedparameters
- parameters to be passed to the rule
LogicException
#parse(String)}
Result eval(java.lang.Integer patientId, LogicCriteria criteria) throws LogicException
patientId
- patient for whom the query is to be runcriteria
- question to be answered (along with the token) for the given patient
LogicException
Result eval(java.lang.Integer patientId, LogicCriteria criteria, java.util.Map<java.lang.String,java.lang.Object> parameters) throws LogicException
patientId
- Patient
for whom the query is to be runcriteria
- Criteria
question to be answered (along with the token) for the
given patientparameters
- Map
of arguments to be passed to the rule
Result
of query
LogicException
java.util.Map<java.lang.String,Result> eval(java.lang.Integer patientId, java.util.Map<java.lang.String,java.lang.Object> parameters, java.lang.String... expressions) throws LogicException
LogicCriteria
... version.)
patientId
- which patient to run the rules onparameters
- global parameters to be passed to all rule evaluationsexpressions
- expressions to be parsed and run
LogicException
#parse(String)}
java.util.Map<LogicCriteria,Result> eval(java.lang.Integer patientId, java.util.Map<java.lang.String,java.lang.Object> parameters, LogicCriteria... criteria) throws LogicException
LogicCriteria
for a single patient.
(The criteria argument is an array and comes last because using a List would give this method
the same type erasure as the String
... version.)
patientId
- which patient to run the rules onparameters
- global parameters to be passed to all rule evaluationscriteria
- what criteria to run
LogicException
@Deprecated Result eval(Patient who, java.lang.String expression) throws LogicException
eval(Integer, String)
who
- patient for whom the rule is to be calculatedexpression
- expression to be parsed and evaluated
LogicException
#parse(String)}
@Deprecated Result eval(Patient who, java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> parameters) throws LogicException
eval(Integer, String, Map)
who
- patient for whom the rule is to be calculatedexpression
- expression to be parsed and evaluatedparameters
- parameters to be passed to the rule
LogicException
#parse(String)}
@Deprecated Result eval(Patient who, LogicCriteria criteria) throws LogicException
eval(Integer, LogicCriteria)
who
- patient for whom the query is to be runcriteria
- question to be answered (along with the token) for the given patient
LogicException
@Deprecated Result eval(Patient who, LogicCriteria criteria, java.util.Map<java.lang.String,java.lang.Object> parameters) throws LogicException
eval(Integer, LogicCriteria, Map)
who
- Patient
for whom the query is to be runcriteria
- Criteria
question to be answered (along with the token) for the
given patientparameters
- Map
of arguments to be passed to the rule
Result
of query
LogicException
java.util.Map<java.lang.Integer,Result> eval(Cohort who, java.lang.String expression) throws LogicException
who
- patients for whom the query is to be runexpression
- expression to be parsed and evaluated for each patient
LogicException
#parse(String)}
java.util.Map<java.lang.Integer,Result> eval(Cohort who, java.lang.String expression, java.util.Map<java.lang.String,java.lang.Object> parameters) throws LogicException
who
- patients for whom the query is to be runexpression
- expression to be parsed and evaluated for each patientparameters
- parameters to be passed to the rule
LogicException
#parse(String)}
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 runcriterias
- parallel list of criteria to be evaluated on each patient
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
- @Deprecated java.util.Collection<java.lang.String> getTagsByToken(java.lang.String token)
getTokenTags(String)
token
- token to look up by
java.util.Set<java.lang.String> getTokenTags(java.lang.String token)
token
- token to look up by
@Deprecated java.util.Set<java.lang.String> getTokensByTag(java.lang.String tag)
getTokensWithTag(String)
tag
- tag to look up by
java.util.List<java.lang.String> getTokensWithTag(java.lang.String tag)
tag
- tag to look up by
@Deprecated java.util.Set<java.lang.String> findTags(java.lang.String partialTag)
getTags(String)
partialTag
- partial match string
java.util.List<java.lang.String> getTags(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)
@Deprecated void registerLogicDataSource(java.lang.String name, LogicDataSource logicDataSource) throws LogicException
name
- name for the data sourcelogicDataSource
- the data source
LogicException
java.util.Map<java.lang.String,LogicDataSource> getLogicDataSources()
@Deprecated void setLogicDataSources(java.util.Map<java.lang.String,LogicDataSource> logicDataSources) throws LogicException
logicDataSources
-
LogicException
LogicDataSource 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)@Deprecated void removeLogicDataSource(java.lang.String name)
name
- name of the logic data source to be unregistered@Deprecated LogicCriteria parseString(java.lang.String inStr)
parse(String)
logicService.parseString("LAST 'CD4 COUNT' < 200");
inStr
- LogicCriteria expression in a plain String object.
LogicCriteria parse(java.lang.String criteria)
logicService.parseString("LAST 'CD4 COUNT' < 200");
criteria
- LogicCriteria expression in a plain String object.
|
OpenMRS-1.7.x | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |