Program: 115115
Project: 115115
Buggy source:
@Override protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
  Stopwatch sw=Stopwatch.createAndStart("String_Node_Str");
  try {
    locale=LocaleResolver.getLocale(request);
    EventCRFBean ecb=(EventCRFBean)request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb=(SectionBean)request.getAttribute(SECTION_BEAN);
    ItemDataDAO iddao=new ItemDataDAO(getDataSource(),locale);
    HttpSession session=request.getSession();
    StudyBean currentStudy=(StudyBean)session.getAttribute("String_Node_Str");
    StudyUserRoleBean currentRole=(StudyUserRoleBean)session.getAttribute("String_Node_Str");
    SectionDAO sdao=new SectionDAO(getDataSource());
    boolean isSubmitted=false;
    boolean hasGroup=false;
    EventCRFDAO ecdao=null;
    FormProcessor fp=new FormProcessor(request);
    logMe("String_Node_Str" + System.currentTimeMillis());
    EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(getDataSource());
    FormDiscrepancyNotes discNotes;
    panel.setStudyInfoShown(false);
    String age="String_Node_Str";
    UserAccountBean ub=(UserAccountBean)request.getSession().getAttribute(USER_BEAN_NAME);
    String instantAtt=CV_INSTANT_META + ecb.getCRFVersionId();
    int isFirstTimeOnSection=fp.getInt("String_Node_Str");
    request.setAttribute("String_Node_Str",isFirstTimeOnSection + "String_Node_Str");
    if (fp.getString(GO_EXIT).equals("String_Node_Str") && !isSubmitted && fp.getString("String_Node_Str").equals("String_Node_Str")&& fp.getString("String_Node_Str").equals("String_Node_Str")) {
      if (getUnavailableCRFList().containsKey(ecb.getId())) {
        int userId=(Integer)getUnavailableCRFList().get(ecb.getId());
        UserAccountDAO udao=new UserAccountDAO(getDataSource());
        UserAccountBean ubean=(UserAccountBean)udao.findByPK(userId);
        addPageMessage(resword.getString("String_Node_Str") + "String_Node_Str" + ubean.getName()+ "String_Node_Str"+ resword.getString("String_Node_Str")+ "String_Node_Str"+ resword.getString("String_Node_Str"),request);
        forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET,request,response);
      }
 else {
        lockThisEventCRF(ecb.getId(),ub.getId());
      }
    }
    if (!ecb.isActive()) {
      throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET,resexception.getString("String_Node_Str"));
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(getDataSource());
    ArrayList<DiscrepancyNoteBean> allNotes=new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteBean> eventCrfNotes=new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteThread> noteThreads=new ArrayList<DiscrepancyNoteThread>();
    dndao=new DiscrepancyNoteDAO(getDataSource());
    allNotes=dndao.findAllTopNotesByEventCRF(ecb.getId());
    eventCrfNotes=dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
    if (!eventCrfNotes.isEmpty()) {
      allNotes.addAll(eventCrfNotes);
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    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++;
        }
      }
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    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");
    String fromViewNotes=fp.getString("String_Node_Str");
    if (fromViewNotes != null && "String_Node_Str".equals(fromViewNotes)) {
      request.setAttribute("String_Node_Str",fromViewNotes);
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    StudySubjectDAO ssdao=new StudySubjectDAO(getDataSource());
    StudySubjectBean ssb=(StudySubjectBean)ssdao.findByPK(ecb.getStudySubjectId());
    Status s=ssb.getStatus();
    if ("String_Node_Str".equalsIgnoreCase(s.getName()) || "String_Node_Str".equalsIgnoreCase(s.getName())) {
      addPageMessage(respage.getString("String_Node_Str") + respage.getString("String_Node_Str"),request);
      request.setAttribute("String_Node_Str",new Integer(ecb.getStudySubjectId()).toString());
      session.removeAttribute(instantAtt);
      forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET,request,response);
    }
    HashMap<String,String> newUploadedFiles=(HashMap<String,String>)session.getAttribute("String_Node_Str");
    if (newUploadedFiles == null) {
      newUploadedFiles=new HashMap<String,String>();
    }
    request.setAttribute("String_Node_Str",newUploadedFiles);
    if (!fp.getString("String_Node_Str").equals("String_Node_Str")) {
      request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    if (!fp.getString(GO_EXIT).equals("String_Node_Str")) {
      session.removeAttribute(GROUP_HAS_DATA);
      session.removeAttribute("String_Node_Str");
      session.removeAttribute("String_Node_Str");
      getUnavailableCRFList().remove(ecb.getId());
      if (newUploadedFiles.size() > 0) {
        if (this.unloadFiles(newUploadedFiles)) {
        }
 else {
          String missed="String_Node_Str";
          Iterator iter=newUploadedFiles.keySet().iterator();
          while (iter.hasNext()) {
            missed+="String_Node_Str" + newUploadedFiles.get(iter.next());
          }
          addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + missed,request);
        }
      }
      session.removeAttribute("String_Node_Str");
      addPageMessage(respage.getString("String_Node_Str"),request);
      if (fromViewNotes != null && "String_Node_Str".equals(fromViewNotes)) {
        String viewNotesURL=(String)session.getAttribute("String_Node_Str");
        if (viewNotesURL != null && viewNotesURL.length() > 0) {
          response.sendRedirect(response.encodeRedirectURL(viewNotesURL));
        }
        return;
      }
      String fromResolvingNotes=fp.getString("String_Node_Str",true);
      String winLocation=(String)session.getAttribute(ViewNotesServlet.WIN_LOCATION);
      session.removeAttribute(instantAtt);
      if (!StringUtil.isBlank(fromResolvingNotes) && !StringUtil.isBlank(winLocation)) {
        response.sendRedirect(response.encodeRedirectURL(winLocation));
      }
 else {
        if (!fp.getString("String_Node_Str").equals("String_Node_Str")) {
          response.sendRedirect(response.encodeRedirectURL(fp.getString("String_Node_Str")));
        }
 else         response.sendRedirect(response.encodeRedirectURL("String_Node_Str"));
      }
      return;
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    hasGroup=checkGroups(fp,ecb);
    Boolean b=(Boolean)request.getAttribute(INPUT_IGNORE_PARAMETERS);
    isSubmitted=fp.isSubmitted() && b == null;
    int eventDefinitionCRFId=0;
    if (fp != null) {
      eventDefinitionCRFId=fp.getInt("String_Node_Str");
    }
    StudyBean study=(StudyBean)session.getAttribute("String_Node_Str");
    logMe("String_Node_Str" + System.currentTimeMillis());
    if (eventDefinitionCRFId <= 0) {
      EventDefinitionCRFBean edcBean=edcdao.findByStudyEventIdAndCRFVersionId(study,ecb.getStudyEventId(),ecb.getCRFVersionId());
      eventDefinitionCRFId=edcBean.getId();
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    logMe("String_Node_Str" + System.currentTimeMillis());
    StudyEventDAO seDao=new StudyEventDAO(getDataSource());
    EventDefinitionCRFBean edcBean=(EventDefinitionCRFBean)edcdao.findByPK(eventDefinitionCRFId);
    EventDefinitionCRFBean edcb=(EventDefinitionCRFBean)edcdao.findByPK(eventDefinitionCRFId);
    request.setAttribute(EVENT_DEF_CRF_BEAN,edcb);
    StudyEventBean studyEventBean=(StudyEventBean)seDao.findByPK(ecb.getStudyEventId());
    edcBean.setId(eventDefinitionCRFId);
    StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(getDataSource());
    StudyEventDefinitionBean studyEventDefinition=(StudyEventDefinitionBean)seddao.findByPK(edcBean.getStudyEventDefinitionId());
    CRFVersionDAO cvdao=new CRFVersionDAO(getDataSource());
    CRFVersionBean crfVersionBean=(CRFVersionBean)cvdao.findByPK(ecb.getCRFVersionId());
    Phase phase2=Phase.INITIAL_DATA_ENTRY;
    if (getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
      phase2=Phase.DOUBLE_DATA_ENTRY;
    }
 else     if (getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET)) {
      phase2=Phase.ADMIN_EDITING;
    }
    logMe("String_Node_Str" + Thread.currentThread());
    logMe("String_Node_Str" + Thread.currentThread() + "String_Node_Str"+ currentStudy+ "String_Node_Str"+ studyEventDefinition+ "String_Node_Str"+ crfVersionBean+ "String_Node_Str"+ studyEventBean+ "String_Node_Str"+ ecb);
    logMe("String_Node_Str" + Thread.currentThread());
    DisplaySectionBean section=getDisplayBean(hasGroup,false,request,isSubmitted);
    if (section.getSection().hasSCDItem()) {
      SimpleConditionalDisplayService cds0=(SimpleConditionalDisplayService)SpringServletAccess.getApplicationContext(getServletContext()).getBean("String_Node_Str");
      section=cds0.initConditionalDisplays(section);
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    String firstFieldId=getSectionFirstFieldId(section.getSection().getId());
    request.setAttribute("String_Node_Str",firstFieldId);
    logMe("String_Node_Str" + System.currentTimeMillis());
    List<DisplayItemWithGroupBean> displayItemWithGroups=createItemWithGroups1(section,hasGroup,eventDefinitionCRFId,request);
    logMe("String_Node_Str" + System.currentTimeMillis());
    this.getItemMetadataService().updateGroupDynamicsInSection(displayItemWithGroups,section.getSection().getId(),ecb);
    section.setDisplayItemGroups(displayItemWithGroups);
    DisplayTableOfContentsBean toc=TableOfContentsServlet.getDisplayBeanWithShownSections(getDataSource(),(DisplayTableOfContentsBean)request.getAttribute(TOC_DISPLAY),(DynamicsMetadataService)SpringServletAccess.getApplicationContext(getServletContext()).getBean("String_Node_Str"));
    request.setAttribute(TOC_DISPLAY,toc);
    LinkedList<Integer> sectionIdsInToc=TableOfContentsServlet.sectionIdsInToc(toc);
    logMe("String_Node_Str" + System.currentTimeMillis());
    int sIndex=TableOfContentsServlet.sectionIndexInToc(section.getSection(),toc,sectionIdsInToc);
    SectionBean previousSec=this.prevSection(section.getSection(),ecb,toc,sIndex);
    logMe("String_Node_Str" + System.currentTimeMillis());
    SectionBean nextSec=this.nextSection(section.getSection(),ecb,toc,sIndex);
    section.setFirstSection(!previousSec.isActive());
    section.setLastSection(!nextSec.isActive());
    SubjectDAO subjectDao=new SubjectDAO(getDataSource());
    StudyDAO studydao=new StudyDAO(getDataSource());
    SubjectBean subject=(SubjectBean)subjectDao.findByPK(ssb.getSubjectId());
    logMe("String_Node_Str" + System.currentTimeMillis());
    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());
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    if (currentStudy.getStudyParameterConfig().getCollectDob().equals("String_Node_Str")) {
      Date enrollmentDate=ssb.getEnrollmentDate();
      age=Utils.getInstacne().processAge(enrollmentDate,subject.getDateOfBirth());
    }
    request.setAttribute("String_Node_Str",ssb);
    request.setAttribute("String_Node_Str",subject);
    request.setAttribute("String_Node_Str",ecb);
    request.setAttribute("String_Node_Str",age);
    request.setAttribute("String_Node_Str",((SecurityManager)SpringServletAccess.getApplicationContext(getServletContext()).getBean("String_Node_Str")).encrytPassword("String_Node_Str",getUserDetails()));
    fp.addPresetValue(INPUT_INTERVIEWER,ecb.getInterviewerName());
    if (ecb.getDateInterviewed() != null) {
      String idateFormatted=local_df.format(ecb.getDateInterviewed());
      fp.addPresetValue(INPUT_INTERVIEW_DATE,idateFormatted);
    }
 else {
      fp.addPresetValue(INPUT_INTERVIEW_DATE,"String_Node_Str");
    }
    setPresetValues(fp.getPresetValues(),request);
    logMe("String_Node_Str" + System.currentTimeMillis());
    if (!isSubmitted) {
      logMe("String_Node_Str" + System.currentTimeMillis());
      long t=System.currentTimeMillis();
      request.setAttribute(BEAN_DISPLAY,section);
      request.setAttribute(BEAN_ANNOTATIONS,getEventCRFAnnotations(request));
      session.setAttribute("String_Node_Str",null);
      session.setAttribute("String_Node_Str",null);
      session.setAttribute(DataEntryServlet.NOTE_SUBMITTED,null);
      discNotes=new FormDiscrepancyNotes();
      section=populateNotesWithDBNoteCounts(discNotes,section,request);
      populateInstantOnChange(request.getSession(),ecb,section);
      logger.debug("String_Node_Str" + discNotes.getFieldNotes().toString());
      logger.debug("String_Node_Str" + discNotes.getNumExistingFieldNotes().toString());
      session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
      if (section.getSection().hasSCDItem()) {
        section=SCDItemDisplayInfo.generateSCDDisplayInfo(section,this.getServletPage(request).equals(Page.INITIAL_DATA_ENTRY) || this.getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET) && !this.isAdminForcedReasonForChange(request));
      }
      int keyId=ecb.getId();
      session.removeAttribute(DoubleDataEntryServlet.COUNT_VALIDATE + keyId);
      setUpPanel(section);
      if (newUploadedFiles.size() > 0) {
        if (this.unloadFiles(newUploadedFiles)) {
        }
 else {
          String missed="String_Node_Str";
          Iterator iter=newUploadedFiles.keySet().iterator();
          while (iter.hasNext()) {
            missed+="String_Node_Str" + newUploadedFiles.get(iter.next());
          }
          addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + missed,request);
        }
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      logMe("String_Node_Str" + (System.currentTimeMillis() - t));
      forwardPage(getJSPPage(),request,response);
      return;
    }
 else {
      logMe("String_Node_Str" + System.currentTimeMillis());
      boolean validate=fp.getBoolean(INPUT_CHECK_INPUTS) && validateInputOnFirstRound();
      errors=new HashMap();
      discNotes=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      if (discNotes == null) {
        discNotes=new FormDiscrepancyNotes();
      }
      List<DisplayItemWithGroupBean> allItems=section.getDisplayItemGroups();
      String attachedFilePath=Utils.getAttachedFilePath(currentStudy);
      DiscrepancyValidator v=new DiscrepancyValidator(request,discNotes);
      RuleValidator ruleValidator=new RuleValidator(request);
      logger.debug("String_Node_Str" + allItems.size());
      logMe("String_Node_Str" + System.currentTimeMillis());
      for (int i=0; i < allItems.size(); i++) {
        logger.trace("String_Node_Str" + i);
        DisplayItemWithGroupBean diwg=allItems.get(i);
        if (diwg.isInGroup()) {
          DisplayItemGroupBean dgb=diwg.getItemGroup();
          List<DisplayItemGroupBean> dbGroups=diwg.getDbItemGroups();
          List<DisplayItemGroupBean> formGroups=new ArrayList<DisplayItemGroupBean>();
          logger.debug("String_Node_Str" + dbGroups.size());
          if (validate) {
            logger.debug("String_Node_Str" + dgb.getGroupMetaBean().getName());
            formGroups=validateDisplayItemGroupBean(v,dgb,dbGroups,formGroups,request,response);
            logger.debug("String_Node_Str" + formGroups.size());
          }
 else {
            logger.debug("String_Node_Str" + dgb.getGroupMetaBean().getName());
            formGroups=loadFormValueForItemGroup(dgb,dbGroups,formGroups,eventDefinitionCRFId,request);
            logger.debug("String_Node_Str" + formGroups.size());
          }
          diwg.setItemGroup(dgb);
          diwg.setItemGroups(formGroups);
          allItems.set(i,diwg);
        }
 else {
          DisplayItemBean dib=diwg.getSingleItem();
          if (validate) {
            String itemName=getInputName(dib);
            dib=validateDisplayItemBean(v,dib,"String_Node_Str",request);
            logger.debug("String_Node_Str" + itemName);
            logger.debug("String_Node_Str" + itemName + "String_Node_Str"+ fp.getString(itemName));
            logger.debug("String_Node_Str" + itemName + "String_Node_Str"+ dib.getMetadata().getResponseSet().getOptions().size()+ "String_Node_Str");
          }
 else {
            String itemName=getInputName(dib);
            logger.debug("String_Node_Str" + itemName + "String_Node_Str"+ fp.getString(itemName));
            dib=loadFormValue(dib,request);
          }
          ArrayList children=dib.getChildren();
          for (int j=0; j < children.size(); j++) {
            DisplayItemBean child=(DisplayItemBean)children.get(j);
            String itemName=getInputName(child);
            child.loadFormValue(fp.getString(itemName));
            if (validate) {
              child=validateDisplayItemBean(v,child,itemName,request);
            }
 else {
              child=loadFormValue(child,request);
            }
            logger.debug("String_Node_Str" + itemName + "String_Node_Str"+ child.getData().getValue());
            children.set(j,child);
          }
          dib.setChildren(children);
          diwg.setSingleItem(runDynamicsItemCheck(dib,null,request));
          logger.debug("String_Node_Str" + i);
          allItems.set(i,diwg);
        }
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      List<ItemBean> itemBeansWithSCDShown=new ArrayList<ItemBean>();
      if (validate && section.getSection().hasSCDItem()) {
        logMe("String_Node_Str" + System.currentTimeMillis());
        for (int i=0; i < allItems.size(); ++i) {
          DisplayItemBean dib=allItems.get(i).getSingleItem();
          ItemFormMetadataBean ifmb=dib.getMetadata();
          if (ifmb.getParentId() == 0) {
            if (dib.getScdData().getScdSetsForControl().size() > 0) {
              section.setShowSCDItemIds(SimpleConditionalDisplayService.conditionalDisplayToBeShown(dib,section.getShowSCDItemIds()));
            }
            if (dib.getScdData().getScdItemMetadataBean().getScdItemFormMetadataId() > 0) {
              dib.setIsSCDtoBeShown(section.getShowSCDItemIds().contains(dib.getMetadata().getItemId()));
              if (dib.getIsSCDtoBeShown())               itemBeansWithSCDShown.add(dib.getItem());
              validateSCDItemBean(v,dib);
            }
            ArrayList<DisplayItemBean> children=dib.getChildren();
            for (int j=0; j < children.size(); j++) {
              DisplayItemBean child=children.get(j);
              if (child.getScdData().getScdSetsForControl().size() > 0) {
                section.setShowSCDItemIds(SimpleConditionalDisplayService.conditionalDisplayToBeShown(child,section.getShowSCDItemIds()));
              }
              if (child.getScdData().getScdItemMetadataBean().getScdItemFormMetadataId() > 0) {
                child.setIsSCDtoBeShown(section.getShowSCDItemIds().contains(child.getMetadata().getItemId()));
                if (child.getIsSCDtoBeShown())                 itemBeansWithSCDShown.add(dib.getItem());
                validateSCDItemBean(v,child);
              }
            }
          }
        }
        logMe("String_Node_Str" + System.currentTimeMillis());
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      List<RuleSetBean> ruleSets=createAndInitializeRuleSet(currentStudy,studyEventDefinition,crfVersionBean,studyEventBean,ecb,true,request,response,itemBeansWithSCDShown);
      boolean shouldRunRules=getRuleSetService(request).shouldRunRulesForRuleSets(ruleSets,phase2);
      HashMap<String,ArrayList<String>> groupOrdinalPLusItemOid=null;
      groupOrdinalPLusItemOid=runRules(allItems,ruleSets,true,shouldRunRules,MessageType.ERROR,phase2,ecb,request);
      logMe("String_Node_Str" + System.currentTimeMillis());
      for (int i=0; i < allItems.size(); i++) {
        DisplayItemWithGroupBean diwg=allItems.get(i);
        if (diwg.isInGroup()) {
          DisplayItemGroupBean dgb=diwg.getItemGroup();
          List<DisplayItemGroupBean> dbGroups=diwg.getDbItemGroups();
          List<DisplayItemGroupBean> formGroups=new ArrayList<DisplayItemGroupBean>();
          if (validate) {
            formGroups=validateDisplayItemGroupBean(v,dgb,dbGroups,formGroups,ruleValidator,groupOrdinalPLusItemOid,request,response);
            logger.debug("String_Node_Str" + formGroups.size());
          }
          diwg.setItemGroup(dgb);
          diwg.setItemGroups(formGroups);
          allItems.set(i,diwg);
        }
 else {
          DisplayItemBean dib=diwg.getSingleItem();
          if (validate) {
            String itemName=getInputName(dib);
            dib=validateDisplayItemBean(v,dib,"String_Node_Str",ruleValidator,groupOrdinalPLusItemOid,false,null,request);
          }
          ArrayList children=dib.getChildren();
          for (int j=0; j < children.size(); j++) {
            DisplayItemBean child=(DisplayItemBean)children.get(j);
            String itemName=getInputName(child);
            child.loadFormValue(fp.getString(itemName));
            if (validate) {
              child=validateDisplayItemBean(v,child,"String_Node_Str",ruleValidator,groupOrdinalPLusItemOid,false,null,request);
            }
            children.set(j,child);
            logger.debug("String_Node_Str" + j);
          }
          dib.setChildren(children);
          diwg.setSingleItem(runDynamicsItemCheck(dib,null,request));
          logger.debug("String_Node_Str" + i);
          allItems.set(i,diwg);
        }
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      HashMap<String,ItemBean> scoreItems=new HashMap<String,ItemBean>();
      HashMap<String,String> scoreItemdata=new HashMap<String,String>();
      HashMap<Integer,String> oldItemdata=prepareSectionItemdata(sb.getId(),request);
      TreeSet<String> changedItems=new TreeSet<String>();
      ArrayList<DisplayItemBean> changedItemsList=new ArrayList<DisplayItemBean>();
      HashMap<String,DisplayItemGroupBean> changedItemsMap=new HashMap<String,DisplayItemGroupBean>();
      HashMap<Integer,TreeSet<Integer>> itemOrdinals=prepareItemdataOrdinals(request);
      updateDataOrdinals(allItems);
      section.setDisplayItemGroups(allItems);
      scoreItems=prepareScoreItems(request);
      scoreItemdata=prepareScoreItemdata(request);
      logMe("String_Node_Str" + System.currentTimeMillis());
      for (int i=0; i < allItems.size(); i++) {
        DisplayItemWithGroupBean diwb=allItems.get(i);
        if (diwb.isInGroup()) {
          List<DisplayItemGroupBean> dbGroups=diwb.getDbItemGroups();
          for (int j=0; j < dbGroups.size(); j++) {
            DisplayItemGroupBean displayGroup=dbGroups.get(j);
            List<DisplayItemBean> items=displayGroup.getItems();
            if ("String_Node_Str".equalsIgnoreCase(displayGroup.getEditFlag())) {
              for (              DisplayItemBean displayItem : items) {
                int itemId=displayItem.getItem().getId();
                int ordinal=displayItem.getData().getOrdinal();
                if (itemOrdinals.containsKey(itemId)) {
                  itemOrdinals.get(itemId).remove(ordinal);
                }
                if (scoreItemdata.containsKey(itemId + "String_Node_Str" + ordinal)) {
                  scoreItemdata.remove(itemId + "String_Node_Str" + ordinal);
                }
                changedItems.add(displayItem.getItem().getName());
                changedItemsList.add(displayItem);
                String formName=displayItem.getItem().getName();
                if (displayGroup.isAuto()) {
                  formName=getGroupItemInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + formName);
                }
 else {
                  formName=getGroupItemManualInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + formName);
                }
                changedItemsMap.put(formName,displayGroup);
                logger.debug("String_Node_Str" + formName);
              }
            }
          }
          List<DisplayItemGroupBean> dgbs=diwb.getItemGroups();
          int groupsize=dgbs.size();
          HashMap<Integer,Integer> maxOrdinals=new HashMap<Integer,Integer>();
          boolean first=true;
          for (int j=0; j < dgbs.size(); j++) {
            DisplayItemGroupBean displayGroup=dgbs.get(j);
            List<DisplayItemBean> items=displayGroup.getItems();
            boolean isAdd="String_Node_Str".equalsIgnoreCase(displayGroup.getEditFlag()) ? true : false;
            for (            DisplayItemBean displayItem : items) {
              ItemBean ib=displayItem.getItem();
              String itemName=ib.getName();
              int itemId=ib.getId();
              if (first) {
                maxOrdinals.put(itemId,iddao.getMaxOrdinalForGroup(ecb,sb,displayGroup.getItemGroupBean()));
              }
              ItemDataBean idb=displayItem.getData();
              String value=idb.getValue();
              scoreItems.put(itemName,ib);
              int ordinal=displayItem.getData().getOrdinal();
              if (isAdd && scoreItemdata.containsKey(itemId + "String_Node_Str" + ordinal)) {
                int formMax=1;
                if (maxOrdinals.containsKey(itemId)) {
                  formMax=maxOrdinals.get(itemId);
                }
                int dbMax=iddao.getMaxOrdinalForGroup(ecb,sb,displayGroup.getItemGroupBean());
                ordinal=ordinal >= dbMax ? formMax + 1 : ordinal;
                maxOrdinals.put(itemId,ordinal);
                displayItem.getData().setOrdinal(ordinal);
                scoreItemdata.put(itemId + "String_Node_Str" + ordinal,value);
              }
 else {
                scoreItemdata.put(itemId + "String_Node_Str" + ordinal,value);
              }
              if (itemOrdinals.containsKey(itemId)) {
                itemOrdinals.get(itemId).add(ordinal);
              }
 else {
                TreeSet<Integer> ordinalSet=new TreeSet<Integer>();
                ordinalSet.add(ordinal);
                itemOrdinals.put(itemId,ordinalSet);
              }
              if (isChanged(displayItem,oldItemdata,attachedFilePath)) {
                changedItems.add(itemName);
                changedItemsList.add(displayItem);
                String formName=displayItem.getItem().getName();
                if (displayGroup.isAuto()) {
                  formName=getGroupItemInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + formName);
                }
 else {
                  formName=getGroupItemManualInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + formName);
                }
                changedItemsMap.put(formName,displayGroup);
                logger.debug("String_Node_Str" + formName);
              }
            }
            first=false;
          }
        }
 else {
          DisplayItemBean dib=diwb.getSingleItem();
          ItemBean ib=dib.getItem();
          ItemDataBean idb=dib.getData();
          int itemId=ib.getId();
          String itemName=ib.getName();
          String value=idb.getValue();
          scoreItems.put(itemName,ib);
          TreeSet<Integer> ordinalset=new TreeSet<Integer>();
          ordinalset.add(1);
          itemOrdinals.put(itemId,ordinalset);
          scoreItemdata.put(itemId + "String_Node_Str" + 1,value);
          if (isChanged(idb,oldItemdata,dib,attachedFilePath)) {
            changedItems.add(itemName);
            changedItemsList.add(dib);
          }
          ArrayList children=dib.getChildren();
          for (int j=0; j < children.size(); j++) {
            DisplayItemBean child=(DisplayItemBean)children.get(j);
            ItemBean cib=child.getItem();
            scoreItems.put(cib.getName(),cib);
            TreeSet<Integer> cordinalset=new TreeSet<Integer>();
            cordinalset.add(1);
            itemOrdinals.put(itemId,cordinalset);
            scoreItemdata.put(cib.getId() + "String_Node_Str" + 1,child.getData().getValue());
            if (isChanged(child.getData(),oldItemdata,child,attachedFilePath)) {
              changedItems.add(itemName);
              changedItemsList.add(child);
            }
          }
        }
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      ScoreItemValidator sv=new ScoreItemValidator(request,discNotes);
      SessionManager sm=(SessionManager)request.getSession().getAttribute("String_Node_Str");
      ScoreCalculator sc=new ScoreCalculator(sm,ecb,ub);
      logMe("String_Node_Str" + System.currentTimeMillis());
      for (int i=0; i < allItems.size(); i++) {
        DisplayItemWithGroupBean diwb=allItems.get(i);
        if (diwb.isInGroup()) {
          List<DisplayItemGroupBean> dgbs=diwb.getItemGroups();
          for (int j=0; j < dgbs.size(); j++) {
            DisplayItemGroupBean displayGroup=dgbs.get(j);
            List<DisplayItemBean> items=displayGroup.getItems();
            for (            DisplayItemBean displayItem : items) {
              ItemFormMetadataBean ifmb=displayItem.getMetadata();
              int responseTypeId=ifmb.getResponseSet().getResponseTypeId();
              if (responseTypeId == 8 || responseTypeId == 9) {
                StringBuffer err=new StringBuffer();
                ResponseOptionBean robBean=(ResponseOptionBean)ifmb.getResponseSet().getOptions().get(0);
                String value="String_Node_Str";
                String inputName="String_Node_Str";
                if (displayGroup.isAuto()) {
                  inputName=getGroupItemInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + inputName);
                }
 else {
                  inputName=getGroupItemManualInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + inputName);
                }
                if (robBean.getValue().startsWith("String_Node_Str") || robBean.getValue().startsWith("String_Node_Str")) {
                  value=fp.getString(inputName);
                  logger.debug("String_Node_Str" + fp.getString(inputName) + "String_Node_Str"+ displayItem.getItem().getName()+ "String_Node_Str"+ inputName);
                }
 else {
                  value=sc.doCalculation(displayItem,scoreItems,scoreItemdata,itemOrdinals,err,displayItem.getData().getOrdinal());
                }
                displayItem.loadFormValue(value);
                if (isChanged(displayItem,oldItemdata,attachedFilePath)) {
                  changedItems.add(displayItem.getItem().getName());
                  changedItemsList.add(displayItem);
                }
                request.setAttribute(inputName,value);
                if (validate) {
                  displayItem=validateCalcTypeDisplayItemBean(sv,displayItem,inputName,request);
                  if (err.length() > 0) {
                    Validation validation=new Validation(Validator.CALCULATION_FAILED);
                    validation.setErrorMessage(err.toString());
                    sv.addValidation(inputName,validation);
                  }
                }
              }
            }
          }
        }
 else {
          DisplayItemBean dib=diwb.getSingleItem();
          ItemFormMetadataBean ifmb=dib.getMetadata();
          int responseTypeId=ifmb.getResponseSet().getResponseTypeId();
          if (responseTypeId == 8 || responseTypeId == 9) {
            StringBuffer err=new StringBuffer();
            ResponseOptionBean robBean=(ResponseOptionBean)ifmb.getResponseSet().getOptions().get(0);
            String value="String_Node_Str";
            if (robBean.getValue().startsWith("String_Node_Str") || robBean.getValue().startsWith("String_Node_Str")) {
              String itemName=getInputName(dib);
              value=fp.getString(itemName);
              logger.debug("String_Node_Str" + fp.getString(itemName) + "String_Node_Str"+ dib.getItem().getName());
              logger.debug("String_Node_Str" + fp.getString(dib.getItem().getName()));
            }
 else {
              value=sc.doCalculation(dib,scoreItems,scoreItemdata,itemOrdinals,err,1);
            }
            dib.loadFormValue(value);
            if (isChanged(dib.getData(),oldItemdata,dib,attachedFilePath)) {
              changedItems.add(dib.getItem().getName());
              changedItemsList.add(dib);
            }
            String inputName=getInputName(dib);
            request.setAttribute(inputName,value);
            if (validate) {
              dib=validateCalcTypeDisplayItemBean(sv,dib,"String_Node_Str",request);
              if (err.length() > 0) {
                Validation validation=new Validation(Validator.CALCULATION_FAILED);
                validation.setErrorMessage(err.toString());
                sv.addValidation(inputName,validation);
              }
            }
          }
          ArrayList children=dib.getChildren();
          for (int j=0; j < children.size(); j++) {
            DisplayItemBean child=(DisplayItemBean)children.get(j);
            ItemFormMetadataBean cifmb=child.getMetadata();
            int resTypeId=cifmb.getResponseSet().getResponseTypeId();
            if (resTypeId == 8 || resTypeId == 9) {
              StringBuffer cerr=new StringBuffer();
              child.getDbData().setValue(child.getData().getValue());
              ResponseOptionBean crobBean=(ResponseOptionBean)cifmb.getResponseSet().getOptions().get(0);
              String cvalue="String_Node_Str";
              if (crobBean.getValue().startsWith("String_Node_Str") || crobBean.getValue().startsWith("String_Node_Str")) {
                String itemName=getInputName(child);
                cvalue=fp.getString(itemName);
                logger.debug("String_Node_Str" + fp.getString(itemName) + "String_Node_Str"+ child.getItem().getName());
              }
 else {
                cvalue=sc.doCalculation(child,scoreItems,scoreItemdata,itemOrdinals,cerr,1);
              }
              child.loadFormValue(cvalue);
              if (isChanged(child.getData(),oldItemdata,child,attachedFilePath)) {
                changedItems.add(child.getItem().getName());
                changedItemsList.add(child);
              }
              String cinputName=getInputName(child);
              request.setAttribute(cinputName,cvalue);
              if (validate) {
                child=validateCalcTypeDisplayItemBean(sv,child,"String_Node_Str",request);
                if (cerr.length() > 0) {
                  Validation cvalidation=new Validation(Validator.CALCULATION_FAILED);
                  cvalidation.setErrorMessage(cerr.toString());
                  sv.addValidation(cinputName,cvalidation);
                }
              }
            }
            children.set(j,child);
          }
        }
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      section.setDisplayItemGroups(allItems);
      section=populateNotesWithDBNoteCounts(discNotes,section,request);
      populateInstantOnChange(request.getSession(),ecb,section);
      if (currentStudy.getStudyParameterConfig().getInterviewerNameRequired().equals("String_Node_Str")) {
        v.addValidation(INPUT_INTERVIEWER,Validator.NO_BLANKS);
      }
      if (currentStudy.getStudyParameterConfig().getInterviewDateRequired().equals("String_Node_Str")) {
        v.addValidation(INPUT_INTERVIEW_DATE,Validator.NO_BLANKS);
      }
      if (!StringUtil.isBlank(fp.getString(INPUT_INTERVIEW_DATE))) {
        v.addValidation(INPUT_INTERVIEW_DATE,Validator.IS_A_DATE);
        v.alwaysExecuteLastValidation(INPUT_INTERVIEW_DATE);
      }
      if (section.getSection().hasSCDItem()) {
        section=SCDItemDisplayInfo.generateSCDDisplayInfo(section,this.getServletPage(request).equals(Page.INITIAL_DATA_ENTRY) || this.getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET) && !this.isAdminForcedReasonForChange(request));
      }
      errors=v.validate();
      if (this.isAdminForcedReasonForChange(request) && this.isAdministrativeEditing() && errors.isEmpty()) {
        String error=respage.getString("String_Node_Str");
        int nonforcedChanges=0;
        if (changedItemsList.size() > 0) {
          logger.debug("String_Node_Str" + changedItems.toString() + "String_Node_Str"+ changedItemsList.toString()+ "String_Node_Str"+ changedItemsMap.toString());
          logMe("String_Node_Str" + System.currentTimeMillis());
          for (          DisplayItemBean displayItem : changedItemsList) {
            String formName=getInputName(displayItem);
            ItemDataBean idb=displayItem.getData();
            ItemFormMetadataBean ifmb=displayItem.getMetadata();
            logger.debug("String_Node_Str" + ifmb.getGroupLabel());
            if (!ifmb.getGroupLabel().equalsIgnoreCase("String_Node_Str") && !ifmb.getGroupLabel().equalsIgnoreCase("String_Node_Str")) {
              Iterator iter=changedItemsMap.entrySet().iterator();
              while (iter.hasNext()) {
                Map.Entry<String,DisplayItemGroupBean> pairs=(Map.Entry)iter.next();
                String formName2=pairs.getKey();
                DisplayItemGroupBean dgb=pairs.getValue();
                String testFormName="String_Node_Str";
                if (dgb.isAuto()) {
                  testFormName=getGroupItemInputName(dgb,dgb.getFormInputOrdinal(),displayItem);
                }
 else {
                  testFormName=getGroupItemManualInputName(dgb,dgb.getFormInputOrdinal(),displayItem);
                }
                logger.debug("String_Node_Str" + testFormName);
                int existingNotes=dndao.findNumExistingNotesForItem(idb.getId());
                if (testFormName.equals(formName2)) {
                  formName=formName2;
                  this.setReasonForChangeError(idb,formName,error,request);
                  changedItemsMap.remove(formName2);
                  logger.debug("String_Node_Str" + formName);
                  break;
                }
              }
            }
 else {
              this.setReasonForChangeError(idb,formName,error,request);
              logger.debug("String_Node_Str" + formName);
            }
          }
          logMe("String_Node_Str" + System.currentTimeMillis());
        }
        if (nonforcedChanges > 0) {
        }
      }
      logger.debug("String_Node_Str" + errors.toString());
      logMe("String_Node_Str" + System.currentTimeMillis());
      if (errors.isEmpty() && shouldRunRules) {
        logger.debug("String_Node_Str");
        if (session.getAttribute("String_Node_Str") != null) {
          HashMap h=ruleValidator.validate();
          Set<String> a=(Set<String>)session.getAttribute("String_Node_Str");
          Set<String> ba=h.keySet();
          Boolean showErrors=false;
          for (          Object key : ba) {
            if (!a.contains(key)) {
              showErrors=true;
            }
          }
          if (showErrors) {
            errors=h;
            if (errors.size() > 0) {
              session.setAttribute("String_Node_Str","String_Node_Str");
              session.setAttribute("String_Node_Str",errors.keySet());
            }
 else {
              session.setAttribute("String_Node_Str",null);
              session.setAttribute("String_Node_Str",null);
            }
          }
 else {
            session.setAttribute("String_Node_Str",null);
            session.setAttribute("String_Node_Str",null);
          }
        }
 else         if (session.getAttribute("String_Node_Str") != null && session.getAttribute("String_Node_Str").toString().equals("String_Node_Str")) {
          session.setAttribute("String_Node_Str",null);
          session.setAttribute("String_Node_Str",null);
        }
 else {
          errors=ruleValidator.validate();
          if (errors.size() > 0) {
            session.setAttribute("String_Node_Str","String_Node_Str");
            session.setAttribute("String_Node_Str",errors.keySet());
          }
        }
      }
      if (!errors.isEmpty()) {
        logger.debug("String_Node_Str");
        String[] textFields={INPUT_INTERVIEWER,INPUT_INTERVIEW_DATE};
        fp.setCurrentStringValuesAsPreset(textFields);
        setPresetValues(fp.getPresetValues(),request);
        logMe("String_Node_Str" + System.currentTimeMillis());
        HashMap<String,ArrayList<String>> siErrors=sv.validate();
        if (siErrors != null && !siErrors.isEmpty()) {
          Iterator iter=siErrors.keySet().iterator();
          while (iter.hasNext()) {
            String fieldName=iter.next().toString();
            errors.put(fieldName,siErrors.get(fieldName));
          }
        }
        Iterator iter2=errors.keySet().iterator();
        while (iter2.hasNext()) {
          String fieldName=iter2.next().toString();
          logger.debug("String_Node_Str" + fieldName);
        }
        errors=reshuffleErrorGroupNamesKK(errors,allItems,request);
        Iterator iter3=errors.keySet().iterator();
        while (iter3.hasNext()) {
          String fieldName=iter3.next().toString();
          logger.debug("String_Node_Str" + fieldName);
        }
        request.setAttribute("String_Node_Str",fp.getString(INPUT_MARK_COMPLETE));
        request.setAttribute(BEAN_DISPLAY,section);
        request.setAttribute(BEAN_ANNOTATIONS,fp.getString(INPUT_ANNOTATIONS));
        setInputMessages(errors,request);
        addPageMessage(respage.getString("String_Node_Str"),request);
        request.setAttribute("String_Node_Str","String_Node_Str");
        session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
        setUpPanel(section);
        forwardPage(getJSPPage(),request,response);
      }
 else {
        logger.debug("String_Node_Str");
        logMe("String_Node_Str" + System.currentTimeMillis());
        boolean success=true;
        boolean temp=true;
        ecb.setInterviewerName(fp.getString(INPUT_INTERVIEWER));
        if (!StringUtil.isBlank(fp.getString(INPUT_INTERVIEW_DATE))) {
          ecb.setDateInterviewed(fp.getDate(INPUT_INTERVIEW_DATE));
        }
 else {
          ecb.setDateInterviewed(null);
        }
        if (ecdao == null) {
          ecdao=new EventCRFDAO(getDataSource());
        }
        DataEntryStage stage=ecb.getStage();
        if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
          ecb.setValidatorId(ub.getId());
        }
        if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED) && changedItemsList.size() > 0) {
          studyEventBean.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
          studyEventBean.setUpdater(ub);
          studyEventBean.setUpdatedDate(new Date());
          seDao.update(studyEventBean);
        }
        logger.debug("String_Node_Str",ssb.getStatus().getName());
        if (ssb.getStatus() == Status.SIGNED && changedItemsList.size() > 0) {
          logger.debug("String_Node_Str");
          StudySubjectDAO studySubjectDao=new StudySubjectDAO(getDataSource());
          ssb.setStatus(Status.AVAILABLE);
          ssb.setUpdater(ub);
          ssb.setUpdatedDate(new Date());
          studySubjectDao.update(ssb);
        }
        if (ecb.isSdvStatus() && changedItemsList.size() > 0) {
          logger.debug("String_Node_Str");
          StudySubjectDAO studySubjectDao=new StudySubjectDAO(getDataSource());
          ssb.setStatus(Status.AVAILABLE);
          ssb.setUpdater(ub);
          ssb.setUpdatedDate(new Date());
          studySubjectDao.update(ssb);
          ecb.setSdvStatus(false);
          ecb.setSdvUpdateId(ub.getId());
        }
        ecb=(EventCRFBean)ecdao.update(ecb);
        FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
        dndao=new DiscrepancyNoteDAO(getDataSource());
        AddNewSubjectServlet.saveFieldNotes(INPUT_INTERVIEWER,fdn,dndao,ecb.getId(),"String_Node_Str",currentStudy);
        AddNewSubjectServlet.saveFieldNotes(INPUT_INTERVIEW_DATE,fdn,dndao,ecb.getId(),"String_Node_Str",currentStudy);
        allItems=section.getDisplayItemGroups();
        logger.debug("String_Node_Str" + allItems.size());
        this.output(allItems);
        logMe("String_Node_Str" + System.currentTimeMillis());
        for (int i=0; i < allItems.size(); i++) {
          DisplayItemWithGroupBean diwb=allItems.get(i);
          if (diwb.isInGroup()) {
            List<DisplayItemGroupBean> dgbs=diwb.getItemGroups();
            List<DisplayItemGroupBean> dbGroups=diwb.getDbItemGroups();
            logger.debug("String_Node_Str" + dgbs.size());
            logger.debug("String_Node_Str" + dbGroups.size());
            for (int j=0; j < dgbs.size(); j++) {
              DisplayItemGroupBean displayGroup=dgbs.get(j);
              List<DisplayItemBean> items=displayGroup.getItems();
              int nextOrdinal=iddao.getMaxOrdinalForGroup(ecb,sb,displayGroup.getItemGroupBean()) + 1;
              for (              DisplayItemBean displayItem : items) {
                String fileName=this.addAttachedFilePath(displayItem,attachedFilePath);
                displayItem.setEditFlag(displayGroup.getEditFlag());
                logger.debug("String_Node_Str" + displayItem.getData().getValue());
                if ("String_Node_Str".equalsIgnoreCase(displayItem.getEditFlag()) && fileName.length() > 0 && !newUploadedFiles.containsKey(fileName)) {
                  displayItem.getData().setValue("String_Node_Str");
                }
                temp=writeToDB(displayItem,iddao,nextOrdinal,request);
                logger.debug("String_Node_Str");
                logger.debug("String_Node_Str" + nextOrdinal);
                if (temp && newUploadedFiles.containsKey(fileName)) {
                  newUploadedFiles.remove(fileName);
                }
                String inputName=getGroupItemInputName(displayGroup,j,displayItem);
                if (!displayGroup.isAuto()) {
                  logger.trace("String_Node_Str");
                  inputName=this.getGroupItemManualInputName(displayGroup,j,displayItem);
                }
                if (j == dgbs.size() - 1) {
                  logger.trace("String_Node_Str");
                  int ordinal=j - this.getManualRows(dgbs);
                  logger.debug("String_Node_Str" + ordinal);
                  inputName=getGroupItemInputName(displayGroup,ordinal,displayItem);
                }
                logger.trace("String_Node_Str" + inputName);
                AddNewSubjectServlet.saveFieldNotes(inputName,fdn,dndao,displayItem.getData().getId(),"String_Node_Str",currentStudy);
                success=success && temp;
              }
            }
            for (int j=0; j < dbGroups.size(); j++) {
              DisplayItemGroupBean displayGroup=dbGroups.get(j);
              if ("String_Node_Str".equalsIgnoreCase(displayGroup.getEditFlag())) {
                List<DisplayItemBean> items=displayGroup.getItems();
                for (                DisplayItemBean displayItem : items) {
                  String fileName=this.addAttachedFilePath(displayItem,attachedFilePath);
                  displayItem.setEditFlag(displayGroup.getEditFlag());
                  logger.debug("String_Node_Str" + displayItem.getData().getValue());
                  if ("String_Node_Str".equalsIgnoreCase(displayItem.getEditFlag()) && fileName.length() > 0 && !newUploadedFiles.containsKey(fileName)) {
                    displayItem.getData().setValue("String_Node_Str");
                  }
                  temp=writeToDB(displayItem,iddao,0,request);
                  logger.debug("String_Node_Str");
                  if (temp && newUploadedFiles.containsKey(fileName)) {
                    newUploadedFiles.remove(fileName);
                  }
                  success=success && temp;
                }
              }
            }
          }
 else {
            DisplayItemBean dib=diwb.getSingleItem();
            this.addAttachedFilePath(dib,attachedFilePath);
            temp=writeToDB(dib,iddao,1,request);
            logger.debug("String_Node_Str");
            if (temp && newUploadedFiles.containsKey(dib.getItem().getId() + "String_Node_Str")) {
              newUploadedFiles.remove(dib.getItem().getId() + "String_Node_Str");
            }
            String inputName=getInputName(dib);
            logger.trace("String_Node_Str" + inputName);
            AddNewSubjectServlet.saveFieldNotes(inputName,fdn,dndao,dib.getData().getId(),"String_Node_Str",currentStudy);
            success=success && temp;
            ArrayList childItems=dib.getChildren();
            for (int j=0; j < childItems.size(); j++) {
              DisplayItemBean child=(DisplayItemBean)childItems.get(j);
              this.addAttachedFilePath(child,attachedFilePath);
              temp=writeToDB(child,iddao,1,request);
              logger.debug("String_Node_Str");
              if (temp && newUploadedFiles.containsKey(child.getItem().getId() + "String_Node_Str")) {
                newUploadedFiles.remove(child.getItem().getId() + "String_Node_Str");
              }
              inputName=getInputName(child);
              AddNewSubjectServlet.saveFieldNotes(inputName,fdn,dndao,child.getData().getId(),"String_Node_Str",currentStudy);
              success=success && temp;
            }
          }
        }
        logMe("String_Node_Str" + System.currentTimeMillis());
        logger.debug("String_Node_Str" + phase2.name());
        List<Integer> prevShownDynItemDataIds=shouldRunRules ? this.getItemMetadataService().getDynamicsItemFormMetadataDao().findShowItemDataIdsInSection(section.getSection().getId(),ecb.getCRFVersionId(),ecb.getId()) : new ArrayList<Integer>();
        logMe("String_Node_Str" + System.currentTimeMillis());
        HashMap<String,ArrayList<String>> rulesPostDryRun=runRules(allItems,ruleSets,false,shouldRunRules,MessageType.WARNING,phase2,ecb,request);
        HashMap<String,ArrayList<String>> errorsPostDryRun=new HashMap<String,ArrayList<String>>();
        logMe("String_Node_Str" + System.currentTimeMillis());
        boolean inSameSection=false;
        logMe("String_Node_Str" + System.currentTimeMillis());
        if (!rulesPostDryRun.isEmpty()) {
          Iterator iter3=rulesPostDryRun.keySet().iterator();
          while (iter3.hasNext()) {
            String fieldName=iter3.next().toString();
            logger.debug("String_Node_Str" + fieldName);
            int ordinal=-1;
            String newFieldName=fieldName;
            String[] fieldNames=fieldName.split("String_Node_Str");
            if (fieldNames.length == 2) {
              newFieldName=fieldNames[1];
              if (fieldNames[0].contains("String_Node_Str")) {
                int p1=fieldNames[0].indexOf("String_Node_Str");
                int p2=fieldNames[0].indexOf("String_Node_Str");
                try {
                  ordinal=Integer.valueOf(fieldNames[0].substring(p1 + 1,p2));
                }
 catch (                NumberFormatException e) {
                  ordinal=-1;
                }
                fieldNames[0]=fieldNames[0].substring(0,p1);
              }
            }
            List<DisplayItemWithGroupBean> displayGroupsWithItems=section.getDisplayItemGroups();
            for (int i=0; i < displayGroupsWithItems.size(); i++) {
              DisplayItemWithGroupBean itemWithGroup=displayGroupsWithItems.get(i);
              if (itemWithGroup.isInGroup()) {
                logger.debug("String_Node_Str" + fieldNames[0]);
                List<DisplayItemGroupBean> digbs=itemWithGroup.getItemGroups();
                logger.debug("String_Node_Str" + digbs.size());
                for (int j=0; j < digbs.size(); j++) {
                  DisplayItemGroupBean displayGroup=digbs.get(j);
                  if (displayGroup.getItemGroupBean().getOid().equals(fieldNames[0]) && displayGroup.getOrdinal() == ordinal - 1) {
                    List<DisplayItemBean> items=displayGroup.getItems();
                    for (int k=0; k < items.size(); k++) {
                      DisplayItemBean dib=items.get(k);
                      if (dib.getItem().getOid().equals(newFieldName)) {
                        if (!dib.getMetadata().isShowItem()) {
                          logger.debug("String_Node_Str" + this.getGroupItemInputName(displayGroup,j,dib) + "String_Node_Str"+ fieldName+ "String_Node_Str"+ dib.getMetadata().isShowItem());
                          dib.getMetadata().setShowItem(true);
                        }
                        if (prevShownDynItemDataIds == null || !prevShownDynItemDataIds.contains(dib.getData().getId())) {
                          inSameSection=true;
                          errorsPostDryRun.put(this.getGroupItemInputName(displayGroup,j,dib),rulesPostDryRun.get(fieldName));
                        }
                      }
                      items.set(k,dib);
                    }
                    displayGroup.setItems(items);
                    digbs.set(j,displayGroup);
                  }
                }
                itemWithGroup.setItemGroups(digbs);
              }
 else {
                DisplayItemBean displayItemBean=itemWithGroup.getSingleItem();
                ItemBean itemBean=displayItemBean.getItem();
                if (newFieldName.equals(itemBean.getOid())) {
                  if (!displayItemBean.getMetadata().isShowItem()) {
                    logger.debug("String_Node_Str" + this.getInputName(displayItemBean) + "String_Node_Str"+ fieldName+ "String_Node_Str"+ displayItemBean.getMetadata().isShowItem());
                    displayItemBean.getMetadata().setShowItem(true);
                    if (prevShownDynItemDataIds == null || !prevShownDynItemDataIds.contains(displayItemBean.getData().getId())) {
                      inSameSection=true;
                      errorsPostDryRun.put(this.getInputName(displayItemBean),rulesPostDryRun.get(fieldName));
                    }
                  }
                }
                itemWithGroup.setSingleItem(displayItemBean);
              }
              displayGroupsWithItems.set(i,itemWithGroup);
            }
            logMe("String_Node_Str" + System.currentTimeMillis());
            List<DisplayItemWithGroupBean> itemGroups=section.getDisplayItemGroups();
            for (            DisplayItemWithGroupBean itemGroup : itemGroups) {
              DisplayItemGroupBean displayGroup=itemGroup.getItemGroup();
              if (newFieldName.equals(displayGroup.getItemGroupBean().getOid())) {
                if (!displayGroup.getGroupMetaBean().isShowGroup()) {
                  inSameSection=true;
                  logger.debug("String_Node_Str" + displayGroup.getItemGroupBean().getOid() + "String_Node_Str"+ fieldName+ "String_Node_Str"+ displayGroup.getGroupMetaBean().isShowGroup());
                  errorsPostDryRun.put(displayGroup.getItemGroupBean().getOid(),rulesPostDryRun.get(fieldName));
                  displayGroup.getGroupMetaBean().setShowGroup(true);
                  loadItemsWithGroupRows(itemGroup,sb,edcb,ecb,request);
                }
              }
            }
            logMe("String_Node_Str" + System.currentTimeMillis());
            section.setDisplayItemGroups(displayGroupsWithItems);
            populateInstantOnChange(request.getSession(),ecb,section);
          }
          this.getItemMetadataService().updateGroupDynamicsInSection(displayItemWithGroups,section.getSection().getId(),ecb);
          toc=TableOfContentsServlet.getDisplayBeanWithShownSections(getDataSource(),(DisplayTableOfContentsBean)request.getAttribute(TOC_DISPLAY),(DynamicsMetadataService)SpringServletAccess.getApplicationContext(getServletContext()).getBean("String_Node_Str"));
          request.setAttribute(TOC_DISPLAY,toc);
          sectionIdsInToc=TableOfContentsServlet.sectionIdsInToc(toc);
          sIndex=TableOfContentsServlet.sectionIndexInToc(section.getSection(),toc,sectionIdsInToc);
          previousSec=this.prevSection(section.getSection(),ecb,toc,sIndex);
          nextSec=this.nextSection(section.getSection(),ecb,toc,sIndex);
          section.setFirstSection(!previousSec.isActive());
          section.setLastSection(!nextSec.isActive());
          logger.debug("String_Node_Str" + inSameSection);
          if (inSameSection) {
            String[] textFields={INPUT_INTERVIEWER,INPUT_INTERVIEW_DATE};
            fp.setCurrentStringValuesAsPreset(textFields);
            setPresetValues(fp.getPresetValues(),request);
            request.setAttribute(BEAN_DISPLAY,section);
            request.setAttribute(BEAN_ANNOTATIONS,fp.getString(INPUT_ANNOTATIONS));
            setInputMessages(errorsPostDryRun,request);
            addPageMessage(respage.getString("String_Node_Str"),request);
            request.setAttribute("String_Node_Str","String_Node_Str");
            request.setAttribute("String_Node_Str","String_Node_Str");
            session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
            setUpPanel(section);
            forwardPage(getJSPPage(),request,response);
          }
        }
        if (!inSameSection) {
          ArrayList<String> updateFailedItems=sc.redoCalculations(scoreItems,scoreItemdata,changedItems,itemOrdinals,sb.getId());
          success=updateFailedItems.size() > 0 ? false : true;
          boolean markComplete=fp.getString(INPUT_MARK_COMPLETE).equals(VALUE_YES);
          boolean markSuccessfully=false;
          if (markComplete && section.isLastSection()) {
            logger.debug("String_Node_Str");
            markSuccessfully=markCRFComplete(request);
            logger.debug("String_Node_Str" + markSuccessfully);
            if (!markSuccessfully) {
              request.setAttribute(BEAN_DISPLAY,section);
              request.setAttribute(BEAN_ANNOTATIONS,fp.getString(INPUT_ANNOTATIONS));
              setUpPanel(section);
              forwardPage(getJSPPage(),request,response);
              return;
            }
          }
          String annotations=fp.getString(INPUT_ANNOTATIONS);
          setEventCRFAnnotations(annotations,request);
          Date now=new Date();
          ecb.setUpdatedDate(now);
          ecb.setUpdater(ub);
          ecb=(EventCRFBean)ecdao.update(ecb);
          success=success && ecb.isActive();
          StudyEventDAO sedao=new StudyEventDAO(getDataSource());
          StudyEventBean seb=(StudyEventBean)sedao.findByPK(ecb.getStudyEventId());
          seb.setUpdatedDate(now);
          seb.setUpdater(ub);
          seb=(StudyEventBean)sedao.update(seb);
          success=success && seb.isActive();
          request.setAttribute(INPUT_IGNORE_PARAMETERS,Boolean.TRUE);
          if (newUploadedFiles.size() > 0) {
            if (this.unloadFiles(newUploadedFiles)) {
            }
 else {
              String missed="String_Node_Str";
              Iterator iter=newUploadedFiles.keySet().iterator();
              while (iter.hasNext()) {
                missed+="String_Node_Str" + newUploadedFiles.get(iter.next());
              }
              addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + missed,request);
            }
          }
          if (!success) {
            if (updateFailedItems.size() > 0) {
              String mess="String_Node_Str";
              for (              String ss : updateFailedItems) {
                mess+=ss + "String_Node_Str";
              }
              mess=mess.substring(0,mess.length() - 2);
              addPageMessage(resexception.getString("String_Node_Str") + mess,request);
            }
 else {
              addPageMessage(resexception.getString("String_Node_Str"),request);
            }
            request.setAttribute(BEAN_DISPLAY,section);
            session.removeAttribute(GROUP_HAS_DATA);
            session.removeAttribute(HAS_DATA_FLAG);
            session.removeAttribute(DDE_PROGESS);
            session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
            logger.debug("String_Node_Str");
            session.removeAttribute("String_Node_Str");
            session.removeAttribute(instantAtt);
            forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET,request,response);
          }
 else {
            boolean forwardingSucceeded=false;
            if (!fp.getString(GO_PREVIOUS).equals("String_Node_Str")) {
              if (previousSec.isActive()) {
                forwardingSucceeded=true;
                request.setAttribute(INPUT_EVENT_CRF,ecb);
                request.setAttribute(INPUT_SECTION,previousSec);
                int tabNum=0;
                if (fp.getString("String_Node_Str") == null) {
                  tabNum=1;
                }
 else {
                  tabNum=fp.getInt("String_Node_Str");
                }
                request.setAttribute("String_Node_Str",new Integer(tabNum - 1).toString());
                forwardPage(getServletPage(request),request,response);
              }
            }
 else             if (!fp.getString(GO_NEXT).equals("String_Node_Str")) {
              if (nextSec.isActive()) {
                forwardingSucceeded=true;
                request.setAttribute(INPUT_EVENT_CRF,ecb);
                request.setAttribute(INPUT_SECTION,nextSec);
                int tabNum=0;
                if (fp.getString("String_Node_Str") == null) {
                  tabNum=1;
                }
 else {
                  tabNum=fp.getInt("String_Node_Str");
                }
                request.setAttribute("String_Node_Str",new Integer(tabNum + 1).toString());
                forwardPage(getServletPage(request),request,response);
              }
            }
            if (!forwardingSucceeded) {
              if (markSuccessfully) {
                addPageMessage(respage.getString("String_Node_Str"),request);
                session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
                session.removeAttribute(GROUP_HAS_DATA);
                session.removeAttribute(HAS_DATA_FLAG);
                session.removeAttribute(DDE_PROGESS);
                session.removeAttribute("String_Node_Str");
                request.setAttribute("String_Node_Str",new Integer(ecb.getStudyEventId()).toString());
                forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET,request,response);
              }
 else {
                addPageMessage(respage.getString("String_Node_Str"),request);
                request.setAttribute(INPUT_EVENT_CRF,ecb);
                request.setAttribute(INPUT_EVENT_CRF_ID,new Integer(ecb.getId()).toString());
                if (!section.isLastSection()) {
                  request.setAttribute(INPUT_SECTION,nextSec);
                  request.setAttribute(INPUT_SECTION_ID,new Integer(nextSec.getId()).toString());
                  session.removeAttribute("String_Node_Str");
                }
 else                 if (section.isLastSection()) {
                  session.removeAttribute(GROUP_HAS_DATA);
                  session.removeAttribute(HAS_DATA_FLAG);
                  session.removeAttribute(DDE_PROGESS);
                  session.removeAttribute("String_Node_Str");
                  session.removeAttribute("String_Node_Str");
                  request.setAttribute("String_Node_Str",new Integer(ecb.getStudyEventId()).toString());
                  if (fromViewNotes != null && "String_Node_Str".equals(fromViewNotes)) {
                    String viewNotesPageFileName=(String)session.getAttribute("String_Node_Str");
                    session.removeAttribute("String_Node_Str");
                    session.removeAttribute("String_Node_Str");
                    if (viewNotesPageFileName != null && viewNotesPageFileName.length() > 0) {
                      forwardPage(Page.setNewPage(viewNotesPageFileName,"String_Node_Str"),request,response);
                    }
                  }
                  session.removeAttribute(instantAtt);
                  forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET,request,response);
                  return;
                }
                int tabNum=0;
                if (fp.getString("String_Node_Str") == null) {
                  tabNum=1;
                }
 else {
                  tabNum=fp.getInt("String_Node_Str");
                }
                if (!section.isLastSection()) {
                  request.setAttribute("String_Node_Str",new Integer(tabNum + 1).toString());
                }
                forwardPage(getServletPage(request),request,response);
              }
            }
          }
        }
      }
    }
  }
  finally {
    sw.stop();
  }
}

