Program: 115335
Project: 115335
Buggy source:
@Override protected void processRequest() throws Exception {
  checkStudyLocked(Page.LIST_STUDY_SUBJECTS,respage.getString("String_Node_Str"));
  panel.setStudyInfoShown(false);
  fp=new FormProcessor(request);
  FormDiscrepancyNotes discNotes=null;
  int studySubjectId=fp.getInt(INPUT_STUDY_SUBJECT_ID_FROM_VIEWSUBJECT);
  int studyEventDefinitionId=fp.getInt(INPUT_STUDY_EVENT_DEFINITION);
  StudySubjectDAO sdao=new StudySubjectDAO(sm.getDataSource());
  StudySubjectBean ssb;
  if (studySubjectId <= 0) {
    ssb=(StudySubjectBean)request.getAttribute(INPUT_STUDY_SUBJECT);
  }
 else {
    ssb=(StudySubjectBean)sdao.findByPK(studySubjectId);
    Status s=ssb.getStatus();
    if ("String_Node_Str".equalsIgnoreCase(s.getName()) || "String_Node_Str".equalsIgnoreCase(s.getName())) {
      addPageMessage(resword.getString("String_Node_Str") + resterm.getString("String_Node_Str") + resterm.getString("String_Node_Str")+ "String_Node_Str"+ respage.getString("String_Node_Str"));
      request.setAttribute("String_Node_Str",new Integer(studySubjectId).toString());
      forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    }
    request.setAttribute(INPUT_REQUEST_STUDY_SUBJECT,"String_Node_Str");
  }
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  StudyBean studyWithEventDefinitions=currentStudy;
  if (currentStudy.getParentStudyId() > 0) {
    studyWithEventDefinitions=new StudyBean();
    studyWithEventDefinitions.setId(currentStudy.getParentStudyId());
  }
  ArrayList eventDefinitions=seddao.findAllActiveByStudy(studyWithEventDefinitions);
  Collections.sort(eventDefinitions);
  ArrayList eventDefinitionsScheduled=eventDefinitions;
  if (!fp.isSubmitted()) {
    HashMap presetValues=new HashMap();
    presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",new Integer(-1));
    presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",new Integer(-1));
    presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",new String("String_Node_Str"));
    presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",new Integer(-1));
    presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",new Integer(-1));
    presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",new String("String_Node_Str"));
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      presetValues.put(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new Integer(-1));
      presetValues.put(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new Integer(-1));
      presetValues.put(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new String("String_Node_Str"));
      presetValues.put(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new Integer(-1));
      presetValues.put(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new Integer(-1));
      presetValues.put(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new String("String_Node_Str"));
    }
    String dateValue=local_df.format(new Date(System.currentTimeMillis()));
    presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",dateValue);
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      presetValues.put(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",dateValue);
      presetValues.put(INPUT_SCHEDULED_LOCATION[i],currentStudy.getFacilityCity());
      presetValues.put(this.DISPLAY_SCHEDULED[i],"String_Node_Str");
    }
    presetValues.put(INPUT_LOCATION,currentStudy.getFacilityCity());
    if (ssb != null && ssb.isActive()) {
      presetValues.put(INPUT_STUDY_SUBJECT,ssb);
      String requestStudySubject=(String)request.getAttribute(INPUT_REQUEST_STUDY_SUBJECT);
      if (requestStudySubject != null) {
        presetValues.put(INPUT_REQUEST_STUDY_SUBJECT,requestStudySubject);
        dateValue=local_df.format(new Date());
        presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",dateValue);
      }
    }
    if (studyEventDefinitionId > 0) {
      StudyEventDefinitionBean sed=(StudyEventDefinitionBean)seddao.findByPK(studyEventDefinitionId);
      presetValues.put(INPUT_STUDY_EVENT_DEFINITION,sed);
    }
    logger.info("String_Node_Str" + presetValues.toString());
    System.out.println("String_Node_Str" + presetValues.toString());
    logger.info("String_Node_Str" + eventDefinitions.size());
    setPresetValues(presetValues);
    ArrayList subjects=new ArrayList();
    setupBeans(subjects,eventDefinitions);
    discNotes=new FormDiscrepancyNotes();
    session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
    request.setAttribute("String_Node_Str",eventDefinitionsScheduled);
    setInputMessages(new HashMap());
    forwardPage(Page.CREATE_NEW_STUDY_EVENT);
  }
 else {
    String dateCheck2=request.getParameter("String_Node_Str");
    String endCheck2=request.getParameter("String_Node_Str");
    logger.info(dateCheck2 + "String_Node_Str" + endCheck2);
    String strEnd=fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX);
    String strEndScheduled[]=new String[ADDITIONAL_SCHEDULED_NUM];
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      strEndScheduled[i]=fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX_SCHEDULED[i]);
    }
    Date start=getInputStartDate();
    Date end=null;
    Date[] startScheduled=new Date[ADDITIONAL_SCHEDULED_NUM];
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      startScheduled[i]=getInputStartDateScheduled(i);
    }
    Date[] endScheduled=new Date[ADDITIONAL_SCHEDULED_NUM];
    discNotes=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    if (discNotes == null) {
      discNotes=new FormDiscrepancyNotes();
      session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
    }
    DiscrepancyValidator v=new DiscrepancyValidator(request,discNotes);
    v.addValidation(INPUT_STARTDATE_PREFIX,Validator.IS_DATE_TIME);
    v.alwaysExecuteLastValidation(INPUT_STARTDATE_PREFIX);
    if (!strEnd.equals("String_Node_Str")) {
      v.addValidation(INPUT_ENDDATE_PREFIX,Validator.IS_DATE_TIME);
      v.alwaysExecuteLastValidation(INPUT_ENDDATE_PREFIX);
    }
    v.addValidation(INPUT_STUDY_EVENT_DEFINITION,Validator.ENTITY_EXISTS_IN_STUDY,seddao,studyWithEventDefinitions);
    v.addValidation(INPUT_LOCATION,Validator.NO_BLANKS);
    v.addValidation(INPUT_STUDY_SUBJECT_LABEL,Validator.NO_BLANKS);
    v.addValidation(INPUT_LOCATION,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,2000);
    v.alwaysExecuteLastValidation(INPUT_LOCATION);
    boolean hasScheduledEvent=false;
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      if (!StringUtil.isBlank(fp.getString(this.INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i]))) {
        v.addValidation(this.INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i],Validator.ENTITY_EXISTS_IN_STUDY,seddao,studyWithEventDefinitions);
        v.addValidation(INPUT_SCHEDULED_LOCATION[i],Validator.NO_BLANKS);
        v.addValidation(INPUT_SCHEDULED_LOCATION[i],Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,2000);
        v.alwaysExecuteLastValidation(INPUT_SCHEDULED_LOCATION[i]);
        v.addValidation(INPUT_STARTDATE_PREFIX_SCHEDULED[i],Validator.IS_DATE_TIME);
        v.alwaysExecuteLastValidation(INPUT_STARTDATE_PREFIX_SCHEDULED[i]);
        if (!strEndScheduled[i].equals("String_Node_Str")) {
          v.addValidation(INPUT_ENDDATE_PREFIX_SCHEDULED[i],Validator.IS_DATE_TIME);
          v.alwaysExecuteLastValidation(INPUT_ENDDATE_PREFIX_SCHEDULED[i]);
        }
        hasScheduledEvent=true;
        fp.addPresetValue(DISPLAY_SCHEDULED[i],"String_Node_Str");
      }
 else {
        fp.addPresetValue(DISPLAY_SCHEDULED[i],"String_Node_Str");
      }
    }
    HashMap errors=v.validate();
    String location=resword.getString("String_Node_Str");
    if (!StringUtil.isBlank(fp.getString(INPUT_LOCATION)) && fp.getString(INPUT_LOCATION).equalsIgnoreCase(location)) {
      Validator.addError(errors,INPUT_LOCATION,restext.getString("String_Node_Str"));
    }
    StudyEventDefinitionBean definition=(StudyEventDefinitionBean)seddao.findByPK(fp.getInt(INPUT_STUDY_EVENT_DEFINITION));
    StudySubjectBean studySubject=(StudySubjectBean)sdao.findByLabelAndStudy(fp.getString(INPUT_STUDY_SUBJECT_LABEL),currentStudy);
    if (request.getAttribute(INPUT_STUDY_SUBJECT) != null) {
      studySubject=(StudySubjectBean)request.getAttribute(INPUT_STUDY_SUBJECT);
    }
    if (studySubject.getLabel() == "String_Node_Str") {
      System.out.println("String_Node_Str");
      Validator.addError(errors,INPUT_STUDY_SUBJECT,respage.getString("String_Node_Str"));
    }
    if (!subjectMayReceiveStudyEvent(sm.getDataSource(),definition,studySubject)) {
      Validator.addError(errors,INPUT_STUDY_EVENT_DEFINITION,restext.getString("String_Node_Str"));
    }
    ArrayList<StudyEventDefinitionBean> definitionScheduleds=new ArrayList<StudyEventDefinitionBean>();
    int[] scheduledDefinitionIds=new int[ADDITIONAL_SCHEDULED_NUM];
    if (hasScheduledEvent) {
      for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
        int pk=fp.getInt(INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i]);
        if (pk > 0) {
          StudyEventDefinitionBean sedb=(StudyEventDefinitionBean)seddao.findByPK(pk);
          System.out.println("String_Node_Str" + pk + "String_Node_Str"+ INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i]+ "String_Node_Str"+ sedb.getName());
          definitionScheduleds.add(sedb);
          scheduledDefinitionIds[i]=pk;
          if (!subjectMayReceiveStudyEvent(sm.getDataSource(),sedb,studySubject)) {
            Validator.addError(errors,INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i],restext.getString("String_Node_Str"));
          }
        }
 else {
          definitionScheduleds.add(new StudyEventDefinitionBean());
        }
      }
    }
    if (!"String_Node_Str".equals(strEnd) && !errors.containsKey(INPUT_STARTDATE_PREFIX) && !errors.containsKey(INPUT_ENDDATE_PREFIX)) {
      end=getInputEndDate();
      if (!fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals(fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str"))) {
        if (end.before(start)) {
          Validator.addError(errors,INPUT_ENDDATE_PREFIX,resexception.getString("String_Node_Str"));
        }
      }
 else {
        if (fp.timeEntered(INPUT_STARTDATE_PREFIX) && fp.timeEntered(INPUT_ENDDATE_PREFIX)) {
          if (end.before(start) || end.equals(start)) {
            Validator.addError(errors,INPUT_ENDDATE_PREFIX,resexception.getString("String_Node_Str"));
          }
        }
      }
    }
    String prevStartPrefix=INPUT_STARTDATE_PREFIX;
    Set<Integer> pickedSeds=new TreeSet<Integer>();
    pickedSeds.add(studyEventDefinitionId);
    HashMap<Integer,Integer> scheduledSeds=new HashMap<Integer,Integer>();
    scheduledSeds.put(studyEventDefinitionId,-1);
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      if (scheduledDefinitionIds[i] > 0 && !errors.containsKey(INPUT_STARTDATE_PREFIX_SCHEDULED[i]) && !errors.containsKey(INPUT_ENDDATE_PREFIX_SCHEDULED[i])) {
        if (scheduledSeds.containsKey(scheduledDefinitionIds[i])) {
          int prevStart=scheduledSeds.get(scheduledDefinitionIds[i]);
          prevStartPrefix=prevStart == -1 ? INPUT_STARTDATE_PREFIX : INPUT_STARTDATE_PREFIX_SCHEDULED[prevStart];
          Date prevStartDate=prevStart == -1 ? this.getInputStartDate() : this.getInputStartDateScheduled(Integer.parseInt(prevStartPrefix.charAt(prevStartPrefix.length() - 1) + "String_Node_Str"));
          if (fp.getString(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str").equals(fp.getString(prevStartPrefix + "String_Node_Str"))) {
            boolean schStartTime=fp.timeEntered(INPUT_STARTDATE_PREFIX_SCHEDULED[i]);
            boolean startTime=fp.timeEntered(prevStartPrefix);
            if (schStartTime && startTime) {
              if (startScheduled[i].before(prevStartDate)) {
                Validator.addError(errors,INPUT_STARTDATE_PREFIX_SCHEDULED[i],resexception.getString("String_Node_Str"));
              }
            }
          }
 else {
            if (startScheduled[i].before(prevStartDate)) {
              Validator.addError(errors,INPUT_STARTDATE_PREFIX_SCHEDULED[i],resexception.getString("String_Node_Str"));
            }
          }
        }
        scheduledSeds.put(scheduledDefinitionIds[i],i);
        if (!strEndScheduled[i].equals("String_Node_Str")) {
          endScheduled[i]=fp.getDateTime(INPUT_ENDDATE_PREFIX_SCHEDULED[i]);
          String prevEndPrefix=i > 0 ? INPUT_ENDDATE_PREFIX_SCHEDULED[i - 1] : INPUT_ENDDATE_PREFIX;
          if (!fp.getString(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str").equals(fp.getString(prevEndPrefix + "String_Node_Str"))) {
            if (endScheduled[i].before(startScheduled[i])) {
              Validator.addError(errors,INPUT_ENDDATE_PREFIX_SCHEDULED[i],resexception.getString("String_Node_Str"));
            }
          }
 else {
            if (fp.timeEntered(INPUT_STARTDATE_PREFIX_SCHEDULED[i]) && fp.timeEntered(INPUT_ENDDATE_PREFIX_SCHEDULED[i])) {
              if (endScheduled[i].before(startScheduled[i]) || endScheduled[i].equals(startScheduled[i])) {
                Validator.addError(errors,INPUT_ENDDATE_PREFIX_SCHEDULED[i],resexception.getString("String_Node_Str"));
              }
            }
          }
        }
      }
    }
    System.out.println("String_Node_Str" + errors.size());
    if (!errors.isEmpty()) {
      logger.info("String_Node_Str" + errors.size());
      System.out.println("String_Node_Str" + fp.getString(INPUT_REQUEST_STUDY_SUBJECT));
      addPageMessage(respage.getString("String_Node_Str"));
      setInputMessages(errors);
      fp.addPresetValue(INPUT_STUDY_EVENT_DEFINITION,definition);
      fp.addPresetValue(INPUT_STUDY_SUBJECT,studySubject);
      fp.addPresetValue(INPUT_STUDY_SUBJECT_LABEL,fp.getString(INPUT_STUDY_SUBJECT_LABEL));
      fp.addPresetValue(INPUT_REQUEST_STUDY_SUBJECT,fp.getString(INPUT_REQUEST_STUDY_SUBJECT));
      fp.addPresetValue(INPUT_LOCATION,fp.getString(INPUT_LOCATION));
      for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
        fp.addPresetValue(INPUT_SCHEDULED_LOCATION[i],fp.getString(INPUT_SCHEDULED_LOCATION[i]));
      }
      String prefixes[]=new String[2 + 2 * ADDITIONAL_SCHEDULED_NUM];
      prefixes[0]=INPUT_STARTDATE_PREFIX;
      prefixes[1]=INPUT_ENDDATE_PREFIX;
      int b=ADDITIONAL_SCHEDULED_NUM + 2;
      for (int i=2; i < b; ++i) {
        prefixes[i]=INPUT_STARTDATE_PREFIX_SCHEDULED[i - 2];
      }
      for (int i=b; i < ADDITIONAL_SCHEDULED_NUM + b; ++i) {
        prefixes[i]=INPUT_ENDDATE_PREFIX_SCHEDULED[i - b];
      }
      fp.setCurrentDateTimeValuesAsPreset(prefixes);
      if (hasScheduledEvent) {
        for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
          fp.addPresetValue(INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i],definitionScheduleds.get(i));
        }
      }
      setPresetValues(fp.getPresetValues());
      ArrayList subjects=new ArrayList();
      setupBeans(subjects,eventDefinitions);
      request.setAttribute("String_Node_Str",eventDefinitionsScheduled);
      forwardPage(Page.CREATE_NEW_STUDY_EVENT);
    }
 else {
      System.out.println("String_Node_Str");
      StudyEventDAO sed=new StudyEventDAO(sm.getDataSource());
      StudyEventBean studyEvent=new StudyEventBean();
      studyEvent.setStudyEventDefinitionId(definition.getId());
      studyEvent.setStudySubjectId(studySubject.getId());
      if ("String_Node_Str".equals(getInputStartHour()) && "String_Node_Str".equals(getInputStartMinute()) && "String_Node_Str".equals(getInputStartHalf())) {
        studyEvent.setStartTimeFlag(false);
      }
 else {
        studyEvent.setStartTimeFlag(true);
      }
      studyEvent.setDateStarted(start);
      logger.info("String_Node_Str" + local_df.format(start));
      Date startScheduled2[]=new Date[ADDITIONAL_SCHEDULED_NUM];
      for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
        startScheduled2[i]=getInputStartDateScheduled(i);
      }
      if (!"String_Node_Str".equals(strEnd)) {
        if ("String_Node_Str".equals(getInputEndHour()) && "String_Node_Str".equals(getInputEndMinute()) && "String_Node_Str".equals(getInputEndHalf())) {
          studyEvent.setEndTimeFlag(false);
        }
 else {
          studyEvent.setEndTimeFlag(true);
        }
        studyEvent.setDateEnded(end);
      }
      studyEvent.setOwner(ub);
      studyEvent.setStatus(Status.AVAILABLE);
      studyEvent.setLocation(fp.getString(INPUT_LOCATION));
      studyEvent.setSubjectEventStatus(SubjectEventStatus.SCHEDULED);
      studyEvent.setSampleOrdinal(sed.getMaxSampleOrdinal(definition,studySubject) + 1);
      studyEvent=(StudyEventBean)sed.create(studyEvent);
      if (!studyEvent.isActive()) {
        throw new OpenClinicaException(restext.getString("String_Node_Str"),"String_Node_Str");
      }
      addPageMessage(restext.getString("String_Node_Str") + definition.getName() + restext.getString("String_Node_Str")+ studySubject.getName()+ respage.getString("String_Node_Str"));
      FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
      String[] eventFields={INPUT_LOCATION,INPUT_STARTDATE_PREFIX,INPUT_ENDDATE_PREFIX};
      for (      String element : eventFields) {
        AddNewSubjectServlet.saveFieldNotes(element,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      }
      if (hasScheduledEvent) {
        for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
          if (scheduledDefinitionIds[i] > 0) {
            if (subjectMayReceiveStudyEvent(sm.getDataSource(),definitionScheduleds.get(i),studySubject)) {
              StudyEventBean studyEventScheduled=new StudyEventBean();
              studyEventScheduled.setStudyEventDefinitionId(scheduledDefinitionIds[i]);
              studyEventScheduled.setStudySubjectId(studySubject.getId());
              if ("String_Node_Str".equals(fp.getString(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str")) && "String_Node_Str".equals(fp.getString(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str")) && "String_Node_Str".equals(fp.getString(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str"))) {
                studyEventScheduled.setStartTimeFlag(false);
              }
 else {
                studyEventScheduled.setStartTimeFlag(true);
              }
              studyEventScheduled.setDateStarted(startScheduled[i]);
              if (!"String_Node_Str".equals(strEndScheduled[i])) {
                endScheduled[i]=fp.getDateTime(INPUT_ENDDATE_PREFIX_SCHEDULED[i]);
                if ("String_Node_Str".equals(fp.getString(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str")) && "String_Node_Str".equals(fp.getString(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str")) && "String_Node_Str".equals(fp.getString(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str"))) {
                  studyEventScheduled.setEndTimeFlag(false);
                }
 else {
                  studyEventScheduled.setEndTimeFlag(true);
                }
              }
              studyEventScheduled.setDateEnded(endScheduled[i]);
              studyEventScheduled.setOwner(ub);
              studyEventScheduled.setStatus(Status.AVAILABLE);
              studyEventScheduled.setLocation(fp.getString(INPUT_SCHEDULED_LOCATION[i]));
              studyEvent.setSubjectEventStatus(SubjectEventStatus.SCHEDULED);
              studyEventScheduled.setSampleOrdinal(sed.getMaxSampleOrdinal(definitionScheduleds.get(i),studySubject) + 1);
              studyEventScheduled=(StudyEventBean)sed.create(studyEventScheduled);
              if (!studyEventScheduled.isActive()) {
                throw new OpenClinicaException(restext.getString("String_Node_Str"),"String_Node_Str");
              }
              AddNewSubjectServlet.saveFieldNotes(INPUT_SCHEDULED_LOCATION[i],fdn,dndao,studyEventScheduled.getId(),"String_Node_Str",currentStudy);
              AddNewSubjectServlet.saveFieldNotes(INPUT_STARTDATE_PREFIX_SCHEDULED[i],fdn,dndao,studyEventScheduled.getId(),"String_Node_Str",currentStudy);
              AddNewSubjectServlet.saveFieldNotes(INPUT_ENDDATE_PREFIX_SCHEDULED[i],fdn,dndao,studyEventScheduled.getId(),"String_Node_Str",currentStudy);
            }
 else {
              addPageMessage(restext.getString("String_Node_Str") + definitionScheduleds.get(i).getName() + restext.getString("String_Node_Str")+ studySubject.getName()+ restext.getString("String_Node_Str")+ restext.getString("String_Node_Str"));
            }
          }
        }
      }
      session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      request.setAttribute(EnterDataForStudyEventServlet.INPUT_EVENT_ID,String.valueOf(studyEvent.getId()));
      response.encodeRedirectURL("String_Node_Str" + studyEvent.getId());
      forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET);
      return;
    }
  }
}

