}
@Override
public ReportDetail generateReport(Report report) {
DateTime begin, end;
ReportDetail reportDetail = new ReportDetail();
for (int i = report.getFromQuarter(); i <= report.getToQuarter(); i++) {
int endMonth = i * 3;
int beginMonth = endMonth - 2;
int year = report.getYear();
int endDate = getTotalDaysOfMonth(year, endMonth);
begin = new DateTime(year, beginMonth, 1, 0, 0);
end = new DateTime(year, endMonth, endDate, 0, 0);
long count = (Long) getSession().createCriteria(Reminder.class)
.add(Restrictions.between("reminderSentOn", begin.toDate(), end.toDate()))
.add(Restrictions.eq("reminderType", "MONTHLY"))
.setProjection(Projections.rowCount()).uniqueResult();
int c = (int) count;
switch (i) {
case 1:
reportDetail.setQ1FirstReminder(c);
break;
case 2:
reportDetail.setQ2FirstReminder(c);
break;
case 3:
reportDetail.setQ3FirstReminder(c);
break;
case 4:
reportDetail.setQ4FirstReminder(c);
break;
}
count = (Long) getSession().createCriteria(Reminder.class)
.add(Restrictions.between("reminderSentOn", begin.toDate(), end.toDate()))
.add(Restrictions.eq("reminderType", "WEEKLY"))
.setProjection(Projections.rowCount()).uniqueResult();
c = (int) count;
switch (i) {
case 1:
reportDetail.setQ1SecondReminder(c);
break;
case 2:
reportDetail.setQ2SecondReminder(c);
break;
case 3:
reportDetail.setQ3SecondReminder(c);
break;
case 4:
reportDetail.setQ4SecondReminder(c);
break;
}
count = (Long) getSession().createCriteria(Mother.class)
.add(Restrictions.between("arrivalTime", begin.toDate(), end.toDate()))
.add(Restrictions.eq("outcome", "Delivered at Home"))
.setProjection(Projections.rowCount()).uniqueResult();
c = (int) count;
switch (i) {
case 1:
reportDetail.setQ1HomeDelivery(c);
break;
case 2:
reportDetail.setQ2HomeDelivery(c);
break;
case 3:
reportDetail.setQ3HomeDelivery(c);
break;
case 4:
reportDetail.setQ4HomeDelivery(c);
break;
}
count = (Long) getSession().createCriteria(Mother.class)
.add(Restrictions.between("arrivalTime", begin.toDate(), end.toDate()))
.add(Restrictions.eq("outcome", "Delivered at HP"))
.setProjection(Projections.rowCount()).uniqueResult();
c = (int) count;
switch (i) {
case 1:
reportDetail.setQ1HpDelivery(c);
break;
case 2:
reportDetail.setQ2HpDelivery(c);
break;
case 3:
reportDetail.setQ3HpDelivery(c);
break;
case 4:
reportDetail.setQ4HpDelivery(c);
break;
}
count = (Long) getSession().createCriteria(Mother.class)
.add(Restrictions.between("arrivalTime", begin.toDate(), end.toDate()))
.add(Restrictions.eq("outcome", "Delivered at HC"))
.setProjection(Projections.rowCount()).uniqueResult();
c = (int) count;
switch (i) {
case 1:
reportDetail.setQ1HcDelivery(c);
break;
case 2:
reportDetail.setQ2HcDelivery(c);
break;
case 3:
reportDetail.setQ3HcDelivery(c);
break;
case 4:
reportDetail.setQ4HcDelivery(c);
break;
}
count = (Long) getSession().createCriteria(Mother.class)
.add(Restrictions.between("arrivalTime", begin.toDate(), end.toDate()))
.add(Restrictions.eq("outcome", "Referred"))
.setProjection(Projections.rowCount()).uniqueResult();
c = (int) count;
switch (i) {
case 1:
reportDetail.setQ1ReferredDelivery(c);
break;
case 2:
reportDetail.setQ2ReferredDelivery(c);
break;
case 3:
reportDetail.setQ3ReferredDelivery(c);
break;
case 4:
reportDetail.setQ4ReferredDelivery(c);
break;
}
count = (Long) getSession().createCriteria(Mother.class)
.add(Restrictions.between("arrivalTime", begin.toDate(), end.toDate()))
.add(Restrictions.eq("outcome", "Unknown"))
.setProjection(Projections.rowCount()).uniqueResult();
c = (int) count;
switch (i) {
case 1:
reportDetail.setQ1UnknownDelivery(c);
break;
case 2:
reportDetail.setQ2UnknownDelivery(c);
break;
case 3:
reportDetail.setQ3UnknownDelivery(c);
break;
case 4:
reportDetail.setQ4UnknownDelivery(c);
break;
}
count = (Long) getSession().createCriteria(Mother.class)
.add(Restrictions.between("edd", begin.toDate(), end.toDate()))
.setProjection(Projections.rowCount()).uniqueResult();
c = (int) count;
switch (i) {
case 1:
reportDetail.setQ1Edd(c);
break;
case 2:
reportDetail.setQ2Edd(c);
break;
case 3:
reportDetail.setQ3Edd(c);
break;
case 4:
reportDetail.setQ4Edd(c);
break;
}
}
return reportDetail;