List of usage examples for org.hibernate.criterion ProjectionList add
public ProjectionList add(Projection projection)
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) *///from ww w . j ava 2 s . 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.DeIdentifiedPatientDataExportModule.api.db.hibernate.HibernateDeIdentifiedExportDAO.java
License:Open Source License
@Override public java.util.List<String> getConceptByCategory(String category) { Criteria c = sessionFactory.getCurrentSession().createCriteria(ExportEntity.class); ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("elementId")); c.setProjection(projList);/*w w w . j a va2 s. c o m*/ c.add(Restrictions.eq("category", category)).list(); List<String> l = c.list(); return l; }
From source file:org.openmrs.module.DeIdentifiedPatientDataExportModule.api.db.hibernate.HibernateDeIdentifiedExportDAO.java
License:Open Source License
public List<String> getProfileNameById(Integer id) { Criteria c = sessionFactory.getCurrentSession().createCriteria(ProfileName.class); ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("profileName")); c.setProjection(projList);//from www . j a va2 s . c o m c.add(Restrictions.eq("pid", id)).list(); List<String> l = c.list(); return l; }
From source file:org.openmrs.module.DeIdentifiedPatientDataExportModule.api.db.hibernate.HibernateDeIdentifiedExportDAO.java
License:Open Source License
public List<String> getConceptsByCategoryByPid(String category, int id) { Criteria c = sessionFactory.getCurrentSession().createCriteria(ExportEntity.class); ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("elementId")); c.setProjection(projList);/* ww w. j av a 2 s . c o m*/ c.add(Restrictions.eq("pid", id)).list(); c.add(Restrictions.eq("category", category)).list(); List<String> l = c.list(); return l; }
From source file:org.openmrs.module.DeIdentifiedPatientDataExportModule.api.db.hibernate.HibernateDeIdentifiedExportDAO.java
License:Open Source License
public List<String> getProfileIdByName(String pname) { Criteria c = sessionFactory.getCurrentSession().createCriteria(ProfileName.class); ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("pid")); c.setProjection(projList);/*from ww w . ja v a 2 s . co m*/ c.add(Restrictions.eq("profileName", pname)).list(); List<String> l = c.list(); return l; }
From source file:org.openmrs.module.DeIdentifiedPatientDataExportModule.api.db.hibernate.HibernateDeIdentifiedExportDAO.java
License:Open Source License
public java.util.List<String> getProfiles() { Criteria c = sessionFactory.getCurrentSession().createCriteria(ProfileName.class); ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("pid")); c.setProjection(projList);/*from ww w. ja va2 s.c o m*/ List<String> l = c.list(); return l; }
From source file:org.openmrs.module.DeIdentifiedPatientDataExportModule.api.db.hibernate.HibernateDeIdentifiedExportDAO.java
License:Open Source License
public List<String> getProfileNames() { Criteria c = sessionFactory.getCurrentSession().createCriteria(ProfileName.class); ProjectionList projList = Projections.projectionList(); projList.add(Projections.property("profileName")); c.setProjection(projList);/*from w ww .j a v a 2 s. c o m*/ List<String> l = c.list(); return l; }
From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernateInventoryDAO.java
public Integer sumCurrentQuantityDrugOfStore(Integer storeId, Integer drugId, Integer formulationId) throws DAOException { Criteria criteria = sessionFactory.getCurrentSession() .createCriteria(InventoryStoreDrugTransactionDetail.class, "transactionDetail") .createAlias("transactionDetail.transaction", "transaction") .add(Restrictions.eq("transaction.store.id", storeId)) .add(Restrictions.eq("transaction.typeTransaction", ActionValue.TRANSACTION[0])) .add(Restrictions.eq("transactionDetail.drug.id", drugId)) .add(Restrictions.eq("transactionDetail.formulation.id", formulationId)); criteria.add(Restrictions.gt("transactionDetail.currentQuantity", 0)); criteria.add(Restrictions.gt("transactionDetail.dateExpiry", new Date())); ProjectionList proList = Projections.projectionList(); proList.add(Projections.sum("currentQuantity")); criteria.setProjection(proList);//from w w w . j a v a 2s . c om Object l = criteria.uniqueResult(); return l != null ? (Integer) l : 0; }
From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernateInventoryDAO.java
public List<InventoryStoreDrugTransactionDetail> listStoreDrugAvaiable(Integer storeId, Collection<Integer> drugs, Collection<Integer> formulations) throws DAOException { Criteria criteria = sessionFactory.getCurrentSession() .createCriteria(InventoryStoreDrugTransactionDetail.class, "transactionDetail") .createAlias("transactionDetail.transaction", "transaction") .setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); ProjectionList proList = Projections.projectionList(); proList.add(Projections.groupProperty("drug")).add(Projections.groupProperty("formulation")) .add(Projections.sum("currentQuantity")); criteria.add(Restrictions.eq("transaction.store.id", storeId)); if (drugs != null) { criteria.createCriteria("transactionDetail.drug", Criteria.INNER_JOIN) .add(Restrictions.in("id", drugs)); }/*from w w w .j av a2 s .com*/ criteria.add(Restrictions.eq("transaction.typeTransaction", ActionValue.TRANSACTION[0])); if (formulations != null) { criteria.createCriteria("transactionDetail.formulation", Criteria.INNER_JOIN) .add(Restrictions.in("id", formulations)); } criteria.setProjection(proList); criteria.add(Restrictions.ge("transactionDetail.dateExpiry", new Date())); List<Object> lst = criteria.list(); if (lst == null || lst.size() == 0) return null; List<InventoryStoreDrugTransactionDetail> list = new ArrayList<InventoryStoreDrugTransactionDetail>(); // System.out.println("lst size: "+lst.size()); 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]); list.add(tDetail); // System.out.println("I: "+i+" drug: "+tDetail.getDrug().getName()+" formulation: "+tDetail.getFormulation().getName()+" quantity: "+tDetail.getCurrentQuantity()); } return list; }
From source file:org.openmrs.module.hospitalcore.db.hibernate.HibernateInventoryDAO.java
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)); }// www . java 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; }