@RequestMapping(method = RequestMethod.GET)
  public ModelMap handleMainPage(HttpServletRequest request) {
    ModelMap map = new ModelMap();
    // setUpSidebar(request);
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");

    eventDefinitionCRFDao = new EventDefinitionCRFDAO(dataSource);
    studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
    crfDao = new CRFDAO(dataSource);
    studyGroupClassDao = new StudyGroupClassDAO(dataSource);
    studyDao = new StudyDAO(dataSource);
    userDao = new UserAccountDAO(dataSource);
    ruleDao = new RuleDAO(dataSource);

    StudyModuleStatus sms = studyModuleStatusDao.findByStudyId(currentStudy.getId());
    if (sms == null) {
      sms = new StudyModuleStatus();
      sms.setStudyId(currentStudy.getId());
    }

    int crfCount = crfDao.findAllByStudy(currentStudy.getId()).size();
    int crfWithEventDefinition = crfDao.findAllActiveByDefinitions(currentStudy.getId()).size();
    int totalCrf = crfCount + crfWithEventDefinition;
    // int eventDefinitionCount = eventDefinitionCRFDao.findAllActiveByStudy(currentStudy).size();
    int eventDefinitionCount = studyEventDefinitionDao.findAllActiveByStudy(currentStudy).size();

    int subjectGroupCount = studyGroupClassDao.findAllActiveByStudy(currentStudy).size();

    List<RuleSetBean> ruleSets = ruleSetService.getRuleSetsByStudy(currentStudy);
    ruleSets = ruleSetService.filterByStatusEqualsAvailableOnlyRuleSetRules(ruleSets);
    int ruleCount = ruleSets != null ? ruleSets.size() : 0;

    int siteCount = studyDao.findOlnySiteIdsByStudy(currentStudy).size();
    int userCount = userDao.findAllUsersByStudy(currentStudy.getId()).size();
    Collection childStudies = studyDao.findAllByParent(currentStudy.getId());
    Map childStudyUserCount = new HashMap();
    for (Object sb : childStudies) {
      StudyBean childStudy = (StudyBean) sb;
      childStudyUserCount.put(
          childStudy.getName(), userDao.findAllUsersByStudy(childStudy.getId()).size());
    }

    if (sms.getCrf() == 0) {
      sms.setCrf(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getCrf() != 3 && totalCrf > 0) {
      sms.setCrf(StudyModuleStatus.IN_PROGRESS);
    }

    if (sms.getEventDefinition() == 0) {
      sms.setEventDefinition(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getEventDefinition() != 3 && eventDefinitionCount > 0) {
      sms.setEventDefinition(StudyModuleStatus.IN_PROGRESS);
    }

    if (sms.getSubjectGroup() == 0) {
      sms.setSubjectGroup(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getSubjectGroup() != 3 && subjectGroupCount > 0) {
      sms.setSubjectGroup(StudyModuleStatus.IN_PROGRESS);
    }

    if (sms.getRule() == 0) {
      sms.setRule(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getRule() != 3 && ruleCount > 0) {
      sms.setRule(StudyModuleStatus.IN_PROGRESS);
    }

    if (sms.getSite() == 0) {
      sms.setSite(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getSite() != 3 && siteCount > 0) {
      sms.setSite(StudyModuleStatus.IN_PROGRESS);
    }

    if (sms.getUsers() == 0) {
      sms.setUsers(StudyModuleStatus.NOT_STARTED);
    }
    if (sms.getUsers() != 3 && userCount > 0) {
      sms.setUsers(StudyModuleStatus.IN_PROGRESS);
    }

    map.addObject(sms);
    map.addAttribute("crfCount", totalCrf);
    map.addAttribute("eventDefinitionCount", eventDefinitionCount);
    map.addAttribute("subjectGroupCount", subjectGroupCount);
    map.addAttribute("ruleCount", ruleCount);
    map.addAttribute("siteCount", siteCount);
    map.addAttribute("userCount", userCount);
    map.addAttribute("childStudyUserCount", childStudyUserCount);
    map.addAttribute("studyId", currentStudy.getId());
    map.addAttribute("currentStudy", currentStudy);

    UserAccountBean userBean = (UserAccountBean) request.getSession().getAttribute("userBean");
    request.setAttribute("userBean", userBean);
    request.setAttribute("statusMap", Status.toStudyUpdateMembersList());

    ArrayList pageMessages = new ArrayList();
    if (request.getSession().getAttribute("pageMessages") != null) {
      pageMessages.addAll((ArrayList) request.getSession().getAttribute("pageMessages"));
      request.setAttribute("pageMessages", pageMessages);
      request.getSession().removeAttribute("pageMessages");
    }
    return map;
  }
  /*
   * (non-Javadoc)
   *
   * @see org.akaza.openclinica.control.core.SecureController#processRequest()
   */
  protected void processRequest() throws Exception {
    // find last 5 modifed sites
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    // ArrayList sites = (ArrayList) sdao.findAllByParentAndLimit(currentStudy.getId(),true);
    ArrayList allSites = (ArrayList) sdao.findAllByParent(currentStudy.getId());
    ArrayList sites = new ArrayList();
    for (int i = 0; i < allSites.size(); i++) {
      sites.add(allSites.get(i));
      if (i == 5) {
        break;
      }
    }
    request.setAttribute("sites", sites);
    request.setAttribute("sitesCount", new Integer(sites.size()));
    request.setAttribute("allSitesCount", new Integer(allSites.size()));

    StudyEventDefinitionDAO edao = new StudyEventDefinitionDAO(sm.getDataSource());
    ArrayList seds = (ArrayList) edao.findAllByStudyAndLimit(currentStudy.getId());
    ArrayList allSeds = (ArrayList) edao.findAllByStudy(currentStudy);
    request.setAttribute("seds", seds);
    request.setAttribute("sedsCount", new Integer(seds.size()));
    request.setAttribute("allSedsCount", new Integer(allSeds.size()));

    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList users = (ArrayList) udao.findAllUsersByStudyIdAndLimit(currentStudy.getId(), true);
    ArrayList allUsers = (ArrayList) udao.findAllUsersByStudy(currentStudy.getId());
    request.setAttribute("users", users);
    request.setAttribute("usersCount", new Integer(users.size()));
    request.setAttribute("allUsersCount", new Integer(allUsers.size()));

    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    // ArrayList subjects = (ArrayList) ssdao.findAllByStudyIdAndLimit(currentStudy.getId(),true);
    ArrayList allSubjects = (ArrayList) ssdao.findAllByStudyId(currentStudy.getId());
    ArrayList subjects = new ArrayList();
    for (int i = 0; i < allSubjects.size(); i++) {
      subjects.add(allSubjects.get(i));
      if (i == 5) {
        break;
      }
    }
    request.setAttribute("subs", subjects);
    request.setAttribute("subsCount", new Integer(subjects.size()));
    request.setAttribute("allSubsCount", new Integer(allSubjects.size()));

    // added tbh, 9-21-2005
    AuditEventDAO aedao = new AuditEventDAO(sm.getDataSource());
    // ArrayList audits = (ArrayList) aedao.findAllByStudyIdAndLimit(currentStudy.getId());
    // request.setAttribute("audits", audits);
    resetPanel();

    if (allSubjects.size() > 0) {
      setToPanel("Subjects", new Integer(allSubjects.size()).toString());
    }
    if (allUsers.size() > 0) {
      setToPanel("Users", new Integer(allUsers.size()).toString());
    }
    if (allSites.size() > 0) {
      setToPanel("Sites", new Integer(allSites.size()).toString());
    }
    if (allSeds.size() > 0) {
      setToPanel("Event Definitions", new Integer(allSeds.size()).toString());
    }

    forwardPage(Page.MANAGE_STUDY);
  }