Program: 115095
Project: 115095
Buggy source:
@Override public void processRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
  FormProcessor fp=new FormProcessor(request);
  StudyBean currentStudy=(StudyBean)request.getSession().getAttribute("String_Node_Str");
  EventCRFBean ecb=(EventCRFBean)request.getAttribute(INPUT_EVENT_CRF);
  SectionBean sb=(SectionBean)request.getAttribute(SECTION_BEAN);
  boolean isSubmitted=false;
  EventDefinitionCRFBean edcb=(EventDefinitionCRFBean)request.getAttribute(EVENT_DEF_CRF_BEAN);
  if (!fp.getString("String_Node_Str").equals("String_Node_Str")) {
    request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
  }
  int crfVersionId=fp.getInt("String_Node_Str",true);
  int sectionId=fp.getInt("String_Node_Str");
  int eventCRFId=fp.getInt(EVENT_CRF_ID,true);
  int studySubjectId=fp.getInt("String_Node_Str",true);
  String action=fp.getString("String_Node_Str");
  HttpSession session=request.getSession();
  String fromResolvingNotes=fp.getString("String_Node_Str",true);
  if (StringUtil.isBlank(fromResolvingNotes)) {
    session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
    session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
  }
  request.setAttribute("String_Node_Str",studySubjectId + "String_Node_Str");
  request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
  request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
  int sedId=fp.getInt("String_Node_Str");
  request.setAttribute("String_Node_Str",sedId + "String_Node_Str");
  int crfId=fp.getInt("String_Node_Str");
  if (crfId == 0 && crfVersionId > 0) {
    CRFVersionDAO crfVDao=new CRFVersionDAO(getDataSource());
    CRFVersionBean crvVBean=(CRFVersionBean)crfVDao.findByPK(crfVersionId);
    if (crvVBean != null) {
      crfId=crvVBean.getCrfId();
    }
  }
  int eventDefinitionCRFId=fp.getInt("String_Node_Str");
  EventDefinitionCRFDAO eventCrfDao=new EventDefinitionCRFDAO(getDataSource());
  edcb=(EventDefinitionCRFBean)eventCrfDao.findByPK(eventDefinitionCRFId);
  if (eventCRFId == 0 && edcb.getStudyId() != currentStudy.getParentStudyId() && edcb.getStudyId() != currentStudy.getId()) {
    addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + respage.getString("String_Node_Str"),request);
    throw new InsufficientPermissionException(Page.MENU_SERVLET,resexception.getString("String_Node_Str"),"String_Node_Str");
  }
  if (crfId == 0 && eventDefinitionCRFId > 0) {
    if (edcb != null) {
      crfId=edcb.getCrfId();
    }
  }
  request.setAttribute("String_Node_Str",crfId + "String_Node_Str");
  request.setAttribute("String_Node_Str",eventDefinitionCRFId + "String_Node_Str");
  String printVersion=fp.getString("String_Node_Str");
  session.removeAttribute("String_Node_Str");
  EventCRFDAO ecdao=new EventCRFDAO(getDataSource());
  SectionDAO sdao=new SectionDAO(getDataSource());
  String age="String_Node_Str";
  if (sectionId == 0 && crfVersionId == 0 && eventCRFId == 0) {
    addPageMessage(respage.getString("String_Node_Str"),request);
    forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET,request,response);
    return;
  }
  if (studySubjectId > 0) {
    StudySubjectDAO ssdao=new StudySubjectDAO(getDataSource());
    StudySubjectBean sub=(StudySubjectBean)ssdao.findByPK(studySubjectId);
    request.setAttribute("String_Node_Str",sub);
  }
  if (eventCRFId > 0) {
    ecb=(EventCRFBean)ecdao.findByPK(eventCRFId);
    StudyEventDAO sedao=new StudyEventDAO(getDataSource());
    StudyEventBean event=(StudyEventBean)sedao.findByPK(ecb.getStudyEventId());
    if (event.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED)) {
      request.setAttribute("String_Node_Str","String_Node_Str");
    }
 else {
      request.setAttribute("String_Node_Str","String_Node_Str");
    }
    if (studySubjectId <= 0) {
      studySubjectId=event.getStudySubjectId();
      request.setAttribute("String_Node_Str",studySubjectId + "String_Node_Str");
    }
    DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(getDataSource());
    ArrayList<DiscrepancyNoteBean> allNotes=new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteBean> eventCrfNotes=new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteThread> noteThreads=new ArrayList<DiscrepancyNoteThread>();
    allNotes=dndao.findAllTopNotesByEventCRF(eventCRFId);
    eventCrfNotes=dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
    if (!eventCrfNotes.isEmpty()) {
      allNotes.addAll(eventCrfNotes);
      this.setAttributeForInterviewerDNotes(eventCrfNotes,request);
    }
    DiscrepancyNoteUtil dNoteUtil=new DiscrepancyNoteUtil();
    noteThreads=dNoteUtil.createThreadsOfParents(allNotes,getDataSource(),currentStudy,null,-1,true);
    int updatedNum=0;
    int openNum=0;
    int closedNum=0;
    int resolvedNum=0;
    int notAppNum=0;
    DiscrepancyNoteBean tempBean;
    for (    DiscrepancyNoteThread dnThread : noteThreads) {
      tempBean=dnThread.getLinkedNoteList().getLast();
      if (tempBean != null) {
        if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) {
          updatedNum++;
        }
 else         if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) {
          openNum++;
        }
 else         if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) {
          closedNum++;
        }
 else         if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) {
          resolvedNum++;
        }
 else         if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) {
          notAppNum++;
        }
      }
    }
    request.setAttribute("String_Node_Str",updatedNum + "String_Node_Str");
    request.setAttribute("String_Node_Str",openNum + "String_Node_Str");
    request.setAttribute("String_Node_Str",closedNum + "String_Node_Str");
    request.setAttribute("String_Node_Str",resolvedNum + "String_Node_Str");
    request.setAttribute("String_Node_Str",notAppNum + "String_Node_Str");
    DisplayTableOfContentsBean displayBean=TableOfContentsServlet.getDisplayBean(ecb,getDataSource(),currentStudy);
    Date tmpDate=displayBean.getEventCRF().getDateInterviewed();
    String formattedInterviewerDate;
    try {
      DateFormat local_df=new SimpleDateFormat(resformat.getString("String_Node_Str"),ResourceBundleProvider.getLocale());
      formattedInterviewerDate=local_df.format(tmpDate);
    }
 catch (    Exception e) {
      formattedInterviewerDate="String_Node_Str";
    }
    HashMap presetVals=(HashMap)session.getAttribute("String_Node_Str");
    if (presetVals == null) {
      presetVals=new HashMap();
      session.setAttribute("String_Node_Str",presetVals);
    }
    presetVals.put("String_Node_Str",formattedInterviewerDate);
    request.setAttribute("String_Node_Str",displayBean);
    ArrayList sections=displayBean.getSections();
    request.setAttribute("String_Node_Str",sections.size() + "String_Node_Str");
    if (!sections.isEmpty()) {
      if (sectionId == 0) {
        SectionBean firstSec=(SectionBean)sections.get(0);
        sectionId=firstSec.getId();
      }
    }
 else {
      addPageMessage(respage.getString("String_Node_Str"),request);
      forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET,request,response);
      return;
    }
  }
 else   if (crfVersionId > 0) {
    DisplayTableOfContentsBean displayBean=ViewTableOfContentServlet.getDisplayBean(getDataSource(),crfVersionId);
    request.setAttribute("String_Node_Str",displayBean);
    ArrayList sections=displayBean.getSections();
    request.setAttribute("String_Node_Str",sections.size() + "String_Node_Str");
    if (!sections.isEmpty()) {
      if (sectionId == 0) {
        SectionBean firstSec=(SectionBean)sections.get(0);
        sectionId=firstSec.getId();
      }
    }
 else {
      addPageMessage(respage.getString("String_Node_Str"),request);
      if (eventCRFId == 0) {
        forwardPage(Page.CRF_LIST_SERVLET,request,response);
      }
 else {
        forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET,request,response);
      }
      return;
    }
  }
  sb=(SectionBean)sdao.findByPK(sectionId);
  if (eventCRFId == 0) {
    ecb=new EventCRFBean();
    ecb.setCRFVersionId(sb.getCRFVersionId());
    if (currentStudy.getParentStudyId() > 0) {
      StudyDAO studydao=new StudyDAO(getDataSource());
      StudyBean parentStudy=(StudyBean)studydao.findByPK(currentStudy.getParentStudyId());
      request.setAttribute("String_Node_Str",parentStudy.getName());
      request.setAttribute("String_Node_Str",currentStudy.getName());
    }
 else {
      request.setAttribute("String_Node_Str",currentStudy.getName());
    }
  }
 else {
    ecb=(EventCRFBean)ecdao.findByPK(eventCRFId);
    request.setAttribute(INPUT_EVENT_CRF,ecb);
    request.setAttribute(SECTION_BEAN,sb);
    StudySubjectDAO ssdao=new StudySubjectDAO(getDataSource());
    StudySubjectBean sub=(StudySubjectBean)ssdao.findByPK(ecb.getStudySubjectId());
    SubjectDAO subjectDao=new SubjectDAO(getDataSource());
    int subjectId=sub.getSubjectId();
    int studyId=sub.getStudyId();
    SubjectBean subject=(SubjectBean)subjectDao.findByPK(subjectId);
    if (currentStudy.getStudyParameterConfig().getCollectDob().equals("String_Node_Str")) {
      StudyEventDAO sedao=new StudyEventDAO(getDataSource());
      StudyEventBean se=(StudyEventBean)sedao.findByPK(ecb.getStudyEventId());
      StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(getDataSource());
      StudyEventDefinitionBean sed=(StudyEventDefinitionBean)seddao.findByPK(se.getStudyEventDefinitionId());
      se.setStudyEventDefinition(sed);
      request.setAttribute("String_Node_Str",se);
      age=Utils.getInstacne().processAge(sub.getEnrollmentDate(),subject.getDateOfBirth());
    }
    StudyDAO studydao=new StudyDAO(getDataSource());
    StudyBean study=(StudyBean)studydao.findByPK(studyId);
    if (study.getParentStudyId() > 0) {
      StudyBean parentStudy=(StudyBean)studydao.findByPK(study.getParentStudyId());
      request.setAttribute("String_Node_Str",parentStudy.getName());
      request.setAttribute("String_Node_Str",study.getName());
    }
 else {
      request.setAttribute("String_Node_Str",study.getName());
    }
    request.setAttribute("String_Node_Str",sub);
    request.setAttribute("String_Node_Str",subject);
    request.setAttribute("String_Node_Str",age);
  }
  boolean hasItemGroup=false;
  ItemGroupDAO igdao=new ItemGroupDAO(getDataSource());
  List<ItemGroupBean> itemGroups=igdao.findLegitGroupBySectionId(sectionId);
  if (!itemGroups.isEmpty()) {
    hasItemGroup=true;
  }
  DisplaySectionBean dsb;
  request.setAttribute(EVENT_DEF_CRF_BEAN,edcb);
  request.setAttribute(INPUT_EVENT_CRF,ecb);
  request.setAttribute(SECTION_BEAN,sb);
  dsb=super.getDisplayBean(hasItemGroup,false,request,isSubmitted);
  FormDiscrepancyNotes discNotes=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
  if (discNotes == null) {
    discNotes=new FormDiscrepancyNotes();
    session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
  }
  List<DisplayItemWithGroupBean> displayItemWithGroups=super.createItemWithGroups(dsb,hasItemGroup,eventDefinitionCRFId,request);
  dsb.setDisplayItemGroups(displayItemWithGroups);
  super.populateNotesWithDBNoteCounts(discNotes,dsb,request);
  if (fp.getString("String_Node_Str") != null && "String_Node_Str".equals(fp.getString("String_Node_Str"))) {
    request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
  }
 else {
    session.removeAttribute("String_Node_Str");
  }
  if ("String_Node_Str".equalsIgnoreCase(action)) {
    LOGGER.info("String_Node_Str" + dsb.getDisplayItemGroups().size());
    DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(getDataSource());
    discNotes=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    for (int i=0; i < dsb.getDisplayItemGroups().size(); i++) {
      DisplayItemWithGroupBean diwb=dsb.getDisplayItemGroups().get(i);
      if (diwb.isInGroup()) {
        List<DisplayItemGroupBean> dgbs=diwb.getItemGroups();
        LOGGER.info("String_Node_Str" + dgbs.size());
        for (int j=0; j < dgbs.size(); j++) {
          DisplayItemGroupBean displayGroup=dgbs.get(j);
          List<DisplayItemBean> items=displayGroup.getItems();
          LOGGER.info("String_Node_Str" + items.size());
          for (          DisplayItemBean displayItem : items) {
            String inputName=getGroupItemInputName(displayGroup,j,displayItem);
            LOGGER.info("String_Node_Str" + inputName);
            LOGGER.info("String_Node_Str" + displayItem.getData().getId());
            AddNewSubjectServlet.saveFieldNotes(inputName,discNotes,dndao,displayItem.getData().getId(),"String_Node_Str",currentStudy);
          }
        }
      }
 else {
        DisplayItemBean dib=diwb.getSingleItem();
        String inputName=getInputName(dib);
        AddNewSubjectServlet.saveFieldNotes(inputName,discNotes,dndao,dib.getData().getId(),"String_Node_Str",currentStudy);
        ArrayList childItems=dib.getChildren();
        for (int j=0; j < childItems.size(); j++) {
          DisplayItemBean child=(DisplayItemBean)childItems.get(j);
          inputName=getInputName(child);
          AddNewSubjectServlet.saveFieldNotes(inputName,discNotes,dndao,dib.getData().getId(),"String_Node_Str",currentStudy);
        }
      }
    }
    addPageMessage("String_Node_Str",request);
    request.setAttribute("String_Node_Str",studySubjectId + "String_Node_Str");
    forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET,request,response);
    return;
  }
 else {
    request.setAttribute(BEAN_DISPLAY,dsb);
    request.setAttribute(BEAN_ANNOTATIONS,ecb.getAnnotations());
    request.setAttribute("String_Node_Str",sb);
    request.setAttribute("String_Node_Str",ecb);
    int tabNum=1;
    if ("String_Node_Str".equalsIgnoreCase(fp.getString("String_Node_Str"))) {
      tabNum=1;
    }
 else {
      tabNum=fp.getInt("String_Node_Str");
    }
    request.setAttribute("String_Node_Str",new Integer(tabNum).toString());
    request.setAttribute(ENCLOSING_PAGE,"String_Node_Str");
    if ("String_Node_Str".equalsIgnoreCase(printVersion)) {
      forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT,request,response);
    }
 else {
      forwardPage(Page.VIEW_SECTION_DATA_ENTRY,request,response);
    }
  }
}

