Example usage for org.hibernate.criterion Restrictions between

List of usage examples for org.hibernate.criterion Restrictions between

Introduction

In this page you can find the example usage for org.hibernate.criterion Restrictions between.

Prototype

public static Criterion between(String propertyName, Object low, Object high) 

Source Link

Document

Apply a "between" constraint to the named property

Usage

From source file:org.openmrs.module.accessmonitor.api.db.hibernate.HibernateVisitAccessDAO.java

public List<VisitServiceAccess> getVisitServiceAccessesByVisitUuid(String visitUuid, Date from, Date to) {
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(VisitServiceAccess.class);
    crit.add(Restrictions.eq("visitUuid", visitUuid));
    if (from != null || to != null) {
        if (from == null) {
            crit.add(Restrictions.le("accessDate", to));
        } else if (to == null) {
            crit.add(Restrictions.ge("accessDate", from));
        } else {/*from   w  w w.  j  ava 2  s. c  o  m*/
            crit.add(Restrictions.between("accessDate", from, to));
        }
    }
    return crit.list();
}

From source file:org.openmrs.module.accessmonitor.api.db.hibernate.HibernateVisitAccessDAO.java

public List<VisitServiceAccess> getVisitServiceAccessesByVoidReason(String voidReason, Date from, Date to) {

    Criteria crit = sessionFactory.getCurrentSession().createCriteria(VisitServiceAccess.class);
    crit.add(Restrictions.eq("voidReason", voidReason));
    if (from != null || to != null) {
        if (from == null) {
            crit.add(Restrictions.le("accessDate", to));
        } else if (to == null) {
            crit.add(Restrictions.ge("accessDate", from));
        } else {/*from  ww w  .  ja va  2s  . c o m*/
            crit.add(Restrictions.between("accessDate", from, to));
        }
    }
    return crit.list();
}

From source file:org.openmrs.module.accessmonitor.api.db.hibernate.HibernateVisitAccessDAO.java

public List<VisitServiceAccess> getVisitServiceAccessesByAccessDate(Date from, Date to) {
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(VisitServiceAccess.class);
    if (from != null || to != null) {
        if (from == null) {
            crit.add(Restrictions.le("accessDate", to));
        } else if (to == null) {
            crit.add(Restrictions.ge("accessDate", from));
        } else {/*from w w w  . j a va 2 s.c  o  m*/
            crit.add(Restrictions.between("accessDate", from, to));
        }
    }
    return crit.list();
}

From source file:org.openmrs.module.accessmonitor.api.db.hibernate.HibernateVisitAccessDAO.java

public List<VisitServiceAccess> getVisitServiceAccessesByVisitStartDate(Date visitStartDate, Date from,
        Date to) {/*  w  w w  .  j a  va  2s  . co m*/
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(VisitServiceAccess.class);
    crit.add(Restrictions.eq("visitStartDate", visitStartDate));
    if (from != null || to != null) {
        if (from == null) {
            crit.add(Restrictions.le("accessDate", to));
        } else if (to == null) {
            crit.add(Restrictions.ge("accessDate", from));
        } else {
            crit.add(Restrictions.between("accessDate", from, to));
        }
    }
    return crit.list();
}

From source file:org.openmrs.module.accessmonitor.api.db.hibernate.HibernateVisitAccessDAO.java

public List<VisitServiceAccess> getVisitServiceAccessesByVisitEndDate(Date visitEndDate, Date from, Date to) {
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(VisitServiceAccess.class);
    crit.add(Restrictions.eq("visitEndDate", visitEndDate));
    if (from != null || to != null) {
        if (from == null) {
            crit.add(Restrictions.le("accessDate", to));
        } else if (to == null) {
            crit.add(Restrictions.ge("accessDate", from));
        } else {/*from w  ww  . ja v a 2 s.c om*/
            crit.add(Restrictions.between("accessDate", from, to));
        }
    }
    return crit.list();
}

From source file:org.openmrs.module.conceptsearch.db.hibernate.HibernateConceptSearchDAO.java

License:Open Source License

/**
 * Method to create the criteria from the ConceptSearch object
 * // ww w.  j  av a2s .  com
 * @param cs ConceptSearch object that contains all criteria
 * @return search criteria
 */
private Criteria createGetConceptsCriteria(ConceptSearch cs) {
    Criteria crit = sessionFactory.getCurrentSession().createCriteria(Concept.class);

    if (!cs.getSearchQuery().isEmpty()) {
        crit.createAlias("names", "names");
        crit.add(Restrictions.like("names.name", "%" + cs.getSearchQuery() + "%"));
    }

    /*      if (CollectionUtils.isNotEmpty(cs.getSearchTermsList())) {
       crit.add(Restrictions.in("description", cs.getSearchTermsList())); //TODO: contains? like?
    }*/

    if (CollectionUtils.isNotEmpty(cs.getDataTypes())) {
        crit.add(Restrictions.in("datatype", cs.getDataTypes()));
    }

    if (CollectionUtils.isNotEmpty(cs.getConceptClasses())) {
        crit.add(Restrictions.in("conceptClass", cs.getConceptClasses()));
    }

    if (cs.getIsSet() != -1) {
        if (cs.getIsSet() == 0) {
            crit.add(Restrictions.eq("set", Boolean.FALSE));
        } else {
            crit.add(Restrictions.eq("set", Boolean.TRUE));
        }
    }

    if ((cs.getDateFrom() != null) && (cs.getDateTo() != null)) {
        crit.add(Restrictions.between("dateCreated", cs.getDateFrom(), cs.getDateTo()));
    } else if (cs.getDateFrom() != null) {
        crit.add(Restrictions.gt("dateCreated", cs.getDateFrom()));
    } else if (cs.getDateTo() != null) {
        crit.add(Restrictions.le("dateCreated", cs.getDateTo()));
    }

    return crit;

}

