Program: 115194
Project: 115194
Buggy source:
/** 
 * The following methods are for 'mark CRF complete'
 * @return
 */
protected boolean markCRFComplete() throws Exception {
}

Fixed version (ground truth):
/** 
 * The following methods are for 'mark CRF complete'
 * @return
 */
protected boolean markCRFComplete() throws Exception {
  locale=request.getLocale();
  getEventCRFBean();
  getEventDefinitionCRFBean();
  DataEntryStage stage=ecb.getStage();
  logger.trace("String_Node_Str" + ecb.getId());
  if (stage.equals(DataEntryStage.UNCOMPLETED) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.LOCKED)) {
    addPageMessage(respage.getString("String_Node_Str"));
    return false;
  }
  if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
    if (!edcb.isDoubleEntry()) {
      addPageMessage(respage.getString("String_Node_Str"));
      return false;
    }
  }
  if (isEachRequiredFieldFillout() == false) {
    addPageMessage(respage.getString("String_Node_Str"));
    return false;
  }
  Status newStatus=ecb.getStatus();
  boolean ide=true;
  if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && edcb.isDoubleEntry()) {
    newStatus=Status.PENDING;
    ecb.setUpdaterId(ub.getId());
    ecb.setUpdater(ub);
    ecb.setUpdatedDate(new Date());
    ecb.setDateCompleted(new Date());
  }
 else   if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && !edcb.isDoubleEntry()) {
    newStatus=Status.UNAVAILABLE;
    ecb.setUpdaterId(ub.getId());
    ecb.setUpdater(ub);
    ecb.setUpdatedDate(new Date());
    ecb.setDateCompleted(new Date());
    ecb.setDateValidateCompleted(new Date());
  }
 else   if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
    newStatus=Status.UNAVAILABLE;
    ecb.setDateValidateCompleted(new Date());
    ide=false;
  }
  if (!isEachSectionReviewedOnce()) {
    boolean canSave=saveItemsToMarkComplete(newStatus);
    if (canSave == false) {
      addPageMessage(respage.getString("String_Node_Str"));
      return false;
    }
  }
  ecb.setStatus(newStatus);
  if (edcb.isElectronicSignature()) {
    ecb.setElectronicSignatureStatus(true);
  }
  ecb=(EventCRFBean)ecdao.update(ecb);
  ecdao.markComplete(ecb,ide);
  iddao.updateStatusByEventCRF(ecb,newStatus);
  StudyEventDAO sedao=new StudyEventDAO(sm.getDataSource());
  StudyEventBean seb=(StudyEventBean)sedao.findByPK(ecb.getStudyEventId());
  seb.setUpdatedDate(new Date());
  seb.setUpdater(ub);
  EventDefinitionCRFDAO edcdao=new EventDefinitionCRFDAO(sm.getDataSource());
  ArrayList allCRFs=ecdao.findAllByStudyEvent(seb);
  StudyBean study=(StudyBean)session.getAttribute("String_Node_Str");
  ArrayList allEDCs=(ArrayList)edcdao.findAllActiveByEventDefinitionId(study,seb.getStudyEventDefinitionId());
  boolean eventCompleted=true;
  boolean allRequired=true;
  int allEDCsize=allEDCs.size();
  ArrayList nonRequiredCrfIds=new ArrayList();
  for (int ii=0; ii < allEDCs.size(); ii++) {
    EventDefinitionCRFBean edcBean=(EventDefinitionCRFBean)allEDCs.get(ii);
    if (!edcBean.isRequiredCRF()) {
      logger.trace("String_Node_Str" + edcBean.getCrfName() + "String_Node_Str"+ edcBean.getCrfId()+ "String_Node_Str"+ edcBean.getDefaultVersionName());
      allRequired=false;
      nonRequiredCrfIds.add(new Integer(edcBean.getCrfId()));
      allEDCsize--;
    }
  }
  logger.trace("String_Node_Str" + nonRequiredCrfIds.toString());
  for (int i=0; i < allCRFs.size(); i++) {
    EventCRFBean ec=(EventCRFBean)allCRFs.get(i);
    logger.trace("String_Node_Str" + ec.getName() + "String_Node_Str"+ ec.getCrf().getName()+ "String_Node_Str"+ ec.getCrf().getId());
    if (!ec.getStatus().equals(Status.UNAVAILABLE) && ec.getDateInterviewed() != null) {
      eventCompleted=false;
      logger.trace("String_Node_Str" + ec.getName());
      break;
    }
  }
  if (!allRequired) {
    logger.trace("String_Node_Str" + allEDCsize + "String_Node_Str"+ allEDCs.size());
  }
  if (eventCompleted && allCRFs.size() >= allEDCsize) {
    if (!allRequired && allEDCsize != 0) {
      addPageMessage(respage.getString("String_Node_Str"));
    }
 else     if (!edcb.isDoubleEntry()) {
      logger.trace("String_Node_Str");
      seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
    }
  }
  seb=(StudyEventBean)sedao.update(seb);
  return true;
}