Fixed version (ground truth):
@Override protected void processRequest() throws Exception {
  checkStudyLocked(Page.LIST_STUDY_SUBJECTS,respage.getString("String_Node_Str"));
  panel.setStudyInfoShown(false);
  fp=new FormProcessor(request);
  FormDiscrepancyNotes discNotes=null;
  int studySubjectId=fp.getInt(INPUT_STUDY_SUBJECT_ID_FROM_VIEWSUBJECT);
  int studyEventDefinitionId=fp.getInt(INPUT_STUDY_EVENT_DEFINITION);
  StudySubjectDAO sdao=new StudySubjectDAO(sm.getDataSource());
  StudySubjectBean ssb;
  if (studySubjectId <= 0) {
    ssb=(StudySubjectBean)request.getAttribute(INPUT_STUDY_SUBJECT);
  }
 else {
    ssb=(StudySubjectBean)sdao.findByPK(studySubjectId);
    Status s=ssb.getStatus();
    if ("String_Node_Str".equalsIgnoreCase(s.getName()) || "String_Node_Str".equalsIgnoreCase(s.getName())) {
      addPageMessage(resword.getString("String_Node_Str") + resterm.getString("String_Node_Str") + resterm.getString("String_Node_Str")+ "String_Node_Str"+ respage.getString("String_Node_Str"));
      request.setAttribute("String_Node_Str",new Integer(studySubjectId).toString());
      forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    }
    request.setAttribute(INPUT_REQUEST_STUDY_SUBJECT,"String_Node_Str");
  }
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  StudyBean studyWithEventDefinitions=currentStudy;
  if (currentStudy.getParentStudyId() > 0) {
    studyWithEventDefinitions=new StudyBean();
    studyWithEventDefinitions.setId(currentStudy.getParentStudyId());
  }
  ArrayList eventDefinitions=seddao.findAllActiveByStudy(studyWithEventDefinitions);
  Collections.sort(eventDefinitions);
  ArrayList eventDefinitionsScheduled=eventDefinitions;
  if (!fp.isSubmitted()) {
    HashMap presetValues=new HashMap();
    presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",new Integer(-1));
    presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",new Integer(-1));
    presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",new String("String_Node_Str"));
    presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",new Integer(-1));
    presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",new Integer(-1));
    presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",new String("String_Node_Str"));
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      presetValues.put(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new Integer(-1));
      presetValues.put(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new Integer(-1));
      presetValues.put(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new String("String_Node_Str"));
      presetValues.put(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new Integer(-1));
      presetValues.put(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new Integer(-1));
      presetValues.put(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",new String("String_Node_Str"));
    }
    String dateValue=local_df.format(new Date(System.currentTimeMillis()));
    presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",dateValue);
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      presetValues.put(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str",dateValue);
      presetValues.put(INPUT_SCHEDULED_LOCATION[i],currentStudy.getFacilityCity());
      presetValues.put(this.DISPLAY_SCHEDULED[i],"String_Node_Str");
    }
    presetValues.put(INPUT_LOCATION,currentStudy.getFacilityCity());
    if (ssb != null && ssb.isActive()) {
      presetValues.put(INPUT_STUDY_SUBJECT,ssb);
      String requestStudySubject=(String)request.getAttribute(INPUT_REQUEST_STUDY_SUBJECT);
      if (requestStudySubject != null) {
        presetValues.put(INPUT_REQUEST_STUDY_SUBJECT,requestStudySubject);
        dateValue=local_df.format(new Date());
        presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",dateValue);
      }
    }
    if (studyEventDefinitionId > 0) {
      StudyEventDefinitionBean sed=(StudyEventDefinitionBean)seddao.findByPK(studyEventDefinitionId);
      presetValues.put(INPUT_STUDY_EVENT_DEFINITION,sed);
    }
    logger.info("String_Node_Str" + presetValues.toString());
    System.out.println("String_Node_Str" + presetValues.toString());
    logger.info("String_Node_Str" + eventDefinitions.size());
    setPresetValues(presetValues);
    ArrayList subjects=new ArrayList();
    setupBeans(subjects,eventDefinitions);
    discNotes=new FormDiscrepancyNotes();
    session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
    request.setAttribute("String_Node_Str",eventDefinitionsScheduled);
    setInputMessages(new HashMap());
    forwardPage(Page.CREATE_NEW_STUDY_EVENT);
  }
 else {
    String dateCheck2=request.getParameter("String_Node_Str");
    String endCheck2=request.getParameter("String_Node_Str");
    logger.info(dateCheck2 + "String_Node_Str" + endCheck2);
    String strEnd=fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX);
    String strEndScheduled[]=new String[ADDITIONAL_SCHEDULED_NUM];
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      strEndScheduled[i]=fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX_SCHEDULED[i]);
    }
    Date start=getInputStartDate();
    Date end=null;
    Date[] startScheduled=new Date[ADDITIONAL_SCHEDULED_NUM];
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      startScheduled[i]=getInputStartDateScheduled(i);
    }
    Date[] endScheduled=new Date[ADDITIONAL_SCHEDULED_NUM];
    discNotes=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    if (discNotes == null) {
      discNotes=new FormDiscrepancyNotes();
      session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
    }
    DiscrepancyValidator v=new DiscrepancyValidator(request,discNotes);
    v.addValidation(INPUT_STARTDATE_PREFIX,Validator.IS_DATE_TIME);
    v.alwaysExecuteLastValidation(INPUT_STARTDATE_PREFIX);
    if (!strEnd.equals("String_Node_Str")) {
      v.addValidation(INPUT_ENDDATE_PREFIX,Validator.IS_DATE_TIME);
      v.alwaysExecuteLastValidation(INPUT_ENDDATE_PREFIX);
    }
    v.addValidation(INPUT_STUDY_EVENT_DEFINITION,Validator.ENTITY_EXISTS_IN_STUDY,seddao,studyWithEventDefinitions);
    v.addValidation(INPUT_STUDY_SUBJECT_LABEL,Validator.NO_BLANKS);
    v.addValidation(INPUT_LOCATION,Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,2000);
    v.alwaysExecuteLastValidation(INPUT_LOCATION);
    boolean hasScheduledEvent=false;
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      if (!StringUtil.isBlank(fp.getString(this.INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i]))) {
        v.addValidation(this.INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i],Validator.ENTITY_EXISTS_IN_STUDY,seddao,studyWithEventDefinitions);
        v.addValidation(INPUT_SCHEDULED_LOCATION[i],Validator.NO_BLANKS);
        v.addValidation(INPUT_SCHEDULED_LOCATION[i],Validator.LENGTH_NUMERIC_COMPARISON,NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO,2000);
        v.alwaysExecuteLastValidation(INPUT_SCHEDULED_LOCATION[i]);
        v.addValidation(INPUT_STARTDATE_PREFIX_SCHEDULED[i],Validator.IS_DATE_TIME);
        v.alwaysExecuteLastValidation(INPUT_STARTDATE_PREFIX_SCHEDULED[i]);
        if (!strEndScheduled[i].equals("String_Node_Str")) {
          v.addValidation(INPUT_ENDDATE_PREFIX_SCHEDULED[i],Validator.IS_DATE_TIME);
          v.alwaysExecuteLastValidation(INPUT_ENDDATE_PREFIX_SCHEDULED[i]);
        }
        hasScheduledEvent=true;
        fp.addPresetValue(DISPLAY_SCHEDULED[i],"String_Node_Str");
      }
 else {
        fp.addPresetValue(DISPLAY_SCHEDULED[i],"String_Node_Str");
      }
    }
    HashMap errors=v.validate();
    String location=resword.getString("String_Node_Str");
    if (!StringUtil.isBlank(fp.getString(INPUT_LOCATION)) && fp.getString(INPUT_LOCATION).equalsIgnoreCase(location)) {
      Validator.addError(errors,INPUT_LOCATION,restext.getString("String_Node_Str"));
    }
    StudyEventDefinitionBean definition=(StudyEventDefinitionBean)seddao.findByPK(fp.getInt(INPUT_STUDY_EVENT_DEFINITION));
    StudySubjectBean studySubject=(StudySubjectBean)sdao.findByLabelAndStudy(fp.getString(INPUT_STUDY_SUBJECT_LABEL),currentStudy);
    if (request.getAttribute(INPUT_STUDY_SUBJECT) != null) {
      studySubject=(StudySubjectBean)request.getAttribute(INPUT_STUDY_SUBJECT);
    }
    if (studySubject.getLabel() == "String_Node_Str") {
      System.out.println("String_Node_Str");
      Validator.addError(errors,INPUT_STUDY_SUBJECT,respage.getString("String_Node_Str"));
    }
    if (!subjectMayReceiveStudyEvent(sm.getDataSource(),definition,studySubject)) {
      Validator.addError(errors,INPUT_STUDY_EVENT_DEFINITION,restext.getString("String_Node_Str"));
    }
    ArrayList<StudyEventDefinitionBean> definitionScheduleds=new ArrayList<StudyEventDefinitionBean>();
    int[] scheduledDefinitionIds=new int[ADDITIONAL_SCHEDULED_NUM];
    if (hasScheduledEvent) {
      for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
        int pk=fp.getInt(INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i]);
        if (pk > 0) {
          StudyEventDefinitionBean sedb=(StudyEventDefinitionBean)seddao.findByPK(pk);
          System.out.println("String_Node_Str" + pk + "String_Node_Str"+ INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i]+ "String_Node_Str"+ sedb.getName());
          definitionScheduleds.add(sedb);
          scheduledDefinitionIds[i]=pk;
          if (!subjectMayReceiveStudyEvent(sm.getDataSource(),sedb,studySubject)) {
            Validator.addError(errors,INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i],restext.getString("String_Node_Str"));
          }
        }
 else {
          definitionScheduleds.add(new StudyEventDefinitionBean());
        }
      }
    }
    if (!"String_Node_Str".equals(strEnd) && !errors.containsKey(INPUT_STARTDATE_PREFIX) && !errors.containsKey(INPUT_ENDDATE_PREFIX)) {
      end=getInputEndDate();
      if (!fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals(fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str"))) {
        if (end.before(start)) {
          Validator.addError(errors,INPUT_ENDDATE_PREFIX,resexception.getString("String_Node_Str"));
        }
      }
 else {
        if (fp.timeEntered(INPUT_STARTDATE_PREFIX) && fp.timeEntered(INPUT_ENDDATE_PREFIX)) {
          if (end.before(start) || end.equals(start)) {
            Validator.addError(errors,INPUT_ENDDATE_PREFIX,resexception.getString("String_Node_Str"));
          }
        }
      }
    }
    String prevStartPrefix=INPUT_STARTDATE_PREFIX;
    Set<Integer> pickedSeds=new TreeSet<Integer>();
    pickedSeds.add(studyEventDefinitionId);
    HashMap<Integer,Integer> scheduledSeds=new HashMap<Integer,Integer>();
    scheduledSeds.put(studyEventDefinitionId,-1);
    for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
      if (scheduledDefinitionIds[i] > 0 && !errors.containsKey(INPUT_STARTDATE_PREFIX_SCHEDULED[i]) && !errors.containsKey(INPUT_ENDDATE_PREFIX_SCHEDULED[i])) {
        if (scheduledSeds.containsKey(scheduledDefinitionIds[i])) {
          int prevStart=scheduledSeds.get(scheduledDefinitionIds[i]);
          prevStartPrefix=prevStart == -1 ? INPUT_STARTDATE_PREFIX : INPUT_STARTDATE_PREFIX_SCHEDULED[prevStart];
          Date prevStartDate=prevStart == -1 ? this.getInputStartDate() : this.getInputStartDateScheduled(Integer.parseInt(prevStartPrefix.charAt(prevStartPrefix.length() - 1) + "String_Node_Str"));
          if (fp.getString(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str").equals(fp.getString(prevStartPrefix + "String_Node_Str"))) {
            boolean schStartTime=fp.timeEntered(INPUT_STARTDATE_PREFIX_SCHEDULED[i]);
            boolean startTime=fp.timeEntered(prevStartPrefix);
            if (schStartTime && startTime) {
              if (startScheduled[i].before(prevStartDate)) {
                Validator.addError(errors,INPUT_STARTDATE_PREFIX_SCHEDULED[i],resexception.getString("String_Node_Str"));
              }
            }
          }
 else {
            if (startScheduled[i].before(prevStartDate)) {
              Validator.addError(errors,INPUT_STARTDATE_PREFIX_SCHEDULED[i],resexception.getString("String_Node_Str"));
            }
          }
        }
        scheduledSeds.put(scheduledDefinitionIds[i],i);
        if (!strEndScheduled[i].equals("String_Node_Str")) {
          endScheduled[i]=fp.getDateTime(INPUT_ENDDATE_PREFIX_SCHEDULED[i]);
          String prevEndPrefix=i > 0 ? INPUT_ENDDATE_PREFIX_SCHEDULED[i - 1] : INPUT_ENDDATE_PREFIX;
          if (!fp.getString(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str").equals(fp.getString(prevEndPrefix + "String_Node_Str"))) {
            if (endScheduled[i].before(startScheduled[i])) {
              Validator.addError(errors,INPUT_ENDDATE_PREFIX_SCHEDULED[i],resexception.getString("String_Node_Str"));
            }
          }
 else {
            if (fp.timeEntered(INPUT_STARTDATE_PREFIX_SCHEDULED[i]) && fp.timeEntered(INPUT_ENDDATE_PREFIX_SCHEDULED[i])) {
              if (endScheduled[i].before(startScheduled[i]) || endScheduled[i].equals(startScheduled[i])) {
                Validator.addError(errors,INPUT_ENDDATE_PREFIX_SCHEDULED[i],resexception.getString("String_Node_Str"));
              }
            }
          }
        }
      }
    }
    System.out.println("String_Node_Str" + errors.size());
    if (!errors.isEmpty()) {
      logger.info("String_Node_Str" + errors.size());
      System.out.println("String_Node_Str" + fp.getString(INPUT_REQUEST_STUDY_SUBJECT));
      addPageMessage(respage.getString("String_Node_Str"));
      setInputMessages(errors);
      fp.addPresetValue(INPUT_STUDY_EVENT_DEFINITION,definition);
      fp.addPresetValue(INPUT_STUDY_SUBJECT,studySubject);
      fp.addPresetValue(INPUT_STUDY_SUBJECT_LABEL,fp.getString(INPUT_STUDY_SUBJECT_LABEL));
      fp.addPresetValue(INPUT_REQUEST_STUDY_SUBJECT,fp.getString(INPUT_REQUEST_STUDY_SUBJECT));
      fp.addPresetValue(INPUT_LOCATION,fp.getString(INPUT_LOCATION));
      for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
        fp.addPresetValue(INPUT_SCHEDULED_LOCATION[i],fp.getString(INPUT_SCHEDULED_LOCATION[i]));
      }
      String prefixes[]=new String[2 + 2 * ADDITIONAL_SCHEDULED_NUM];
      prefixes[0]=INPUT_STARTDATE_PREFIX;
      prefixes[1]=INPUT_ENDDATE_PREFIX;
      int b=ADDITIONAL_SCHEDULED_NUM + 2;
      for (int i=2; i < b; ++i) {
        prefixes[i]=INPUT_STARTDATE_PREFIX_SCHEDULED[i - 2];
      }
      for (int i=b; i < ADDITIONAL_SCHEDULED_NUM + b; ++i) {
        prefixes[i]=INPUT_ENDDATE_PREFIX_SCHEDULED[i - b];
      }
      fp.setCurrentDateTimeValuesAsPreset(prefixes);
      if (hasScheduledEvent) {
        for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
          fp.addPresetValue(INPUT_STUDY_EVENT_DEFINITION_SCHEDULED[i],definitionScheduleds.get(i));
        }
      }
      setPresetValues(fp.getPresetValues());
      ArrayList subjects=new ArrayList();
      setupBeans(subjects,eventDefinitions);
      request.setAttribute("String_Node_Str",eventDefinitionsScheduled);
      forwardPage(Page.CREATE_NEW_STUDY_EVENT);
    }
 else {
      System.out.println("String_Node_Str");
      StudyEventDAO sed=new StudyEventDAO(sm.getDataSource());
      StudyEventBean studyEvent=new StudyEventBean();
      studyEvent.setStudyEventDefinitionId(definition.getId());
      studyEvent.setStudySubjectId(studySubject.getId());
      if ("String_Node_Str".equals(getInputStartHour()) && "String_Node_Str".equals(getInputStartMinute()) && "String_Node_Str".equals(getInputStartHalf())) {
        studyEvent.setStartTimeFlag(false);
      }
 else {
        studyEvent.setStartTimeFlag(true);
      }
      studyEvent.setDateStarted(start);
      logger.info("String_Node_Str" + local_df.format(start));
      Date startScheduled2[]=new Date[ADDITIONAL_SCHEDULED_NUM];
      for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
        startScheduled2[i]=getInputStartDateScheduled(i);
      }
      if (!"String_Node_Str".equals(strEnd)) {
        if ("String_Node_Str".equals(getInputEndHour()) && "String_Node_Str".equals(getInputEndMinute()) && "String_Node_Str".equals(getInputEndHalf())) {
          studyEvent.setEndTimeFlag(false);
        }
 else {
          studyEvent.setEndTimeFlag(true);
        }
        studyEvent.setDateEnded(end);
      }
      studyEvent.setOwner(ub);
      studyEvent.setStatus(Status.AVAILABLE);
      studyEvent.setLocation(fp.getString(INPUT_LOCATION));
      studyEvent.setSubjectEventStatus(SubjectEventStatus.SCHEDULED);
      studyEvent.setSampleOrdinal(sed.getMaxSampleOrdinal(definition,studySubject) + 1);
      studyEvent=(StudyEventBean)sed.create(studyEvent);
      if (!studyEvent.isActive()) {
        throw new OpenClinicaException(restext.getString("String_Node_Str"),"String_Node_Str");
      }
      addPageMessage(restext.getString("String_Node_Str") + definition.getName() + restext.getString("String_Node_Str")+ studySubject.getName()+ respage.getString("String_Node_Str"));
      FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
      String[] eventFields={INPUT_LOCATION,INPUT_STARTDATE_PREFIX,INPUT_ENDDATE_PREFIX};
      for (      String element : eventFields) {
        AddNewSubjectServlet.saveFieldNotes(element,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      }
      if (hasScheduledEvent) {
        for (int i=0; i < ADDITIONAL_SCHEDULED_NUM; ++i) {
          if (scheduledDefinitionIds[i] > 0) {
            if (subjectMayReceiveStudyEvent(sm.getDataSource(),definitionScheduleds.get(i),studySubject)) {
              StudyEventBean studyEventScheduled=new StudyEventBean();
              studyEventScheduled.setStudyEventDefinitionId(scheduledDefinitionIds[i]);
              studyEventScheduled.setStudySubjectId(studySubject.getId());
              if ("String_Node_Str".equals(fp.getString(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str")) && "String_Node_Str".equals(fp.getString(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str")) && "String_Node_Str".equals(fp.getString(INPUT_STARTDATE_PREFIX_SCHEDULED[i] + "String_Node_Str"))) {
                studyEventScheduled.setStartTimeFlag(false);
              }
 else {
                studyEventScheduled.setStartTimeFlag(true);
              }
              studyEventScheduled.setDateStarted(startScheduled[i]);
              if (!"String_Node_Str".equals(strEndScheduled[i])) {
                endScheduled[i]=fp.getDateTime(INPUT_ENDDATE_PREFIX_SCHEDULED[i]);
                if ("String_Node_Str".equals(fp.getString(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str")) && "String_Node_Str".equals(fp.getString(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str")) && "String_Node_Str".equals(fp.getString(INPUT_ENDDATE_PREFIX_SCHEDULED[i] + "String_Node_Str"))) {
                  studyEventScheduled.setEndTimeFlag(false);
                }
 else {
                  studyEventScheduled.setEndTimeFlag(true);
                }
              }
              studyEventScheduled.setDateEnded(endScheduled[i]);
              studyEventScheduled.setOwner(ub);
              studyEventScheduled.setStatus(Status.AVAILABLE);
              studyEventScheduled.setLocation(fp.getString(INPUT_SCHEDULED_LOCATION[i]));
              studyEvent.setSubjectEventStatus(SubjectEventStatus.SCHEDULED);
              studyEventScheduled.setSampleOrdinal(sed.getMaxSampleOrdinal(definitionScheduleds.get(i),studySubject) + 1);
              studyEventScheduled=(StudyEventBean)sed.create(studyEventScheduled);
              if (!studyEventScheduled.isActive()) {
                throw new OpenClinicaException(restext.getString("String_Node_Str"),"String_Node_Str");
              }
              AddNewSubjectServlet.saveFieldNotes(INPUT_SCHEDULED_LOCATION[i],fdn,dndao,studyEventScheduled.getId(),"String_Node_Str",currentStudy);
              AddNewSubjectServlet.saveFieldNotes(INPUT_STARTDATE_PREFIX_SCHEDULED[i],fdn,dndao,studyEventScheduled.getId(),"String_Node_Str",currentStudy);
              AddNewSubjectServlet.saveFieldNotes(INPUT_ENDDATE_PREFIX_SCHEDULED[i],fdn,dndao,studyEventScheduled.getId(),"String_Node_Str",currentStudy);
            }
 else {
              addPageMessage(restext.getString("String_Node_Str") + definitionScheduleds.get(i).getName() + restext.getString("String_Node_Str")+ studySubject.getName()+ restext.getString("String_Node_Str")+ restext.getString("String_Node_Str"));
            }
          }
        }
      }
      session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      request.setAttribute(EnterDataForStudyEventServlet.INPUT_EVENT_ID,String.valueOf(studyEvent.getId()));
      response.encodeRedirectURL("String_Node_Str" + studyEvent.getId());
      forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET);
      return;
    }
  }
}