Example usage for org.hibernate.criterion Restrictions lt

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

Introduction

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

Prototype

public static SimpleExpression lt(String propertyName, Object value) 

Source Link

Document

Apply a "less than" constraint to the named property

Usage

From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernateLabDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<LabTest> getLatestLabTestByDate(Date today, Date nextDay, Lab lab) throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(LabTest.class);
    criteria.add(Restrictions.eq("lab", lab));
    criteria.add(Restrictions.ge("acceptDate", new java.sql.Date(today.getTime())));
    criteria.add(Restrictions.lt("acceptDate", new java.sql.Date(nextDay.getTime())));
    return criteria.list();
}

From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernatePatientQueueDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<OpdPatientQueue> getAllPatientInQueue() throws DAOException {
    //for sure everything always get less than one date
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(OpdPatientQueue.class,
            "opdPatientQueue");
    String date = formatterExt.format(new Date());
    String startFromDate = date + " 00:00:00";
    try {//from   w  w  w  . j  a va2  s  . c om
        criteria.add(Restrictions.lt("opdPatientQueue.createdOn", formatter.parse(startFromDate)));
    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("Error convert date: " + e.toString());
        e.printStackTrace();
    }
    return criteria.list();
}

From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernatePatientQueueDAO.java

License:Open Source License

public List<Obs> getAllDiagnosis(Integer personId) throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Obs.class, "obs");
    String toDdate = formatter1.format(new Date());

    Date date1 = new Date();

    Date oldDate = new Date(date1.getTime() - TimeUnit.HOURS.toMillis(24));
    String fromDate = formatter1.format(oldDate);

    try {//from   w ww.ja  v a  2s  . c o m
        criteria.add(Restrictions.lt("obs.obsDatetime", formatter1.parse(toDdate)));
        criteria.add(Restrictions.gt("obs.obsDatetime", formatter1.parse(fromDate)));

    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("Error convert date: " + e.toString());
        e.printStackTrace();
    }

    criteria.add(Restrictions.eq("obs.personId", personId));
    criteria.add(
            Restrictions.eq("obs.concept", Context.getConceptService().getConcept("PROVISIONAL DIAGNOSIS")));

    return criteria.list();
}

From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernatePatientQueueDAO.java

License:Open Source License

public List<Obs> getAllSymptom(Integer personId) throws DAOException {

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Obs.class, "obs");
    String toDdate = formatter1.format(new Date());

    Date date1 = new Date();

    Date oldDate = new Date(date1.getTime() - TimeUnit.HOURS.toMillis(24));
    String fromDate = formatter1.format(oldDate);

    try {// w w  w .java 2 s . c om
        criteria.add(Restrictions.lt("obs.obsDatetime", formatter1.parse(toDdate)));
        criteria.add(Restrictions.gt("obs.obsDatetime", formatter1.parse(fromDate)));

    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("Error convert date: " + e.toString());
        e.printStackTrace();
    }

    criteria.add(Restrictions.eq("obs.personId", personId));
    criteria.add(Restrictions.eq("obs.concept", Context.getConceptService().getConcept("SYMPTOM")));

    return criteria.list();
}

From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernatePatientQueueDAO.java

License:Open Source License

public List<Obs> getAllExamination(Integer personId) throws DAOException {
    // TODO Auto-generated method stub
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Obs.class, "obs");
    String toDdate = formatter1.format(new Date());

    Date date1 = new Date();

    Date oldDate = new Date(date1.getTime() - TimeUnit.HOURS.toMillis(24));
    String fromDate = formatter1.format(oldDate);

    try {//from w  ww  .j  a v  a2s. co m
        criteria.add(Restrictions.lt("obs.obsDatetime", formatter1.parse(toDdate)));
        criteria.add(Restrictions.gt("obs.obsDatetime", formatter1.parse(fromDate)));

    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("Error convert date: " + e.toString());
        e.printStackTrace();
    }

    criteria.add(Restrictions.eq("obs.personId", personId));
    criteria.add(Restrictions.eq("obs.concept", Context.getConceptService().getConcept("EXAMINATION")));

    return criteria.list();
}

