List of usage examples for org.hibernate CacheMode IGNORE
CacheMode IGNORE
To view the source code for org.hibernate CacheMode IGNORE.
Click Source Link
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
public Cohort getPatientsByCharacteristics(String gender, Date minBirthdate, Date maxBirthdate, Integer minAge, Integer maxAge, Boolean aliveOnly, Boolean deadOnly, Date effectiveDate) throws DAOException { if (effectiveDate == null) { effectiveDate = new Date(); }/*from w w w .jav a 2 s . c o m*/ StringBuffer queryString = new StringBuffer("select patientId from Patient patient"); List<String> clauses = new ArrayList<String>(); clauses.add("patient.voided = false"); if (gender != null) { gender = gender.toUpperCase(); clauses.add("patient.gender = :gender"); } if (minBirthdate != null) { clauses.add("patient.birthdate >= :minBirthdate"); } if (maxBirthdate != null) { clauses.add("patient.birthdate <= :maxBirthdate"); } if (aliveOnly != null && aliveOnly) { clauses.add("patient.dead = false"); } if (deadOnly != null && deadOnly) { clauses.add("patient.dead = true"); } Date maxBirthFromAge = null; if (minAge != null) { Calendar cal = Calendar.getInstance(); cal.setTime(effectiveDate); cal.add(Calendar.YEAR, -minAge); maxBirthFromAge = cal.getTime(); clauses.add("patient.birthdate <= :maxBirthFromAge"); } Date minBirthFromAge = null; if (maxAge != null) { Calendar cal = Calendar.getInstance(); cal.setTime(effectiveDate); cal.add(Calendar.YEAR, -(maxAge + 1)); minBirthFromAge = cal.getTime(); clauses.add("patient.birthdate > :minBirthFromAge"); } clauses.add("(patient.birthdate is null or patient.birthdate <= :effectiveDate)"); boolean first = true; for (String clause : clauses) { if (first) { queryString.append(" where ").append(clause); first = false; } else { queryString.append(" and ").append(clause); } } Query query = sessionFactory.getCurrentSession().createQuery(queryString.toString()); query.setCacheMode(CacheMode.IGNORE); if (gender != null) { query.setString("gender", gender); } if (minBirthdate != null) { query.setDate("minBirthdate", minBirthdate); } if (maxBirthdate != null) { query.setDate("maxBirthdate", maxBirthdate); } if (minAge != null) { query.setDate("maxBirthFromAge", maxBirthFromAge); } if (maxAge != null) { query.setDate("minBirthFromAge", minBirthFromAge); } query.setDate("effectiveDate", effectiveDate); return new Cohort(query.list()); }
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
@SuppressWarnings("unchecked") public Map<Integer, String> getShortPatientDescriptions(Collection<Integer> patientIds) throws DAOException { Map<Integer, String> ret = new HashMap<Integer, String>(); Query query = sessionFactory.getCurrentSession().createQuery( "select patient.personId, patient.gender, patient.birthdate from Patient patient where voided = false"); query.setCacheMode(CacheMode.IGNORE); List<Object[]> temp = query.list(); long now = System.currentTimeMillis(); for (Object[] results : temp) { if (!patientIds.contains(results[0])) { continue; }//from w w w . ja va 2s.c o m StringBuffer sb = new StringBuffer(); if ("M".equals(results[1])) { sb.append("Male"); } else { sb.append("Female"); } Date bd = (Date) results[2]; if (bd != null) { int age = (int) ((now - bd.getTime()) / MS_PER_YEAR); sb.append(", ").append(age).append(" years old"); } ret.put((Integer) results[0], sb.toString()); } return ret; }
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
@SuppressWarnings("unchecked") public Map<Integer, Map<String, Object>> getCharacteristics(Cohort patients) throws DAOException { Map<Integer, Map<String, Object>> ret = new HashMap<Integer, Map<String, Object>>(); Collection<Integer> ids = patients.getMemberIds(); Query query = sessionFactory.getCurrentSession().createQuery( "select patient.personId, patient.gender, patient.birthdate from Patient patient where patient.voided = false"); query.setCacheMode(CacheMode.IGNORE); List<Object[]> temp = query.list(); long now = System.currentTimeMillis(); for (Object[] results : temp) { Integer patientId = (Integer) results[0]; if (!ids.contains(patientId)) { continue; }//ww w . ja va2s . c o m Map<String, Object> holder = new HashMap<String, Object>(); holder.put("gender", results[1]); Date bd = (Date) results[2]; if (bd != null) { int age = (int) ((now - bd.getTime()) / MS_PER_YEAR); holder.put("age_years", age); holder.put("birthdate", bd); } ret.put(patientId, holder); } return ret; }
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
@SuppressWarnings("unchecked") /**/* w w w .jav a 2 s. co m*/ * fromDate and toDate are both inclusive */ public Map<Integer, List<Obs>> getObservations(Cohort patients, Concept concept, Date fromDate, Date toDate) throws DAOException { Map<Integer, List<Obs>> ret = new HashMap<Integer, List<Obs>>(); /* Query query = sessionFactory.getCurrentSession().createQuery("select obs, obs.patientId " + "from Obs obs where obs.conceptId = :conceptId " + " and obs.patientId in :ids " + "order by obs.obsDatetime asc"); query.setInteger("conceptId", conceptId); query.set List<Object[]> temp = query.list(); for (Object[] holder : temp) { Obs obs = (Obs) holder[0]; Integer ptId = (Integer) holder[1]; List<Obs> forPatient = ret.get(ptId); if (forPatient == null) { forPatient = new ArrayList<Obs>(); ret.put(ptId, forPatient); } forPatient.add(obs); } */ Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Obs.class); criteria.setCacheMode(CacheMode.IGNORE); criteria.add(Restrictions.eq("concept", concept)); // only add this where clause if patients were passed in if (patients != null) { criteria.add(Restrictions.in("person.personId", patients.getMemberIds())); } criteria.add(Restrictions.eq("voided", false)); criteria.addOrder(org.hibernate.criterion.Order.desc("obsDatetime")); log.debug("criteria: " + criteria); List<Obs> temp = criteria.list(); for (Obs obs : temp) { Integer ptId = obs.getPersonId(); List<Obs> forPatient = ret.get(ptId); if (forPatient == null) { forPatient = new ArrayList<Obs>(); ret.put(ptId, forPatient); } forPatient.add(obs); } return ret; }
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
@SuppressWarnings("unchecked") public Map<Integer, List<List<Object>>> getObservationsValues(Cohort patients, Concept c, List<String> attributes, Integer limit, boolean showMostRecentFirst) { Map<Integer, List<List<Object>>> ret = new HashMap<Integer, List<List<Object>>>(); List<String> aliases = new Vector<String>(); Boolean conditional = false;//from www . j a v a 2s . c om Criteria criteria = sessionFactory.getCurrentSession().createCriteria("org.openmrs.Obs", "obs"); criteria.setCacheMode(CacheMode.IGNORE); List<String> columns = new Vector<String>(); for (String attribute : attributes) { List<String> classNames = new Vector<String>(); if (attribute == null) { columns = findObsValueColumnName(c); if (columns.size() > 1) { conditional = true; } continue; //log.debug("c: " + c.getConceptId() + " attribute: " + attribute); } else if ("valueDate".equals(attribute)) { // pass -- same column name } else if ("valueTime".equals(attribute)) { // pass -- same column name } else if ("valueDatetime".equals(attribute)) { // pass -- same column name } else if ("obsDatetime".equals(attribute)) { // pass -- same column name } else if ("location".equals(attribute)) { // pass -- same column name classNames.add("obs.location"); attribute = "location.name"; } else if ("comment".equals(attribute)) { // pass -- same column name } else if ("encouterType".equals(attribute)) { classNames.add("obs.encounter"); classNames.add("encounter.encounterType"); attribute = "encounterType.name"; } else if ("provider".equals(attribute)) { classNames.add("obs.encounter"); attribute = "encounter.provider"; } else { throw new DAOException("Attribute: " + attribute + " is not recognized. Please add reference in " + this.getClass()); } for (String className : classNames) { // if aliasing is necessary if (!aliases.contains(className)) { // if we haven't aliased this already criteria.createAlias(className, className.split("\\.")[1]); aliases.add(className); } } columns.add(attribute); } String aliasName = "obs"; // set up the query ProjectionList projections = Projections.projectionList(); projections.add(Projections.property("obs.personId")); for (String col : columns) { if (col.contains(".")) { projections.add(Projections.property(col)); } else { projections.add(Projections.property(aliasName + "." + col)); } } criteria.setProjection(projections); // only restrict on patient ids if some were passed in if (patients != null) { criteria.add(Restrictions.in("obs.personId", patients.getMemberIds())); } criteria.add(Restrictions.eq("obs.concept", c)); criteria.add(Restrictions.eq("obs.voided", false)); if (showMostRecentFirst) { criteria.addOrder(org.hibernate.criterion.Order.desc("obs.obsDatetime")); } else { criteria.addOrder(org.hibernate.criterion.Order.asc("obs.obsDatetime")); } long start = System.currentTimeMillis(); List<Object[]> rows = criteria.list(); log.debug("Took: " + (System.currentTimeMillis() - start) + " ms to run the patient/obs query"); // set up the return map for (Object[] rowArray : rows) { //log.debug("row[0]: " + row[0] + " row[1]: " + row[1] + (row.length > 2 ? " row[2]: " + row[2] : "")); Integer ptId = (Integer) rowArray[0]; List<List<Object>> oldArr = ret.get(ptId); // if we have already fetched all of the results the user wants if (limit != null && limit > 0 && oldArr != null && oldArr.size() >= limit) { // the user provided a limit value and this patient already has more than // that number of values. // do nothing with this row } else { Boolean tmpConditional = conditional.booleanValue(); // get all columns int index = 1; List<Object> row = new Vector<Object>(); while (index < rowArray.length) { Object value = rowArray[index++]; if (tmpConditional) { if (index == 2 && value != null) { // skip null first value if we must row.add(value); } else { row.add(rowArray[index]); } tmpConditional = false; index++; // increment counter for next column. (Skips over value_concept) } else { row.add(value == null ? "" : value); } } // if we haven't seen a different row for this patient already: if (oldArr == null) { List<List<Object>> arr = new Vector<List<Object>>(); arr.add(row); ret.put(ptId, arr); } // if we have seen a row for this patient already else { oldArr.add(row); ret.put(ptId, oldArr); } } } return ret; }
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
@SuppressWarnings("unchecked") public Map<Integer, Encounter> getEncountersByType(Cohort patients, List<EncounterType> encTypes) { Map<Integer, Encounter> ret = new HashMap<Integer, Encounter>(); // default query Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.class); criteria.setCacheMode(CacheMode.IGNORE); // this "where clause" is only necessary if patients were passed in if (patients != null && patients.size() > 0) { criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); }/* www. j av a 2 s. c om*/ criteria.add(Restrictions.eq("voided", false)); if (encTypes != null && encTypes.size() > 0) { criteria.add(Restrictions.in("encounterType", encTypes)); } criteria.addOrder(org.hibernate.criterion.Order.desc("patient.personId")); criteria.addOrder(org.hibernate.criterion.Order.desc("encounterDatetime")); List<Encounter> encounters = criteria.list(); // set up the return map for (Encounter enc : encounters) { Integer ptId = enc.getPatientId(); if (!ret.containsKey(ptId)) { ret.put(ptId, enc); } } return ret; }
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
/** * Gets a list of encounters associated with the given form, filtered by the given patient set. * // w w w . j a va2s. co m * @param patients the patients to filter by (null will return all encounters for all patients) * @param forms the forms to filter by */ @SuppressWarnings("unchecked") public List<Encounter> getEncountersByForm(Cohort patients, List<Form> forms) { // default query Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.class); criteria.setCacheMode(CacheMode.IGNORE); // this "where clause" is only necessary if patients were passed in if (patients != null && patients.size() > 0) { criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); } criteria.add(Restrictions.eq("voided", false)); if (forms != null && forms.size() > 0) { criteria.add(Restrictions.in("form", forms)); } criteria.addOrder(org.hibernate.criterion.Order.desc("patient.personId")); criteria.addOrder(org.hibernate.criterion.Order.desc("encounterDatetime")); return criteria.list(); }
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
@SuppressWarnings("unchecked") public Map<Integer, Object> getEncounterAttrsByType(Cohort patients, List<EncounterType> encTypes, String attr, Boolean earliestFirst) {//from w ww .j av a 2 s . co m Map<Integer, Object> ret = new HashMap<Integer, Object>(); // default query Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.class); criteria.setCacheMode(CacheMode.IGNORE); // this "where clause" is only necessary if patients were specified if (patients != null) { criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); } criteria.add(Restrictions.eq("voided", false)); if (encTypes != null && encTypes.size() > 0) { criteria.add(Restrictions.in("encounterType", encTypes)); } criteria.setProjection(Projections.projectionList().add(Projections.property("patient.personId")) .add(Projections.property(attr))); criteria.addOrder(org.hibernate.criterion.Order.desc("patient.personId")); if (earliestFirst) { criteria.addOrder(org.hibernate.criterion.Order.asc("encounterDatetime")); } else { criteria.addOrder(org.hibernate.criterion.Order.desc("encounterDatetime")); } List<Object[]> attrs = criteria.list(); // set up the return map for (Object[] row : attrs) { Integer ptId = (Integer) row[0]; if (!ret.containsKey(ptId)) { ret.put(ptId, row[1]); } } return ret; }
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
@SuppressWarnings("unchecked") public Map<Integer, Encounter> getEncounters(Cohort patients) { Map<Integer, Encounter> ret = new HashMap<Integer, Encounter>(); // default query Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.class); criteria.setCacheMode(CacheMode.IGNORE); // only include this where clause if patients were passed in if (patients != null) { criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); }//from w w w .j av a2 s.c o m criteria.add(Restrictions.eq("voided", false)); criteria.addOrder(org.hibernate.criterion.Order.desc("patient.personId")); criteria.addOrder(org.hibernate.criterion.Order.desc("encounterDatetime")); List<Encounter> encounters = criteria.list(); // set up the return map for (Encounter enc : encounters) { Integer ptId = enc.getPatientId(); if (!ret.containsKey(ptId)) { ret.put(ptId, enc); } } return ret; }
From source file:org.openmrs.api.db.hibernate.HibernatePatientSetDAO.java
License:Mozilla Public License
@SuppressWarnings("unchecked") public Map<Integer, Encounter> getFirstEncountersByType(Cohort patients, List<EncounterType> types) { Map<Integer, Encounter> ret = new HashMap<Integer, Encounter>(); // default query Criteria criteria = sessionFactory.getCurrentSession().createCriteria(Encounter.class); criteria.setCacheMode(CacheMode.IGNORE); // this "where clause" is only needed if patients were specified if (patients != null) { criteria.add(Restrictions.in("patient.personId", patients.getMemberIds())); }/* w ww. ja va 2 s . c om*/ criteria.add(Restrictions.eq("voided", false)); if (types != null && types.size() > 0) { criteria.add(Restrictions.in("encounterType", types)); } criteria.addOrder(org.hibernate.criterion.Order.desc("patient.personId")); criteria.addOrder(org.hibernate.criterion.Order.asc("encounterDatetime")); List<Encounter> encounters = criteria.list(); // set up the return map for (Encounter enc : encounters) { Integer ptId = enc.getPatientId(); if (!ret.containsKey(ptId)) { ret.put(ptId, enc); } } return ret; }