Example usage for org.hibernate.criterion Restrictions isNotNull

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

Introduction

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

Prototype

public static Criterion isNotNull(String propertyName) 

Source Link

Document

Apply an "is not null" constraint to the named property

Usage

From source file:org.openmrs.module.clinicalsummary.db.hibernate.HibernateIndexDAO.java

License:Open Source License

/**
 * @see IndexDAO#getIndexCohort(org.openmrs.Location, org.openmrs.module.clinicalsummary.Summary, java.util.Date, java.util.Date)
 *///from  w w  w .j ava2 s  .  c  o m
@Override
@SuppressWarnings("unchecked")
public Cohort getIndexCohort(final Location location, final Summary summary, final Date startVisitDate,
        final Date endVisitDate) throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Index.class);
    criteria.createAlias("patient", "patient");
    criteria.createAlias("patient.identifiers", "identifier");
    criteria.add(Restrictions.eq("location", location));

    criteria.add(Restrictions.eq("patient.voided", Boolean.FALSE));
    criteria.add(Restrictions.isNotNull("identifier.identifier"));

    if (summary != null)
        criteria.add(Restrictions.eq("summary", summary));

    if (startVisitDate != null)
        criteria.add(Restrictions.ge("returnDate", startVisitDate));

    if (endVisitDate != null)
        criteria.add(Restrictions.le("returnDate", endVisitDate));

    criteria.addOrder(Order.asc("returnDate"));
    criteria.addOrder(Order.asc("identifier.identifier"));
    criteria.setProjection(Projections.property("patient.patientId"));

    Cohort cohort = new Cohort();
    cohort.setMemberIds(new LinkedHashSet<Integer>(criteria.list()));
    return cohort;
}

From source file:org.openmrs.module.clinicalsummary.db.hibernate.HibernateReminderDAO.java

License:Open Source License

/**
 * @see ReminderDAO#aggregateReminders(java.util.Map, java.util.Collection, java.util.Date, java.util.Date)
 *///from   w ww. ja v a2s .c  o  m
@Override
@SuppressWarnings("unchecked")
public List<Object[]> aggregateReminders(final Map<String, Collection<OpenmrsObject>> restrictions,
        final Collection<String> groupingProperties, final Date reminderStart, final Date reminderEnd)
        throws DAOException {

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Reminder.class);

    if (MapUtils.isNotEmpty(restrictions)) {
        Reminder reminder = new Reminder();
        for (String property : restrictions.keySet()) {
            Collection<OpenmrsObject> objects = restrictions.get(property);
            if (CollectionUtils.isNotEmpty(objects) && PropertyUtils.isReadable(reminder, property))
                criteria.add(Restrictions.in(property, objects));
        }
    }

    if (reminderStart != null)
        criteria.add(Restrictions.ge("reminderDatetime", reminderStart));

    if (reminderEnd != null)
        criteria.add(Restrictions.le("reminderDatetime", reminderEnd));

    ProjectionList projectionList = Projections.projectionList();
    for (String groupingProperty : groupingProperties) {
        // group by the property and order by the same property desc and the property must not null
        criteria.add(Restrictions.isNotNull(groupingProperty));
        projectionList.add(Projections.groupProperty(groupingProperty));
        criteria.addOrder(Order.asc(groupingProperty));
    }
    // add the row count projection to the projection list
    projectionList.add(Projections.rowCount());
    criteria.setProjection(projectionList);

    return criteria.list();
}

From source file:org.openmrs.module.clinicalsummary.db.hibernate.HibernateUtilDAO.java

License:Open Source License

/**
 * @see UtilDAO#getOrderedObs(java.util.Map, java.util.Date, java.util.Date)
 *///ww w. ja  v  a 2s . c o m