From source file:org.openmrs.module.dataentrydelay.db.hibernate.DataEntryDAOImpl.java

License:Open Source License

/**
 * @see org.openmrs.module.dataentrydelay.db.DataEntryDAO#getDataEntryByProviderDate(org.openmrs.User,
 *      java.util.Date, java.util.Date, java.lang.Boolean)
 *//*from ww w.j  a  va  2  s  . com*/
@SuppressWarnings("unchecked")
public Collection<Encounter> getDataEntryByProviderDate(User provider, Date startDate, Date endDate) {
    Session session = getSessionFactory().getCurrentSession();
    Criteria query = session.createCriteria(Encounter.class);
    if (provider != null)
        query.add(Restrictions.eq("provider", provider));

    List<Encounter> listOfEncounters = query.add(Restrictions.between("encounterDatetime", startDate, endDate))
            .list();

    return listOfEncounters;
}

From source file:org.openmrs.module.dataentrydelay.db.hibernate.DataEntryDAOImpl.java

License:Open Source License

/**
 * @see org.openmrs.module.dataentrydelay.db.DataEntryDAO#getDataEntryByLocationDate(org.openmrs.Location,
 *      java.util.Date, java.util.Date)//from www  .j  a  v  a 2 s  .c o  m
 */
@SuppressWarnings("unchecked")
public Collection<Encounter> getDataEntryByLocationDate(Location location, Date startdate, Date enddate) {

    Session session = getSessionFactory().getCurrentSession();
    List<Encounter> listOfEncounters = session.createCriteria(Encounter.class)
            .add(Restrictions.eq("location", location))
            .add(Restrictions.between("encounterDatetime", startdate, enddate)).list();

    return listOfEncounters;
}

From source file:org.openmrs.module.dataentrydelay.db.hibernate.DataEntryDAOImpl.java

License:Open Source License

/**
 * @see org.openmrs.module.dataentrydelay.db.DataEntryDAO#getDataEntryStat(org.openmrs.User,
 *      java.util.Date, java.util.Date, org.openmrs.Location)
 *///from w ww .  j a va  2s  .  c o  m
@SuppressWarnings("unchecked")
public Collection<Encounter> getDataEntryStat(User user, Date startdate, Date enddate, Location location) {
    Session session = getSessionFactory().getCurrentSession();

    Criteria query = session.createCriteria(Encounter.class);

    if (user != null)
        query.add(Restrictions.eq("provider", user));
    if (location != null)
        query.add(Restrictions.eq("location", location));
    List<Encounter> listOfEncounters = query.add(Restrictions.between("encounterDatetime", startdate, enddate))
            .list();
    return listOfEncounters;

}

From source file:org.openmrs.module.mohbilling.db.hibernate.HibernateBillingDAO.java

License:Open Source License

@Override
public Object[] getBills(Date startDate, Date endDate, User collector) {

    Criteria crit = sessionFactory.getCurrentSession().createCriteria(BillPayment.class)
            .add(Restrictions.between("createdDate", startDate, endDate));
    //Criteria crit1 = sessionFactory.getCurrentSession().createCriteria(PatientBill.class).add(Restrictions.between("createdDate", startDate, endDate));

    if (collector != null && collector.getUserId() != null) {
        crit.add(Expression.eq("collector", collector));
    }// w  ww. j a v a 2  s.  c  o  m

    List<BillPayment> payments = crit.list();
    List<PatientBill> bills = crit.list();

    Set<PatientBill> patientBillsFullPaids = new HashSet<PatientBill>();
    Double fullReceived = 0.0;
    Double allPartiallypaid = 0.0;

    for (BillPayment pay : payments) {
        //full paid patient bill

        PatientBill pb = pay.getPatientBill();
        if (pb.getStatus().equals("FULLY PAID")) {
            patientBillsFullPaids.add(pay.getPatientBill());

            fullReceived = fullReceived + pay.getAmountPaid().doubleValue();
        }
        if (pb.getStatus().equals("PARTLY PAID")) {
            allPartiallypaid = allPartiallypaid + pay.getAmountPaid().doubleValue();

        }

    }

    //facture object compiled for all facture and set all paid bills at
    //index 0 and received amount .for      
    Object[] factureCompiled = new Object[] { patientBillsFullPaids, fullReceived, allPartiallypaid };

    return factureCompiled;
}