public interface LogicService
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
Modifier and Type | Method and Description |
---|---|
void |
addRule(String token,
Rule rule)
Registers a new rule with the logic service.
|
void |
addRule(String token,
String[] tags,
Rule rule)
Registers a new rule with the logic service, associating the tags with the given token
|
void |
addTokenTag(String token,
String tag)
Adds a tag to the given token.
|
Map<LogicCriteria,Map<Integer,Result>> |
eval(Cohort who,
List<LogicCriteria> criterias)
Evaluates a collection of queries for a set of patients
|
Map<Integer,Result> |
eval(Cohort who,
LogicCriteria criteria)
Evaluates a query over a list of patients
|
Map<Integer,Result> |
eval(Cohort who,
LogicCriteria criteria,
Map<String,Object> parameters)
Evaluates a query over a list of patients
|
Map<Integer,Result> |
eval(Cohort who,
String expression)
Evaluates a query over a list of patients
|
Map<Integer,Result> |
eval(Cohort who,
String expression,
Map<String,Object> parameters)
Evaluates a query over a list of patients
|
Result |
eval(Integer patientId,
LogicCriteria criteria)
Evaluates a query for a given patient
|
Result |
eval(Integer patientId,
LogicCriteria criteria,
Map<String,Object> parameters)
Evaluates a query for a given patient
|
Map<LogicCriteria,Result> |
eval(Integer patientId,
Map<String,Object> parameters,
LogicCriteria... criteria)
Evaluates multiple
LogicCriteria for a single patient. |
Map<String,Result> |
eval(Integer patientId,
Map<String,Object> parameters,
String... expressions)
Evaluates multiple logic expressions for a single patient.
|
Result |
eval(Integer patientId,
String expression)
Evaluates a rule for a given patient, given the token for the rule.
|
Result |
eval(Integer patientId,
String expression,
Map<String,Object> parameters)
Evaluates a rule for a given patient, given a token and parameters for the rule.
|
List<String> |
getAllTokens()
Fetch all known (registered) tokens
|
Result.Datatype |
getDefaultDatatype(String token)
Fetches the default datatype this token will return when fed to an eval() call.
|
LogicDataSource |
getLogicDataSource(String name)
Get a logic data source by name
|
Map<String,LogicDataSource> |
getLogicDataSources()
Get all registered logic data sources
|
Set<RuleParameterInfo> |
getParameterList(String token)
Fetches the parameters expected by a given rule
|
Rule |
getRule(String token)
Gets the rule registered under a given token
|
List<String> |
getTags(String partialTag)
Performs a partial match search for token tags among all known tokens.
|
List<String> |
getTokens(String partialToken)
Fetch all known (registered) tokens matching a given string
|
List<String> |
getTokensWithTag(String tag)
Gets all tokens associated with this tag.
|
Set<String> |
getTokenTags(String token)
Gets all tags associated with this token.
|
LogicCriteria |
parse(String criteria)
Parse a criteria String to create a new LogicCriteria.
|
void |
removeRule(String token)
Removes a rule from the logic service
|
void |
removeTokenTag(String token,
String tag)
Removes a token's previously assigned tag.
|
void |
updateRule(String token,
Rule rule)
Update a rule that has previously been registered
|
List<String> getAllTokens()
List<String> getTokens(String partialToken)
partialToken
- full or partial token namevoid addRule(String token, Rule rule) throws LogicException
token
- the lookup key ("token") for this rulerule
- new rule to be registeredLogicException
Should not fail when another rule is registered on the same token
Should persist the rule and associate it with the token
void addRule(String token, 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 registeredLogicException
- Should not fail when no tags is specified
Should persist rule with the tagsRule getRule(String token) throws LogicException
token
- lookup key ("token") under which the rule is registeredLogicException
- if no rule by that name is found
Should return Rule associated with the input token
Should fail when no Rule is associated with the input token
Should return ReferenceRulevoid updateRule(String token, Rule rule) throws LogicException
token
- lookup key ("token") for the rule to be updatedrule
- new version of rule (replaces existing rule)LogicException
- Should update Rule when another Rule is registered under the same tokenvoid removeRule(String token) throws LogicException
token
- lookup key ("token") under which rule to be removed is registeredLogicException
- Should remove ruleResult eval(Integer patientId, String expression) throws LogicException
patientId
- patient for whom the rule is to be calculatedexpression
- expression to be parsed and evaluatedLogicException
parse(String)
Result eval(Integer patientId, String expression, Map<String,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 ruleLogicException
parse(String)
Result eval(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 patientLogicException
Result eval(Integer patientId, LogicCriteria criteria, Map<String,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 ruleResult
of queryLogicException
Map<String,Result> eval(Integer patientId, Map<String,Object> parameters, 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 runLogicException
parse(String)
Map<LogicCriteria,Result> eval(Integer patientId, Map<String,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 runLogicException
Map<Integer,Result> eval(Cohort who, String expression) throws LogicException
who
- patients for whom the query is to be runexpression
- expression to be parsed and evaluated for each patientLogicException
parse(String)
Map<Integer,Result> eval(Cohort who, String expression, Map<String,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 ruleLogicException
parse(String)
Map<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 patientLogicException
Map<Integer,Result> eval(Cohort who, LogicCriteria criteria, Map<String,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 ruleLogicException
Map<LogicCriteria,Map<Integer,Result>> eval(Cohort who, List<LogicCriteria> criterias) throws LogicException
who
- patients for whom the queries are to be runcriterias
- parallel list of criteria to be evaluated on each patientLogicException
void addTokenTag(String token, String tag)
token
- tag
- Should add tag for a tokenvoid removeTokenTag(String token, String tag)
token
- tag
- Should remove tag from a tokenSet<String> getTokenTags(String token)
token
- token to look up byList<String> getTokensWithTag(String tag)
tag
- tag to look up byList<String> getTags(String partialTag)
partialTag
- partial match stringResult.Datatype getDefaultDatatype(String token)
token
- token to look the datatype up forSet<RuleParameterInfo> getParameterList(String token)
Map<String,LogicDataSource> getLogicDataSources()
LogicDataSource getLogicDataSource(String name)
name
- name of the desired logic data sourcenull
if there is no data
source registered under the given name (must be an exact match)LogicCriteria parse(String criteria)
logicService.parseString("LAST 'CD4 COUNT' < 200");
criteria
- LogicCriteria expression in a plain String object.Copyright © 2024 OpenMRS Inc.. All rights reserved.