From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernatePatientQueueDAO.java

License:Open Source License

public List<Obs> getAllUnderlinedCondition(Integer personId) throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Obs.class, "obs");
    String toDdate = formatter1.format(new Date());

    Date date1 = new Date();

    Date oldDate = new Date(date1.getTime() - TimeUnit.HOURS.toMillis(24));
    String fromDate = formatter1.format(oldDate);

    try {//from w w w  .ja va 2s . co m
        criteria.add(Restrictions.lt("obs.obsDatetime", formatter1.parse(toDdate)));
        criteria.add(Restrictions.gt("obs.obsDatetime", formatter1.parse(fromDate)));

    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("Error convert date: " + e.toString());
        e.printStackTrace();
    }

    criteria.add(Restrictions.eq("obs.personId", personId));
    criteria.add(
            Restrictions.eq("obs.concept", Context.getConceptService().getConcept("UNDERLINED CONDITION")));

    return criteria.list();
}

From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernatePatientQueueDAO.java

License:Open Source License

public List<Obs> getAllSigns(Integer personId) throws DAOException {

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Obs.class, "obs");
    String toDdate = formatter1.format(new Date());

    Date date1 = new Date();

    Date oldDate = new Date(date1.getTime() - TimeUnit.HOURS.toMillis(24));
    String fromDate = formatter1.format(oldDate);

    try {/*  w  ww. ja v  a  2  s .  c  om*/
        criteria.add(Restrictions.lt("obs.obsDatetime", formatter1.parse(toDdate)));
        criteria.add(Restrictions.gt("obs.obsDatetime", formatter1.parse(fromDate)));

    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("Error convert date: " + e.toString());
        e.printStackTrace();
    }

    criteria.add(Restrictions.eq("obs.personId", personId));
    criteria.add(Restrictions.eq("obs.concept", Context.getConceptService().getConcept("SIGNS")));

    return criteria.list();
}

From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernatePatientQueueDAO.java

License:Open Source License

public List<Obs> getAllDifferentialDiagnosis(Integer personId) throws DAOException {

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Obs.class, "obs");
    String toDdate = formatter1.format(new Date());

    Date date1 = new Date();

    Date oldDate = new Date(date1.getTime() - TimeUnit.HOURS.toMillis(24));
    String fromDate = formatter1.format(oldDate);

    try {//from  ww w .j av  a  2 s .c o m
        criteria.add(Restrictions.lt("obs.obsDatetime", formatter1.parse(toDdate)));
        criteria.add(Restrictions.gt("obs.obsDatetime", formatter1.parse(fromDate)));

    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("Error convert date: " + e.toString());
        e.printStackTrace();
    }

    criteria.add(Restrictions.eq("obs.personId", personId));
    criteria.add(
            Restrictions.eq("obs.concept", Context.getConceptService().getConcept("DIFFERENTIAL DIAGNOSIS")));

    return criteria.list();
}

From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernatePatientQueueDAO.java

License:Open Source License

public List<Obs> getAllWorkingDiagnosis(Integer personId) throws DAOException {

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Obs.class, "obs");
    String toDdate = formatter1.format(new Date());

    Date date1 = new Date();

    Date oldDate = new Date(date1.getTime() - TimeUnit.HOURS.toMillis(24));
    String fromDate = formatter1.format(oldDate);

    try {/*  w  w w  .  j  a va  2  s.c  o m*/
        criteria.add(Restrictions.lt("obs.obsDatetime", formatter1.parse(toDdate)));
        criteria.add(Restrictions.gt("obs.obsDatetime", formatter1.parse(fromDate)));

    } catch (Exception e) {
        // TODO: handle exception
        System.out.println("Error convert date: " + e.toString());
        e.printStackTrace();
    }

    criteria.add(Restrictions.eq("obs.personId", personId));
    criteria.add(Restrictions.eq("obs.concept", Context.getConceptService().getConcept("WORKING DIAGNOSIS")));

    return criteria.list();
}

From source file:org.openmrs.module.inventory.db.hibernate.HibernateInventoryDAO.java

License:Open Source License

