List of usage examples for org.hibernate.criterion Restrictions gt
public static SimpleExpression gt(String propertyName, Object value)
From source file:org.openmrs.module.reportingcompatibility.service.db.HibernateReportingCompatibilityDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public Map<Integer, List<DrugOrder>> getCurrentDrugOrders(Cohort patients, List<Concept> drugConcepts) throws DAOException { Map<Integer, List<DrugOrder>> ret = new HashMap<Integer, List<DrugOrder>>(); Date now = new Date(); Criteria criteria = sessionFactory.getCurrentSession().createCriteria(DrugOrder.class); criteria.setFetchMode("patient", FetchMode.JOIN); criteria.setCacheMode(CacheMode.IGNORE); // this "where clause" is only necessary if patients were passed in if (patients != null) criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); //criteria.add(Restrictions.in("encounter.patient.personId", ids)); //criteria.createCriteria("encounter").add(Restrictions.in("patient.personId", ids)); if (drugConcepts != null) criteria.add(Restrictions.in("concept", drugConcepts)); criteria.add(Restrictions.eq("voided", false)); criteria.add(Restrictions.le("startDate", now)); criteria.add(Restrictions.or(/* ww w .ja v a2 s . c om*/ Restrictions.and(Restrictions.eq("discontinued", false), Restrictions.or(Restrictions.isNull("autoExpireDate"), Restrictions.gt("autoExpireDate", now))), Restrictions.and(Restrictions.eq("discontinued", true), Restrictions.gt("discontinuedDate", now)))); criteria.addOrder(org.hibernate.criterion.Order.asc("startDate")); log.debug("criteria: " + criteria); List<DrugOrder> temp = criteria.list(); for (DrugOrder regimen : temp) { Integer ptId = regimen.getPatient().getPatientId(); List<DrugOrder> list = ret.get(ptId); if (list == null) { list = new ArrayList<DrugOrder>(); ret.put(ptId, list); } list.add(regimen); } return ret; }
From source file:org.openmrs.module.sync.api.db.hibernate.HibernateSyncDAO.java
License:Open Source License
/** * @see org.openmrs.module.sync.api.SyncService#getNextRecord(SyncRecord) *///from w w w. ja va2 s . c o m public SyncRecord getNextRecord(SyncRecord record) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SyncRecord.class); criteria.setProjection(Projections.min("recordId")); criteria.add(Restrictions.gt("recordId", record.getRecordId())); Object nextRecordId = criteria.uniqueResult(); if (nextRecordId == null) { return null; } return getSyncRecord((Integer) nextRecordId); }
From source file:org.openmrs.module.sync.api.db.hibernate.HibernateSyncDAO.java
License:Open Source License
/** * @see org.openmrs.module.sync.api.db.SyncDAO#getSyncRecords(java.util.Date, java.util.Date, * Integer, Integer)//w ww . j a v a2 s.c o m */ @SuppressWarnings("unchecked") public List<SyncRecord> getSyncRecords(Date from, Date to, Integer firstRecordId, Integer numberToReturn, boolean oldestToNewest) throws DAOException { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SyncRecord.class); if (from != null) criteria.add(Restrictions.gt("timestamp", from)); // greater than if (to != null) criteria.add(Restrictions.le("timestamp", to)); // less-than or equal if (numberToReturn != null) criteria.setMaxResults(numberToReturn); if (oldestToNewest) { if (firstRecordId != null) criteria.add(Restrictions.ge("recordId", firstRecordId)); criteria.addOrder(Order.asc("timestamp")); criteria.addOrder(Order.asc("recordId")); } else { if (firstRecordId != null) criteria.add(Restrictions.le("recordId", firstRecordId)); criteria.addOrder(Order.desc("timestamp")); criteria.addOrder(Order.desc("recordId")); } return criteria.list(); }
From source file:org.openmrs.module.sync.api.db.hibernate.HibernateSyncDAO.java
License:Open Source License
public Long getCountOfSyncRecords(RemoteServer server, Date from, Date to, SyncRecordState... states) { Criteria criteria = sessionFactory.getCurrentSession().createCriteria(SyncRecord.class); criteria.setProjection(Projections.rowCount()); if (from != null) criteria.add(Restrictions.gt("timestamp", from)); // greater than if (to != null) criteria.add(Restrictions.le("timestamp", to)); // less-than or equal // only check for matching states if any were passed in if (states != null && states.length > 0) criteria.add(Restrictions.in("state", states)); if (server != null) { criteria.createCriteria("serverRecords", "sr"); criteria.add(Restrictions.in("sr.state", states)); criteria.add(Restrictions.eq("sr.syncServer", server)); }//from w w w . ja v a 2 s.co m return (Long) criteria.uniqueResult(); }
From source file:org.openmrs.notification.db.hibernate.HibernateAlertDAO.java
License:Mozilla Public License
/** * @see org.openmrs.notification.AlertService#getAllAlerts(boolean) *///w w w . j av a 2 s . c o m @SuppressWarnings("unchecked") public List<Alert> getAllAlerts(boolean includeExpired) throws DAOException { Criteria crit = sessionFactory.getCurrentSession().createCriteria(Alert.class); // exclude the expired alerts unless requested if (!includeExpired) { crit.add(Restrictions.or(Restrictions.isNull("dateToExpire"), Restrictions.gt("dateToExpire", new Date()))); } return crit.list(); }
From source file:org.openmrs.notification.db.hibernate.HibernateAlertDAO.java
License:Mozilla Public License
/** * @see org.openmrs.notification.db.AlertDAO#getAlerts(org.openmrs.User, boolean, boolean) *//*from w ww . j ava 2 s . c o m*/ @SuppressWarnings("unchecked") public List<Alert> getAlerts(User user, boolean includeRead, boolean includeExpired) throws DAOException { log.debug("Getting alerts for user " + user + " read? " + includeRead + " expired? " + includeExpired); Criteria crit = sessionFactory.getCurrentSession().createCriteria(Alert.class, "alert"); if (user != null && user.getUserId() != null) { crit.createCriteria("recipients", "recipient"); crit.add(Restrictions.eq("recipient.recipient", user)); } else { // getting here means we passed in no user or a blank user. // a null recipient column means get stuff for the anonymous user //crit.add(Expression.isNull("recipient.recipient")); // returning an empty list for now because the above throws an error. // we may need to remodel how recipients are handled to get anonymous users alerts return Collections.emptyList(); } // exclude the expired alerts unless requested if (!includeExpired) { crit.add(Restrictions.or(Restrictions.isNull("dateToExpire"), Restrictions.gt("dateToExpire", new Date()))); } // exclude the read alerts unless requested if (!includeRead && user.getUserId() != null) { crit.add(Restrictions.eq("alertRead", false)); crit.add(Restrictions.eq("recipient.alertRead", false)); } crit.addOrder(Order.desc("dateChanged")); return crit.list(); }
From source file:org.opennms.dashboard.server.DefaultSurveillanceService.java
License:Open Source License
/** {@inheritDoc} */ @Override// w ww . j av a 2s . co m public Notification[] getNotificationsForSet(SurveillanceSet set) { List<Notification> notifications = new ArrayList<Notification>(); Date fifteenMinutesAgo = new Date(System.currentTimeMillis() - (15 * 60 * 1000)); Date oneWeekAgo = new Date(System.currentTimeMillis() - (7 * 24 * 60 * 60 * 1000)); notifications.addAll( getNotificationsWithCriterion(set, "Critical", Restrictions.isNull("notification.respondTime"), Restrictions.le("notification.pageTime", fifteenMinutesAgo))); notifications .addAll(getNotificationsWithCriterion(set, "Minor", Restrictions.isNull("notification.respondTime"), Restrictions.gt("notification.pageTime", fifteenMinutesAgo))); notifications.addAll( getNotificationsWithCriterion(set, "Normal", Restrictions.isNotNull("notification.respondTime"), Restrictions.gt("notification.pageTime", oneWeekAgo))); return notifications.toArray(new Notification[notifications.size()]); }
From source file:org.opennms.netmgt.ackd.readers.HypericAckProcessor.java
License:Open Source License
/** * <p>fetchUnclearedHypericAlarms</p> * * @return a {@link java.util.List} object. *///www.ja v a 2 s.co m public List<OnmsAlarm> fetchUnclearedHypericAlarms() { // Query for existing, unacknowledged alarms in OpenNMS that were generated based on Hyperic alerts OnmsCriteria criteria = new OnmsCriteria(OnmsAlarm.class, "alarm"); // criteria.add(Restrictions.isNull("alarmAckUser")); // Restrict to Hyperic alerts criteria.add(Restrictions.eq("uei", "uei.opennms.org/external/hyperic/alert")); // Only consider alarms that are above severity NORMAL // {@see org.opennms.netmgt.model.OnmsSeverity} criteria.add(Restrictions.gt("severity", OnmsSeverity.NORMAL)); // TODO Figure out how to query by parameters (maybe necessary) // Query list of outstanding alerts with remote platform identifiers return m_alarmDao.findMatching(criteria); }
From source file:org.opennms.web.filter.GreaterThanFilter.java
License:Open Source License
/** {@inheritDoc} */ @Override public Criterion getCriterion() { return Restrictions.gt(getPropertyName(), getValue()); }
From source file:org.opennms.web.outage.filter.RecentOutagesFilter.java
License:Open Source License
/** {@inheritDoc} */ @Override//from w w w. ja v a2 s.c om public Criterion getCriterion() { return Restrictions.or(Restrictions.gt(getPropertyName(), getValue()), Restrictions.isNull(getPropertyName())); }