Program: 86791
Project: 86791
Buggy source:
/** 
 * @see org.openmrs.module.reporting.encounter.query.db.EncounterQueryDAO#getEncounters(org.openmrs.Cohort,java.util.List,java.util.List,java.util.Date,java.util.Date,org.openmrs.module.reporting.common.TimeQualifier) Caveat for this implementation: For @param encounterDatetimeOnOrBefore if time is not set (00:00:00), then time is changed to 23:59:59
 */
public List<Encounter> getEncounters(Cohort cohort,List<EncounterType> encounterTypes,List<Form> forms,Date encounterDatetimeOnOrAfter,Date encounterDatetimeOnOrBefore,TimeQualifier whichEncounterQualifier){
  if (cohort != null && cohort.size() == 0) {
    return new ArrayList<Encounter>();
  }
 else {
    Criteria criteria=sessionFactory.getCurrentSession().createCriteria(Encounter.class);
    if (cohort != null)     criteria.add(Restrictions.in("String_Node_Str",cohort.getMemberIds()));
    criteria.add(Restrictions.eq("String_Node_Str",false));
    if (encounterTypes != null && encounterTypes.size() > 0)     criteria.add(Restrictions.in("String_Node_Str",encounterTypes));
    if (forms != null && forms.size() > 0)     criteria.add(Restrictions.in("String_Node_Str",forms));
    if (encounterDatetimeOnOrAfter != null)     criteria.add(Expression.ge("String_Node_Str",encounterDatetimeOnOrAfter));
    if (encounterDatetimeOnOrBefore != null)     criteria.add(Expression.le("String_Node_Str",DateUtil.getEndOfDayIfTimeExcluded(encounterDatetimeOnOrBefore)));
    criteria.addOrder(org.hibernate.criterion.Order.asc("String_Node_Str"));
    if (whichEncounterQualifier != null && whichEncounterQualifier.equals(TimeQualifier.LAST))     criteria.addOrder(org.hibernate.criterion.Order.desc("String_Node_Str"));
 else     criteria.addOrder(org.hibernate.criterion.Order.asc("String_Node_Str"));
    return criteria.list();
  }
}

Fixed version (ground truth):
/** 
 * @see org.openmrs.module.reporting.encounter.query.db.EncounterQueryDAO#getEncounters(org.openmrs.Cohort,java.util.List,java.util.List,java.util.Date,java.util.Date,org.openmrs.module.reporting.common.TimeQualifier) Caveat for this implementation: For @param encounterDatetimeOnOrBefore if time is not set (00:00:00), then time is changed to 23:59:59
 */
public List<Encounter> getEncounters(Cohort cohort,List<EncounterType> encounterTypes,List<Form> forms,Date encounterDatetimeOnOrAfter,Date encounterDatetimeOnOrBefore,TimeQualifier whichEncounterQualifier){
  if (cohort != null && cohort.size() == 0) {
    return new ArrayList<Encounter>();
  }
 else {
    Criteria criteria=sessionFactory.getCurrentSession().createCriteria(Encounter.class);
    if (cohort != null)     criteria.add(Restrictions.in("String_Node_Str",cohort.getMemberIds()));
    criteria.add(Restrictions.eq("String_Node_Str",false));
    if (encounterTypes != null && encounterTypes.size() > 0)     criteria.add(Restrictions.in("String_Node_Str",encounterTypes));
    if (forms != null && forms.size() > 0)     criteria.add(Restrictions.in("String_Node_Str",forms));
    if (encounterDatetimeOnOrAfter != null)     criteria.add(Expression.ge("String_Node_Str",encounterDatetimeOnOrAfter));
    if (encounterDatetimeOnOrBefore != null)     criteria.add(Expression.le("String_Node_Str",DateUtil.getEndOfDayIfTimeExcluded(encounterDatetimeOnOrBefore)));
    criteria.addOrder(org.hibernate.criterion.Order.asc("String_Node_Str"));
    if (whichEncounterQualifier != null && whichEncounterQualifier.equals(TimeQualifier.LAST))     criteria.addOrder(org.hibernate.criterion.Order.desc("String_Node_Str"));
 else     criteria.addOrder(org.hibernate.criterion.Order.asc("String_Node_Str"));
    criteria.createCriteria("String_Node_Str").add(Restrictions.eq("String_Node_Str",false));
    return criteria.list();
  }
}