| 1 |
package org.openmrs.module.chica.rule; |
|---|
| 2 |
|
|---|
| 3 |
import java.util.Date; |
|---|
| 4 |
import java.util.Map; |
|---|
| 5 |
import java.util.Set; |
|---|
| 6 |
|
|---|
| 7 |
import org.openmrs.Patient; |
|---|
| 8 |
import org.openmrs.api.context.Context; |
|---|
| 9 |
import org.openmrs.logic.LogicContext; |
|---|
| 10 |
import org.openmrs.logic.LogicException; |
|---|
| 11 |
import org.openmrs.logic.LogicService; |
|---|
| 12 |
import org.openmrs.logic.Rule; |
|---|
| 13 |
import org.openmrs.logic.result.Result; |
|---|
| 14 |
import org.openmrs.logic.result.Result.Datatype; |
|---|
| 15 |
import org.openmrs.logic.rule.RuleParameterInfo; |
|---|
| 16 |
import org.openmrs.module.chica.util.Util; |
|---|
| 17 |
|
|---|
| 18 |
public class chicaAge implements Rule |
|---|
| 19 |
{ |
|---|
| 20 |
private LogicService logicService = Context.getLogicService(); |
|---|
| 21 |
|
|---|
| 22 |
/** |
|---|
| 23 |
* * |
|---|
| 24 |
* |
|---|
| 25 |
* @see org.openmrs.logic.rule.Rule#getParameterList() |
|---|
| 26 |
*/ |
|---|
| 27 |
public Set<RuleParameterInfo> getParameterList() |
|---|
| 28 |
{ |
|---|
| 29 |
return null; |
|---|
| 30 |
} |
|---|
| 31 |
|
|---|
| 32 |
/** |
|---|
| 33 |
* * |
|---|
| 34 |
* |
|---|
| 35 |
* @see org.openmrs.logic.rule.Rule#getDependencies() |
|---|
| 36 |
*/ |
|---|
| 37 |
public String[] getDependencies() |
|---|
| 38 |
{ |
|---|
| 39 |
return new String[] |
|---|
| 40 |
{}; |
|---|
| 41 |
} |
|---|
| 42 |
|
|---|
| 43 |
/** |
|---|
| 44 |
* * |
|---|
| 45 |
* |
|---|
| 46 |
* @see org.openmrs.logic.rule.Rule#getTTL() |
|---|
| 47 |
*/ |
|---|
| 48 |
public int getTTL() |
|---|
| 49 |
{ |
|---|
| 50 |
return 0; // 60 * 30; // 30 minutes |
|---|
| 51 |
} |
|---|
| 52 |
|
|---|
| 53 |
/** |
|---|
| 54 |
* * |
|---|
| 55 |
* |
|---|
| 56 |
* @see org.openmrs.logic.rule.Rule#getDatatype(String) |
|---|
| 57 |
*/ |
|---|
| 58 |
public Datatype getDefaultDatatype() |
|---|
| 59 |
{ |
|---|
| 60 |
return Datatype.CODED; |
|---|
| 61 |
} |
|---|
| 62 |
public Result eval(LogicContext context, Patient patient, |
|---|
| 63 |
Map<String, Object> parameters) throws LogicException |
|---|
| 64 |
{ |
|---|
| 65 |
Result ruleResult = null; |
|---|
| 66 |
|
|---|
| 67 |
if (parameters != null && parameters.get("param0") != null) |
|---|
| 68 |
{ |
|---|
| 69 |
ruleResult = (Result) parameters.get("param0"); |
|---|
| 70 |
if(ruleResult != null) |
|---|
| 71 |
{ |
|---|
| 72 |
Date result = ruleResult.toDatetime(); |
|---|
| 73 |
if (result != null) |
|---|
| 74 |
{ |
|---|
| 75 |
String chicaAge = |
|---|
| 76 |
Util.adjustAgeUnits(result, null); |
|---|
| 77 |
return new Result(chicaAge); |
|---|
| 78 |
} |
|---|
| 79 |
} |
|---|
| 80 |
} |
|---|
| 81 |
return Result.emptyResult(); |
|---|
| 82 |
} |
|---|
| 83 |
} |
|---|