/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package web.operator.request;
import domain.Client;
import domain.UserRequest;
import domain.address.Address;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import utils.Converter;
import web.generic.CH;
import web.generic.GenericAbstractController;
/**
* Контроллер поиска пациентов из базы по данным UserRequesta
* Обязательные параметры:
* clientrequested - ID UserRequestа
* @author lacoste
*/
public class RequestController extends GenericAbstractController {
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
String requestStr = request.getParameter("clientrequested");
if (requestStr == null || requestStr.isEmpty()) {
return new ModelAndView("redirect:/operator/request/index.htm");
}
UserRequest userRequest = null;
try {
userRequest = CH.get(getDao(), UserRequest.class, requestStr);
} catch (Exception ex) {
}
if (userRequest == null) {
return new ModelAndView("redirect:/operator/request/index.htm");
}
ClientData data = new ClientData();
data.surname = userRequest.getSurname() != null ? userRequest.getSurname().trim() : "";
data.name = userRequest.getName() != null ? userRequest.getName().trim() : "";
data.patron = userRequest.getPatronymic() != null ? userRequest.getPatronymic().trim() : "";
List<Client> clientList = getDao().findOutClientsByData(data);
List<ClientData> clients = new LinkedList<ClientData>();
for (Client client : clientList) {
ClientData clientData = new ClientData();
clientData.client = client;
Address address = null;
if (client.getAddressID() != null) {
address = getDao().getById(Address.class, client.getAddressID());
}
clientData.address = address != null ? address.getAsStringShort() : "";
clientData.born = Converter.dateToString(client.getBorn());
clients.add(clientData);
}
HashMap model = new HashMap();
ClientRequestedData requestedData = new ClientRequestedData();
requestedData.requested = userRequest;
Address address = userRequest.getAddress();
if (address != null && address.getAddressObject() != null) {
requestedData.address = address.getAsStringShort();
}
model.put("userrequest", requestedData);
model.put("clients", clients);
return new ModelAndView("operator/request/request", model);
}
}