private boolean updateStudy2(FormProcessor fp) {

    study.setOldStatus(study.getStatus());
    study.setStatus(Status.get(fp.getInt("statusId")));

    if (StringUtil.isBlank(fp.getString(INPUT_VER_DATE))) {
      study.setProtocolDateVerification(null);
    } else {
      study.setProtocolDateVerification(fp.getDate(INPUT_VER_DATE));
    }

    study.setDatePlannedStart(fp.getDate(INPUT_START_DATE));

    if (StringUtil.isBlank(fp.getString(INPUT_END_DATE))) {
      study.setDatePlannedEnd(null);
    } else {
      study.setDatePlannedEnd(fp.getDate(INPUT_END_DATE));
    }

    study.setPhase(fp.getString("phase"));

    if (fp.getInt("genetic") == 1) {
      study.setGenetic(true);
    } else {
      study.setGenetic(false);
    }

    String interventional = resadmin.getString("interventional");
    return interventional.equalsIgnoreCase(study.getProtocolType());
  }
  private boolean mayProceedPreview(String studyOid) throws Exception {
    boolean accessPermission = false;
    StudyBean study = getParentStudy(studyOid);
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(dataSource);

    StudyParameterValueBean pStatus =
        spvdao.findByHandleAndStudy(study.getId(), "participantPortal");
    participantPortalRegistrar = new ParticipantPortalRegistrar();
    String pManageStatus =
        participantPortalRegistrar.getRegistrationStatus(studyOid).toString(); // ACTIVE ,
    // PENDING ,
    // INACTIVE
    String participateStatus = pStatus.getValue().toString(); // enabled , disabled
    String studyStatus =
        study.getStatus().getName().toString(); // available , pending , frozen , locked
    logger.info(
        "pManageStatus: "
            + pManageStatus
            + "  participantStatus: "
            + participateStatus
            + "   studyStatus: "
            + studyStatus);
    if (participateStatus.equalsIgnoreCase("enabled")
        && (studyStatus.equalsIgnoreCase("available")
            || studyStatus.equalsIgnoreCase("pending")
            || studyStatus.equalsIgnoreCase("frozen")
            || studyStatus.equalsIgnoreCase("locked"))
        && (pManageStatus.equalsIgnoreCase("ACTIVE")
            || pManageStatus.equalsIgnoreCase("PENDING")
            || pManageStatus.equalsIgnoreCase("INACTIVE"))) {
      accessPermission = true;
    }
    return accessPermission;
  }
 private StudyUserRoleBean getRole(UserAccountBean userAccount, StudyBean study) throws Exception {
   StudyUserRoleBean role = new StudyUserRoleBean();
   if (study == null || userAccount == null || study.getId() == 0) {
     throw new Exception();
   }
   if (userAccount.getId() > 0
       && study.getId() > 0
       && !study.getStatus().getName().equals("removed")) {
     role = userAccount.getRoleByStudy(study.getId());
     if (study.getParentStudyId() > 0) {
       StudyUserRoleBean roleInParent = userAccount.getRoleByStudy(study.getParentStudyId());
       role.setRole(Role.max(role.getRole(), roleInParent.getRole()));
     }
   } else {
     throw new Exception();
   }
   return role;
 }
 private void confirmWholeStudy(FormProcessor fp, Validator v) {
   errors = v.validate();
   if (study.getStatus().isLocked()) {
     study.getStudyParameterConfig().setDiscrepancyManagement("false");
   } else {
     study
         .getStudyParameterConfig()
         .setDiscrepancyManagement(fp.getString("discrepancyManagement"));
   }
   study.getStudyParameterConfig().setCollectDob(fp.getString("collectDob"));
   study.getStudyParameterConfig().setGenderRequired(fp.getString("genderRequired"));
   study
       .getStudyParameterConfig()
       .setInterviewerNameRequired(fp.getString("interviewerNameRequired"));
   study
       .getStudyParameterConfig()
       .setInterviewerNameDefault(fp.getString("interviewerNameDefault"));
   study.getStudyParameterConfig().setInterviewDateEditable(fp.getString("interviewDateEditable"));
   study.getStudyParameterConfig().setInterviewDateRequired(fp.getString("interviewDateRequired"));
   study
       .getStudyParameterConfig()
       .setInterviewerNameEditable(fp.getString("interviewerNameEditable"));
   study.getStudyParameterConfig().setInterviewDateDefault(fp.getString("interviewDateDefault"));
   study.getStudyParameterConfig().setSubjectIdGeneration(fp.getString("subjectIdGeneration"));
   study
       .getStudyParameterConfig()
       .setSubjectPersonIdRequired(fp.getString("subjectPersonIdRequired"));
   study.getStudyParameterConfig().setSubjectIdPrefixSuffix(fp.getString("subjectIdPrefixSuffix"));
   study.getStudyParameterConfig().setPersonIdShownOnCRF(fp.getString("personIdShownOnCRF"));
   study
       .getStudyParameterConfig()
       .setSecondaryLabelViewable(fp.getString("secondaryLabelViewable"));
   study
       .getStudyParameterConfig()
       .setAdminForcedReasonForChange(fp.getString("adminForcedReasonForChange"));
   if (!errors.isEmpty()) {
     request.setAttribute("formMessages", errors);
   }
 }
  /** Inserts the new study into database */
  private void submitStudy() {
    FormProcessor fp = new FormProcessor(request);
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    StudyBean study = (StudyBean) session.getAttribute("newStudy");

    ArrayList parameters = study.getStudyParameters();
    logger.info("study bean to be created:\n");
    logger.info(
        study.getName()
            + "\n"
            + study.getIdentifier()
            + "\n"
            + study.getParentStudyId()
            + "\n"
            + study.getSummary()
            + "\n"
            + study.getPrincipalInvestigator()
            + "\n"
            + study.getDatePlannedStart()
            + "\n"
            + study.getDatePlannedEnd()
            + "\n"
            + study.getFacilityName()
            + "\n"
            + study.getFacilityCity()
            + "\n"
            + study.getFacilityState()
            + "\n"
            + study.getFacilityZip()
            + "\n"
            + study.getFacilityCountry()
            + "\n"
            + study.getFacilityRecruitmentStatus()
            + "\n"
            + study.getFacilityContactName()
            + "\n"
            + study.getFacilityContactEmail()
            + "\n"
            + study.getFacilityContactPhone()
            + "\n"
            + study.getFacilityContactDegree());

    study.setOwner(ub);
    study.setCreatedDate(new Date());
    StudyBean parent = (StudyBean) sdao.findByPK(study.getParentStudyId());
    study.setType(parent.getType());
    // YW 10-10-2007, enable setting site status
    study.setStatus(study.getStatus());
    // YW >>

    study.setGenetic(parent.isGenetic());
    study = (StudyBean) sdao.create(study);

    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    for (int i = 0; i < parameters.size(); i++) {
      StudyParamsConfig config = (StudyParamsConfig) parameters.get(i);
      StudyParameterValueBean spv = config.getValue();
      spv.setStudyId(study.getId());
      spv = (StudyParameterValueBean) spvdao.create(config.getValue());
    }

    // YW << here only "collectDob" and "genderRequired" have been corrected
    // for sites.
    StudyParameterValueBean spv = new StudyParameterValueBean();
    StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parent.getId(), "collectDob");
    spv.setStudyId(study.getId());
    spv.setParameter("collectDob");
    spv.setValue(parentSPV.getValue());
    spvdao.create(spv);

    parentSPV = spvdao.findByHandleAndStudy(parent.getId(), "genderRequired");
    spv.setParameter("genderRequired");
    spv.setValue(parentSPV.getValue());
    spvdao.create(spv);
    // YW >>

    // switch user to the newly created site
    session.setAttribute("study", session.getAttribute("newStudy"));
    currentStudy = (StudyBean) session.getAttribute("study");

    session.removeAttribute("newStudy");
    addPageMessage(respage.getString("the_new_site_created_succesfully_current"));
    forwardPage(Page.SITE_LIST_SERVLET);
  }