Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.


Orderset rules to be applied to calculate the dosage that can vary from implementation to implementation. To facilitate that, Rules engine is designed with extensibility in mind. By default Bahmni provides two rules "mg/kg" and "mg/m2" out of the box and these rules can also be configured with the help of csv file. Please check Using rules link for further information.

Extending rules engine with new rules:

Rules engine can be extended by writing appropriate groovy scripts and deploying at rules engine folder. Rules engine does nothing but transferring calls to its appropriate dosage calculator rule. Dosage calculator rule should adhere to the following interface in order to pickup automatically by the rules engine and apply the calculation.

Code Block
titleDosageRule interface
public interface DosageRule {
     Dose calculateDose(DosageRequest request) throws Exception ;

A sample groovy rule:

The following groovy rule is only for illustration purpose. Write a groovy class implementing DosageRule interface and attribute the class with "RuleName" attribute to assign a name for this particular rule. Rule assigned here will automatically populated at the drug order set creation Rules dropdown. If No rule name is assigned using "RuleName" attribute, then class name will be chosen as the rule name by default.

titleExpand to see NewRule.groovy
Code Block
package org.openmrs.module.rulesengine.rule 
import org.openmrs.module.rulesengine.domain.DosageRequest 
import org.openmrs.module.rulesengine.domain.Dose 
import org.openmrs.module.rulesengine.domain.RuleName 
@RuleName(name = "testrule") 
class NewDosageRule implements DosageRule 
Dose calculateDose(DosageRequest request) throws Exception
 { // write the new logic for calculating dosage and return Dose object. 
return null; 
		Patient patient = PatientService.getPatientByUuid(request.getPatientUuid());

       	Double weight = ObservationService.getLatestObsValueNumeric(patient, ObservationService.ConceptRepo.WEIGHT);

       Double roundUpValue = BahmniMath.getTwoDigitRoundUpValue(weight * request.getBaseDose());
       return new Dose(request.getDrugName(),roundUpValue,;

After writing the rule, the same has to be deployed in the appropriate place for the rule engine to pickup automatically.

titleRules location

All the new rules written in groovy language should be deployed at:


After deploying the rules at the above location, restart openmrs for the rules engine to pickup new rules.Existing default rules that are already part of rules engine should already be populated. System must be restarted only for new groovy file based rules. 

titleOn this Page

Table of Contents

titleFeature Details

Using rules

titleRelated Links

Authoring Order Sets