@Override
@SuppressWarnings("unchecked")
public List<Object[]> aggregateOrderedObs(final Map<String, Collection<OpenmrsObject>> restrictions,
        final Collection<String> groupingProperties, final StatusType statusType, final Date startTime,
        final Date endTime) throws DAOException {

    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(OrderedObs.class);

    // hack to prevent results for tests ordered concept when grouping results on concept
    if (groupingProperties.contains("concept"))
        criteria.add(Restrictions
                .not(Restrictions.eq("concept", CacheUtils.getConcept(EvaluableNameConstants.TESTS_ORDERED))));

    if (MapUtils.isNotEmpty(restrictions)) {
        OrderedObs orderedObs = new OrderedObs();
        for (String property : restrictions.keySet()) {
            Collection<OpenmrsObject> objects = restrictions.get(property);
            if (CollectionUtils.isNotEmpty(objects) && PropertyUtils.isReadable(orderedObs, property))
                criteria.add(Restrictions.in(property, objects));
        }
    }

    if (statusType != null)
        criteria.add(Restrictions.eq("status", statusType));

    if (startTime != null)
        criteria.add(Restrictions.ge("orderedDatetime", startTime));

    if (endTime != null)
        criteria.add(Restrictions.le("orderedDatetime", endTime));

    ProjectionList projectionList = Projections.projectionList();
    for (String groupingProperty : groupingProperties) {
        // group by the property and order by the same property desc and the property must not null
        criteria.add(Restrictions.isNotNull(groupingProperty));
        projectionList.add(Projections.groupProperty(groupingProperty));
        criteria.addOrder(Order.asc(groupingProperty));
    }
    // add the row count projection to the projection list
    projectionList.add(Projections.rowCount());
    criteria.setProjection(projectionList);

    return criteria.list();
}

From source file:org.openmrs.module.dms.db.hibernate.HibernateDmsDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<DmsOpdUnit> getDmsOpdActivatedList() throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DmsOpdUnit.class);
    criteria.add(Restrictions.isNotNull("unitActiveDate"));
    return criteria.list();
}

From source file:org.openmrs.module.dms.db.hibernate.HibernateDmsDAO.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<DmsOpdUnit> getDmsOpdDeActivatedList() throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DmsOpdUnit.class);
    criteria.add(Restrictions.isNotNull("unitDeactiveDate"));
    return criteria.list();
}

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

License:Open Source License

public List<IndoorPatientServiceBill> getSelectedCategory(Encounter encounter, Patient patient)
        throws DAOException {
    Criteria criteria = sessionFactory.getCurrentSession().createCriteria(IndoorPatientServiceBill.class);
    criteria.add(Restrictions.eq("encounter", encounter));
    criteria.add(Restrictions.eq("patient", patient));
    criteria.add(Restrictions.isNotNull("selectedCategory"));
    return criteria.list();
}

From source file:org.openmrs.module.muzima.api.db.hibernate.HibernateCoreDao.java

License:Open Source License

/**
 * {@inheritDoc}/*from w w w.  j av  a2 s  .c om*/
 *
 * @see CoreDao#getObservations(java.util.List, java.util.List, Date, int, int)
 */
@Override
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public List<Obs> getObservations(final List<String> patientUuids, final List<String> conceptUuids,
        final Date syncDate, final int startIndex, final int size) throws DAOException {
    Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Obs.class);
    criteria.createAlias("person", "person");
    criteria.add(Restrictions.in("person.uuid", patientUuids));
    criteria.createAlias("concept", "concept");
    criteria.add(Restrictions.in("concept.uuid", conceptUuids));
    if (syncDate != null) {
        criteria.add(
                Restrictions.or(
                        Restrictions.and(
                                Restrictions.and(Restrictions.isNotNull("dateCreated"),
                                        Restrictions.ge("dateCreated", syncDate)),
                                Restrictions.isNull("dateVoided")),
                        Restrictions.and(
                                Restrictions.and(Restrictions.isNotNull("dateVoided"),
                                        Restrictions.ge("dateVoided", syncDate)),
                                Restrictions.isNotNull("dateCreated"))));
    }
    criteria.add(Restrictions.eq("voided", false));

    criteria.setMaxResults(size);
    criteria.setFirstResult(startIndex);
    return criteria.list();
}

From source file:org.openmrs.module.muzima.api.db.hibernate.HibernateCoreDao.java

License:Open Source License

/**
 * {@inheritDoc}/*from  w  w  w.ja v  a  2  s .c om*/
 *
 * @see CoreDao#countObservations(java.util.List, java.util.List, Date)
 */
