List of usage examples for org.hibernate.criterion Restrictions isNotNull
public static Criterion isNotNull(String propertyName)
From source file:org.openmrs.module.muzima.api.db.hibernate.HibernateCoreDao.java
License:Open Source License
@Override @Transactional(readOnly = true)//from w ww . j a v a 2 s .com @SuppressWarnings("unchecked") public List<Cohort> getCohorts(final String name, final Date syncDate, final int startIndex, final int size) throws DAOException { Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Cohort.class); criteria.add(Expression.ilike("name", name, MatchMode.ANYWHERE)); criteria.addOrder(Order.asc("name")); 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
@Override @Transactional(readOnly = true)//from www. j a v a 2s. com public Number countCohorts(final String name, final Date syncDate) throws DAOException { Criteria criteria = getSessionFactory().getCurrentSession().createCriteria(Cohort.class); criteria.add(Expression.ilike("name", name, MatchMode.ANYWHERE)); criteria.addOrder(Order.asc("name")); 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(); }
From source file:org.openmrs.module.openconceptlab.ImportServiceImpl.java
License:Mozilla Public License
@Override public Import getLastSuccessfulSubscriptionImport() { Criteria updateCriteria = getSession().createCriteria(Import.class); updateCriteria.add(Restrictions.isNull("errorMessage")); updateCriteria.add(Restrictions.isNotNull("oclDateStarted")); updateCriteria.addOrder(Order.desc("importId")); updateCriteria.setMaxResults(1);/*from ww w .j av a 2 s .c om*/ return (Import) updateCriteria.uniqueResult(); }
From source file:org.openmrs.module.openconceptlab.UpdateServiceImpl.java
License:Mozilla Public License
@Override public Update getLastSuccessfulSubscriptionUpdate() { Criteria updateCriteria = getSession().createCriteria(Update.class); updateCriteria.add(Restrictions.isNull("errorMessage")); updateCriteria.add(Restrictions.isNotNull("oclDateStarted")); updateCriteria.addOrder(Order.desc("updateId")); updateCriteria.setMaxResults(1);/* w w w. j av a2s . c om*/ return (Update) updateCriteria.uniqueResult(); }
From source file:org.openmrs.module.openhmis.commons.api.entity.search.BaseObjectTemplateSearch.java
License:Open Source License
protected Criterion createCriterion(String field, Object value, ComparisonType comparisonType) { ComparisonType comparison = comparisonType == null ? ComparisonType.EQUAL : comparisonType; Criterion result;/* w ww . j av a2s. c om*/ switch (comparison) { case EQUAL: result = Restrictions.eq(field, value); break; case NOT_EQUAL: result = Restrictions.ne(field, value); break; case IS_NULL: result = Restrictions.isNull(field); break; case IS_NOT_NULL: result = Restrictions.isNotNull(field); break; default: throw new IllegalArgumentException(); } return result; }
From source file:org.openmrs.module.openhmis.commons.api.entity.search.BaseObjectTemplateSearch.java
License:Open Source License
protected Criterion createCriterion(String field, String value, StringComparisonType comparisonType) { StringComparisonType comparison = comparisonType == null ? StringComparisonType.EQUAL : comparisonType; Criterion result;//from w w w .j a v a 2s. c o m switch (comparison) { case EQUAL: result = Restrictions.eq(field, value); break; case NOT_EQUAL: result = Restrictions.ne(field, value); break; case IS_NULL: result = Restrictions.isNull(field); break; case IS_NOT_NULL: result = Restrictions.isNotNull(field); break; case IS_EMPTY: result = Restrictions.isEmpty(field); break; case IS_NOT_EMPTY: result = Restrictions.isNotEmpty(field); break; case LIKE: result = Restrictions.ilike(field, value); break; default: throw new IllegalArgumentException(); } return result; }
From source file:org.openmrs.module.openhmis.commons.api.entity.search.BaseObjectTemplateSearch.java
License:Open Source License
protected Criterion createCriterion(String field, Date value, DateComparisonType comparisonType) { DateComparisonType comparison = comparisonType == null ? DateComparisonType.EQUAL : comparisonType; Criterion result;/*from w w w . jav a 2 s . c om*/ switch (comparison) { case EQUAL: result = Restrictions.eq(field, value); break; case NOT_EQUAL: result = Restrictions.ne(field, value); break; case IS_NULL: result = Restrictions.isNull(field); break; case IS_NOT_NULL: result = Restrictions.isNotNull(field); break; case GREATER_THAN: result = Restrictions.gt(field, value); break; case GREATER_THAN_EQUAL: result = Restrictions.ge(field, value); break; case LESS_THAN: result = Restrictions.lt(field, value); break; case LESS_THAN_EQUAL: result = Restrictions.le(field, value); break; default: throw new IllegalArgumentException(); } return result; }
From source file:org.openmrs.module.orderextension.api.db.HibernateOrderExtensionDAO.java
License:Open Source License
/** * @see OrderExtensionDAO#getAllOrderSets(boolean) *///from w w w.j av a 2s .c om @Override @SuppressWarnings("unchecked") public List<OrderSet> getNamedOrderSets(String partialName, Concept indication, boolean includeRetired) { Criteria criteria = getCurrentSession().createCriteria(OrderSet.class); criteria.add(Restrictions.isNotNull("name")); if (!includeRetired) { criteria.add(Restrictions.eq("retired", false)); } if (partialName != null) { criteria.add(Restrictions.ilike("name", partialName, MatchMode.ANYWHERE)); } if (indication != null) { criteria.add(Restrictions.eq("indication", indication)); } criteria.addOrder(Order.asc("name")); return criteria.list(); }
From source file:org.openmrs.module.patientportal.api.db.hibernate.HibernatePatientPortalReminderDAO.java
License:Open Source License
@Override public List<PatientPortalReminder> getPatientPortalReminders(Patient pat) { //Query query = sessionFactory.getCurrentSession().createQuery("from LafReminder where allowedUrl = :url "); //query.setParameter("url", url); //List list0 = query.list(); Criteria crit = sessionFactory.getCurrentSession().createCriteria(PatientPortalReminder.class); crit.add(Restrictions.eq("patient", pat)); crit.add(Restrictions.isNull("completeDate")); crit.add(Restrictions.isNotNull("targetDate")); crit.addOrder(Order.asc("targetDate")); @SuppressWarnings("unchecked") List<PatientPortalReminder> list = (List<PatientPortalReminder>) crit.list(); if (list.size() >= 1) return list; else// w w w . ja v a 2 s . c o m return null; }
From source file:org.openmrs.module.patientportal.api.db.hibernate.HibernatePatientPortalReminderDAO.java
License:Open Source License
@Override public List<PatientPortalReminder> getPatientPortalRemindersCompleted(Patient pat) { //Query query = sessionFactory.getCurrentSession().createQuery("from LafReminder where allowedUrl = :url "); //query.setParameter("url", url); //List list0 = query.list(); Criteria crit = sessionFactory.getCurrentSession().createCriteria(PatientPortalReminder.class); crit.add(Restrictions.eq("patient", pat)); crit.add(Restrictions.isNotNull("completeDate")); crit.add(Restrictions.isNull("targetDate")); crit.addOrder(Order.asc("completeDate")); @SuppressWarnings("unchecked") List<PatientPortalReminder> list = (List<PatientPortalReminder>) crit.list(); if (list.size() >= 1) return list; else//from ww w. j a v a2 s . co m return null; }