@RequestMapping(value = "getmothers", method = RequestMethod.GET)
public @ResponseBody CustomMotherResponse fetchMothers(@RequestParam("postId") int postId,
@RequestParam("workerId") int workerId, @RequestParam("status") String status,
@RequestParam("time") String time, @RequestParam("rows") int rows, @RequestParam("page") int page) {
CustomMotherResponse response = new CustomMotherResponse();
//StringBuilder sb = new StringBuilder();
Map<String, String> sb = new HashMap<String, String> ();
List<Mother> mothers = motherService.getMothersByCriteria(postId, workerId, status, time, rows, page, sb);
List<MotherDTO> motherDTOs = new ArrayList<MotherDTO>();
for (Mother mother : mothers) {
if (!motherService.motherExistsInList(motherDTOs, mother)) {
MotherDTO mDTO = new MotherDTO();
mDTO.setSeqId(mother.getSeqId());
mDTO.setMotherId(mother.getMotherId());
mDTO.setFullName(mother.getFullName());
mDTO.setAge(mother.getAge());
mDTO.setGott(mother.getGott());
DateTime edd = new DateTime(mother.getEdd()).withChronology(EthiopicChronology.getInstance());
mDTO.setEdd(edd.getDayOfMonth() + "/" + edd.getMonthOfYear() + "/" + edd.getYear());
mDTO.setPassed(edd.isBeforeNow());
mDTO.setGott(mother.getGott());
HealthExtensionWorker worker = mother.getHealthWorker();
if (worker != null) {
mDTO.setWorkerName(worker.getFullName());
mDTO.setWorkerPhone(worker.getPhoneNumber());
mDTO.setHealthPost(worker.getHealthPost().getPostName());
}
String outcome = mother.getOutcome();
//Delivery delivery = motherService.getRecentDelivery(mother);
if (outcome != null) {
mDTO.setDeliveryStatus(outcome);
} else {
mDTO.setDeliveryStatus("Not Delivered");
}
List<Reminder> reminders = mother.getReminders();
for(Reminder reminder : reminders) {
String reminderType = reminder.getReminderType();
String reminderStatus = reminder.getStatus();
if (reminderType.equalsIgnoreCase("MONTHLY")) {
mDTO.setFirstReminder(true);
mDTO.setFirstConfirmation(reminderStatus);
} else if (reminderType.equalsIgnoreCase("WEEKLY")) {
mDTO.setSecondReminder(true);
mDTO.setSecondConfirmation(reminderStatus);
}
}
motherDTOs.add(mDTO);
}
}
response.setPage(String.valueOf(page));
response.setRows(motherDTOs);
response.setTotal(sb.get("totalPages").toString());
response.setRecords(sb.get("records").toString());
return response;
}