public List<InventoryStoreDrugTransactionDetail> listViewStockBalance(Integer storeId, Integer categoryId,
        String drugName, String fromDate, String toDate, boolean isExpiry, int min, int max)
        throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession()
            .createCriteria(InventoryStoreDrugTransactionDetail.class, "transactionDetail")
            .createAlias("transactionDetail.transaction", "transaction")
            .createAlias("transactionDetail.drug", "drugAlias")
            .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.groupProperty("drug")).add(Projections.groupProperty("formulation"))
            .add(Projections.sum("currentQuantity")).add(Projections.sum("quantity"))
            .add(Projections.sum("issueQuantity"));
    criteria.add(Restrictions.eq("transaction.store.id", storeId));
    if (categoryId != null) {
        criteria.add(Restrictions.eq("drugAlias.category.id", categoryId));
    }//from w ww. j a  v  a  2  s .c  om
    if (!StringUtils.isBlank(drugName)) {
        criteria.add(Restrictions.like("drugAlias.name", "%" + drugName + "%"));
    }
    if (!StringUtils.isBlank(fromDate) && StringUtils.isBlank(toDate)) {
        String startFromDate = fromDate + " 00:00:00";
        String endFromDate = fromDate + " 23:59:59";
        try {
            criteria.add(Restrictions.and(
                    Restrictions.ge("transactionDetail.createdOn", formatter.parse(startFromDate)),
                    Restrictions.le("transactionDetail.createdOn", formatter.parse(endFromDate))));
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("listSubStoreIndent>>Error convert date: " + e.toString());
            e.printStackTrace();
        }
    } else if (StringUtils.isBlank(fromDate) && !StringUtils.isBlank(toDate)) {
        String startToDate = toDate + " 00:00:00";
        String endToDate = toDate + " 23:59:59";
        try {
            criteria.add(Restrictions.and(
                    Restrictions.ge("transactionDetail.createdOn", formatter.parse(startToDate)),
                    Restrictions.le("transactionDetail.createdOn", formatter.parse(endToDate))));
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("listSubStoreIndent>>Error convert date: " + e.toString());
            e.printStackTrace();
        }
    } else if (!StringUtils.isBlank(fromDate) && !StringUtils.isBlank(toDate)) {
        String startToDate = fromDate + " 00:00:00";
        String endToDate = toDate + " 23:59:59";
        try {
            criteria.add(Restrictions.and(
                    Restrictions.ge("transactionDetail.createdOn", formatter.parse(startToDate)),
                    Restrictions.le("transactionDetail.createdOn", formatter.parse(endToDate))));
        } catch (Exception e) {
            // TODO: handle exception
            System.out.println("listInventorySubStoreIndent>>Error convert date: " + e.toString());
            e.printStackTrace();
        }
    }
    if (isExpiry) {
        criteria.add(Restrictions.lt("transactionDetail.dateExpiry", new Date()));
    } else {
        criteria.add(Restrictions.ge("transactionDetail.dateExpiry", new Date()));
    }

    /*
     * Sagar Bele : 13-08-2012 Bug #330 ( [INVENTORY]-error in Current
     * quantity of pharmacy )
     */
    criteria.add(Restrictions.ge("transactionDetail.currentQuantity", 0));

    criteria.setProjection(proList);
    if (max > 0) {
        criteria.setFirstResult(min).setMaxResults(max);
    }
    List<Object> lst = criteria.list();
    if (lst == null || lst.size() == 0) {
        return null;
    }
    List<InventoryStoreDrugTransactionDetail> list = new ArrayList<InventoryStoreDrugTransactionDetail>();
    for (int i = 0; i < lst.size(); i++) {
        Object[] row = (Object[]) lst.get(i);
        InventoryStoreDrugTransactionDetail tDetail = new InventoryStoreDrugTransactionDetail();
        tDetail.setDrug((InventoryDrug) row[0]);
        tDetail.setFormulation((InventoryDrugFormulation) row[1]);
        tDetail.setCurrentQuantity((Integer) row[2]);
        tDetail.setQuantity((Integer) row[3]);
        tDetail.setIssueQuantity((Integer) row[4]);
        list.add(tDetail);
    }

    return list;
}