Fixed version (ground truth):
@Override protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws Exception {
  Stopwatch sw=Stopwatch.createAndStart("String_Node_Str");
  try {
    locale=LocaleResolver.getLocale(request);
    EventCRFBean ecb=(EventCRFBean)request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb=(SectionBean)request.getAttribute(SECTION_BEAN);
    ItemDataDAO iddao=new ItemDataDAO(getDataSource(),locale);
    HttpSession session=request.getSession();
    StudyBean currentStudy=(StudyBean)session.getAttribute("String_Node_Str");
    StudyUserRoleBean currentRole=(StudyUserRoleBean)session.getAttribute("String_Node_Str");
    SectionDAO sdao=new SectionDAO(getDataSource());
    boolean isSubmitted=false;
    boolean hasGroup=false;
    EventCRFDAO ecdao=null;
    FormProcessor fp=new FormProcessor(request);
    logMe("String_Node_Str" + System.currentTimeMillis());
    EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(getDataSource());
    FormDiscrepancyNotes discNotes;
    panel.setStudyInfoShown(false);
    String age="String_Node_Str";
    UserAccountBean ub=(UserAccountBean)request.getSession().getAttribute(USER_BEAN_NAME);
    String instantAtt=CV_INSTANT_META + ecb.getCRFVersionId();
    int isFirstTimeOnSection=fp.getInt("String_Node_Str");
    request.setAttribute("String_Node_Str",isFirstTimeOnSection + "String_Node_Str");
    if (fp.getString(GO_EXIT).equals("String_Node_Str") && !isSubmitted && fp.getString("String_Node_Str").equals("String_Node_Str")&& fp.getString("String_Node_Str").equals("String_Node_Str")) {
      if (getUnavailableCRFList().containsKey(ecb.getId())) {
        int userId=(Integer)getUnavailableCRFList().get(ecb.getId());
        UserAccountDAO udao=new UserAccountDAO(getDataSource());
        UserAccountBean ubean=(UserAccountBean)udao.findByPK(userId);
        addPageMessage(resword.getString("String_Node_Str") + "String_Node_Str" + ubean.getName()+ "String_Node_Str"+ resword.getString("String_Node_Str")+ "String_Node_Str"+ resword.getString("String_Node_Str"),request);
        forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET,request,response);
      }
 else {
        lockThisEventCRF(ecb.getId(),ub.getId());
      }
    }
    if (!ecb.isActive()) {
      throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET,resexception.getString("String_Node_Str"));
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(getDataSource());
    ArrayList<DiscrepancyNoteBean> allNotes=new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteBean> eventCrfNotes=new ArrayList<DiscrepancyNoteBean>();
    List<DiscrepancyNoteThread> noteThreads=new ArrayList<DiscrepancyNoteThread>();
    dndao=new DiscrepancyNoteDAO(getDataSource());
    allNotes=dndao.findAllTopNotesByEventCRF(ecb.getId());
    eventCrfNotes=dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
    if (!eventCrfNotes.isEmpty()) {
      allNotes.addAll(eventCrfNotes);
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    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++;
        }
      }
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    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");
    String fromViewNotes=fp.getString("String_Node_Str");
    if (fromViewNotes != null && "String_Node_Str".equals(fromViewNotes)) {
      request.setAttribute("String_Node_Str",fromViewNotes);
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    StudySubjectDAO ssdao=new StudySubjectDAO(getDataSource());
    StudySubjectBean ssb=(StudySubjectBean)ssdao.findByPK(ecb.getStudySubjectId());
    Status s=ssb.getStatus();
    if ("String_Node_Str".equalsIgnoreCase(s.getName()) || "String_Node_Str".equalsIgnoreCase(s.getName())) {
      addPageMessage(respage.getString("String_Node_Str") + respage.getString("String_Node_Str"),request);
      request.setAttribute("String_Node_Str",new Integer(ecb.getStudySubjectId()).toString());
      session.removeAttribute(instantAtt);
      forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET,request,response);
    }
    HashMap<String,String> newUploadedFiles=(HashMap<String,String>)session.getAttribute("String_Node_Str");
    if (newUploadedFiles == null) {
      newUploadedFiles=new HashMap<String,String>();
    }
    request.setAttribute("String_Node_Str",newUploadedFiles);
    if (!fp.getString("String_Node_Str").equals("String_Node_Str")) {
      request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    if (!fp.getString(GO_EXIT).equals("String_Node_Str")) {
      session.removeAttribute(GROUP_HAS_DATA);
      session.removeAttribute("String_Node_Str");
      session.removeAttribute("String_Node_Str");
      getUnavailableCRFList().remove(ecb.getId());
      if (newUploadedFiles.size() > 0) {
        if (this.unloadFiles(newUploadedFiles)) {
        }
 else {
          String missed="String_Node_Str";
          Iterator iter=newUploadedFiles.keySet().iterator();
          while (iter.hasNext()) {
            missed+="String_Node_Str" + newUploadedFiles.get(iter.next());
          }
          addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + missed,request);
        }
      }
      session.removeAttribute("String_Node_Str");
      addPageMessage(respage.getString("String_Node_Str"),request);
      if (fromViewNotes != null && "String_Node_Str".equals(fromViewNotes)) {
        String viewNotesURL=(String)session.getAttribute("String_Node_Str");
        if (viewNotesURL != null && viewNotesURL.length() > 0) {
          response.sendRedirect(response.encodeRedirectURL(viewNotesURL));
        }
        return;
      }
      String fromResolvingNotes=fp.getString("String_Node_Str",true);
      String winLocation=(String)session.getAttribute(ViewNotesServlet.WIN_LOCATION);
      session.removeAttribute(instantAtt);
      if (!StringUtil.isBlank(fromResolvingNotes) && !StringUtil.isBlank(winLocation)) {
        response.sendRedirect(response.encodeRedirectURL(winLocation));
      }
 else {
        if (!fp.getString("String_Node_Str").equals("String_Node_Str")) {
          response.sendRedirect(response.encodeRedirectURL(fp.getString("String_Node_Str")));
        }
 else         response.sendRedirect(response.encodeRedirectURL("String_Node_Str"));
      }
      return;
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    hasGroup=checkGroups(fp,ecb);
    Boolean b=(Boolean)request.getAttribute(INPUT_IGNORE_PARAMETERS);
    isSubmitted=fp.isSubmitted() && b == null;
    int eventDefinitionCRFId=0;
    if (fp != null) {
      eventDefinitionCRFId=fp.getInt("String_Node_Str");
    }
    StudyBean study=(StudyBean)session.getAttribute("String_Node_Str");
    logMe("String_Node_Str" + System.currentTimeMillis());
    if (eventDefinitionCRFId <= 0) {
      EventDefinitionCRFBean edcBean=edcdao.findByStudyEventIdAndCRFVersionId(study,ecb.getStudyEventId(),ecb.getCRFVersionId());
      eventDefinitionCRFId=edcBean.getId();
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    logMe("String_Node_Str" + System.currentTimeMillis());
    StudyEventDAO seDao=new StudyEventDAO(getDataSource());
    EventDefinitionCRFBean edcBean=(EventDefinitionCRFBean)edcdao.findByPK(eventDefinitionCRFId);
    EventDefinitionCRFBean edcb=(EventDefinitionCRFBean)edcdao.findByPK(eventDefinitionCRFId);
    request.setAttribute(EVENT_DEF_CRF_BEAN,edcb);
    StudyEventBean studyEventBean=(StudyEventBean)seDao.findByPK(ecb.getStudyEventId());
    edcBean.setId(eventDefinitionCRFId);
    StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(getDataSource());
    StudyEventDefinitionBean studyEventDefinition=(StudyEventDefinitionBean)seddao.findByPK(edcBean.getStudyEventDefinitionId());
    CRFVersionDAO cvdao=new CRFVersionDAO(getDataSource());
    CRFVersionBean crfVersionBean=(CRFVersionBean)cvdao.findByPK(ecb.getCRFVersionId());
    Phase phase2=Phase.INITIAL_DATA_ENTRY;
    if (getServletPage(request).equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
      phase2=Phase.DOUBLE_DATA_ENTRY;
    }
 else     if (getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET)) {
      phase2=Phase.ADMIN_EDITING;
    }
    logMe("String_Node_Str" + Thread.currentThread());
    logMe("String_Node_Str" + Thread.currentThread() + "String_Node_Str"+ currentStudy+ "String_Node_Str"+ studyEventDefinition+ "String_Node_Str"+ crfVersionBean+ "String_Node_Str"+ studyEventBean+ "String_Node_Str"+ ecb);
    logMe("String_Node_Str" + Thread.currentThread());
    DisplaySectionBean section=getDisplayBean(hasGroup,false,request,isSubmitted);
    if (section.getSection().hasSCDItem()) {
      SimpleConditionalDisplayService cds0=(SimpleConditionalDisplayService)SpringServletAccess.getApplicationContext(getServletContext()).getBean("String_Node_Str");
      section=cds0.initConditionalDisplays(section);
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    String firstFieldId=getSectionFirstFieldId(section.getSection().getId());
    request.setAttribute("String_Node_Str",firstFieldId);
    logMe("String_Node_Str" + System.currentTimeMillis());
    List<DisplayItemWithGroupBean> displayItemWithGroups=createItemWithGroups(section,hasGroup,eventDefinitionCRFId,request);
    logMe("String_Node_Str" + System.currentTimeMillis());
    this.getItemMetadataService().updateGroupDynamicsInSection(displayItemWithGroups,section.getSection().getId(),ecb);
    section.setDisplayItemGroups(displayItemWithGroups);
    DisplayTableOfContentsBean toc=TableOfContentsServlet.getDisplayBeanWithShownSections(getDataSource(),(DisplayTableOfContentsBean)request.getAttribute(TOC_DISPLAY),(DynamicsMetadataService)SpringServletAccess.getApplicationContext(getServletContext()).getBean("String_Node_Str"));
    request.setAttribute(TOC_DISPLAY,toc);
    LinkedList<Integer> sectionIdsInToc=TableOfContentsServlet.sectionIdsInToc(toc);
    logMe("String_Node_Str" + System.currentTimeMillis());
    int sIndex=TableOfContentsServlet.sectionIndexInToc(section.getSection(),toc,sectionIdsInToc);
    SectionBean previousSec=this.prevSection(section.getSection(),ecb,toc,sIndex);
    logMe("String_Node_Str" + System.currentTimeMillis());
    SectionBean nextSec=this.nextSection(section.getSection(),ecb,toc,sIndex);
    section.setFirstSection(!previousSec.isActive());
    section.setLastSection(!nextSec.isActive());
    SubjectDAO subjectDao=new SubjectDAO(getDataSource());
    StudyDAO studydao=new StudyDAO(getDataSource());
    SubjectBean subject=(SubjectBean)subjectDao.findByPK(ssb.getSubjectId());
    logMe("String_Node_Str" + System.currentTimeMillis());
    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());
    }
    logMe("String_Node_Str" + System.currentTimeMillis());
    if (currentStudy.getStudyParameterConfig().getCollectDob().equals("String_Node_Str")) {
      Date enrollmentDate=ssb.getEnrollmentDate();
      age=Utils.getInstacne().processAge(enrollmentDate,subject.getDateOfBirth());
    }
    request.setAttribute("String_Node_Str",ssb);
    request.setAttribute("String_Node_Str",subject);
    request.setAttribute("String_Node_Str",ecb);
    request.setAttribute("String_Node_Str",age);
    request.setAttribute("String_Node_Str",((SecurityManager)SpringServletAccess.getApplicationContext(getServletContext()).getBean("String_Node_Str")).encrytPassword("String_Node_Str",getUserDetails()));
    fp.addPresetValue(INPUT_INTERVIEWER,ecb.getInterviewerName());
    if (ecb.getDateInterviewed() != null) {
      String idateFormatted=local_df.format(ecb.getDateInterviewed());
      fp.addPresetValue(INPUT_INTERVIEW_DATE,idateFormatted);
    }
 else {
      fp.addPresetValue(INPUT_INTERVIEW_DATE,"String_Node_Str");
    }
    setPresetValues(fp.getPresetValues(),request);
    logMe("String_Node_Str" + System.currentTimeMillis());
    if (!isSubmitted) {
      logMe("String_Node_Str" + System.currentTimeMillis());
      long t=System.currentTimeMillis();
      request.setAttribute(BEAN_DISPLAY,section);
      request.setAttribute(BEAN_ANNOTATIONS,getEventCRFAnnotations(request));
      session.setAttribute("String_Node_Str",null);
      session.setAttribute("String_Node_Str",null);
      session.setAttribute(DataEntryServlet.NOTE_SUBMITTED,null);
      discNotes=new FormDiscrepancyNotes();
      section=populateNotesWithDBNoteCounts(discNotes,section,request);
      populateInstantOnChange(request.getSession(),ecb,section);
      logger.debug("String_Node_Str" + discNotes.getFieldNotes().toString());
      logger.debug("String_Node_Str" + discNotes.getNumExistingFieldNotes().toString());
      session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
      if (section.getSection().hasSCDItem()) {
        section=SCDItemDisplayInfo.generateSCDDisplayInfo(section,this.getServletPage(request).equals(Page.INITIAL_DATA_ENTRY) || this.getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET) && !this.isAdminForcedReasonForChange(request));
      }
      int keyId=ecb.getId();
      session.removeAttribute(DoubleDataEntryServlet.COUNT_VALIDATE + keyId);
      setUpPanel(section);
      if (newUploadedFiles.size() > 0) {
        if (this.unloadFiles(newUploadedFiles)) {
        }
 else {
          String missed="String_Node_Str";
          Iterator iter=newUploadedFiles.keySet().iterator();
          while (iter.hasNext()) {
            missed+="String_Node_Str" + newUploadedFiles.get(iter.next());
          }
          addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + missed,request);
        }
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      logMe("String_Node_Str" + (System.currentTimeMillis() - t));
      forwardPage(getJSPPage(),request,response);
      return;
    }
 else {
      logMe("String_Node_Str" + System.currentTimeMillis());
      boolean validate=fp.getBoolean(INPUT_CHECK_INPUTS) && validateInputOnFirstRound();
      errors=new HashMap();
      discNotes=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      if (discNotes == null) {
        discNotes=new FormDiscrepancyNotes();
      }
      List<DisplayItemWithGroupBean> allItems=section.getDisplayItemGroups();
      String attachedFilePath=Utils.getAttachedFilePath(currentStudy);
      DiscrepancyValidator v=new DiscrepancyValidator(request,discNotes);
      RuleValidator ruleValidator=new RuleValidator(request);
      logger.debug("String_Node_Str" + allItems.size());
      logMe("String_Node_Str" + System.currentTimeMillis());
      for (int i=0; i < allItems.size(); i++) {
        logger.trace("String_Node_Str" + i);
        DisplayItemWithGroupBean diwg=allItems.get(i);
        if (diwg.isInGroup()) {
          DisplayItemGroupBean dgb=diwg.getItemGroup();
          List<DisplayItemGroupBean> dbGroups=diwg.getDbItemGroups();
          List<DisplayItemGroupBean> formGroups=new ArrayList<DisplayItemGroupBean>();
          logger.debug("String_Node_Str" + dbGroups.size());
          if (validate) {
            logger.debug("String_Node_Str" + dgb.getGroupMetaBean().getName());
            formGroups=validateDisplayItemGroupBean(v,dgb,dbGroups,formGroups,request,response);
            logger.debug("String_Node_Str" + formGroups.size());
          }
 else {
            logger.debug("String_Node_Str" + dgb.getGroupMetaBean().getName());
            formGroups=loadFormValueForItemGroup(dgb,dbGroups,formGroups,eventDefinitionCRFId,request);
            logger.debug("String_Node_Str" + formGroups.size());
          }
          diwg.setItemGroup(dgb);
          diwg.setItemGroups(formGroups);
          allItems.set(i,diwg);
        }
 else {
          DisplayItemBean dib=diwg.getSingleItem();
          if (validate) {
            String itemName=getInputName(dib);
            dib=validateDisplayItemBean(v,dib,"String_Node_Str",request);
            logger.debug("String_Node_Str" + itemName);
            logger.debug("String_Node_Str" + itemName + "String_Node_Str"+ fp.getString(itemName));
            logger.debug("String_Node_Str" + itemName + "String_Node_Str"+ dib.getMetadata().getResponseSet().getOptions().size()+ "String_Node_Str");
          }
 else {
            String itemName=getInputName(dib);
            logger.debug("String_Node_Str" + itemName + "String_Node_Str"+ fp.getString(itemName));
            dib=loadFormValue(dib,request);
          }
          ArrayList children=dib.getChildren();
          for (int j=0; j < children.size(); j++) {
            DisplayItemBean child=(DisplayItemBean)children.get(j);
            String itemName=getInputName(child);
            child.loadFormValue(fp.getString(itemName));
            if (validate) {
              child=validateDisplayItemBean(v,child,itemName,request);
            }
 else {
              child=loadFormValue(child,request);
            }
            logger.debug("String_Node_Str" + itemName + "String_Node_Str"+ child.getData().getValue());
            children.set(j,child);
          }
          dib.setChildren(children);
          diwg.setSingleItem(runDynamicsItemCheck(dib,null,request));
          logger.debug("String_Node_Str" + i);
          allItems.set(i,diwg);
        }
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      List<ItemBean> itemBeansWithSCDShown=new ArrayList<ItemBean>();
      if (validate && section.getSection().hasSCDItem()) {
        logMe("String_Node_Str" + System.currentTimeMillis());
        for (int i=0; i < allItems.size(); ++i) {
          DisplayItemBean dib=allItems.get(i).getSingleItem();
          ItemFormMetadataBean ifmb=dib.getMetadata();
          if (ifmb.getParentId() == 0) {
            if (dib.getScdData().getScdSetsForControl().size() > 0) {
              section.setShowSCDItemIds(SimpleConditionalDisplayService.conditionalDisplayToBeShown(dib,section.getShowSCDItemIds()));
            }
            if (dib.getScdData().getScdItemMetadataBean().getScdItemFormMetadataId() > 0) {
              dib.setIsSCDtoBeShown(section.getShowSCDItemIds().contains(dib.getMetadata().getItemId()));
              if (dib.getIsSCDtoBeShown())               itemBeansWithSCDShown.add(dib.getItem());
              validateSCDItemBean(v,dib);
            }
            ArrayList<DisplayItemBean> children=dib.getChildren();
            for (int j=0; j < children.size(); j++) {
              DisplayItemBean child=children.get(j);
              if (child.getScdData().getScdSetsForControl().size() > 0) {
                section.setShowSCDItemIds(SimpleConditionalDisplayService.conditionalDisplayToBeShown(child,section.getShowSCDItemIds()));
              }
              if (child.getScdData().getScdItemMetadataBean().getScdItemFormMetadataId() > 0) {
                child.setIsSCDtoBeShown(section.getShowSCDItemIds().contains(child.getMetadata().getItemId()));
                if (child.getIsSCDtoBeShown())                 itemBeansWithSCDShown.add(dib.getItem());
                validateSCDItemBean(v,child);
              }
            }
          }
        }
        logMe("String_Node_Str" + System.currentTimeMillis());
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      List<RuleSetBean> ruleSets=createAndInitializeRuleSet(currentStudy,studyEventDefinition,crfVersionBean,studyEventBean,ecb,true,request,response,itemBeansWithSCDShown);
      boolean shouldRunRules=getRuleSetService(request).shouldRunRulesForRuleSets(ruleSets,phase2);
      HashMap<String,ArrayList<String>> groupOrdinalPLusItemOid=null;
      groupOrdinalPLusItemOid=runRules(allItems,ruleSets,true,shouldRunRules,MessageType.ERROR,phase2,ecb,request);
      logMe("String_Node_Str" + System.currentTimeMillis());
      for (int i=0; i < allItems.size(); i++) {
        DisplayItemWithGroupBean diwg=allItems.get(i);
        if (diwg.isInGroup()) {
          DisplayItemGroupBean dgb=diwg.getItemGroup();
          List<DisplayItemGroupBean> dbGroups=diwg.getDbItemGroups();
          List<DisplayItemGroupBean> formGroups=new ArrayList<DisplayItemGroupBean>();
          if (validate) {
            formGroups=validateDisplayItemGroupBean(v,dgb,dbGroups,formGroups,ruleValidator,groupOrdinalPLusItemOid,request,response);
            logger.debug("String_Node_Str" + formGroups.size());
          }
          diwg.setItemGroup(dgb);
          diwg.setItemGroups(formGroups);
          allItems.set(i,diwg);
        }
 else {
          DisplayItemBean dib=diwg.getSingleItem();
          if (validate) {
            String itemName=getInputName(dib);
            dib=validateDisplayItemBean(v,dib,"String_Node_Str",ruleValidator,groupOrdinalPLusItemOid,false,null,request);
          }
          ArrayList children=dib.getChildren();
          for (int j=0; j < children.size(); j++) {
            DisplayItemBean child=(DisplayItemBean)children.get(j);
            String itemName=getInputName(child);
            child.loadFormValue(fp.getString(itemName));
            if (validate) {
              child=validateDisplayItemBean(v,child,"String_Node_Str",ruleValidator,groupOrdinalPLusItemOid,false,null,request);
            }
            children.set(j,child);
            logger.debug("String_Node_Str" + j);
          }
          dib.setChildren(children);
          diwg.setSingleItem(runDynamicsItemCheck(dib,null,request));
          logger.debug("String_Node_Str" + i);
          allItems.set(i,diwg);
        }
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      HashMap<String,ItemBean> scoreItems=new HashMap<String,ItemBean>();
      HashMap<String,String> scoreItemdata=new HashMap<String,String>();
      HashMap<Integer,String> oldItemdata=prepareSectionItemdata(sb.getId(),request);
      TreeSet<String> changedItems=new TreeSet<String>();
      ArrayList<DisplayItemBean> changedItemsList=new ArrayList<DisplayItemBean>();
      HashMap<String,DisplayItemGroupBean> changedItemsMap=new HashMap<String,DisplayItemGroupBean>();
      HashMap<Integer,TreeSet<Integer>> itemOrdinals=prepareItemdataOrdinals(request);
      updateDataOrdinals(allItems);
      section.setDisplayItemGroups(allItems);
      scoreItems=prepareScoreItems(request);
      scoreItemdata=prepareScoreItemdata(request);
      logMe("String_Node_Str" + System.currentTimeMillis());
      for (int i=0; i < allItems.size(); i++) {
        DisplayItemWithGroupBean diwb=allItems.get(i);
        if (diwb.isInGroup()) {
          List<DisplayItemGroupBean> dbGroups=diwb.getDbItemGroups();
          for (int j=0; j < dbGroups.size(); j++) {
            DisplayItemGroupBean displayGroup=dbGroups.get(j);
            List<DisplayItemBean> items=displayGroup.getItems();
            if ("String_Node_Str".equalsIgnoreCase(displayGroup.getEditFlag())) {
              for (              DisplayItemBean displayItem : items) {
                int itemId=displayItem.getItem().getId();
                int ordinal=displayItem.getData().getOrdinal();
                if (itemOrdinals.containsKey(itemId)) {
                  itemOrdinals.get(itemId).remove(ordinal);
                }
                if (scoreItemdata.containsKey(itemId + "String_Node_Str" + ordinal)) {
                  scoreItemdata.remove(itemId + "String_Node_Str" + ordinal);
                }
                changedItems.add(displayItem.getItem().getName());
                changedItemsList.add(displayItem);
                String formName=displayItem.getItem().getName();
                if (displayGroup.isAuto()) {
                  formName=getGroupItemInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + formName);
                }
 else {
                  formName=getGroupItemManualInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + formName);
                }
                changedItemsMap.put(formName,displayGroup);
                logger.debug("String_Node_Str" + formName);
              }
            }
          }
          List<DisplayItemGroupBean> dgbs=diwb.getItemGroups();
          int groupsize=dgbs.size();
          HashMap<Integer,Integer> maxOrdinals=new HashMap<Integer,Integer>();
          boolean first=true;
          for (int j=0; j < dgbs.size(); j++) {
            DisplayItemGroupBean displayGroup=dgbs.get(j);
            List<DisplayItemBean> items=displayGroup.getItems();
            boolean isAdd="String_Node_Str".equalsIgnoreCase(displayGroup.getEditFlag()) ? true : false;
            for (            DisplayItemBean displayItem : items) {
              ItemBean ib=displayItem.getItem();
              String itemName=ib.getName();
              int itemId=ib.getId();
              if (first) {
                maxOrdinals.put(itemId,iddao.getMaxOrdinalForGroup(ecb,sb,displayGroup.getItemGroupBean()));
              }
              ItemDataBean idb=displayItem.getData();
              String value=idb.getValue();
              scoreItems.put(itemName,ib);
              int ordinal=displayItem.getData().getOrdinal();
              if (isAdd && scoreItemdata.containsKey(itemId + "String_Node_Str" + ordinal)) {
                int formMax=1;
                if (maxOrdinals.containsKey(itemId)) {
                  formMax=maxOrdinals.get(itemId);
                }
                int dbMax=iddao.getMaxOrdinalForGroup(ecb,sb,displayGroup.getItemGroupBean());
                ordinal=ordinal >= dbMax ? formMax + 1 : ordinal;
                maxOrdinals.put(itemId,ordinal);
                displayItem.getData().setOrdinal(ordinal);
                scoreItemdata.put(itemId + "String_Node_Str" + ordinal,value);
              }
 else {
                scoreItemdata.put(itemId + "String_Node_Str" + ordinal,value);
              }
              if (itemOrdinals.containsKey(itemId)) {
                itemOrdinals.get(itemId).add(ordinal);
              }
 else {
                TreeSet<Integer> ordinalSet=new TreeSet<Integer>();
                ordinalSet.add(ordinal);
                itemOrdinals.put(itemId,ordinalSet);
              }
              if (isChanged(displayItem,oldItemdata,attachedFilePath)) {
                changedItems.add(itemName);
                changedItemsList.add(displayItem);
                String formName=displayItem.getItem().getName();
                if (displayGroup.isAuto()) {
                  formName=getGroupItemInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + formName);
                }
 else {
                  formName=getGroupItemManualInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + formName);
                }
                changedItemsMap.put(formName,displayGroup);
                logger.debug("String_Node_Str" + formName);
              }
            }
            first=false;
          }
        }
 else {
          DisplayItemBean dib=diwb.getSingleItem();
          ItemBean ib=dib.getItem();
          ItemDataBean idb=dib.getData();
          int itemId=ib.getId();
          String itemName=ib.getName();
          String value=idb.getValue();
          scoreItems.put(itemName,ib);
          TreeSet<Integer> ordinalset=new TreeSet<Integer>();
          ordinalset.add(1);
          itemOrdinals.put(itemId,ordinalset);
          scoreItemdata.put(itemId + "String_Node_Str" + 1,value);
          if (isChanged(idb,oldItemdata,dib,attachedFilePath)) {
            changedItems.add(itemName);
            changedItemsList.add(dib);
          }
          ArrayList children=dib.getChildren();
          for (int j=0; j < children.size(); j++) {
            DisplayItemBean child=(DisplayItemBean)children.get(j);
            ItemBean cib=child.getItem();
            scoreItems.put(cib.getName(),cib);
            TreeSet<Integer> cordinalset=new TreeSet<Integer>();
            cordinalset.add(1);
            itemOrdinals.put(itemId,cordinalset);
            scoreItemdata.put(cib.getId() + "String_Node_Str" + 1,child.getData().getValue());
            if (isChanged(child.getData(),oldItemdata,child,attachedFilePath)) {
              changedItems.add(itemName);
              changedItemsList.add(child);
            }
          }
        }
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      ScoreItemValidator sv=new ScoreItemValidator(request,discNotes);
      SessionManager sm=(SessionManager)request.getSession().getAttribute("String_Node_Str");
      ScoreCalculator sc=new ScoreCalculator(sm,ecb,ub);
      logMe("String_Node_Str" + System.currentTimeMillis());
      for (int i=0; i < allItems.size(); i++) {
        DisplayItemWithGroupBean diwb=allItems.get(i);
        if (diwb.isInGroup()) {
          List<DisplayItemGroupBean> dgbs=diwb.getItemGroups();
          for (int j=0; j < dgbs.size(); j++) {
            DisplayItemGroupBean displayGroup=dgbs.get(j);
            List<DisplayItemBean> items=displayGroup.getItems();
            for (            DisplayItemBean displayItem : items) {
              ItemFormMetadataBean ifmb=displayItem.getMetadata();
              int responseTypeId=ifmb.getResponseSet().getResponseTypeId();
              if (responseTypeId == 8 || responseTypeId == 9) {
                StringBuffer err=new StringBuffer();
                ResponseOptionBean robBean=(ResponseOptionBean)ifmb.getResponseSet().getOptions().get(0);
                String value="String_Node_Str";
                String inputName="String_Node_Str";
                if (displayGroup.isAuto()) {
                  inputName=getGroupItemInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + inputName);
                }
 else {
                  inputName=getGroupItemManualInputName(displayGroup,displayGroup.getFormInputOrdinal(),displayItem);
                  logger.debug("String_Node_Str" + inputName);
                }
                if (robBean.getValue().startsWith("String_Node_Str") || robBean.getValue().startsWith("String_Node_Str")) {
                  value=fp.getString(inputName);
                  logger.debug("String_Node_Str" + fp.getString(inputName) + "String_Node_Str"+ displayItem.getItem().getName()+ "String_Node_Str"+ inputName);
                }
 else {
                  value=sc.doCalculation(displayItem,scoreItems,scoreItemdata,itemOrdinals,err,displayItem.getData().getOrdinal());
                }
                displayItem.loadFormValue(value);
                if (isChanged(displayItem,oldItemdata,attachedFilePath)) {
                  changedItems.add(displayItem.getItem().getName());
                  changedItemsList.add(displayItem);
                }
                request.setAttribute(inputName,value);
                if (validate) {
                  displayItem=validateCalcTypeDisplayItemBean(sv,displayItem,inputName,request);
                  if (err.length() > 0) {
                    Validation validation=new Validation(Validator.CALCULATION_FAILED);
                    validation.setErrorMessage(err.toString());
                    sv.addValidation(inputName,validation);
                  }
                }
              }
            }
          }
        }
 else {
          DisplayItemBean dib=diwb.getSingleItem();
          ItemFormMetadataBean ifmb=dib.getMetadata();
          int responseTypeId=ifmb.getResponseSet().getResponseTypeId();
          if (responseTypeId == 8 || responseTypeId == 9) {
            StringBuffer err=new StringBuffer();
            ResponseOptionBean robBean=(ResponseOptionBean)ifmb.getResponseSet().getOptions().get(0);
            String value="String_Node_Str";
            if (robBean.getValue().startsWith("String_Node_Str") || robBean.getValue().startsWith("String_Node_Str")) {
              String itemName=getInputName(dib);
              value=fp.getString(itemName);
              logger.debug("String_Node_Str" + fp.getString(itemName) + "String_Node_Str"+ dib.getItem().getName());
              logger.debug("String_Node_Str" + fp.getString(dib.getItem().getName()));
            }
 else {
              value=sc.doCalculation(dib,scoreItems,scoreItemdata,itemOrdinals,err,1);
            }
            dib.loadFormValue(value);
            if (isChanged(dib.getData(),oldItemdata,dib,attachedFilePath)) {
              changedItems.add(dib.getItem().getName());
              changedItemsList.add(dib);
            }
            String inputName=getInputName(dib);
            request.setAttribute(inputName,value);
            if (validate) {
              dib=validateCalcTypeDisplayItemBean(sv,dib,"String_Node_Str",request);
              if (err.length() > 0) {
                Validation validation=new Validation(Validator.CALCULATION_FAILED);
                validation.setErrorMessage(err.toString());
                sv.addValidation(inputName,validation);
              }
            }
          }
          ArrayList children=dib.getChildren();
          for (int j=0; j < children.size(); j++) {
            DisplayItemBean child=(DisplayItemBean)children.get(j);
            ItemFormMetadataBean cifmb=child.getMetadata();
            int resTypeId=cifmb.getResponseSet().getResponseTypeId();
            if (resTypeId == 8 || resTypeId == 9) {
              StringBuffer cerr=new StringBuffer();
              child.getDbData().setValue(child.getData().getValue());
              ResponseOptionBean crobBean=(ResponseOptionBean)cifmb.getResponseSet().getOptions().get(0);
              String cvalue="String_Node_Str";
              if (crobBean.getValue().startsWith("String_Node_Str") || crobBean.getValue().startsWith("String_Node_Str")) {
                String itemName=getInputName(child);
                cvalue=fp.getString(itemName);
                logger.debug("String_Node_Str" + fp.getString(itemName) + "String_Node_Str"+ child.getItem().getName());
              }
 else {
                cvalue=sc.doCalculation(child,scoreItems,scoreItemdata,itemOrdinals,cerr,1);
              }
              child.loadFormValue(cvalue);
              if (isChanged(child.getData(),oldItemdata,child,attachedFilePath)) {
                changedItems.add(child.getItem().getName());
                changedItemsList.add(child);
              }
              String cinputName=getInputName(child);
              request.setAttribute(cinputName,cvalue);
              if (validate) {
                child=validateCalcTypeDisplayItemBean(sv,child,"String_Node_Str",request);
                if (cerr.length() > 0) {
                  Validation cvalidation=new Validation(Validator.CALCULATION_FAILED);
                  cvalidation.setErrorMessage(cerr.toString());
                  sv.addValidation(cinputName,cvalidation);
                }
              }
            }
            children.set(j,child);
          }
        }
      }
      logMe("String_Node_Str" + System.currentTimeMillis());
      section.setDisplayItemGroups(allItems);
      section=populateNotesWithDBNoteCounts(discNotes,section,request);
      populateInstantOnChange(request.getSession(),ecb,section);
      if (currentStudy.getStudyParameterConfig().getInterviewerNameRequired().equals("String_Node_Str")) {
        v.addValidation(INPUT_INTERVIEWER,Validator.NO_BLANKS);
      }
      if (currentStudy.getStudyParameterConfig().getInterviewDateRequired().equals("String_Node_Str")) {
        v.addValidation(INPUT_INTERVIEW_DATE,Validator.NO_BLANKS);
      }
      if (!StringUtil.isBlank(fp.getString(INPUT_INTERVIEW_DATE))) {
        v.addValidation(INPUT_INTERVIEW_DATE,Validator.IS_A_DATE);
        v.alwaysExecuteLastValidation(INPUT_INTERVIEW_DATE);
      }
      if (section.getSection().hasSCDItem()) {
        section=SCDItemDisplayInfo.generateSCDDisplayInfo(section,this.getServletPage(request).equals(Page.INITIAL_DATA_ENTRY) || this.getServletPage(request).equals(Page.ADMIN_EDIT_SERVLET) && !this.isAdminForcedReasonForChange(request));
      }
      errors=v.validate();
      if (this.isAdminForcedReasonForChange(request) && this.isAdministrativeEditing() && errors.isEmpty()) {
        String error=respage.getString("String_Node_Str");
        int nonforcedChanges=0;
        if (changedItemsList.size() > 0) {
          logger.debug("String_Node_Str" + changedItems.toString() + "String_Node_Str"+ changedItemsList.toString()+ "String_Node_Str"+ changedItemsMap.toString());
          logMe("String_Node_Str" + System.currentTimeMillis());
          for (          DisplayItemBean displayItem : changedItemsList) {
            String formName=getInputName(displayItem);
            ItemDataBean idb=displayItem.getData();
            ItemFormMetadataBean ifmb=displayItem.getMetadata();
            logger.debug("String_Node_Str" + ifmb.getGroupLabel());
            if (!ifmb.getGroupLabel().equalsIgnoreCase("String_Node_Str") && !ifmb.getGroupLabel().equalsIgnoreCase("String_Node_Str")) {
              Iterator iter=changedItemsMap.entrySet().iterator();
              while (iter.hasNext()) {
                Map.Entry<String,DisplayItemGroupBean> pairs=(Map.Entry)iter.next();
                String formName2=pairs.getKey();
                DisplayItemGroupBean dgb=pairs.getValue();
                String testFormName="String_Node_Str";
                if (dgb.isAuto()) {
                  testFormName=getGroupItemInputName(dgb,dgb.getFormInputOrdinal(),displayItem);
                }
 else {
                  testFormName=getGroupItemManualInputName(dgb,dgb.getFormInputOrdinal(),displayItem);
                }
                logger.debug("String_Node_Str" + testFormName);
                int existingNotes=dndao.findNumExistingNotesForItem(idb.getId());
                if (testFormName.equals(formName2)) {
                  formName=formName2;
                  this.setReasonForChangeError(idb,formName,error,request);
                  changedItemsMap.remove(formName2);
                  logger.debug("String_Node_Str" + formName);
                  break;
                }
              }
            }
 else {
              this.setReasonForChangeError(idb,formName,error,request);
              logger.debug("String_Node_Str" + formName);
            }
          }
          logMe("String_Node_Str" + System.currentTimeMillis());
        }
        if (nonforcedChanges > 0) {
        }
      }
      logger.debug("String_Node_Str" + errors.toString());
      logMe("String_Node_Str" + System.currentTimeMillis());
      if (errors.isEmpty() && shouldRunRules) {
        logger.debug("String_Node_Str");
        if (session.getAttribute("String_Node_Str") != null) {
          HashMap h=ruleValidator.validate();
          Set<String> a=(Set<String>)session.getAttribute("String_Node_Str");
          Set<String> ba=h.keySet();
          Boolean showErrors=false;
          for (          Object key : ba) {
            if (!a.contains(key)) {
              showErrors=true;
            }
          }
          if (showErrors) {
            errors=h;
            if (errors.size() > 0) {
              session.setAttribute("String_Node_Str","String_Node_Str");
              session.setAttribute("String_Node_Str",errors.keySet());
            }
 else {
              session.setAttribute("String_Node_Str",null);
              session.setAttribute("String_Node_Str",null);
            }
          }
 else {
            session.setAttribute("String_Node_Str",null);
            session.setAttribute("String_Node_Str",null);
          }
        }
 else         if (session.getAttribute("String_Node_Str") != null && session.getAttribute("String_Node_Str").toString().equals("String_Node_Str")) {
          session.setAttribute("String_Node_Str",null);
          session.setAttribute("String_Node_Str",null);
        }
 else {
          errors=ruleValidator.validate();
          if (errors.size() > 0) {
            session.setAttribute("String_Node_Str","String_Node_Str");
            session.setAttribute("String_Node_Str",errors.keySet());
          }
        }
      }
      if (!errors.isEmpty()) {
        logger.debug("String_Node_Str");
        String[] textFields={INPUT_INTERVIEWER,INPUT_INTERVIEW_DATE};
        fp.setCurrentStringValuesAsPreset(textFields);
        setPresetValues(fp.getPresetValues(),request);
        logMe("String_Node_Str" + System.currentTimeMillis());
        HashMap<String,ArrayList<String>> siErrors=sv.validate();
        if (siErrors != null && !siErrors.isEmpty()) {
          Iterator iter=siErrors.keySet().iterator();
          while (iter.hasNext()) {
            String fieldName=iter.next().toString();
            errors.put(fieldName,siErrors.get(fieldName));
          }
        }
        Iterator iter2=errors.keySet().iterator();
        while (iter2.hasNext()) {
          String fieldName=iter2.next().toString();
          logger.debug("String_Node_Str" + fieldName);
        }
        errors=reshuffleErrorGroupNamesKK(errors,allItems,request);
        Iterator iter3=errors.keySet().iterator();
        while (iter3.hasNext()) {
          String fieldName=iter3.next().toString();
          logger.debug("String_Node_Str" + fieldName);
        }
        request.setAttribute("String_Node_Str",fp.getString(INPUT_MARK_COMPLETE));
        request.setAttribute(BEAN_DISPLAY,section);
        request.setAttribute(BEAN_ANNOTATIONS,fp.getString(INPUT_ANNOTATIONS));
        setInputMessages(errors,request);
        addPageMessage(respage.getString("String_Node_Str"),request);
        request.setAttribute("String_Node_Str","String_Node_Str");
        session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
        setUpPanel(section);
        forwardPage(getJSPPage(),request,response);
      }
 else {
        logger.debug("String_Node_Str");
        logMe("String_Node_Str" + System.currentTimeMillis());
        boolean success=true;
        boolean temp=true;
        ecb.setInterviewerName(fp.getString(INPUT_INTERVIEWER));
        if (!StringUtil.isBlank(fp.getString(INPUT_INTERVIEW_DATE))) {
          ecb.setDateInterviewed(fp.getDate(INPUT_INTERVIEW_DATE));
        }
 else {
          ecb.setDateInterviewed(null);
        }
        if (ecdao == null) {
          ecdao=new EventCRFDAO(getDataSource());
        }
        DataEntryStage stage=ecb.getStage();
        if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
          ecb.setValidatorId(ub.getId());
        }
        if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED) && changedItemsList.size() > 0) {
          studyEventBean.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
          studyEventBean.setUpdater(ub);
          studyEventBean.setUpdatedDate(new Date());
          seDao.update(studyEventBean);
        }
        logger.debug("String_Node_Str",ssb.getStatus().getName());
        if (ssb.getStatus() == Status.SIGNED && changedItemsList.size() > 0) {
          logger.debug("String_Node_Str");
          StudySubjectDAO studySubjectDao=new StudySubjectDAO(getDataSource());
          ssb.setStatus(Status.AVAILABLE);
          ssb.setUpdater(ub);
          ssb.setUpdatedDate(new Date());
          studySubjectDao.update(ssb);
        }
        if (ecb.isSdvStatus() && changedItemsList.size() > 0) {
          logger.debug("String_Node_Str");
          StudySubjectDAO studySubjectDao=new StudySubjectDAO(getDataSource());
          ssb.setStatus(Status.AVAILABLE);
          ssb.setUpdater(ub);
          ssb.setUpdatedDate(new Date());
          studySubjectDao.update(ssb);
          ecb.setSdvStatus(false);
          ecb.setSdvUpdateId(ub.getId());
        }
        ecb=(EventCRFBean)ecdao.update(ecb);
        FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
        dndao=new DiscrepancyNoteDAO(getDataSource());
        AddNewSubjectServlet.saveFieldNotes(INPUT_INTERVIEWER,fdn,dndao,ecb.getId(),"String_Node_Str",currentStudy);
        AddNewSubjectServlet.saveFieldNotes(INPUT_INTERVIEW_DATE,fdn,dndao,ecb.getId(),"String_Node_Str",currentStudy);
        allItems=section.getDisplayItemGroups();
        logger.debug("String_Node_Str" + allItems.size());
        this.output(allItems);
        logMe("String_Node_Str" + System.currentTimeMillis());
        for (int i=0; i < allItems.size(); i++) {
          DisplayItemWithGroupBean diwb=allItems.get(i);
          if (diwb.isInGroup()) {
            List<DisplayItemGroupBean> dgbs=diwb.getItemGroups();
            List<DisplayItemGroupBean> dbGroups=diwb.getDbItemGroups();
            logger.debug("String_Node_Str" + dgbs.size());
            logger.debug("String_Node_Str" + dbGroups.size());
            for (int j=0; j < dgbs.size(); j++) {
              DisplayItemGroupBean displayGroup=dgbs.get(j);
              List<DisplayItemBean> items=displayGroup.getItems();
              int nextOrdinal=iddao.getMaxOrdinalForGroup(ecb,sb,displayGroup.getItemGroupBean()) + 1;
              for (              DisplayItemBean displayItem : items) {
                String fileName=this.addAttachedFilePath(displayItem,attachedFilePath);
                displayItem.setEditFlag(displayGroup.getEditFlag());
                logger.debug("String_Node_Str" + displayItem.getData().getValue());
                if ("String_Node_Str".equalsIgnoreCase(displayItem.getEditFlag()) && fileName.length() > 0 && !newUploadedFiles.containsKey(fileName)) {
                  displayItem.getData().setValue("String_Node_Str");
                }
                temp=writeToDB(displayItem,iddao,nextOrdinal,request);
                logger.debug("String_Node_Str");
                logger.debug("String_Node_Str" + nextOrdinal);
                if (temp && newUploadedFiles.containsKey(fileName)) {
                  newUploadedFiles.remove(fileName);
                }
                String inputName=getGroupItemInputName(displayGroup,j,displayItem);
                if (!displayGroup.isAuto()) {
                  logger.trace("String_Node_Str");
                  inputName=this.getGroupItemManualInputName(displayGroup,j,displayItem);
                }
                if (j == dgbs.size() - 1) {
                  logger.trace("String_Node_Str");
                  int ordinal=j - this.getManualRows(dgbs);
                  logger.debug("String_Node_Str" + ordinal);
                  inputName=getGroupItemInputName(displayGroup,ordinal,displayItem);
                }
                logger.trace("String_Node_Str" + inputName);
                AddNewSubjectServlet.saveFieldNotes(inputName,fdn,dndao,displayItem.getData().getId(),"String_Node_Str",currentStudy);
                success=success && temp;
              }
            }
            for (int j=0; j < dbGroups.size(); j++) {
              DisplayItemGroupBean displayGroup=dbGroups.get(j);
              if ("String_Node_Str".equalsIgnoreCase(displayGroup.getEditFlag())) {
                List<DisplayItemBean> items=displayGroup.getItems();
                for (                DisplayItemBean displayItem : items) {
                  String fileName=this.addAttachedFilePath(displayItem,attachedFilePath);
                  displayItem.setEditFlag(displayGroup.getEditFlag());
                  logger.debug("String_Node_Str" + displayItem.getData().getValue());
                  if ("String_Node_Str".equalsIgnoreCase(displayItem.getEditFlag()) && fileName.length() > 0 && !newUploadedFiles.containsKey(fileName)) {
                    displayItem.getData().setValue("String_Node_Str");
                  }
                  temp=writeToDB(displayItem,iddao,0,request);
                  logger.debug("String_Node_Str");
                  if (temp && newUploadedFiles.containsKey(fileName)) {
                    newUploadedFiles.remove(fileName);
                  }
                  success=success && temp;
                }
              }
            }
          }
 else {
            DisplayItemBean dib=diwb.getSingleItem();
            this.addAttachedFilePath(dib,attachedFilePath);
            temp=writeToDB(dib,iddao,1,request);
            logger.debug("String_Node_Str");
            if (temp && newUploadedFiles.containsKey(dib.getItem().getId() + "String_Node_Str")) {
              newUploadedFiles.remove(dib.getItem().getId() + "String_Node_Str");
            }
            String inputName=getInputName(dib);
            logger.trace("String_Node_Str" + inputName);
            AddNewSubjectServlet.saveFieldNotes(inputName,fdn,dndao,dib.getData().getId(),"String_Node_Str",currentStudy);
            success=success && temp;
            ArrayList childItems=dib.getChildren();
            for (int j=0; j < childItems.size(); j++) {
              DisplayItemBean child=(DisplayItemBean)childItems.get(j);
              this.addAttachedFilePath(child,attachedFilePath);
              temp=writeToDB(child,iddao,1,request);
              logger.debug("String_Node_Str");
              if (temp && newUploadedFiles.containsKey(child.getItem().getId() + "String_Node_Str")) {
                newUploadedFiles.remove(child.getItem().getId() + "String_Node_Str");
              }
              inputName=getInputName(child);
              AddNewSubjectServlet.saveFieldNotes(inputName,fdn,dndao,child.getData().getId(),"String_Node_Str",currentStudy);
              success=success && temp;
            }
          }
        }
        logMe("String_Node_Str" + System.currentTimeMillis());
        logger.debug("String_Node_Str" + phase2.name());
        List<Integer> prevShownDynItemDataIds=shouldRunRules ? this.getItemMetadataService().getDynamicsItemFormMetadataDao().findShowItemDataIdsInSection(section.getSection().getId(),ecb.getCRFVersionId(),ecb.getId()) : new ArrayList<Integer>();
        logMe("String_Node_Str" + System.currentTimeMillis());
        HashMap<String,ArrayList<String>> rulesPostDryRun=runRules(allItems,ruleSets,false,shouldRunRules,MessageType.WARNING,phase2,ecb,request);
        HashMap<String,ArrayList<String>> errorsPostDryRun=new HashMap<String,ArrayList<String>>();
        logMe("String_Node_Str" + System.currentTimeMillis());
        boolean inSameSection=false;
        logMe("String_Node_Str" + System.currentTimeMillis());
        if (!rulesPostDryRun.isEmpty()) {
          Iterator iter3=rulesPostDryRun.keySet().iterator();
          while (iter3.hasNext()) {
            String fieldName=iter3.next().toString();
            logger.debug("String_Node_Str" + fieldName);
            int ordinal=-1;
            String newFieldName=fieldName;
            String[] fieldNames=fieldName.split("String_Node_Str");
            if (fieldNames.length == 2) {
              newFieldName=fieldNames[1];
              if (fieldNames[0].contains("String_Node_Str")) {
                int p1=fieldNames[0].indexOf("String_Node_Str");
                int p2=fieldNames[0].indexOf("String_Node_Str");
                try {
                  ordinal=Integer.valueOf(fieldNames[0].substring(p1 + 1,p2));
                }
 catch (                NumberFormatException e) {
                  ordinal=-1;
                }
                fieldNames[0]=fieldNames[0].substring(0,p1);
              }
            }
            List<DisplayItemWithGroupBean> displayGroupsWithItems=section.getDisplayItemGroups();
            for (int i=0; i < displayGroupsWithItems.size(); i++) {
              DisplayItemWithGroupBean itemWithGroup=displayGroupsWithItems.get(i);
              if (itemWithGroup.isInGroup()) {
                logger.debug("String_Node_Str" + fieldNames[0]);
                List<DisplayItemGroupBean> digbs=itemWithGroup.getItemGroups();
                logger.debug("String_Node_Str" + digbs.size());
                for (int j=0; j < digbs.size(); j++) {
                  DisplayItemGroupBean displayGroup=digbs.get(j);
                  if (displayGroup.getItemGroupBean().getOid().equals(fieldNames[0]) && displayGroup.getOrdinal() == ordinal - 1) {
                    List<DisplayItemBean> items=displayGroup.getItems();
                    for (int k=0; k < items.size(); k++) {
                      DisplayItemBean dib=items.get(k);
                      if (dib.getItem().getOid().equals(newFieldName)) {
                        if (!dib.getMetadata().isShowItem()) {
                          logger.debug("String_Node_Str" + this.getGroupItemInputName(displayGroup,j,dib) + "String_Node_Str"+ fieldName+ "String_Node_Str"+ dib.getMetadata().isShowItem());
                          dib.getMetadata().setShowItem(true);
                        }
                        if (prevShownDynItemDataIds == null || !prevShownDynItemDataIds.contains(dib.getData().getId())) {
                          inSameSection=true;
                          errorsPostDryRun.put(this.getGroupItemInputName(displayGroup,j,dib),rulesPostDryRun.get(fieldName));
                        }
                      }
                      items.set(k,dib);
                    }
                    displayGroup.setItems(items);
                    digbs.set(j,displayGroup);
                  }
                }
                itemWithGroup.setItemGroups(digbs);
              }
 else {
                DisplayItemBean displayItemBean=itemWithGroup.getSingleItem();
                ItemBean itemBean=displayItemBean.getItem();
                if (newFieldName.equals(itemBean.getOid())) {
                  if (!displayItemBean.getMetadata().isShowItem()) {
                    logger.debug("String_Node_Str" + this.getInputName(displayItemBean) + "String_Node_Str"+ fieldName+ "String_Node_Str"+ displayItemBean.getMetadata().isShowItem());
                    displayItemBean.getMetadata().setShowItem(true);
                    if (prevShownDynItemDataIds == null || !prevShownDynItemDataIds.contains(displayItemBean.getData().getId())) {
                      inSameSection=true;
                      errorsPostDryRun.put(this.getInputName(displayItemBean),rulesPostDryRun.get(fieldName));
                    }
                  }
                }
                itemWithGroup.setSingleItem(displayItemBean);
              }
              displayGroupsWithItems.set(i,itemWithGroup);
            }
            logMe("String_Node_Str" + System.currentTimeMillis());
            List<DisplayItemWithGroupBean> itemGroups=section.getDisplayItemGroups();
            for (            DisplayItemWithGroupBean itemGroup : itemGroups) {
              DisplayItemGroupBean displayGroup=itemGroup.getItemGroup();
              if (newFieldName.equals(displayGroup.getItemGroupBean().getOid())) {
                if (!displayGroup.getGroupMetaBean().isShowGroup()) {
                  inSameSection=true;
                  logger.debug("String_Node_Str" + displayGroup.getItemGroupBean().getOid() + "String_Node_Str"+ fieldName+ "String_Node_Str"+ displayGroup.getGroupMetaBean().isShowGroup());
                  errorsPostDryRun.put(displayGroup.getItemGroupBean().getOid(),rulesPostDryRun.get(fieldName));
                  displayGroup.getGroupMetaBean().setShowGroup(true);
                  loadItemsWithGroupRows(itemGroup,sb,edcb,ecb,request);
                }
              }
            }
            logMe("String_Node_Str" + System.currentTimeMillis());
            section.setDisplayItemGroups(displayGroupsWithItems);
            populateInstantOnChange(request.getSession(),ecb,section);
          }
          this.getItemMetadataService().updateGroupDynamicsInSection(displayItemWithGroups,section.getSection().getId(),ecb);
          toc=TableOfContentsServlet.getDisplayBeanWithShownSections(getDataSource(),(DisplayTableOfContentsBean)request.getAttribute(TOC_DISPLAY),(DynamicsMetadataService)SpringServletAccess.getApplicationContext(getServletContext()).getBean("String_Node_Str"));
          request.setAttribute(TOC_DISPLAY,toc);
          sectionIdsInToc=TableOfContentsServlet.sectionIdsInToc(toc);
          sIndex=TableOfContentsServlet.sectionIndexInToc(section.getSection(),toc,sectionIdsInToc);
          previousSec=this.prevSection(section.getSection(),ecb,toc,sIndex);
          nextSec=this.nextSection(section.getSection(),ecb,toc,sIndex);
          section.setFirstSection(!previousSec.isActive());
          section.setLastSection(!nextSec.isActive());
          logger.debug("String_Node_Str" + inSameSection);
          if (inSameSection) {
            String[] textFields={INPUT_INTERVIEWER,INPUT_INTERVIEW_DATE};
            fp.setCurrentStringValuesAsPreset(textFields);
            setPresetValues(fp.getPresetValues(),request);
            request.setAttribute(BEAN_DISPLAY,section);
            request.setAttribute(BEAN_ANNOTATIONS,fp.getString(INPUT_ANNOTATIONS));
            setInputMessages(errorsPostDryRun,request);
            addPageMessage(respage.getString("String_Node_Str"),request);
            request.setAttribute("String_Node_Str","String_Node_Str");
            request.setAttribute("String_Node_Str","String_Node_Str");
            session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
            setUpPanel(section);
            forwardPage(getJSPPage(),request,response);
          }
        }
        if (!inSameSection) {
          ArrayList<String> updateFailedItems=sc.redoCalculations(scoreItems,scoreItemdata,changedItems,itemOrdinals,sb.getId());
          success=updateFailedItems.size() > 0 ? false : true;
          boolean markComplete=fp.getString(INPUT_MARK_COMPLETE).equals(VALUE_YES);
          boolean markSuccessfully=false;
          if (markComplete && section.isLastSection()) {
            logger.debug("String_Node_Str");
            markSuccessfully=markCRFComplete(request);
            logger.debug("String_Node_Str" + markSuccessfully);
            if (!markSuccessfully) {
              request.setAttribute(BEAN_DISPLAY,section);
              request.setAttribute(BEAN_ANNOTATIONS,fp.getString(INPUT_ANNOTATIONS));
              setUpPanel(section);
              forwardPage(getJSPPage(),request,response);
              return;
            }
          }
          String annotations=fp.getString(INPUT_ANNOTATIONS);
          setEventCRFAnnotations(annotations,request);
          Date now=new Date();
          ecb.setUpdatedDate(now);
          ecb.setUpdater(ub);
          ecb=(EventCRFBean)ecdao.update(ecb);
          success=success && ecb.isActive();
          StudyEventDAO sedao=new StudyEventDAO(getDataSource());
          StudyEventBean seb=(StudyEventBean)sedao.findByPK(ecb.getStudyEventId());
          seb.setUpdatedDate(now);
          seb.setUpdater(ub);
          seb=(StudyEventBean)sedao.update(seb);
          success=success && seb.isActive();
          request.setAttribute(INPUT_IGNORE_PARAMETERS,Boolean.TRUE);
          if (newUploadedFiles.size() > 0) {
            if (this.unloadFiles(newUploadedFiles)) {
            }
 else {
              String missed="String_Node_Str";
              Iterator iter=newUploadedFiles.keySet().iterator();
              while (iter.hasNext()) {
                missed+="String_Node_Str" + newUploadedFiles.get(iter.next());
              }
              addPageMessage(respage.getString("String_Node_Str") + "String_Node_Str" + missed,request);
            }
          }
          if (!success) {
            if (updateFailedItems.size() > 0) {
              String mess="String_Node_Str";
              for (              String ss : updateFailedItems) {
                mess+=ss + "String_Node_Str";
              }
              mess=mess.substring(0,mess.length() - 2);
              addPageMessage(resexception.getString("String_Node_Str") + mess,request);
            }
 else {
              addPageMessage(resexception.getString("String_Node_Str"),request);
            }
            request.setAttribute(BEAN_DISPLAY,section);
            session.removeAttribute(GROUP_HAS_DATA);
            session.removeAttribute(HAS_DATA_FLAG);
            session.removeAttribute(DDE_PROGESS);
            session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
            logger.debug("String_Node_Str");
            session.removeAttribute("String_Node_Str");
            session.removeAttribute(instantAtt);
            forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET,request,response);
          }
 else {
            boolean forwardingSucceeded=false;
            if (!fp.getString(GO_PREVIOUS).equals("String_Node_Str")) {
              if (previousSec.isActive()) {
                forwardingSucceeded=true;
                request.setAttribute(INPUT_EVENT_CRF,ecb);
                request.setAttribute(INPUT_SECTION,previousSec);
                int tabNum=0;
                if (fp.getString("String_Node_Str") == null) {
                  tabNum=1;
                }
 else {
                  tabNum=fp.getInt("String_Node_Str");
                }
                request.setAttribute("String_Node_Str",new Integer(tabNum - 1).toString());
                forwardPage(getServletPage(request),request,response);
              }
            }
 else             if (!fp.getString(GO_NEXT).equals("String_Node_Str")) {
              if (nextSec.isActive()) {
                forwardingSucceeded=true;
                request.setAttribute(INPUT_EVENT_CRF,ecb);
                request.setAttribute(INPUT_SECTION,nextSec);
                int tabNum=0;
                if (fp.getString("String_Node_Str") == null) {
                  tabNum=1;
                }
 else {
                  tabNum=fp.getInt("String_Node_Str");
                }
                request.setAttribute("String_Node_Str",new Integer(tabNum + 1).toString());
                forwardPage(getServletPage(request),request,response);
              }
            }
            if (!forwardingSucceeded) {
              if (markSuccessfully) {
                addPageMessage(respage.getString("String_Node_Str"),request);
                session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
                session.removeAttribute(GROUP_HAS_DATA);
                session.removeAttribute(HAS_DATA_FLAG);
                session.removeAttribute(DDE_PROGESS);
                session.removeAttribute("String_Node_Str");
                request.setAttribute("String_Node_Str",new Integer(ecb.getStudyEventId()).toString());
                forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET,request,response);
              }
 else {
                addPageMessage(respage.getString("String_Node_Str"),request);
                request.setAttribute(INPUT_EVENT_CRF,ecb);
                request.setAttribute(INPUT_EVENT_CRF_ID,new Integer(ecb.getId()).toString());
                if (!section.isLastSection()) {
                  request.setAttribute(INPUT_SECTION,nextSec);
                  request.setAttribute(INPUT_SECTION_ID,new Integer(nextSec.getId()).toString());
                  session.removeAttribute("String_Node_Str");
                }
 else                 if (section.isLastSection()) {
                  session.removeAttribute(GROUP_HAS_DATA);
                  session.removeAttribute(HAS_DATA_FLAG);
                  session.removeAttribute(DDE_PROGESS);
                  session.removeAttribute("String_Node_Str");
                  session.removeAttribute("String_Node_Str");
                  request.setAttribute("String_Node_Str",new Integer(ecb.getStudyEventId()).toString());
                  if (fromViewNotes != null && "String_Node_Str".equals(fromViewNotes)) {
                    String viewNotesPageFileName=(String)session.getAttribute("String_Node_Str");
                    session.removeAttribute("String_Node_Str");
                    session.removeAttribute("String_Node_Str");
                    if (viewNotesPageFileName != null && viewNotesPageFileName.length() > 0) {
                      forwardPage(Page.setNewPage(viewNotesPageFileName,"String_Node_Str"),request,response);
                    }
                  }
                  session.removeAttribute(instantAtt);
                  forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET,request,response);
                  return;
                }
                int tabNum=0;
                if (fp.getString("String_Node_Str") == null) {
                  tabNum=1;
                }
 else {
                  tabNum=fp.getInt("String_Node_Str");
                }
                if (!section.isLastSection()) {
                  request.setAttribute("String_Node_Str",new Integer(tabNum + 1).toString());
                }
                forwardPage(getServletPage(request),request,response);
              }
            }
          }
        }
      }
    }
  }
  finally {
    sw.stop();
  }
}