/** Retrieves message to be send from database and passes to SMSManager instance */ public void run() { String message = ""; if (this.SMS_TYPE == ALERT_TYPE) { message = getMessageContent(patient.getMsgId()); updateAlertCount(); logger.debug("Sending \n message:" + message + "\n Phone Number:" + patient.getPhoneNumber()); new SMSManager(patient).sendSMS(message); } else if (this.SMS_TYPE == FOLLOWUP_TYPE) { // TODO: Get actual phonenumbers String pnumber = "9160741100"; message = followupQstn.getQstn(); int count = 0; for (FollowupChoice followupChoice : getFollowupChoices(followupQstn.getFid())) { count++; message += "\n" + count + ". " + followupChoice.getChoice(); } int followupCacheId = getCacheId(followupQstn.getFid()); message += "\n" + "Type " + FOLLOWUP_KEYWORD + " " + followupCacheId + " (your option)to send your option."; new SMSManager(followupQstn).sendSMS(pnumber, message); } }
/** 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(); }