We upgraded to 1.7.x in our clinics this week and we have noticed some strange intermittent slowness in our rule executions. For example, about 92% of our PSF forms can be created in less than 15 seconds. However, 8% take as high as 2 minutes or more. We never saw this kind of behavior in 1.5 openmrs. Also, a simple java rule like bmi takes anywhere from 152 milliseconds to 12.8 seconds! All the bmi rule does is do a context.read for height and a context.read for weight and compute the bmi. Was anything changed in the hibernate configuration or the obs table between 1.5 and 1.7.x that could explain this intermittent slowness? It is killing us in the clinics.

Thanks,

Tammy Dugan

--
Tammy Dugan
CHIRDL Technical Lead
Children's Health Services Research
IU School of Medicine


_________________________________________

To unsubscribe from OpenMRS Developers' mailing list, send an e-mail to 
[email protected] with "SIGNOFF openmrs-devel-l" in the  body (not 
the subject) of your e-mail.

[mailto:[email protected]?body=SIGNOFF%20openmrs-devel-l]
package org.openmrs.module.dss.ruleLibrary;

import java.util.Map;
import java.util.Set;

import org.openmrs.Patient;
import org.openmrs.api.context.Context;
import org.openmrs.logic.LogicContext;
import org.openmrs.logic.impl.LogicCriteriaImpl;
import org.openmrs.logic.LogicCriteria;
import org.openmrs.logic.LogicException;
import org.openmrs.logic.LogicService;
import org.openmrs.logic.Rule;
import org.openmrs.logic.op.Operator;
import org.openmrs.logic.result.Result;
import org.openmrs.logic.result.Result.Datatype;
import org.openmrs.logic.rule.RuleParameterInfo;

public class bmi implements Rule
{
        private LogicService logicService = Context.getLogicService();

        /**
         * *
         * 
         * @see org.openmrs.logic.rule.Rule#getParameterList()
         */
        public Set<RuleParameterInfo> getParameterList()
        {
                return null;
        }

        /**
         * *
         * 
         * @see org.openmrs.logic.rule.Rule#getDependencies()
         */
        public String[] getDependencies()
        {
                return new String[]
                {};
        }

        /**
         * *
         * 
         * @see org.openmrs.logic.rule.Rule#getTTL()
         */
        public int getTTL()
        {
                return 0; // 60 * 30; // 30 minutes
        }

        /**
         * *
         * 
         * @see org.openmrs.logic.rule.Rule#getDatatype(String)
         */
        public Datatype getDefaultDatatype()
        {
                return Datatype.CODED;
        }

        public Result eval(LogicContext context, Integer patientId,
                        Map<String, Object> parameters) throws LogicException
        {
                Result weightResult = null;
                Result heightResult = null;
                String conceptName = "WEIGHT";
                Integer encounterId = (Integer) parameters.get("encounterId");
                
                LogicCriteria conceptCriteria = new LogicCriteriaImpl(
                                conceptName);
                
                LogicCriteria fullCriteria = null;
                
                if(encounterId != null)
                {
                        LogicCriteria encounterCriteria = new 
LogicCriteriaImpl("encounterId").equalTo(encounterId.intValue());
                        
                        fullCriteria = conceptCriteria.and(encounterCriteria);
                }else
                {
                        fullCriteria = conceptCriteria;
                }
                weightResult = context.read(patientId, 
context.getLogicDataSource("obs"),
                                fullCriteria.last());
                
                conceptName = "HEIGHT";
                encounterId = (Integer) parameters.get("encounterId");
                
                conceptCriteria = new LogicCriteriaImpl(
                                conceptName);
                
                fullCriteria = null;
                
                if(encounterId != null)
                {
                        LogicCriteria encounterCriteria = new 
LogicCriteriaImpl("encounterId").equalTo(encounterId.intValue());
                        
                        fullCriteria = conceptCriteria.and(encounterCriteria);
                }else
                {
                        fullCriteria = conceptCriteria;
                }
                heightResult = context.read(patientId, 
context.getLogicDataSource("obs"),
                                fullCriteria.last());

                if(weightResult != null && heightResult != null)
                {
                        Double weightNum = weightResult.toNumber();
                        Double heightNum = heightResult.toNumber();
                        //check for division by zero
                        if(heightNum==null||heightNum==0){
                                return Result.emptyResult();
                        }
                        if(weightNum != null && heightNum != null)
                        {
                                Double bmi = ( weightNum / 
                                                (heightNum * heightNum) ) * 703;
                                return new Result(bmi);
                        }
                }
                
                return Result.emptyResult();
        }
}

Reply via email to