int smscCode = Integer.parseInt(message.getRefNo());
String recipient = "+" + message.getRecipient();
mainForm.setLogText("\n\nIncoming status Report ...");
TextMessage textMessage = textMessageDao.getBySmscCodeAndRecipient(smscCode, recipient);
if (textMessage != null) {
Mother mother = motherDao.getMother(textMessage.getSeqId());
String reminderType = textMessage.getMessageType();
boolean reminderAlreadySent;
if (reminderType.equals("MONTHLY")) {
reminderAlreadySent = motherDao.hasMonthlyReminder(mother);
} else {
reminderAlreadySent = motherDao.hasWeeklyReminder(mother);
}
if (!reminderAlreadySent) {
textMessageDao.changeStatus(textMessage, "A");
mainForm.setLogText("\nReminder to be written to database ...");
DateTime eddGreg = new DateTime(mother.getEdd());
LocalDate eddEth = eddGreg.withChronology(EthiopicChronology.getInstance()).toLocalDate();
String date = eddEth.getDayOfMonth() + "/" + eddEth.getMonthOfYear() + "/" + eddEth.getYear();
String gott = (mother.getGott() == null) ? "Urban" : mother.getGott();
String template = "ID: " + mother.getSeqId() + "\n" + mother.getFullName() + "\n" + gott + "\nEDD: " + date;
Reminder reminder = new Reminder();
reminder.setStatus("UNCONFIRMED");
reminder.setContent(template);
reminder.setMother(mother);
reminder.setReminderSentOn(new DateTime().toLocalDate().toDate());
reminder.setReminderType(textMessage.getMessageType());
reminderDao.save(reminder);
} else {
if (textMessage.getStatus().equals("P")) {
textMessageDao.changeStatus(textMessage, "R");
}
}
}
mainForm.setLogText("\nProcess completed.");