Program: 115330
Project: 115330
Buggy source:
@Override protected void processRequest() throws Exception {
  locale=request.getLocale();
  FormDiscrepancyNotes discNotes;
  panel.setStudyInfoShown(false);
  String age="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(sm.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"));
      forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
    }
 else {
      lockThisEventCRF(ecb.getId(),ub.getId());
    }
  }
  if (!ecb.isActive()) {
    throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET,resexception.getString("String_Node_Str"));
  }
  DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
  ArrayList<DiscrepancyNoteBean> allNotes=new ArrayList<DiscrepancyNoteBean>();
  List<DiscrepancyNoteBean> eventCrfNotes=new ArrayList<DiscrepancyNoteBean>();
  List<DiscrepancyNoteThread> noteThreads=new ArrayList<DiscrepancyNoteThread>();
  dndao=new DiscrepancyNoteDAO(sm.getDataSource());
  allNotes=dndao.findAllTopNotesByEventCRF(ecb.getId());
  eventCrfNotes=dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
  if (!eventCrfNotes.isEmpty()) {
    allNotes.addAll(eventCrfNotes);
  }
  DiscrepancyNoteUtil dNoteUtil=new DiscrepancyNoteUtil();
  noteThreads=dNoteUtil.createThreadsOfParents(allNotes,sm.getDataSource(),currentStudy,null,-1,true);
  int updatedNum=0;
  int openNum=0;
  int closedNum=0;
  int resolvedNum=0;
  int notAppNum=0;
  DiscrepancyNoteBean tempBean;
  for (  DiscrepancyNoteThread dnThread : noteThreads) {
    tempBean=dnThread.getLinkedNoteList().getLast();
    if (tempBean != null) {
      if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) {
        updatedNum++;
      }
 else       if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) {
        openNum++;
      }
 else       if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) {
        closedNum++;
      }
 else       if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) {
        resolvedNum++;
      }
 else       if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) {
        notAppNum++;
      }
    }
  }
  request.setAttribute("String_Node_Str",updatedNum + "String_Node_Str");
  request.setAttribute("String_Node_Str",openNum + "String_Node_Str");
  request.setAttribute("String_Node_Str",closedNum + "String_Node_Str");
  request.setAttribute("String_Node_Str",resolvedNum + "String_Node_Str");
  request.setAttribute("String_Node_Str",notAppNum + "String_Node_Str");
  StudySubjectDAO ssdao=new StudySubjectDAO(sm.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.setAttribute("String_Node_Str",new Integer(ecb.getStudySubjectId()).toString());
    forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
  }
  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"));
  }
  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);
      }
    }
    session.removeAttribute("String_Node_Str");
    addPageMessage(respage.getString("String_Node_Str"));
    String fromResolvingNotes=fp.getString("String_Node_Str",true);
    String winLocation=(String)session.getAttribute(ViewNotesServlet.WIN_LOCATION);
    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;
  }
  hasGroup=checkGroups();
  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");
  edcdao=new EventDefinitionCRFDAO(sm.getDataSource());
  if (eventDefinitionCRFId <= 0) {
    EventDefinitionCRFBean edcBean=edcdao.findByStudyEventIdAndCRFVersionId(study,ecb.getStudyEventId(),ecb.getCRFVersionId());
    eventDefinitionCRFId=edcBean.getId();
  }
  StudyEventDAO seDao=new StudyEventDAO(sm.getDataSource());
  EventDefinitionCRFBean edcBean=(EventDefinitionCRFBean)edcdao.findByPK(eventDefinitionCRFId);
  edcb=(EventDefinitionCRFBean)edcdao.findByPK(eventDefinitionCRFId);
  StudyEventBean studyEventBean=(StudyEventBean)seDao.findByPK(ecb.getStudyEventId());
  edcBean.setId(eventDefinitionCRFId);
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  StudyEventDefinitionBean studyEventDefinition=(StudyEventDefinitionBean)seddao.findByPK(edcBean.getStudyEventDefinitionId());
  CRFVersionDAO cvdao=new CRFVersionDAO(sm.getDataSource());
  CRFVersionBean crfVersionBean=(CRFVersionBean)cvdao.findByPK(ecb.getCRFVersionId());
  List<RuleSetBean> ruleSets=createAndInitializeRuleSet(currentStudy,studyEventDefinition,crfVersionBean,studyEventBean,ecb,shouldRunRules());
  DisplaySectionBean section=getDisplayBean(hasGroup,false);
  String firstFieldId=getSectionFirstFieldId(section.getSection().getId());
  request.setAttribute("String_Node_Str",firstFieldId);
  List<DisplayItemWithGroupBean> displayItemWithGroups=createItemWithGroups(section,hasGroup,eventDefinitionCRFId);
  section.setDisplayItemGroups(displayItemWithGroups);
  SectionBean previousSec=sdao.findPrevious(ecb,sb);
  SectionBean nextSec=sdao.findNext(ecb,sb);
  section.setFirstSection(!previousSec.isActive());
  section.setLastSection(!nextSec.isActive());
  SubjectDAO subjectDao=new SubjectDAO(sm.getDataSource());
  StudyDAO studydao=new StudyDAO(sm.getDataSource());
  SubjectBean subject=(SubjectBean)subjectDao.findByPK(ssb.getSubjectId());
  if (study.getParentStudyId() > 0) {
    StudyBean parentStudy=(StudyBean)studydao.findByPK(study.getParentStudyId());
    request.setAttribute("String_Node_Str",parentStudy.getName() + "String_Node_Str" + study.getName());
  }
 else {
    request.setAttribute("String_Node_Str",study.getName());
  }
  if (currentStudy.getStudyParameterConfig().getCollectDob().equals("String_Node_Str")) {
    Date enrollmentDate=ssb.getEnrollmentDate();
    age=Utils.getInstacne().processAge(enrollmentDate,subject.getDateOfBirth());
  }
  ArrayList beans=ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(ssb,sm.getDataSource(),ub,currentRole);
  request.setAttribute("String_Node_Str",ssb);
  request.setAttribute("String_Node_Str",subject);
  request.setAttribute("String_Node_Str",beans);
  request.setAttribute("String_Node_Str",ecb);
  request.setAttribute("String_Node_Str",age);
  request.setAttribute("String_Node_Str",((SecurityManager)SpringServletAccess.getApplicationContext(context).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());
  if (!isSubmitted) {
    request.setAttribute(BEAN_DISPLAY,section);
    request.setAttribute(BEAN_ANNOTATIONS,getEventCRFAnnotations());
    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);
    logger.debug("String_Node_Str" + discNotes.getFieldNotes().toString());
    logger.debug("String_Node_Str" + discNotes.getNumExistingFieldNotes().toString());
    session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
    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);
      }
    }
    forwardPage(getJSPPage());
  }
 else {
    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();
    DiscrepancyValidator v=new DiscrepancyValidator(request,discNotes);
    RuleValidator ruleValidator=new RuleValidator(request);
    logger.debug("String_Node_Str" + allItems.size());
    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.info("String_Node_Str" + dbGroups.size());
        if (validate) {
          logger.debug("String_Node_Str" + dgb.getGroupMetaBean().getName());
          formGroups=validateDisplayItemGroupBean(v,dgb,dbGroups,formGroups);
          logger.debug("String_Node_Str" + formGroups.size());
        }
 else {
          logger.debug("String_Node_Str" + dgb.getGroupMetaBean().getName());
          formGroups=loadFormValueForItemGroup(dgb,dbGroups,formGroups,eventDefinitionCRFId);
          logger.debug("String_Node_Str" + formGroups.size());
        }
        diwg.setItemGroup(dgb);
        diwg.setItemGroups(formGroups);
        allItems.set(i,diwg);
      }
 else {
        DisplayItemBean dib=diwg.getSingleItem();
        boolean hasSCDItemInSection=section.getSection().hasSCDItem();
        Set<Integer> showSCDItemIds=section.getShowSCDItemIds();
        if (validate) {
          String itemName=getInputName(dib);
          dib=validateDisplayItemBean(v,dib,"String_Node_Str");
          if (section.getSection().hasSCDItem()) {
            if (dib.getSCDPairs().size() > 0) {
              section.setShowSCDItemIds(this.conditionalDisplayToBeShown(dib,section.getShowSCDItemIds()));
            }
 else             if (dib.getMetadata().isConditionalDisplayItem()) {
              dib.setIsSCDtoBeShown(section.getShowSCDItemIds().contains(dib.getMetadata().getItemId()));
              validateSCDItemBean(v,dib);
            }
          }
          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);
        }
        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);
            if (section.getSection().hasSCDItem()) {
              if (child.getSCDPairs().size() > 0) {
                section.setShowSCDItemIds(this.conditionalDisplayToBeShown(child,section.getShowSCDItemIds()));
              }
 else               if (child.getMetadata().isConditionalDisplayItem()) {
                dib.setIsSCDtoBeShown(section.getShowSCDItemIds().contains(child.getMetadata().getItemId()));
                validateSCDItemBean(v,child);
              }
            }
          }
 else {
            child=loadFormValue(child);
          }
          logger.debug("String_Node_Str" + itemName + "String_Node_Str"+ child.getData().getValue());
          children.set(j,child);
        }
        dib.setChildren(children);
        diwg.setSingleItem(runDynamicsItemCheck(dib));
        logger.debug("String_Node_Str" + i);
        allItems.set(i,diwg);
      }
    }
    Phase phase2=Phase.INITIAL_DATA_ENTRY;
    if (getServletPage().equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
      phase2=Phase.DOUBLE_DATA_ENTRY;
    }
 else     if (getServletPage().equals(Page.ADMIN_EDIT_SERVLET)) {
      phase2=Phase.ADMIN_EDITING;
    }
    HashMap<String,ArrayList<String>> groupOrdinalPLusItemOid=runRules(allItems,ruleSets,true,shouldRunRules(),MessageType.ERROR,phase2);
    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);
          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);
        }
        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);
          }
          children.set(j,child);
          logger.debug("String_Node_Str" + j);
        }
        dib.setChildren(children);
        diwg.setSingleItem(runDynamicsItemCheck(dib));
        logger.debug("String_Node_Str" + i);
        allItems.set(i,diwg);
      }
    }
    HashMap<String,ItemBean> scoreItems=new HashMap<String,ItemBean>();
    HashMap<String,String> scoreItemdata=new HashMap<String,String>();
    HashMap<Integer,String> oldItemdata=prepareSectionItemdata(sb.getId());
    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();
    updateDataOrdinals(allItems);
    section.setDisplayItemGroups(allItems);
    scoreItems=prepareScoreItems();
    scoreItemdata=prepareScoreItemdata();
    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(idb,oldItemdata)) {
              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)) {
          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)) {
            changedItems.add(itemName);
            changedItemsList.add(child);
          }
        }
      }
    }
    ScoreItemValidator sv=new ScoreItemValidator(request,discNotes);
    ScoreCalculator sc=new ScoreCalculator(sm,ecb,ub);
    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.getData(),oldItemdata))               changedItems.add(displayItem.getItem().getName());
              request.setAttribute(inputName,value);
              if (validate) {
                displayItem=validateCalcTypeDisplayItemBean(sv,displayItem,inputName);
                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)) {
            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");
            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)) {
              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");
              if (cerr.length() > 0) {
                Validation cvalidation=new Validation(Validator.CALCULATION_FAILED);
                cvalidation.setErrorMessage(cerr.toString());
                sv.addValidation(cinputName,cvalidation);
              }
            }
          }
          children.set(j,child);
        }
      }
    }
    section.setDisplayItemGroups(allItems);
    section=populateNotesWithDBNoteCounts(discNotes,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);
    }
    errors=v.validate();
    if (this.isAdminForcedReasonForChange() && 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());
        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);
                changedItemsMap.remove(formName2);
                logger.debug("String_Node_Str" + formName);
                break;
              }
            }
          }
 else {
            this.setReasonForChangeError(idb,formName,error);
            logger.debug("String_Node_Str" + formName);
          }
        }
      }
      if (nonforcedChanges > 0) {
      }
    }
    logger.debug("String_Node_Str" + errors.toString());
    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());
      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);
      Iterator iter3=errors.keySet().iterator();
      while (iter3.hasNext()) {
        String fieldName=iter3.next().toString();
        logger.debug("String_Node_Str" + fieldName);
      }
      request.setAttribute(BEAN_DISPLAY,section);
      request.setAttribute(BEAN_ANNOTATIONS,fp.getString(INPUT_ANNOTATIONS));
      setInputMessages(errors);
      addPageMessage(respage.getString("String_Node_Str"));
      request.setAttribute("String_Node_Str","String_Node_Str");
      session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
      setUpPanel(section);
      forwardPage(getJSPPage());
    }
 else {
      logger.debug("String_Node_Str");
      ItemDataDAO iddao=new ItemDataDAO(sm.getDataSource());
      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(sm.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)) {
        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) {
        logger.debug("String_Node_Str");
        StudySubjectDAO studySubjectDao=new StudySubjectDAO(sm.getDataSource());
        ssb.setStatus(Status.AVAILABLE);
        ssb.setUpdater(ub);
        ssb.setUpdatedDate(new Date());
        studySubjectDao.update(ssb);
      }
      if (ecb.isSdvStatus()) {
        logger.debug("String_Node_Str");
        StudySubjectDAO studySubjectDao=new StudySubjectDAO(sm.getDataSource());
        ssb.setStatus(Status.AVAILABLE);
        ssb.setUpdater(ub);
        ssb.setUpdatedDate(new Date());
        studySubjectDao.update(ssb);
        ecb.setSdvStatus(false);
      }
      ecb=(EventCRFBean)ecdao.update(ecb);
      FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      dndao=new DiscrepancyNoteDAO(sm.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);
      String attachedFilePath=Utils.getAttachedFilePath(currentStudy);
      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);
              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.info("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);
                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);
          if (dib.getMetadata().isConditionalDisplayItem()) {
            temp=this.writeConditionalDisplayItemToDB(dib,iddao,1,section.getShowSCDItemIds().contains(dib.getMetadata().getItemId()));
          }
 else {
            temp=writeToDB(dib,iddao,1);
          }
          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);
            if (child.getMetadata().isConditionalDisplayItem()) {
              temp=this.writeConditionalDisplayItemToDB(child,iddao,1,section.getShowSCDItemIds().contains(child.getMetadata().getItemId()));
            }
 else {
              temp=writeToDB(child,iddao,1);
            }
            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;
          }
        }
      }
      logger.debug("String_Node_Str" + phase2.name());
      HashMap<String,ArrayList<String>> rulesPostDryRun=runRules(allItems,ruleSets,false,shouldRunRules(),MessageType.WARNING,phase2);
      HashMap<String,ArrayList<String>> errorsPostDryRun=new HashMap<String,ArrayList<String>>();
      boolean inSameSection=false;
      if (!rulesPostDryRun.isEmpty()) {
        Iterator iter3=rulesPostDryRun.keySet().iterator();
        while (iter3.hasNext()) {
          String fieldName=iter3.next().toString();
          logger.debug("String_Node_Str" + fieldName);
          String newFieldName=fieldName;
          String[] fieldNames=fieldName.split("String_Node_Str");
          if (fieldNames.length == 2) {
            newFieldName=fieldNames[1];
          }
          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])) {
                  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);
                        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())) {
                System.out.println("String_Node_Str" + displayItemBean.getItem().getId() + "String_Node_Str"+ displayItemBean.getMetadata().isShowItem());
                if (!displayItemBean.getMetadata().isShowItem() && !runDynamicsItemCheck(displayItemBean).getMetadata().isShowItem()) {
                  inSameSection=true;
                  logger.debug("String_Node_Str" + this.getInputName(displayItemBean) + "String_Node_Str"+ fieldName+ "String_Node_Str"+ displayItemBean.getMetadata().isShowItem());
                  errorsPostDryRun.put(this.getInputName(displayItemBean),rulesPostDryRun.get(fieldName));
                  displayItemBean.getMetadata().setShowItem(true);
                }
              }
              itemWithGroup.setSingleItem(displayItemBean);
            }
            displayGroupsWithItems.set(i,itemWithGroup);
          }
          List<DisplayItemGroupBean> itemGroups=new ArrayList<DisplayItemGroupBean>();
          itemGroups=section.getDisplayFormGroups();
          for (          DisplayItemGroupBean displayGroup : itemGroups) {
            if (fieldName.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);
              }
            }
          }
          section.setDisplayItemGroups(displayGroupsWithItems);
        }
        List<DisplayItemWithGroupBean> displayItemWithGroups2=createItemWithGroups(section,hasGroup,eventDefinitionCRFId);
        section.setDisplayItemGroups(displayItemWithGroups2);
        logger.debug("String_Node_Str" + inSameSection);
        System.out.println("String_Node_Str" + inSameSection);
        if (inSameSection) {
          String[] textFields={INPUT_INTERVIEWER,INPUT_INTERVIEW_DATE};
          fp.setCurrentStringValuesAsPreset(textFields);
          setPresetValues(fp.getPresetValues());
          request.setAttribute(BEAN_DISPLAY,section);
          request.setAttribute(BEAN_ANNOTATIONS,fp.getString(INPUT_ANNOTATIONS));
          setInputMessages(errorsPostDryRun);
          addPageMessage(respage.getString("String_Node_Str"));
          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());
        }
      }
      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) {
          logger.debug("String_Node_Str");
          markSuccessfully=markCRFComplete();
          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());
            return;
          }
        }
        String annotations=fp.getString(INPUT_ANNOTATIONS);
        setEventCRFAnnotations(annotations);
        Date now=new Date();
        ecb.setUpdatedDate(now);
        ecb.setUpdater(ub);
        ecb=(EventCRFBean)ecdao.update(ecb);
        success=success && ecb.isActive();
        StudyEventDAO sedao=new StudyEventDAO(sm.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);
          }
        }
        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);
          }
 else {
            addPageMessage(resexception.getString("String_Node_Str"));
          }
          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");
          forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
        }
 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());
            }
          }
 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());
            }
          }
          if (!forwardingSucceeded) {
            if (markSuccessfully) {
              addPageMessage(respage.getString("String_Node_Str"));
              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);
            }
 else {
              addPageMessage(respage.getString("String_Node_Str"));
              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 {
                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());
                forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET);
                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());
            }
          }
        }
      }
    }
  }
}