@Override
@Transactional(readOnly = true)
public Number countObservations(final List<String> patientUuids, final List<String> conceptUuids,
        final Date syncDate) throws DAOException {
    Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Obs.class);
    criteria.createAlias("person", "person");
    criteria.add(Restrictions.in("person.uuid", patientUuids));
    criteria.createAlias("concept", "concept");
    criteria.add(Restrictions.in("concept.uuid", conceptUuids));
    if (syncDate != null) {
        criteria.add(
                Restrictions.or(
                        Restrictions.and(
                                Restrictions.and(Restrictions.isNotNull("dateCreated"),
                                        Restrictions.ge("dateCreated", syncDate)),
                                Restrictions.isNull("dateVoided")),
                        Restrictions.and(
                                Restrictions.and(Restrictions.isNotNull("dateVoided"),
                                        Restrictions.ge("dateVoided", syncDate)),
                                Restrictions.isNotNull("dateCreated"))));
    }
    criteria.add(Restrictions.eq("voided", false));

    criteria.setProjection(Projections.rowCount());
    return (Number) criteria.uniqueResult();
}

From source file:org.openmrs.module.muzima.api.db.hibernate.HibernateCoreDao.java

License:Open Source License

/**
 * {@inheritDoc}//from w  w  w .  j  a  v a  2  s  .c  o  m
 *
 * @see CoreDao#getEncounters(java.util.List, Date, int, int)
 */
@Override
@Transactional(readOnly = true)
@SuppressWarnings("unchecked")
public List<Encounter> getEncounters(final List<String> patientUuids, final Date syncDate, final int startIndex,
        final int size) throws DAOException {
    Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Encounter.class);
    criteria.createAlias("patient", "patient");
    criteria.add(Restrictions.in("patient.uuid", patientUuids));
    if (syncDate != null) {
        criteria.add(Restrictions.or(
                Restrictions.or(
                        Restrictions.and(
                                Restrictions.and(Restrictions.isNotNull("dateCreated"),
                                        Restrictions.ge("dateCreated", syncDate)),
                                Restrictions.and(Restrictions.isNull("dateChanged"),
                                        Restrictions.isNull("dateVoided"))),
                        Restrictions.and(
                                Restrictions.and(Restrictions.isNotNull("dateChanged"),
                                        Restrictions.ge("dateChanged", syncDate)),
                                Restrictions.and(Restrictions.isNotNull("dateCreated"),
                                        Restrictions.isNull("dateVoided")))),
                Restrictions.and(
                        Restrictions.and(Restrictions.isNotNull("dateVoided"),
                                Restrictions.ge("dateVoided", syncDate)),
                        Restrictions.and(Restrictions.isNotNull("dateCreated"),
                                Restrictions.isNotNull("dateChanged")))));
    }
    criteria.add(Restrictions.eq("voided", false));

    criteria.setMaxResults(size);
    criteria.setFirstResult(startIndex);
    return criteria.list();
}

From source file:org.openmrs.module.muzima.api.db.hibernate.HibernateCoreDao.java

License:Open Source License

/**
 * {@inheritDoc}/*www . j a  v a 2s.  c  o  m*/
 *
 * @see CoreDao#countEncounters(java.util.List, Date)
 */
@Override
@Transactional(readOnly = true)
public Number countEncounters(final List<String> patientUuids, final Date syncDate) throws DAOException {
    Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Encounter.class);
    criteria.createAlias("patient", "patient");
    criteria.add(Restrictions.in("patient.uuid", patientUuids));
    if (syncDate != null) {
        criteria.add(Restrictions.or(
                Restrictions.or(
                        Restrictions.and(
                                Restrictions.and(Restrictions.isNotNull("dateCreated"),
                                        Restrictions.ge("dateCreated", syncDate)),
                                Restrictions.and(Restrictions.isNull("dateChanged"),
                                        Restrictions.isNull("dateVoided"))),
                        Restrictions.and(
                                Restrictions.and(Restrictions.isNotNull("dateChanged"),
                                        Restrictions.ge("dateChanged", syncDate)),
                                Restrictions.and(Restrictions.isNotNull("dateCreated"),
                                        Restrictions.isNull("dateVoided")))),
                Restrictions.and(
                        Restrictions.and(Restrictions.isNotNull("dateVoided"),
                                Restrictions.ge("dateVoided", syncDate)),
                        Restrictions.and(Restrictions.isNotNull("dateCreated"),
                                Restrictions.isNotNull("dateChanged")))));
    }
    criteria.add(Restrictions.eq("voided", false));

    criteria.setProjection(Projections.rowCount());
    return (Number) criteria.uniqueResult();
}