Package web.reception

Source Code of web.reception.CollaboratorController

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

package web.reception;

import domain.Client;
import domain.Collaborator;
import domain.Lpu;
import domain.Speciality;
import domain.shedule.WorkType;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import utils.Day;
import web.generic.CH;
import web.generic.GenericAbstractController;
import web.rechelper.IncomingParamsValidator;
import web.rechelper.ReceptionDTO;
import web.rechelper.ReceptionHelper;
import web.rechelper.Ticket;
import web.rechelper.WeekDay;

/**
* Выбор сотрудника, к которому будет производиться запись на прием
* Обязательные параметры:
*     client - ID пациента на запись
*     lpu - ID ЛПУ
*     type - ID типа приема
* Поиск проводится по ЛПУ и типу приема
* @author petr
*/
public class CollaboratorController extends GenericAbstractController {

    @Override
    protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Client client = CH.getOptional(getDao(), Client.class, request.getParameter("client"));
        WorkType type = CH.getOptional(getDao(), WorkType.class, request.getParameter("type"));
        Lpu lpu = CH.getOptional(getDao(), Lpu.class, request.getParameter("lpu"));

        if (client == null) {
            return IncomingParamsValidator.redirectTo("/reception/index.htm", client, type, lpu, null);
        } else if (lpu == null && type == null) {
            return IncomingParamsValidator.redirectTo("/reception/work.htm", client, type, lpu, null);
        } else if (lpu == null) {
            return IncomingParamsValidator.redirectTo("/reception/lpu.htm", client, type, lpu, null);
        } else if (type == null) {
            return IncomingParamsValidator.redirectTo("/reception/work.htm", client, type, lpu, null);
        }

        HashMap model = new HashMap();
        model.put("client", client);
        model.put("type", type);
        model.put("lpu", lpu);
        List<Collaborator> collaborators = getDao().getCollaboratorsByLpuAndWorkType(lpu, type);

        Map<Collaborator, String>  fmap = new HashMap<Collaborator, String>();
        String functions;

        for (Collaborator collaborator : collaborators) {
            functions = "";
            List<Speciality> list = getDao().getCollaboratorSpecialities(collaborator);
            for (Speciality speciality : list) {
                functions += speciality + ", ";
            }
            fmap.put(collaborator, functions);
        }

        Map<Collaborator, Ticket> collabTicketMap = new HashMap<Collaborator, Ticket>();
        for (Collaborator collaborator : collaborators) {
            ReceptionDTO dto = new ReceptionDTO();
            dto.setCollaborator(collaborator);
            dto.setLpu(lpu);
            dto.setType(type);
            Day day = new Day(new Date());
            Date dateStart = day.getDate();
            Calendar calendar = day.getCalendar();
            calendar.add(Calendar.DAY_OF_MONTH, 13);
            day = new Day(calendar);
            Date dateEnd = day.getEndDate();

            ReceptionHelper rh = new ReceptionHelper(getDao(), dto, dateStart, dateEnd);
            List<WeekDay> wModel = rh.getModel();
            for (int i = 0; i < wModel.size() && collabTicketMap.get(collaborator) == null; i++) {
                WeekDay weekDay = wModel.get(i);
                List<Ticket> tickets = weekDay.getTickets();
                if (tickets != null){
                    for (Ticket ticket : tickets) {
                        if (!ticket.isBuzy()){
                            collabTicketMap.put(collaborator, ticket);
                            break;
                        }
                    }
                }
            }
        }

        model.put("tikets", collabTicketMap);
        model.put("collaborators", collaborators);
        model.put("functions", fmap);

        model.put("pageBreadcrumb", ReceptionController.initBreadCrumb(client, type, lpu, null));
       
        return new ModelAndView("reception/collaborator", model);
    }

}
TOP

Related Classes of web.reception.CollaboratorController

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.