Esempio n. 1
0
 /** Update retryCount. Presently used for reminder alert messages */
 public void updateAlertCount() {
   Session session = HibernateUtil.getSessionFactory().openSession();
   session.beginTransaction();
   String hql = "from Alert where aid=:aid and alertType=:alertType";
   Query query = session.createQuery(hql);
   query.setString("aid", patient.getAlertId());
   query.setInteger("alertType", SMS_TYPE);
   Alert alert = (Alert) query.list().get(0);
   int retryCount = alert.getretryCount() + 1;
   alert.setretryCount(retryCount);
   session.update(alert);
   session.getTransaction().commit();
   session.close();
 }
Esempio n. 2
0
 /**
  * Get followup choices for given fid
  *
  * @param fid
  * @return
  */
 private List<FollowupChoice> getFollowupChoices(int fid) {
   // Get followup choices
   List<FollowupChoice> followupChoices = null;
   try {
     Session session = HibernateUtil.getSessionFactory().openSession();
     session.beginTransaction();
     String hqlChoice = "from FollowupChoice where fid=:fid";
     Query queryChoice = session.createQuery(hqlChoice);
     queryChoice.setInteger("fid", fid);
     followupChoices = (List<FollowupChoice>) queryChoice.list();
     session.getTransaction().commit();
     session.close();
   } catch (Exception ex) {
     logger.info("Some error occured while fetching followupChoices");
     logger.error("\n ERROR Caused by\n", ex);
   }
   return followupChoices;
 }
Esempio n. 3
0
 /**
  * the fid can get really long in the future. Also it should ideally be internal to the system.
  * hence a cache id is being generated (auto-increment primary key) and stored in the
  * followupcache table. the user response for a followup question is uniquely identified using
  * this cache id this is particularly required in cases such as one patient having mutiple
  * followups around the same time, multiple patients using the same number etc.
  *
  * <p>TODO: Clear the database in regular intervals to reuse previous smaller cache ids.
  *
  * @param fid
  * @return
  */
 private int getCacheId(int fid) {
   int cacheId = 0;
   try {
     String sql = "INSERT INTO followupcache (fid) VALUES (?)";
     Session session = HibernateUtil.getSessionFactory().openSession();
     session.beginTransaction();
     SQLQuery query = session.createSQLQuery(sql);
     query.setInteger(0, fid);
     query.executeUpdate();
     sql = "SELECT LAST_INSERT_ID() FROM followupcache";
     BigInteger result = (BigInteger) session.createSQLQuery(sql).uniqueResult();
     cacheId = result.intValue();
     session.getTransaction().commit();
     session.close();
   } catch (Exception ex) {
     logger.info("Some error occured while fetching followupChoices");
     logger.error("\n ERROR Caused by\n", ex);
   }
   return cacheId;
 }
Esempio n. 4
0
 /**
  * Given a msgID returns all the message associated with it Used for reminder alert messages
  *
  * @param msgId
  * @return List<String> all messages in a serial order
  */
 private List<String> getContentFromDB(int msgId) {
   Logger logger = getLog();
   logger.debug("Getting content for medicine Reminder having msgId" + msgId);
   try {
     String hql = "select content from SmsMsg where smsId=:msgId order by itemNumber";
     Session session = HibernateUtil.getSessionFactory().openSession();
     session.beginTransaction();
     Query query = session.createQuery(hql);
     query.setInteger("msgId", msgId);
     List<String> content = (List<String>) query.list();
     session.getTransaction().commit();
     session.close();
     logger.debug("Successfully retreived msg content from database with msgId" + msgId);
     return content;
   } catch (Exception ex) {
     logger.info("Some error occured while fetching content from msgId:" + msgId);
     logger.error("\n ERROR Caused by\n", ex);
   }
   return null;
 }