Program: 115362
Project: 115362
Buggy source:
@Override public void processRequest() throws Exception {
  FormDiscrepancyNotes discNotes=null;
  FormProcessor fp=new FormProcessor(request);
  int studyEventId=fp.getInt(EVENT_ID,true);
  int studySubjectId=fp.getInt(STUDY_SUBJECT_ID,true);
  String module=fp.getString(MODULE);
  request.setAttribute(MODULE,module);
  String fromResolvingNotes=fp.getString("String_Node_Str",true);
  if (StringUtil.isBlank(fromResolvingNotes)) {
    session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
    session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
    checkStudyLocked(Page.MANAGE_STUDY,respage.getString("String_Node_Str"));
    checkStudyFrozen(Page.MANAGE_STUDY,respage.getString("String_Node_Str"));
  }
  if (studyEventId == 0 || studySubjectId == 0) {
    addPageMessage(respage.getString("String_Node_Str"));
    request.setAttribute("String_Node_Str",new Integer(studySubjectId).toString());
    forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    return;
  }
  StudySubjectDAO ssdao=new StudySubjectDAO(sm.getDataSource());
  StudySubjectBean ssub=null;
  if (studySubjectId > 0) {
    ssub=(StudySubjectBean)ssdao.findByPK(studySubjectId);
    request.setAttribute("String_Node_Str",ssub);
    request.setAttribute("String_Node_Str",studySubjectId + "String_Node_Str");
  }
  Status s=ssub.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(STUDY_SUBJECT_ID,new Integer(studySubjectId).toString());
  StudyEventDAO sedao=new StudyEventDAO(sm.getDataSource());
  EventCRFDAO ecrfdao=new EventCRFDAO(sm.getDataSource());
  StudyEventBean studyEvent=(StudyEventBean)sedao.findByPK(studyEventId);
  studyEvent.setEventCRFs(ecrfdao.findAllByStudyEvent(studyEvent));
  ArrayList statuses=SubjectEventStatus.toArrayList();
  StudyDAO sdao=new StudyDAO(this.sm.getDataSource());
  StudyBean studyBean=(StudyBean)sdao.findByPK(ssub.getStudyId());
  EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(sm.getDataSource());
  boolean removeSign=false;
  ArrayList eventCrfs=studyEvent.getEventCRFs();
  for (int i=0; i < eventCrfs.size(); i++) {
    EventCRFBean ecrf=(EventCRFBean)eventCrfs.get(i);
    EventDefinitionCRFBean edcBean=edcdao.findByStudyEventIdAndCRFVersionId(studyBean,studyEventId,ecrf.getCRFVersionId());
    if (ecrf.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY) || ecrf.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) && edcBean.isDoubleEntry() == true) {
      removeSign=true;
      break;
    }
  }
  if (currentRole.isResearchAssistant()) {
    removeSign=true;
  }
  if (removeSign == true) {
    statuses.remove(SubjectEventStatus.SIGNED);
  }
  if (!studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.NOT_SCHEDULED)) {
    statuses.remove(SubjectEventStatus.NOT_SCHEDULED);
  }
  if (!studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
    statuses.remove(SubjectEventStatus.SCHEDULED);
  }
  if (studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED)) {
    statuses.remove(SubjectEventStatus.SKIPPED);
  }
  ArrayList getECRFs=studyEvent.getEventCRFs();
  EventDefinitionCRFDAO edefcrfdao=new EventDefinitionCRFDAO(sm.getDataSource());
  ArrayList getAllECRFs=(ArrayList)edefcrfdao.findAllByDefinition(studyBean,studyEvent.getStudyEventDefinitionId());
  logger.info("String_Node_Str" + getAllECRFs.size());
  for (int u=0; u < getAllECRFs.size(); u++) {
    EventDefinitionCRFBean ecrfBean=(EventDefinitionCRFBean)getAllECRFs.get(u);
    logger.info("String_Node_Str" + getECRFs.size());
    if (getECRFs.size() == 0) {
      statuses.remove(SubjectEventStatus.COMPLETED);
      statuses.remove(SubjectEventStatus.LOCKED);
    }
    for (int uv=0; uv < getECRFs.size(); uv++) {
      EventCRFBean existingBean=(EventCRFBean)getECRFs.get(uv);
      logger.info("String_Node_Str" + existingBean.getCRFVersionId() + "String_Node_Str"+ existingBean.getCrf().getId()+ "String_Node_Str"+ existingBean.getCrfVersion().getName()+ "String_Node_Str"+ existingBean.getStatus().getName()+ "String_Node_Str"+ existingBean.getStage().getName());
      logger.info("String_Node_Str" + ecrfBean.getDefaultVersionId());
      if (!existingBean.getStatus().equals(Status.UNAVAILABLE) && edefcrfdao.isRequiredInDefinition(existingBean.getCRFVersionId(),studyEvent)) {
        logger.info("String_Node_Str" + existingBean.getCrfVersion().getName() + "String_Node_Str");
        statuses.remove(SubjectEventStatus.COMPLETED);
        statuses.remove(SubjectEventStatus.LOCKED);
      }
    }
  }
  if (!ub.isSysAdmin() && !currentRole.getRole().equals(Role.STUDYDIRECTOR) && !currentRole.getRole().equals(Role.COORDINATOR)) {
    statuses.remove(SubjectEventStatus.LOCKED);
  }
  if (studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED)) {
    statuses.remove(SubjectEventStatus.NOT_SCHEDULED);
    statuses.remove(SubjectEventStatus.SCHEDULED);
  }
  request.setAttribute("String_Node_Str",statuses);
  String action=fp.getString("String_Node_Str");
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  StudyEventDefinitionBean sed=(StudyEventDefinitionBean)seddao.findByPK(studyEvent.getStudyEventDefinitionId());
  request.setAttribute(EVENT_DEFINITION_BEAN,sed);
  if (action.equalsIgnoreCase("String_Node_Str")) {
    discNotes=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    DiscrepancyValidator v=new DiscrepancyValidator(request,discNotes);
    SubjectEventStatus ses=SubjectEventStatus.get(fp.getInt(SUBJECT_EVENT_STATUS_ID));
    studyEvent.setSubjectEventStatus(ses);
    if (ses.equals(SubjectEventStatus.SKIPPED) || ses.equals(SubjectEventStatus.STOPPED)) {
      studyEvent.setStatus(Status.UNAVAILABLE);
      EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
      ArrayList eventCRFs=ecdao.findAllByStudyEvent(studyEvent);
      for (int i=0; i < eventCRFs.size(); i++) {
        EventCRFBean ecb=(EventCRFBean)eventCRFs.get(i);
        ecb.setStatus(Status.UNAVAILABLE);
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecdao.update(ecb);
      }
    }
    String strEnd=fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX);
    String strEndScheduled=fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX);
    Date start=fp.getDateTime(INPUT_STARTDATE_PREFIX);
    Date end=null;
    v.addValidation(INPUT_STARTDATE_PREFIX,Validator.IS_DATE_TIME);
    v.alwaysExecuteLastValidation(INPUT_STARTDATE_PREFIX);
    if (!strEndScheduled.equals("String_Node_Str")) {
      v.addValidation(INPUT_ENDDATE_PREFIX,Validator.IS_DATE_TIME);
      v.alwaysExecuteLastValidation(INPUT_ENDDATE_PREFIX);
    }
    v.addValidation(INPUT_LOCATION,Validator.NO_BLANKS);
    HashMap errors=v.validate();
    if (!strEnd.equals("String_Node_Str") && !errors.containsKey(INPUT_STARTDATE_PREFIX) && !errors.containsKey(INPUT_ENDDATE_PREFIX)) {
      end=fp.getDateTime(INPUT_ENDDATE_PREFIX);
      if (!fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals(fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str"))) {
        if (end.before(start)) {
          v.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)) {
            v.addError(errors,INPUT_ENDDATE_PREFIX,resexception.getString("String_Node_Str"));
          }
        }
      }
    }
    if (!errors.isEmpty()) {
      setInputMessages(errors);
      String prefixes[]={INPUT_STARTDATE_PREFIX,INPUT_ENDDATE_PREFIX};
      fp.setCurrentDateTimeValuesAsPreset(prefixes);
      setPresetValues(fp.getPresetValues());
      studyEvent.setLocation(fp.getString(INPUT_LOCATION));
      request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
      request.setAttribute(EVENT_BEAN,studyEvent);
      forwardPage(Page.UPDATE_STUDY_EVENT);
    }
 else     if (studyEvent.getSubjectEventStatus().isSigned()) {
      request.setAttribute(STUDY_SUBJECT_ID,new Integer(studySubjectId).toString());
      if (fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str")) {
        studyEvent.setStartTimeFlag(false);
      }
 else {
        studyEvent.setStartTimeFlag(true);
      }
      studyEvent.setDateStarted(start);
      if (!strEnd.equals("String_Node_Str")) {
        studyEvent.setDateEnded(end);
        if (fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str")) {
          studyEvent.setEndTimeFlag(false);
        }
 else {
          studyEvent.setEndTimeFlag(true);
        }
      }
      studyEvent.setLocation(fp.getString(INPUT_LOCATION));
      studyEvent.setStudyEventDefinition(sed);
      ssdao=new StudySubjectDAO(sm.getDataSource());
      StudySubjectBean ssb=(StudySubjectBean)ssdao.findByPK(studyEvent.getStudySubjectId());
      EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
      ArrayList<EventCRFBean> eventCRFs=ecdao.findAllByStudyEvent(studyEvent);
      ArrayList<Boolean> doRuleSetsExist=new ArrayList<Boolean>();
      RuleSetDAO ruleSetDao=new RuleSetDAO(sm.getDataSource());
      StudyBean study=(StudyBean)sdao.findByPK(ssb.getStudyId());
      ArrayList eventDefinitionCRFs=(ArrayList)edcdao.findAllActiveByEventDefinitionId(study,studyEvent.getStudyEventDefinitionId());
      ArrayList uncompletedEventDefinitionCRFs=getUncompletedCRFs(eventDefinitionCRFs,eventCRFs);
      populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
      ArrayList displayEventCRFs=ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(),eventCRFs,eventDefinitionCRFs,ub,currentRole,studyEvent.getSubjectEventStatus(),study);
      request.setAttribute("String_Node_Str",ssb);
      request.setAttribute("String_Node_Str",uncompletedEventDefinitionCRFs);
      request.setAttribute("String_Node_Str",displayEventCRFs);
      request.setAttribute("String_Node_Str",studyEvent);
      session.setAttribute("String_Node_Str",studyEvent);
      DiscrepancyNoteUtil discNoteUtil=new DiscrepancyNoteUtil();
      DisplayStudyEventBean displayEvBean=new DisplayStudyEventBean();
      List<DisplayStudyEventBean> displayEvents=new ArrayList<DisplayStudyEventBean>();
      displayEvBean.setStudyEvent(studyEvent);
      displayEvents.add(displayEvBean);
      discNoteUtil.injectParentDiscNotesIntoDisplayStudyEvents(displayEvents,new HashSet(),sm.getDataSource(),0);
      Map discNoteByEventCRFid=discNoteUtil.createDiscNoteMapByEventCRF(displayEvents);
      request.setAttribute("String_Node_Str",discNoteByEventCRFid);
      forwardPage(Page.UPDATE_STUDY_EVENT_SIGNED);
    }
 else {
      logger.info("String_Node_Str");
      if (fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str")) {
        studyEvent.setStartTimeFlag(false);
      }
 else {
        studyEvent.setStartTimeFlag(true);
      }
      studyEvent.setDateStarted(start);
      if (!strEnd.equals("String_Node_Str")) {
        studyEvent.setDateEnded(end);
        if (fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str")) {
          studyEvent.setEndTimeFlag(false);
        }
 else {
          studyEvent.setEndTimeFlag(true);
        }
      }
      studyEvent.setLocation(fp.getString(INPUT_LOCATION));
      logger.info("String_Node_Str");
      studyEvent.setUpdater(ub);
      studyEvent.setUpdatedDate(new Date());
      sedao.update(studyEvent);
      FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
      AddNewSubjectServlet.saveFieldNotes(INPUT_LOCATION,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      AddNewSubjectServlet.saveFieldNotes(INPUT_STARTDATE_PREFIX,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      AddNewSubjectServlet.saveFieldNotes(INPUT_ENDDATE_PREFIX,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      addPageMessage(respage.getString("String_Node_Str"));
      request.setAttribute("String_Node_Str",new Integer(studySubjectId).toString());
      session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    }
  }
 else   if (action.equalsIgnoreCase("String_Node_Str")) {
    String username=request.getParameter("String_Node_Str");
    String password=request.getParameter("String_Node_Str");
    SecurityManager securityManager=((SecurityManager)SpringServletAccess.getApplicationContext(context).getBean("String_Node_Str"));
    UserAccountBean ub=(UserAccountBean)session.getAttribute("String_Node_Str");
    StudyEventBean seb=(StudyEventBean)session.getAttribute("String_Node_Str");
    if (securityManager.isPasswordValid(ub.getPasswd(),password,getUserDetails()) && ub.getName().equals(username)) {
      seb.setUpdater(ub);
      seb.setUpdatedDate(new Date());
      sedao.update(seb);
      List studyEvents=sedao.findAllByStudySubject(ssub);
      boolean allSigned=true;
      for (Iterator iterator=studyEvents.iterator(); iterator.hasNext(); ) {
        StudyEventBean temp=(StudyEventBean)iterator.next();
        if (!temp.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED)) {
          allSigned=false;
          break;
        }
      }
      if (allSigned) {
        logger.info("String_Node_Str" + ssub.getSubjectId() + "String_Node_Str");
        ssub.setStatus(Status.SIGNED);
        ssub.setUpdater(ub);
        ssdao.update(ssub);
      }
      FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
      AddNewSubjectServlet.saveFieldNotes(INPUT_LOCATION,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      AddNewSubjectServlet.saveFieldNotes(INPUT_STARTDATE_PREFIX,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      AddNewSubjectServlet.saveFieldNotes(INPUT_ENDDATE_PREFIX,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      session.removeAttribute("String_Node_Str");
      request.setAttribute("String_Node_Str",new Integer(studySubjectId).toString());
      addPageMessage(respage.getString("String_Node_Str"));
      forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    }
 else {
      request.setAttribute(STUDY_SUBJECT_ID,new Integer(studySubjectId).toString());
      request.setAttribute("String_Node_Str",seb);
      ssdao=new StudySubjectDAO(sm.getDataSource());
      StudySubjectBean ssb=(StudySubjectBean)ssdao.findByPK(studyEvent.getStudySubjectId());
      EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
      ArrayList<EventCRFBean> eventCRFs=ecdao.findAllByStudyEvent(studyEvent);
      ArrayList<Boolean> doRuleSetsExist=new ArrayList<Boolean>();
      RuleSetDAO ruleSetDao=new RuleSetDAO(sm.getDataSource());
      StudyBean study=(StudyBean)sdao.findByPK(ssb.getStudyId());
      ArrayList eventDefinitionCRFs=(ArrayList)edcdao.findAllActiveByEventDefinitionId(study,studyEvent.getStudyEventDefinitionId());
      ArrayList uncompletedEventDefinitionCRFs=getUncompletedCRFs(eventDefinitionCRFs,eventCRFs);
      populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
      ArrayList displayEventCRFs=ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(),eventCRFs,eventDefinitionCRFs,ub,currentRole,studyEvent.getSubjectEventStatus(),study);
      request.setAttribute("String_Node_Str",ssb);
      request.setAttribute("String_Node_Str",uncompletedEventDefinitionCRFs);
      request.setAttribute("String_Node_Str",displayEventCRFs);
      request.setAttribute("String_Node_Str",session.getAttribute("String_Node_Str"));
      addPageMessage(restext.getString("String_Node_Str"));
      forwardPage(Page.UPDATE_STUDY_EVENT_SIGNED);
    }
  }
 else {
    logger.info("String_Node_Str");
    HashMap presetValues=new HashMap();
    if (studyEvent.getStartTimeFlag() == true) {
      Calendar c=new GregorianCalendar();
      c.setTime(studyEvent.getDateStarted());
      presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",new Integer(c.get(Calendar.HOUR)));
      presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",new Integer(c.get(Calendar.MINUTE)));
switch (c.get(Calendar.AM_PM)) {
case 0:
        presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str","String_Node_Str");
      break;
case 1:
    presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str","String_Node_Str");
  break;
default :
presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str","String_Node_Str");
break;
}
}
 else {
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","String_Node_Str");
}
String dateValue=local_df.format(studyEvent.getDateStarted());
presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",dateValue);
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","String_Node_Str");
if (studyEvent.getDateEnded() != null) {
if (studyEvent.getEndTimeFlag() == true) {
Calendar c=new GregorianCalendar();
c.setTime(studyEvent.getDateEnded());
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",new Integer(c.get(Calendar.HOUR)));
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",new Integer(c.get(Calendar.MINUTE)));
switch (c.get(Calendar.AM_PM)) {
case 0:
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str","String_Node_Str");
break;
case 1:
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str","String_Node_Str");
break;
default :
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str","String_Node_Str");
break;
}
}
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",local_df.format(studyEvent.getDateEnded()));
}
setPresetValues(presetValues);
request.setAttribute(EVENT_BEAN,studyEvent);
discNotes=new FormDiscrepancyNotes();
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
forwardPage(Page.UPDATE_STUDY_EVENT);
}
}

Fixed version (ground truth):
@Override public void processRequest() throws Exception {
  FormDiscrepancyNotes discNotes=null;
  FormProcessor fp=new FormProcessor(request);
  int studyEventId=fp.getInt(EVENT_ID,true);
  int studySubjectId=fp.getInt(STUDY_SUBJECT_ID,true);
  String module=fp.getString(MODULE);
  request.setAttribute(MODULE,module);
  String fromResolvingNotes=fp.getString("String_Node_Str",true);
  if (StringUtil.isBlank(fromResolvingNotes)) {
    session.removeAttribute(ViewNotesServlet.WIN_LOCATION);
    session.removeAttribute(ViewNotesServlet.NOTES_TABLE);
    checkStudyLocked(Page.MANAGE_STUDY,respage.getString("String_Node_Str"));
    checkStudyFrozen(Page.MANAGE_STUDY,respage.getString("String_Node_Str"));
  }
  if (studyEventId == 0 || studySubjectId == 0) {
    addPageMessage(respage.getString("String_Node_Str"));
    request.setAttribute("String_Node_Str",new Integer(studySubjectId).toString());
    forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    return;
  }
  StudySubjectDAO ssdao=new StudySubjectDAO(sm.getDataSource());
  StudySubjectBean ssub=null;
  if (studySubjectId > 0) {
    ssub=(StudySubjectBean)ssdao.findByPK(studySubjectId);
    request.setAttribute("String_Node_Str",ssub);
    request.setAttribute("String_Node_Str",studySubjectId + "String_Node_Str");
  }
  Status s=ssub.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(STUDY_SUBJECT_ID,new Integer(studySubjectId).toString());
  StudyEventDAO sedao=new StudyEventDAO(sm.getDataSource());
  EventCRFDAO ecrfdao=new EventCRFDAO(sm.getDataSource());
  StudyEventBean studyEvent=(StudyEventBean)sedao.findByPK(studyEventId);
  studyEvent.setEventCRFs(ecrfdao.findAllByStudyEvent(studyEvent));
  ArrayList statuses=SubjectEventStatus.toArrayList();
  StudyDAO sdao=new StudyDAO(this.sm.getDataSource());
  StudyBean studyBean=(StudyBean)sdao.findByPK(ssub.getStudyId());
  EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(sm.getDataSource());
  boolean removeSign=false;
  ArrayList eventCrfs=studyEvent.getEventCRFs();
  for (int i=0; i < eventCrfs.size(); i++) {
    EventCRFBean ecrf=(EventCRFBean)eventCrfs.get(i);
    EventDefinitionCRFBean edcBean=edcdao.findByStudyEventIdAndCRFVersionId(studyBean,studyEventId,ecrf.getCRFVersionId());
    if (ecrf.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY) || ecrf.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) && edcBean.isDoubleEntry() == true) {
      removeSign=true;
      break;
    }
  }
  if (currentRole.isResearchAssistant()) {
    removeSign=true;
  }
  if (removeSign == true || !currentRole.isInvestigator()) {
    statuses.remove(SubjectEventStatus.SIGNED);
  }
  if (!studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.NOT_SCHEDULED)) {
    statuses.remove(SubjectEventStatus.NOT_SCHEDULED);
  }
  if (!studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
    statuses.remove(SubjectEventStatus.SCHEDULED);
  }
  if (studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED)) {
    statuses.remove(SubjectEventStatus.SKIPPED);
  }
  ArrayList getECRFs=studyEvent.getEventCRFs();
  EventDefinitionCRFDAO edefcrfdao=new EventDefinitionCRFDAO(sm.getDataSource());
  ArrayList getAllECRFs=(ArrayList)edefcrfdao.findAllByDefinition(studyBean,studyEvent.getStudyEventDefinitionId());
  logger.info("String_Node_Str" + getAllECRFs.size());
  for (int u=0; u < getAllECRFs.size(); u++) {
    EventDefinitionCRFBean ecrfBean=(EventDefinitionCRFBean)getAllECRFs.get(u);
    logger.info("String_Node_Str" + getECRFs.size());
    if (getECRFs.size() == 0) {
      statuses.remove(SubjectEventStatus.COMPLETED);
      statuses.remove(SubjectEventStatus.LOCKED);
    }
    for (int uv=0; uv < getECRFs.size(); uv++) {
      EventCRFBean existingBean=(EventCRFBean)getECRFs.get(uv);
      logger.info("String_Node_Str" + existingBean.getCRFVersionId() + "String_Node_Str"+ existingBean.getCrf().getId()+ "String_Node_Str"+ existingBean.getCrfVersion().getName()+ "String_Node_Str"+ existingBean.getStatus().getName()+ "String_Node_Str"+ existingBean.getStage().getName());
      logger.info("String_Node_Str" + ecrfBean.getDefaultVersionId());
      if (!existingBean.getStatus().equals(Status.UNAVAILABLE) && edefcrfdao.isRequiredInDefinition(existingBean.getCRFVersionId(),studyEvent)) {
        logger.info("String_Node_Str" + existingBean.getCrfVersion().getName() + "String_Node_Str");
        statuses.remove(SubjectEventStatus.COMPLETED);
        statuses.remove(SubjectEventStatus.LOCKED);
      }
    }
  }
  if (!ub.isSysAdmin() && !currentRole.getRole().equals(Role.STUDYDIRECTOR) && !currentRole.getRole().equals(Role.COORDINATOR)) {
    statuses.remove(SubjectEventStatus.LOCKED);
  }
  if (studyEvent.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED)) {
    statuses.remove(SubjectEventStatus.NOT_SCHEDULED);
    statuses.remove(SubjectEventStatus.SCHEDULED);
  }
  request.setAttribute("String_Node_Str",statuses);
  String action=fp.getString("String_Node_Str");
  StudyEventDefinitionDAO seddao=new StudyEventDefinitionDAO(sm.getDataSource());
  StudyEventDefinitionBean sed=(StudyEventDefinitionBean)seddao.findByPK(studyEvent.getStudyEventDefinitionId());
  request.setAttribute(EVENT_DEFINITION_BEAN,sed);
  if (action.equalsIgnoreCase("String_Node_Str")) {
    discNotes=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    DiscrepancyValidator v=new DiscrepancyValidator(request,discNotes);
    SubjectEventStatus ses=SubjectEventStatus.get(fp.getInt(SUBJECT_EVENT_STATUS_ID));
    studyEvent.setSubjectEventStatus(ses);
    if (ses.equals(SubjectEventStatus.SKIPPED) || ses.equals(SubjectEventStatus.STOPPED)) {
      studyEvent.setStatus(Status.UNAVAILABLE);
      EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
      ArrayList eventCRFs=ecdao.findAllByStudyEvent(studyEvent);
      for (int i=0; i < eventCRFs.size(); i++) {
        EventCRFBean ecb=(EventCRFBean)eventCRFs.get(i);
        ecb.setStatus(Status.UNAVAILABLE);
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecdao.update(ecb);
      }
    }
    String strEnd=fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX);
    String strEndScheduled=fp.getDateTimeInputString(INPUT_ENDDATE_PREFIX);
    Date start=fp.getDateTime(INPUT_STARTDATE_PREFIX);
    Date end=null;
    v.addValidation(INPUT_STARTDATE_PREFIX,Validator.IS_DATE_TIME);
    v.alwaysExecuteLastValidation(INPUT_STARTDATE_PREFIX);
    if (!strEndScheduled.equals("String_Node_Str")) {
      v.addValidation(INPUT_ENDDATE_PREFIX,Validator.IS_DATE_TIME);
      v.alwaysExecuteLastValidation(INPUT_ENDDATE_PREFIX);
    }
    v.addValidation(INPUT_LOCATION,Validator.NO_BLANKS);
    HashMap errors=v.validate();
    if (!strEnd.equals("String_Node_Str") && !errors.containsKey(INPUT_STARTDATE_PREFIX) && !errors.containsKey(INPUT_ENDDATE_PREFIX)) {
      end=fp.getDateTime(INPUT_ENDDATE_PREFIX);
      if (!fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals(fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str"))) {
        if (end.before(start)) {
          v.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)) {
            v.addError(errors,INPUT_ENDDATE_PREFIX,resexception.getString("String_Node_Str"));
          }
        }
      }
    }
    if (!errors.isEmpty()) {
      setInputMessages(errors);
      String prefixes[]={INPUT_STARTDATE_PREFIX,INPUT_ENDDATE_PREFIX};
      fp.setCurrentDateTimeValuesAsPreset(prefixes);
      setPresetValues(fp.getPresetValues());
      studyEvent.setLocation(fp.getString(INPUT_LOCATION));
      request.setAttribute("String_Node_Str",fp.getString("String_Node_Str"));
      request.setAttribute(EVENT_BEAN,studyEvent);
      forwardPage(Page.UPDATE_STUDY_EVENT);
    }
 else     if (studyEvent.getSubjectEventStatus().isSigned()) {
      request.setAttribute(STUDY_SUBJECT_ID,new Integer(studySubjectId).toString());
      if (fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str")) {
        studyEvent.setStartTimeFlag(false);
      }
 else {
        studyEvent.setStartTimeFlag(true);
      }
      studyEvent.setDateStarted(start);
      if (!strEnd.equals("String_Node_Str")) {
        studyEvent.setDateEnded(end);
        if (fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str")) {
          studyEvent.setEndTimeFlag(false);
        }
 else {
          studyEvent.setEndTimeFlag(true);
        }
      }
      studyEvent.setLocation(fp.getString(INPUT_LOCATION));
      studyEvent.setStudyEventDefinition(sed);
      ssdao=new StudySubjectDAO(sm.getDataSource());
      StudySubjectBean ssb=(StudySubjectBean)ssdao.findByPK(studyEvent.getStudySubjectId());
      EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
      ArrayList<EventCRFBean> eventCRFs=ecdao.findAllByStudyEvent(studyEvent);
      ArrayList<Boolean> doRuleSetsExist=new ArrayList<Boolean>();
      RuleSetDAO ruleSetDao=new RuleSetDAO(sm.getDataSource());
      StudyBean study=(StudyBean)sdao.findByPK(ssb.getStudyId());
      ArrayList eventDefinitionCRFs=(ArrayList)edcdao.findAllActiveByEventDefinitionId(study,studyEvent.getStudyEventDefinitionId());
      ArrayList uncompletedEventDefinitionCRFs=getUncompletedCRFs(eventDefinitionCRFs,eventCRFs);
      populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
      ArrayList displayEventCRFs=ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(),eventCRFs,eventDefinitionCRFs,ub,currentRole,studyEvent.getSubjectEventStatus(),study);
      request.setAttribute("String_Node_Str",ssb);
      request.setAttribute("String_Node_Str",uncompletedEventDefinitionCRFs);
      request.setAttribute("String_Node_Str",displayEventCRFs);
      request.setAttribute("String_Node_Str",studyEvent);
      session.setAttribute("String_Node_Str",studyEvent);
      DiscrepancyNoteUtil discNoteUtil=new DiscrepancyNoteUtil();
      DisplayStudyEventBean displayEvBean=new DisplayStudyEventBean();
      List<DisplayStudyEventBean> displayEvents=new ArrayList<DisplayStudyEventBean>();
      displayEvBean.setStudyEvent(studyEvent);
      displayEvents.add(displayEvBean);
      discNoteUtil.injectParentDiscNotesIntoDisplayStudyEvents(displayEvents,new HashSet(),sm.getDataSource(),0);
      Map discNoteByEventCRFid=discNoteUtil.createDiscNoteMapByEventCRF(displayEvents);
      request.setAttribute("String_Node_Str",discNoteByEventCRFid);
      forwardPage(Page.UPDATE_STUDY_EVENT_SIGNED);
    }
 else {
      logger.info("String_Node_Str");
      if (fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_STARTDATE_PREFIX + "String_Node_Str").equals("String_Node_Str")) {
        studyEvent.setStartTimeFlag(false);
      }
 else {
        studyEvent.setStartTimeFlag(true);
      }
      studyEvent.setDateStarted(start);
      if (!strEnd.equals("String_Node_Str")) {
        studyEvent.setDateEnded(end);
        if (fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str") && fp.getString(INPUT_ENDDATE_PREFIX + "String_Node_Str").equals("String_Node_Str")) {
          studyEvent.setEndTimeFlag(false);
        }
 else {
          studyEvent.setEndTimeFlag(true);
        }
      }
      studyEvent.setLocation(fp.getString(INPUT_LOCATION));
      logger.info("String_Node_Str");
      studyEvent.setUpdater(ub);
      studyEvent.setUpdatedDate(new Date());
      sedao.update(studyEvent);
      FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
      AddNewSubjectServlet.saveFieldNotes(INPUT_LOCATION,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      AddNewSubjectServlet.saveFieldNotes(INPUT_STARTDATE_PREFIX,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      AddNewSubjectServlet.saveFieldNotes(INPUT_ENDDATE_PREFIX,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      addPageMessage(respage.getString("String_Node_Str"));
      request.setAttribute("String_Node_Str",new Integer(studySubjectId).toString());
      session.removeAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    }
  }
 else   if (action.equalsIgnoreCase("String_Node_Str")) {
    String username=request.getParameter("String_Node_Str");
    String password=request.getParameter("String_Node_Str");
    SecurityManager securityManager=((SecurityManager)SpringServletAccess.getApplicationContext(context).getBean("String_Node_Str"));
    UserAccountBean ub=(UserAccountBean)session.getAttribute("String_Node_Str");
    StudyEventBean seb=(StudyEventBean)session.getAttribute("String_Node_Str");
    if (securityManager.isPasswordValid(ub.getPasswd(),password,getUserDetails()) && ub.getName().equals(username)) {
      seb.setUpdater(ub);
      seb.setUpdatedDate(new Date());
      sedao.update(seb);
      List studyEvents=sedao.findAllByStudySubject(ssub);
      boolean allSigned=true;
      for (Iterator iterator=studyEvents.iterator(); iterator.hasNext(); ) {
        StudyEventBean temp=(StudyEventBean)iterator.next();
        if (!temp.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED)) {
          allSigned=false;
          break;
        }
      }
      if (allSigned) {
        logger.info("String_Node_Str" + ssub.getSubjectId() + "String_Node_Str");
        ssub.setStatus(Status.SIGNED);
        ssub.setUpdater(ub);
        ssdao.update(ssub);
      }
      FormDiscrepancyNotes fdn=(FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
      DiscrepancyNoteDAO dndao=new DiscrepancyNoteDAO(sm.getDataSource());
      AddNewSubjectServlet.saveFieldNotes(INPUT_LOCATION,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      AddNewSubjectServlet.saveFieldNotes(INPUT_STARTDATE_PREFIX,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      AddNewSubjectServlet.saveFieldNotes(INPUT_ENDDATE_PREFIX,fdn,dndao,studyEvent.getId(),"String_Node_Str",currentStudy);
      session.removeAttribute("String_Node_Str");
      request.setAttribute("String_Node_Str",new Integer(studySubjectId).toString());
      addPageMessage(respage.getString("String_Node_Str"));
      forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    }
 else {
      request.setAttribute(STUDY_SUBJECT_ID,new Integer(studySubjectId).toString());
      request.setAttribute("String_Node_Str",seb);
      ssdao=new StudySubjectDAO(sm.getDataSource());
      StudySubjectBean ssb=(StudySubjectBean)ssdao.findByPK(studyEvent.getStudySubjectId());
      EventCRFDAO ecdao=new EventCRFDAO(sm.getDataSource());
      ArrayList<EventCRFBean> eventCRFs=ecdao.findAllByStudyEvent(studyEvent);
      ArrayList<Boolean> doRuleSetsExist=new ArrayList<Boolean>();
      RuleSetDAO ruleSetDao=new RuleSetDAO(sm.getDataSource());
      StudyBean study=(StudyBean)sdao.findByPK(ssb.getStudyId());
      ArrayList eventDefinitionCRFs=(ArrayList)edcdao.findAllActiveByEventDefinitionId(study,studyEvent.getStudyEventDefinitionId());
      ArrayList uncompletedEventDefinitionCRFs=getUncompletedCRFs(eventDefinitionCRFs,eventCRFs);
      populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
      ArrayList displayEventCRFs=ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(),eventCRFs,eventDefinitionCRFs,ub,currentRole,studyEvent.getSubjectEventStatus(),study);
      request.setAttribute("String_Node_Str",ssb);
      request.setAttribute("String_Node_Str",uncompletedEventDefinitionCRFs);
      request.setAttribute("String_Node_Str",displayEventCRFs);
      request.setAttribute("String_Node_Str",session.getAttribute("String_Node_Str"));
      addPageMessage(restext.getString("String_Node_Str"));
      forwardPage(Page.UPDATE_STUDY_EVENT_SIGNED);
    }
  }
 else {
    logger.info("String_Node_Str");
    HashMap presetValues=new HashMap();
    if (studyEvent.getStartTimeFlag() == true) {
      Calendar c=new GregorianCalendar();
      c.setTime(studyEvent.getDateStarted());
      presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",new Integer(c.get(Calendar.HOUR)));
      presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",new Integer(c.get(Calendar.MINUTE)));
switch (c.get(Calendar.AM_PM)) {
case 0:
        presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str","String_Node_Str");
      break;
case 1:
    presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str","String_Node_Str");
  break;
default :
presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str","String_Node_Str");
break;
}
}
 else {
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","String_Node_Str");
}
String dateValue=local_df.format(studyEvent.getDateStarted());
presetValues.put(INPUT_STARTDATE_PREFIX + "String_Node_Str",dateValue);
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","String_Node_Str");
if (studyEvent.getDateEnded() != null) {
if (studyEvent.getEndTimeFlag() == true) {
Calendar c=new GregorianCalendar();
c.setTime(studyEvent.getDateEnded());
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",new Integer(c.get(Calendar.HOUR)));
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",new Integer(c.get(Calendar.MINUTE)));
switch (c.get(Calendar.AM_PM)) {
case 0:
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str","String_Node_Str");
break;
case 1:
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str","String_Node_Str");
break;
default :
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str","String_Node_Str");
break;
}
}
presetValues.put(INPUT_ENDDATE_PREFIX + "String_Node_Str",local_df.format(studyEvent.getDateEnded()));
}
setPresetValues(presetValues);
request.setAttribute(EVENT_BEAN,studyEvent);
discNotes=new FormDiscrepancyNotes();
session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME,discNotes);
forwardPage(Page.UPDATE_STUDY_EVENT);
}
}