Fixed version (ground truth):
@Override protected void processRequest() throws Exception {
  locale=request.getLocale();
  FormDiscrepancyNotes discNotes;
  panel.setStudyInfoShown(false);
  String age="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(sm.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"));
      forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
    }
 else {
      lockThisEventCRF(ecb.getId(),ub.getId());
    }
  }
  if (!ecb.isActive()) {
    throw new InconsistentStateException(Page.LIST_STUDY_SUBJECTS_SERVLET,resexception.getString("String_Node_Str"));
  }
  DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
  ArrayList<DiscrepancyNoteBean> allNotes=new ArrayList<DiscrepancyNoteBean>();
  List<DiscrepancyNoteBean> eventCrfNotes=new ArrayList<DiscrepancyNoteBean>();
  List<DiscrepancyNoteThread> noteThreads=new ArrayList<DiscrepancyNoteThread>();
  dndao=new DiscrepancyNoteDAO(sm.getDataSource());
  allNotes=dndao.findAllTopNotesByEventCRF(ecb.getId());
  eventCrfNotes=dndao.findOnlyParentEventCRFDNotesFromEventCRF(ecb);
  if (!eventCrfNotes.isEmpty()) {
    allNotes.addAll(eventCrfNotes);
  }
  DiscrepancyNoteUtil dNoteUtil=new DiscrepancyNoteUtil();
  noteThreads=dNoteUtil.createThreadsOfParents(allNotes,sm.getDataSource(),currentStudy,null,-1,true);
  int updatedNum=0;
  int openNum=0;
  int closedNum=0;
  int resolvedNum=0;
  int notAppNum=0;
  DiscrepancyNoteBean tempBean;
  for (  DiscrepancyNoteThread dnThread : noteThreads) {
    tempBean=dnThread.getLinkedNoteList().getLast();
    if (tempBean != null) {
      if (ResolutionStatus.UPDATED.equals(tempBean.getResStatus())) {
        updatedNum++;
      }
 else       if (ResolutionStatus.OPEN.equals(tempBean.getResStatus())) {
        openNum++;
      }
 else       if (ResolutionStatus.CLOSED.equals(tempBean.getResStatus())) {
        closedNum++;
      }
 else       if (ResolutionStatus.RESOLVED.equals(tempBean.getResStatus())) {
        resolvedNum++;
      }
 else       if (ResolutionStatus.NOT_APPLICABLE.equals(tempBean.getResStatus())) {
        notAppNum++;
      }
    }
  }
  request.setAttribute("String_Node_Str",updatedNum + "String_Node_Str");
  request.setAttribute("String_Node_Str",openNum + "String_Node_Str");
  request.setAttribute("String_Node_Str",closedNum + "String_Node_Str");
  request.setAttribute("String_Node_Str",resolvedNum + "String_Node_Str");
  request.setAttribute("String_Node_Str",notAppNum + "String_Node_Str");
  StudySubjectDAO ssdao=new StudySubjectDAO(sm.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.setAttribute("String_Node_Str",new Integer(ecb.getStudySubjectId()).toString());
    forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
  }
  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"));
  }
  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);
      }
    }
    session.removeAttribute("String_Node_Str");
    addPageMessage(respage.getString("String_Node_Str"));
    String fromResolvingNotes=fp.getString("String_Node_Str",true);
    String winLocation=(String)session.getAttribute(ViewNotesServlet.WIN_LOCATION);
    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;
  }
  hasGroup=checkGroups();
  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");
  edcdao=new EventDefinitionCRFDAO(sm.getDataSource());
  if (eventDefinitionCRFId <= 0) {
    EventDefinitionCRFBean edcBean=edcdao.findByStudyEventIdAndCRFVersionId(study,ecb.getStudyEventId(),ecb.getCRFVersionId());
    eventDefinitionCRFId=edcBean.getId();
  }
  StudyEventDAO seDao=new StudyEventDAO(sm.getDataSource());
  EventDefinitionCRFBean edcBean=(EventDefinitionCRFBean)edcdao.findByPK(eventDefinitionCRFId);
  edcb=(EventDefinitionCRFBean)edcdao.findByPK(eventDefinitionCRFId);
  StudyEventBean studyEventBean=(StudyEventBean)seDao.findByPK(ecb.getStudyEventId());
  edcBean.setId(eventDefinitionCRFId);
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  StudyEventDefinitionBean studyEventDefinition=(StudyEventDefinitionBean)seddao.findByPK(edcBean.getStudyEventDefinitionId());
  CRFVersionDAO cvdao=new CRFVersionDAO(sm.getDataSource());
  CRFVersionBean crfVersionBean=(CRFVersionBean)cvdao.findByPK(ecb.getCRFVersionId());
  List<RuleSetBean> ruleSets=createAndInitializeRuleSet(currentStudy,studyEventDefinition,crfVersionBean,studyEventBean,ecb,shouldRunRules());
  DisplaySectionBean section=getDisplayBean(hasGroup,false);
  String firstFieldId=getSectionFirstFieldId(section.getSection().getId());
  request.setAttribute("String_Node_Str",firstFieldId);
  List<DisplayItemWithGroupBean> displayItemWithGroups=createItemWithGroups(section,hasGroup,eventDefinitionCRFId);
  section.setDisplayItemGroups(displayItemWithGroups);
  SectionBean previousSec=sdao.findPrevious(ecb,sb);
  SectionBean nextSec=sdao.findNext(ecb,sb);
  section.setFirstSection(!previousSec.isActive());
  section.setLastSection(!nextSec.isActive());
  SubjectDAO subjectDao=new SubjectDAO(sm.getDataSource());
  StudyDAO studydao=new StudyDAO(sm.getDataSource());
  SubjectBean subject=(SubjectBean)subjectDao.findByPK(ssb.getSubjectId());
  if (study.getParentStudyId() > 0) {
    StudyBean parentStudy=(StudyBean)studydao.findByPK(study.getParentStudyId());
    request.setAttribute("String_Node_Str",parentStudy.getName() + "String_Node_Str" + study.getName());
  }
 else {
    request.setAttribute("String_Node_Str",study.getName());
  }
  if (currentStudy.getStudyParameterConfig().getCollectDob().equals("String_Node_Str")) {
    Date enrollmentDate=ssb.getEnrollmentDate();
    age=Utils.getInstacne().processAge(enrollmentDate,subject.getDateOfBirth());
  }
  ArrayList beans=ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(ssb,sm.getDataSource(),ub,currentRole);
  request.setAttribute("String_Node_Str",ssb);
  request.setAttribute("String_Node_Str",subject);
  request.setAttribute("String_Node_Str",beans);
  request.setAttribute("String_Node_Str",ecb);
  request.setAttribute("String_Node_Str",age);
  request.setAttribute("String_Node_Str",((SecurityManager)SpringServletAccess.getApplicationContext(context).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());
  if (!isSubmitted) {
    request.setAttribute(BEAN_DISPLAY,section);
    request.setAttribute(BEAN_ANNOTATIONS,getEventCRFAnnotations());
    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);
    logger.debug("String_Node_Str" + discNotes.getFieldNotes().toString());
    logger.debug("String_Node_Str" + discNotes.getNumExistingFieldNotes().toString());
    session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
    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);
      }
    }
    forwardPage(getJSPPage());
  }
 else {
    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();
    DiscrepancyValidator v=new DiscrepancyValidator(request,discNotes);
    RuleValidator ruleValidator=new RuleValidator(request);
    logger.debug("String_Node_Str" + allItems.size());
    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.info("String_Node_Str" + dbGroups.size());
        if (validate) {
          logger.debug("String_Node_Str" + dgb.getGroupMetaBean().getName());
          formGroups=validateDisplayItemGroupBean(v,dgb,dbGroups,formGroups);
          logger.debug("String_Node_Str" + formGroups.size());
        }
 else {
          logger.debug("String_Node_Str" + dgb.getGroupMetaBean().getName());
          formGroups=loadFormValueForItemGroup(dgb,dbGroups,formGroups,eventDefinitionCRFId);
          logger.debug("String_Node_Str" + formGroups.size());
        }
        diwg.setItemGroup(dgb);
        diwg.setItemGroups(formGroups);
        allItems.set(i,diwg);
      }
 else {
        DisplayItemBean dib=diwg.getSingleItem();
        boolean hasSCDItemInSection=section.getSection().hasSCDItem();
        Set<Integer> showSCDItemIds=section.getShowSCDItemIds();
        if (validate) {
          String itemName=getInputName(dib);
          dib=validateDisplayItemBean(v,dib,"String_Node_Str");
          if (section.getSection().hasSCDItem()) {
            if (dib.getSCDPairs().size() > 0) {
              section.setShowSCDItemIds(this.conditionalDisplayToBeShown(dib,section.getShowSCDItemIds()));
            }
 else             if (dib.getMetadata().isConditionalDisplayItem()) {
              dib.setIsSCDtoBeShown(section.getShowSCDItemIds().contains(dib.getMetadata().getItemId()));
              validateSCDItemBean(v,dib);
            }
          }
          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);
        }
        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);
            if (section.getSection().hasSCDItem()) {
              if (child.getSCDPairs().size() > 0) {
                section.setShowSCDItemIds(this.conditionalDisplayToBeShown(child,section.getShowSCDItemIds()));
              }
 else               if (child.getMetadata().isConditionalDisplayItem()) {
                child.setIsSCDtoBeShown(section.getShowSCDItemIds().contains(child.getMetadata().getItemId()));
                validateSCDItemBean(v,child);
              }
            }
          }
 else {
            child=loadFormValue(child);
          }
          logger.debug("String_Node_Str" + itemName + "String_Node_Str"+ child.getData().getValue());
          children.set(j,child);
        }
        dib.setChildren(children);
        diwg.setSingleItem(runDynamicsItemCheck(dib));
        logger.debug("String_Node_Str" + i);
        allItems.set(i,diwg);
      }
    }
    Phase phase2=Phase.INITIAL_DATA_ENTRY;
    if (getServletPage().equals(Page.DOUBLE_DATA_ENTRY_SERVLET)) {
      phase2=Phase.DOUBLE_DATA_ENTRY;
    }
 else     if (getServletPage().equals(Page.ADMIN_EDIT_SERVLET)) {
      phase2=Phase.ADMIN_EDITING;
    }
    HashMap<String,ArrayList<String>> groupOrdinalPLusItemOid=runRules(allItems,ruleSets,true,shouldRunRules(),MessageType.ERROR,phase2);
    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);
          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);
        }
        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);
          }
          children.set(j,child);
          logger.debug("String_Node_Str" + j);
        }
        dib.setChildren(children);
        diwg.setSingleItem(runDynamicsItemCheck(dib));
        logger.debug("String_Node_Str" + i);
        allItems.set(i,diwg);
      }
    }
    HashMap<String,ItemBean> scoreItems=new HashMap<String,ItemBean>();
    HashMap<String,String> scoreItemdata=new HashMap<String,String>();
    HashMap<Integer,String> oldItemdata=prepareSectionItemdata(sb.getId());
    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();
    updateDataOrdinals(allItems);
    section.setDisplayItemGroups(allItems);
    scoreItems=prepareScoreItems();
    scoreItemdata=prepareScoreItemdata();
    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(idb,oldItemdata)) {
              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)) {
          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)) {
            changedItems.add(itemName);
            changedItemsList.add(child);
          }
        }
      }
    }
    ScoreItemValidator sv=new ScoreItemValidator(request,discNotes);
    ScoreCalculator sc=new ScoreCalculator(sm,ecb,ub);
    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.getData(),oldItemdata))               changedItems.add(displayItem.getItem().getName());
              request.setAttribute(inputName,value);
              if (validate) {
                displayItem=validateCalcTypeDisplayItemBean(sv,displayItem,inputName);
                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)) {
            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");
            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)) {
              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");
              if (cerr.length() > 0) {
                Validation cvalidation=new Validation(Validator.CALCULATION_FAILED);
                cvalidation.setErrorMessage(cerr.toString());
                sv.addValidation(cinputName,cvalidation);
              }
            }
          }
          children.set(j,child);
        }
      }
    }
    section.setDisplayItemGroups(allItems);
    section=populateNotesWithDBNoteCounts(discNotes,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);
    }
    errors=v.validate();
    if (this.isAdminForcedReasonForChange() && 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());
        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);
                changedItemsMap.remove(formName2);
                logger.debug("String_Node_Str" + formName);
                break;
              }
            }
          }
 else {
            this.setReasonForChangeError(idb,formName,error);
            logger.debug("String_Node_Str" + formName);
          }
        }
      }
      if (nonforcedChanges > 0) {
      }
    }
    logger.debug("String_Node_Str" + errors.toString());
    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());
      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);
      Iterator iter3=errors.keySet().iterator();
      while (iter3.hasNext()) {
        String fieldName=iter3.next().toString();
        logger.debug("String_Node_Str" + fieldName);
      }
      request.setAttribute(BEAN_DISPLAY,section);
      request.setAttribute(BEAN_ANNOTATIONS,fp.getString(INPUT_ANNOTATIONS));
      setInputMessages(errors);
      addPageMessage(respage.getString("String_Node_Str"));
      request.setAttribute("String_Node_Str","String_Node_Str");
      session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
      setUpPanel(section);
      forwardPage(getJSPPage());
    }
 else {
      logger.debug("String_Node_Str");
      ItemDataDAO iddao=new ItemDataDAO(sm.getDataSource());
      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(sm.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)) {
        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) {
        logger.debug("String_Node_Str");
        StudySubjectDAO studySubjectDao=new StudySubjectDAO(sm.getDataSource());
        ssb.setStatus(Status.AVAILABLE);
        ssb.setUpdater(ub);
        ssb.setUpdatedDate(new Date());
        studySubjectDao.update(ssb);
      }
      if (ecb.isSdvStatus()) {
        logger.debug("String_Node_Str");
        StudySubjectDAO studySubjectDao=new StudySubjectDAO(sm.getDataSource());
        ssb.setStatus(Status.AVAILABLE);
        ssb.setUpdater(ub);
        ssb.setUpdatedDate(new Date());
        studySubjectDao.update(ssb);
        ecb.setSdvStatus(false);
      }
      ecb=(EventCRFBean)ecdao.update(ecb);
      FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      dndao=new DiscrepancyNoteDAO(sm.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);
      String attachedFilePath=Utils.getAttachedFilePath(currentStudy);
      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);
              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.info("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);
                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);
          if (dib.getMetadata().isConditionalDisplayItem()) {
            temp=this.writeConditionalDisplayItemToDB(dib,iddao,1,section.getShowSCDItemIds().contains(dib.getMetadata().getItemId()));
          }
 else {
            temp=writeToDB(dib,iddao,1);
          }
          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);
            if (child.getMetadata().isConditionalDisplayItem()) {
              temp=this.writeConditionalDisplayItemToDB(child,iddao,1,section.getShowSCDItemIds().contains(child.getMetadata().getItemId()));
            }
 else {
              temp=writeToDB(child,iddao,1);
            }
            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;
          }
        }
      }
      logger.debug("String_Node_Str" + phase2.name());
      HashMap<String,ArrayList<String>> rulesPostDryRun=runRules(allItems,ruleSets,false,shouldRunRules(),MessageType.WARNING,phase2);
      HashMap<String,ArrayList<String>> errorsPostDryRun=new HashMap<String,ArrayList<String>>();
      boolean inSameSection=false;
      if (!rulesPostDryRun.isEmpty()) {
        Iterator iter3=rulesPostDryRun.keySet().iterator();
        while (iter3.hasNext()) {
          String fieldName=iter3.next().toString();
          logger.debug("String_Node_Str" + fieldName);
          String newFieldName=fieldName;
          String[] fieldNames=fieldName.split("String_Node_Str");
          if (fieldNames.length == 2) {
            newFieldName=fieldNames[1];
          }
          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])) {
                  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);
                        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())) {
                System.out.println("String_Node_Str" + displayItemBean.getItem().getId() + "String_Node_Str"+ displayItemBean.getMetadata().isShowItem());
                if (!displayItemBean.getMetadata().isShowItem() && !runDynamicsItemCheck(displayItemBean).getMetadata().isShowItem()) {
                  inSameSection=true;
                  logger.debug("String_Node_Str" + this.getInputName(displayItemBean) + "String_Node_Str"+ fieldName+ "String_Node_Str"+ displayItemBean.getMetadata().isShowItem());
                  errorsPostDryRun.put(this.getInputName(displayItemBean),rulesPostDryRun.get(fieldName));
                  displayItemBean.getMetadata().setShowItem(true);
                }
              }
              itemWithGroup.setSingleItem(displayItemBean);
            }
            displayGroupsWithItems.set(i,itemWithGroup);
          }
          List<DisplayItemGroupBean> itemGroups=new ArrayList<DisplayItemGroupBean>();
          itemGroups=section.getDisplayFormGroups();
          for (          DisplayItemGroupBean displayGroup : itemGroups) {
            if (fieldName.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);
              }
            }
          }
          section.setDisplayItemGroups(displayGroupsWithItems);
        }
        List<DisplayItemWithGroupBean> displayItemWithGroups2=createItemWithGroups(section,hasGroup,eventDefinitionCRFId);
        section.setDisplayItemGroups(displayItemWithGroups2);
        logger.debug("String_Node_Str" + inSameSection);
        System.out.println("String_Node_Str" + inSameSection);
        if (inSameSection) {
          String[] textFields={INPUT_INTERVIEWER,INPUT_INTERVIEW_DATE};
          fp.setCurrentStringValuesAsPreset(textFields);
          setPresetValues(fp.getPresetValues());
          request.setAttribute(BEAN_DISPLAY,section);
          request.setAttribute(BEAN_ANNOTATIONS,fp.getString(INPUT_ANNOTATIONS));
          setInputMessages(errorsPostDryRun);
          addPageMessage(respage.getString("String_Node_Str"));
          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());
        }
      }
      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) {
          logger.debug("String_Node_Str");
          markSuccessfully=markCRFComplete();
          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());
            return;
          }
        }
        String annotations=fp.getString(INPUT_ANNOTATIONS);
        setEventCRFAnnotations(annotations);
        Date now=new Date();
        ecb.setUpdatedDate(now);
        ecb.setUpdater(ub);
        ecb=(EventCRFBean)ecdao.update(ecb);
        success=success && ecb.isActive();
        StudyEventDAO sedao=new StudyEventDAO(sm.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);
          }
        }
        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);
          }
 else {
            addPageMessage(resexception.getString("String_Node_Str"));
          }
          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");
          forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
        }
 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());
            }
          }
 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());
            }
          }
          if (!forwardingSucceeded) {
            if (markSuccessfully) {
              addPageMessage(respage.getString("String_Node_Str"));
              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);
            }
 else {
              addPageMessage(respage.getString("String_Node_Str"));
              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 {
                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());
                forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET);
                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());
            }
          }
        }
      }
    }
  }
}