Fixed version (ground truth):
@Override public void processRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
  FormProcessor fp=new FormProcessor(request);
  StudyBean currentStudy=(StudyBean)request.getSession().getAttribute("String_Node_Str");
  EventCRFBean ecb=(EventCRFBean)request.getAttribute(INPUT_EVENT_CRF);
  SectionBean sb=(SectionBean)request.getAttribute(SECTION_BEAN);
  boolean isSubmitted=false;
  EventDefinitionCRFBean edcb=(EventDefinitionCRFBean)request.getAttribute(EVENT_DEF_CRF_BEAN);
  if (!fp.getString("String_Node_Str").equals("String_Node_Str")) {
    request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
  }
  int crfVersionId=fp.getInt("String_Node_Str",true);
  int sectionId=fp.getInt("String_Node_Str");
  int eventCRFId=fp.getInt(EVENT_CRF_ID,true);
  int studySubjectId=fp.getInt("String_Node_Str",true);
  String action=fp.getString("String_Node_Str");
  HttpSession session=request.getSession();
  String fromResolvingNotes=fp.getString("String_Node_Str",true);
  if (StringUtil.isBlank(fromResolvingNotes)) {
    session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
    session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
  }
  request.setAttribute("String_Node_Str",studySubjectId + "String_Node_Str");
  request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
  request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
  int sedId=fp.getInt("String_Node_Str");
  request.setAttribute("String_Node_Str",sedId + "String_Node_Str");
  int crfId=fp.getInt("String_Node_Str");
  if (crfId == 0 && crfVersionId > 0) {
    CRFVersionDAO crfVDao=new CRFVersionDAO(getDataSource());
    CRFVersionBean crvVBean=(CRFVersionBean)crfVDao.findByPK(crfVersionId);
    if (crvVBean != null) {
      crfId=crvVBean.getCrfId();
    }
  }
  int eventDefinitionCRFId=fp.getInt("String_Node_Str");
  EventDefinitionCRFDAO eventCrfDao=new EventDefinitionCRFDAO(getDataSource());
  edcb=(EventDefinitionCRFBean)eventCrfDao.findByPK(eventDefinitionCRFId);
  if (eventCRFId == 0 && edcb.getStudyId() != currentStudy.getParentStudyId() && edcb.getStudyId() != currentStudy.getId()) {
    addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + respage.getString("String_Node_Str"),request);
    throw new InsufficientPermissionException(Page.MENU_SERVLET,resexception.getString("String_Node_Str"),"String_Node_Str");
  }
  if (crfId == 0 && eventDefinitionCRFId > 0) {
    if (edcb != null) {
      crfId=edcb.getCrfId();
    }
  }
  request.setAttribute("String_Node_Str",crfId + "String_Node_Str");
  request.setAttribute("String_Node_Str",eventDefinitionCRFId + "String_Node_Str");
  String printVersion=fp.getString("String_Node_Str");
  session.removeAttribute("String_Node_Str");
  EventCRFDAO ecdao=new EventCRFDAO(getDataSource());
  SectionDAO sdao=new SectionDAO(getDataSource());
  String age="String_Node_Str";
  if (sectionId == 0 && crfVersionId == 0 && eventCRFId == 0) {
    addPageMessage(respage.getString("String_Node_Str"),request);
    forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET,request,response);
    return;
  }
  if (studySubjectId > 0) {
    StudySubjectDAO ssdao=new StudySubjectDAO(getDataSource());
    StudySubjectBean sub=(StudySubjectBean)ssdao.findByPK(studySubjectId);
    request.setAttribute("String_Node_Str",sub);
  }
  if (eventCRFId > 0) {
    ecb=(EventCRFBean)ecdao.findByPK(eventCRFId);
    StudyEventDAO sedao=new StudyEventDAO(getDataSource());
    StudyEventBean event=(StudyEventBean)sedao.findByPK(ecb.getStudyEventId());
    if (event.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED)) {
      request.setAttribute("String_Node_Str","String_Node_Str");
    }
 else {
      request.setAttribute("String_Node_Str","String_Node_Str");
    }
    if (studySubjectId <= 0) {
      studySubjectId=event.getStudySubjectId();
      request.setAttribute("String_Node_Str",studySubjectId + "String_Node_Str");
    }
    DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(getDataSource());
    ArrayList<DiscrepancyNoteBean> allNotes=new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteBean> eventCrfNotes=new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteThread> noteThreads=new ArrayList<DiscrepancyNoteThread>();
    allNotes=dndao.findAllTopNotesByEventCRF(eventCRFId);
    eventCrfNotes=dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
    if (!eventCrfNotes.isEmpty()) {
      allNotes.addAll(eventCrfNotes);
      this.setAttributeForInterviewerDNotes(eventCrfNotes,request);
    }
    DiscrepancyNoteUtil dNoteUtil=new DiscrepancyNoteUtil();
    noteThreads=dNoteUtil.createThreadsOfParents(allNotes,getDataSource(),currentStudy,null,-1,true);
    int updatedNum=0;
    int openNum=0;
    int closedNum=0;
    int resolvedNum=0;
    int notAppNum=0;
    DiscrepancyNoteBean tempBean;
    for (    DiscrepancyNoteThread dnThread : noteThreads) {
      tempBean=dnThread.getLinkedNoteList().getLast();
      if (tempBean != null) {
        if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) {
          updatedNum++;
        }
 else         if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) {
          openNum++;
        }
 else         if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) {
          closedNum++;
        }
 else         if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) {
          resolvedNum++;
        }
 else         if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) {
          notAppNum++;
        }
      }
    }
    request.setAttribute("String_Node_Str",updatedNum + "String_Node_Str");
    request.setAttribute("String_Node_Str",openNum + "String_Node_Str");
    request.setAttribute("String_Node_Str",closedNum + "String_Node_Str");
    request.setAttribute("String_Node_Str",resolvedNum + "String_Node_Str");
    request.setAttribute("String_Node_Str",notAppNum + "String_Node_Str");
    DisplayTableOfContentsBean displayBean=TableOfContentsServlet.getDisplayBean(ecb,getDataSource(),currentStudy);
    Date tmpDate=displayBean.getEventCRF().getDateInterviewed();
    String formattedInterviewerDate;
    try {
      DateFormat local_df=new SimpleDateFormat(resformat.getString("String_Node_Str"),ResourceBundleProvider.getLocale());
      formattedInterviewerDate=local_df.format(tmpDate);
    }
 catch (    Exception e) {
      formattedInterviewerDate="String_Node_Str";
    }
    HashMap presetVals=(HashMap)session.getAttribute("String_Node_Str");
    if (presetVals == null) {
      presetVals=new HashMap();
      session.setAttribute("String_Node_Str",presetVals);
    }
    presetVals.put("String_Node_Str",formattedInterviewerDate);
    request.setAttribute("String_Node_Str",displayBean);
    ArrayList sections=displayBean.getSections();
    request.setAttribute("String_Node_Str",sections.size() + "String_Node_Str");
    if (!sections.isEmpty()) {
      if (sectionId == 0) {
        SectionBean firstSec=(SectionBean)sections.get(0);
        sectionId=firstSec.getId();
      }
    }
 else {
      addPageMessage(respage.getString("String_Node_Str"),request);
      forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET,request,response);
      return;
    }
  }
 else   if (crfVersionId > 0) {
    DisplayTableOfContentsBean displayBean=ViewTableOfContentServlet.getDisplayBean(getDataSource(),crfVersionId);
    request.setAttribute("String_Node_Str",displayBean);
    ArrayList sections=displayBean.getSections();
    request.setAttribute("String_Node_Str",sections.size() + "String_Node_Str");
    if (!sections.isEmpty()) {
      if (sectionId == 0) {
        SectionBean firstSec=(SectionBean)sections.get(0);
        sectionId=firstSec.getId();
      }
    }
 else {
      addPageMessage(respage.getString("String_Node_Str"),request);
      if (eventCRFId == 0) {
        forwardPage(Page.CRF_LIST_SERVLET,request,response);
      }
 else {
        forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET,request,response);
      }
      return;
    }
  }
  sb=(SectionBean)sdao.findByPK(sectionId);
  if (eventCRFId == 0) {
    ecb=new EventCRFBean();
    ecb.setCRFVersionId(sb.getCRFVersionId());
    if (currentStudy.getParentStudyId() > 0) {
      StudyDAO studydao=new StudyDAO(getDataSource());
      StudyBean parentStudy=(StudyBean)studydao.findByPK(currentStudy.getParentStudyId());
      request.setAttribute("String_Node_Str",parentStudy.getName());
      request.setAttribute("String_Node_Str",currentStudy.getName());
    }
 else {
      request.setAttribute("String_Node_Str",currentStudy.getName());
    }
  }
 else {
    ecb=(EventCRFBean)ecdao.findByPK(eventCRFId);
    request.setAttribute(INPUT_EVENT_CRF,ecb);
    request.setAttribute(SECTION_BEAN,sb);
    StudySubjectDAO ssdao=new StudySubjectDAO(getDataSource());
    StudySubjectBean sub=(StudySubjectBean)ssdao.findByPK(ecb.getStudySubjectId());
    SubjectDAO subjectDao=new SubjectDAO(getDataSource());
    int subjectId=sub.getSubjectId();
    int studyId=sub.getStudyId();
    SubjectBean subject=(SubjectBean)subjectDao.findByPK(subjectId);
    if (currentStudy.getStudyParameterConfig().getCollectDob().equals("String_Node_Str")) {
      StudyEventDAO sedao=new StudyEventDAO(getDataSource());
      StudyEventBean se=(StudyEventBean)sedao.findByPK(ecb.getStudyEventId());
      StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(getDataSource());
      StudyEventDefinitionBean sed=(StudyEventDefinitionBean)seddao.findByPK(se.getStudyEventDefinitionId());
      se.setStudyEventDefinition(sed);
      request.setAttribute("String_Node_Str",se);
      age=Utils.getInstacne().processAge(sub.getEnrollmentDate(),subject.getDateOfBirth());
    }
    StudyDAO studydao=new StudyDAO(getDataSource());
    StudyBean study=(StudyBean)studydao.findByPK(studyId);
    if (study.getParentStudyId() > 0) {
      StudyBean parentStudy=(StudyBean)studydao.findByPK(study.getParentStudyId());
      request.setAttribute("String_Node_Str",parentStudy.getName());
      request.setAttribute("String_Node_Str",study.getName());
    }
 else {
      request.setAttribute("String_Node_Str",study.getName());
    }
    request.setAttribute("String_Node_Str",sub);
    request.setAttribute("String_Node_Str",subject);
    request.setAttribute("String_Node_Str",age);
  }
  boolean hasItemGroup=false;
  ItemGroupDAO igdao=new ItemGroupDAO(getDataSource());
  List<ItemGroupBean> itemGroups=igdao.findLegitGroupBySectionId(sectionId);
  if (!itemGroups.isEmpty()) {
    hasItemGroup=true;
  }
  DisplaySectionBean dsb;
  request.setAttribute(EVENT_DEF_CRF_BEAN,edcb);
  request.setAttribute(INPUT_EVENT_CRF,ecb);
  request.setAttribute(SECTION_BEAN,sb);
  dsb=super.getDisplayBean(hasItemGroup,false,request,isSubmitted);
  FormDiscrepancyNotes discNotes=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
  if (discNotes == null) {
    discNotes=new FormDiscrepancyNotes();
    session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
  }
  List<DisplayItemWithGroupBean> displayItemWithGroups=super.createItemWithGroups(dsb,hasItemGroup,eventDefinitionCRFId,request,isSubmitted);
  dsb.setDisplayItemGroups(displayItemWithGroups);
  super.populateNotesWithDBNoteCounts(discNotes,dsb,request);
  if (fp.getString("String_Node_Str") != null && "String_Node_Str".equals(fp.getString("String_Node_Str"))) {
    request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
  }
 else {
    session.removeAttribute("String_Node_Str");
  }
  if ("String_Node_Str".equalsIgnoreCase(action)) {
    LOGGER.info("String_Node_Str" + dsb.getDisplayItemGroups().size());
    DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(getDataSource());
    discNotes=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    for (int i=0; i < dsb.getDisplayItemGroups().size(); i++) {
      DisplayItemWithGroupBean diwb=dsb.getDisplayItemGroups().get(i);
      if (diwb.isInGroup()) {
        List<DisplayItemGroupBean> dgbs=diwb.getItemGroups();
        LOGGER.info("String_Node_Str" + dgbs.size());
        for (int j=0; j < dgbs.size(); j++) {
          DisplayItemGroupBean displayGroup=dgbs.get(j);
          List<DisplayItemBean> items=displayGroup.getItems();
          LOGGER.info("String_Node_Str" + items.size());
          for (          DisplayItemBean displayItem : items) {
            String inputName=getGroupItemInputName(displayGroup,j,displayItem);
            LOGGER.info("String_Node_Str" + inputName);
            LOGGER.info("String_Node_Str" + displayItem.getData().getId());
            AddNewSubjectServlet.saveFieldNotes(inputName,discNotes,dndao,displayItem.getData().getId(),"String_Node_Str",currentStudy);
          }
        }
      }
 else {
        DisplayItemBean dib=diwb.getSingleItem();
        String inputName=getInputName(dib);
        AddNewSubjectServlet.saveFieldNotes(inputName,discNotes,dndao,dib.getData().getId(),"String_Node_Str",currentStudy);
        ArrayList childItems=dib.getChildren();
        for (int j=0; j < childItems.size(); j++) {
          DisplayItemBean child=(DisplayItemBean)childItems.get(j);
          inputName=getInputName(child);
          AddNewSubjectServlet.saveFieldNotes(inputName,discNotes,dndao,dib.getData().getId(),"String_Node_Str",currentStudy);
        }
      }
    }
    addPageMessage("String_Node_Str",request);
    request.setAttribute("String_Node_Str",studySubjectId + "String_Node_Str");
    forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET,request,response);
    return;
  }
 else {
    request.setAttribute(BEAN_DISPLAY,dsb);
    request.setAttribute(BEAN_ANNOTATIONS,ecb.getAnnotations());
    request.setAttribute("String_Node_Str",sb);
    request.setAttribute("String_Node_Str",ecb);
    int tabNum=1;
    if ("String_Node_Str".equalsIgnoreCase(fp.getString("String_Node_Str"))) {
      tabNum=1;
    }
 else {
      tabNum=fp.getInt("String_Node_Str");
    }
    request.setAttribute("String_Node_Str",new Integer(tabNum).toString());
    request.setAttribute(ENCLOSING_PAGE,"String_Node_Str");
    if ("String_Node_Str".equalsIgnoreCase(printVersion)) {
      forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT,request,response);
    }
 else {
      forwardPage(Page.VIEW_SECTION_DATA_ENTRY,request,response);
    }
  }
}