Search in sources :

Example 81 with CRFVersionDAO

use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.

the class UpdateStudyEventServlet method populateUncompletedCRFsWithCRFAndVersions.

private void populateUncompletedCRFsWithCRFAndVersions(ArrayList uncompletedEventDefinitionCRFs) {
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    int size = uncompletedEventDefinitionCRFs.size();
    for (int i = 0; i < size; i++) {
        DisplayEventDefinitionCRFBean dedcrf = (DisplayEventDefinitionCRFBean) uncompletedEventDefinitionCRFs.get(i);
        CRFBean cb = (CRFBean) cdao.findByPK(dedcrf.getEdc().getCrfId());
        // check it here, tbh 102007
        if (cb.getStatus().equals(Status.AVAILABLE)) {
            // the above does not allow us to show the CRF as a thing with
            // status of 'invalid' so we have to
            // go to the JSP for this one, I think
            dedcrf.getEdc().setCrf(cb);
            ArrayList versions = (ArrayList) cvdao.findAllActiveByCRF(dedcrf.getEdc().getCrfId());
            dedcrf.getEdc().setVersions(versions);
            // added tbh 092007, fix for 1461
            if (versions != null && versions.size() != 0) {
                boolean isLocked = false;
                for (int ii = 0; ii < versions.size(); ii++) {
                    CRFVersionBean crfvb = (CRFVersionBean) versions.get(ii);
                    logger.debug("...checking versions..." + crfvb.getName());
                    if (!crfvb.getStatus().equals(Status.AVAILABLE)) {
                        logger.debug("found a non active crf version");
                        isLocked = true;
                    }
                }
                logger.debug("re-set event def, line 240: " + isLocked);
                if (isLocked) {
                    dedcrf.setStatus(Status.LOCKED);
                    dedcrf.getEventCRF().setStage(DataEntryStage.LOCKED);
                }
                uncompletedEventDefinitionCRFs.set(i, dedcrf);
            } else {
                // above added 092007, tbh
                dedcrf.setStatus(Status.LOCKED);
                dedcrf.getEventCRF().setStage(DataEntryStage.LOCKED);
                uncompletedEventDefinitionCRFs.set(i, dedcrf);
            }
        // added 102007, tbh
        } else {
            dedcrf.getEdc().setCrf(cb);
            logger.debug("_found a non active crf _");
            dedcrf.setStatus(Status.LOCKED);
            dedcrf.getEventCRF().setStage(DataEntryStage.LOCKED);
            dedcrf.getEdc().getCrf().setStatus(Status.LOCKED);
            uncompletedEventDefinitionCRFs.set(i, dedcrf);
        }
    // enclosing if statement added 102007, tbh
    }
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ArrayList(java.util.ArrayList) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 82 with CRFVersionDAO

use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.

the class RestoreEventCRFServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // eventCRFId
    int eventCRFId = fp.getInt("id");
    // studySubjectId
    int studySubId = fp.getInt("studySubId");
    checkStudyLocked("ViewStudySubject?id" + studySubId, respage.getString("current_study_locked"));
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    if (eventCRFId == 0) {
        addPageMessage(respage.getString("please_choose_an_event_CRF_to_restore"));
        request.setAttribute("id", new Integer(studySubId).toString());
        forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
    } else {
        EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
        StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
        // YW 11-07-2007, an event CRF could not be restored if its study
        // subject has been removed
        Status s = studySub.getStatus();
        if ("removed".equalsIgnoreCase(s.getName()) || "auto-removed".equalsIgnoreCase(s.getName())) {
            addPageMessage(resword.getString("event_CRF") + resterm.getString("could_not_be") + resterm.getString("restored") + "." + respage.getString("study_subject_has_been_deleted"));
            request.setAttribute("id", new Integer(studySubId).toString());
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        }
        // YW
        request.setAttribute("studySub", studySub);
        // construct info needed on view event crf page
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
        int crfVersionId = eventCRF.getCRFVersionId();
        CRFBean cb = cdao.findByVersionId(crfVersionId);
        eventCRF.setCrf(cb);
        CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
        eventCRF.setCrfVersion(cvb);
        // then get the definition so we can call
        // DisplayEventCRFBean.setFlags
        int studyEventId = eventCRF.getStudyEventId();
        StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
        int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
        event.setStudyEventDefinition(sed);
        request.setAttribute("event", event);
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
        EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
        DisplayEventCRFBean dec = new DisplayEventCRFBean();
        dec.setEventCRF(eventCRF);
        dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
        // find all item data
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        ArrayList itemData = iddao.findAllByEventCRFId(eventCRF.getId());
        request.setAttribute("items", itemData);
        String action = request.getParameter("action");
        if ("confirm".equalsIgnoreCase(action)) {
            if (!eventCRF.getStatus().equals(Status.DELETED) && !eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
                addPageMessage(respage.getString("this_event_CRF_avilable_for_study") + " " + " " + respage.getString("please_contact_sysadmin_for_more_information"));
                request.setAttribute("id", new Integer(studySubId).toString());
                forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
                return;
            }
            request.setAttribute("displayEventCRF", dec);
            forwardPage(Page.RESTORE_EVENT_CRF);
        } else {
            logger.info("submit to restore the event CRF from study");
            // Set crf status to AVAILABLE to allow data
            // to be repopulated in the form properly
            eventCRF.setStatus(Status.AVAILABLE);
            ecdao.update(eventCRF);
            // restore all the item data to the appropriate status
            for (int a = 0; a < itemData.size(); a++) {
                ItemDataBean item = (ItemDataBean) itemData.get(a);
                if (item.getStatus().equals(Status.AUTO_DELETED)) {
                    item.setStatus(Status.AVAILABLE);
                    item.setUpdater(ub);
                    item.setUpdatedDate(new Date());
                    iddao.update(item);
                }
            }
            Status restoredStatus = null;
            if (eventCRF.getDateCompleted() != null) {
                if (edc.isDoubleEntry() && eventCRF.getDateValidateCompleted() == null) {
                    restoredStatus = Status.PENDING;
                    eventCRF.setStage(DataEntryStage.INITIAL_DATA_ENTRY);
                } else {
                    restoredStatus = Status.UNAVAILABLE;
                    eventCRF.setStage(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE);
                }
                // Reset the DisplayEventCRFBean
                dec.setEventCRF(eventCRF);
                dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
            } else {
                restoredStatus = Status.AVAILABLE;
            }
            eventCRF.setStatus(restoredStatus);
            eventCRF.setUpdater(ub);
            eventCRF.setUpdatedDate(new Date());
            ecdao.update(eventCRF);
            String emailBody = respage.getString("the_event_CRF") + cb.getName() + " " + respage.getString("has_been_restored_to_the_event") + " " + event.getStudyEventDefinition().getName() + ".";
            addPageMessage(emailBody);
            sendEmail(emailBody);
            request.setAttribute("id", new Integer(studySubId).toString());
            forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) Status(org.akaza.openclinica.bean.core.Status) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 83 with CRFVersionDAO

use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.

the class UpdateEventDefinitionServlet method confirmDefinition.

/**
 * @throws Exception
 */
private void confirmDefinition() throws Exception {
    Validator v = new Validator(request);
    FormProcessor fp = new FormProcessor(request);
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
    if (participateFormStatus.equals("enabled"))
        baseUrl();
    request.setAttribute("participateFormStatus", participateFormStatus);
    v.addValidation("name", Validator.NO_BLANKS);
    v.addValidation("name", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
    v.addValidation("description", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
    v.addValidation("category", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 2000);
    ArrayList<EventDefinitionCRFBean> edcsInSession = (ArrayList<EventDefinitionCRFBean>) session.getAttribute("eventDefinitionCRFs");
    int parentStudyId = sed.getStudyId();
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    ArrayList<EventDefinitionCRFBean> eventDefCrfList = (ArrayList<EventDefinitionCRFBean>) edcdao.findAllActiveSitesAndStudiesPerParentStudy(parentStudyId);
    // logger.info("no errors");
    sed.setName(fp.getString("name"));
    // OC-12780
    if (sed.isRepeating() && !fp.getBoolean("repeating")) {
        EventCRFDAO ecrfDao = new EventCRFDAO(sm.getDataSource());
        ArrayList<EventCRFBean> crfList = ecrfDao.findAllByStudyEventDefinition(sed.getId(), parentStudyId);
        if (crfList.size() > 0) {
            v.addValidation("repeating", Validator.CAN_NOT_CHANGE_NONE_REPEATING_NOW);
        }
        StudyEventDAO seDao = new StudyEventDAO(sm.getDataSource());
        if (seDao.isThisRepeatingEventScheduledMoreThanOneTime(parentStudyId, sed.getId())) {
            v.addValidation("repeating", Validator.CAN_NOT_CHANGE_NONE_REPEATING_NOW);
        }
    }
    sed.setRepeating(fp.getBoolean("repeating"));
    sed.setCategory(fp.getString("category"));
    sed.setDescription(fp.getString("description"));
    sed.setType(fp.getString("type"));
    // OC-12780
    session.setAttribute("definition", sed);
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    ArrayList<EventDefinitionCRFBean> edcs = (ArrayList) session.getAttribute("eventDefinitionCRFs");
    for (int i = 0; i < edcs.size(); i++) {
        EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) edcs.get(i);
        if (!edcBean.getStatus().equals(Status.DELETED) && !edcBean.getStatus().equals(Status.AUTO_DELETED)) {
            // only get inputs from web page if AVAILABLE
            int defaultVersionId = fp.getInt("defaultVersionId" + i);
            edcBean.setDefaultVersionId(defaultVersionId);
            CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edcBean.getDefaultVersionId());
            edcBean.setDefaultVersionName(defaultVersion.getName());
            String requiredCRF = fp.getString("requiredCRF" + i);
            String doubleEntry = fp.getString("doubleEntry" + i);
            String decisionCondition = fp.getString("decisionCondition" + i);
            String electronicSignature = fp.getString("electronicSignature" + i);
            String hideCRF = fp.getString("hideCRF" + i);
            int sdvId = fp.getInt("sdvOption" + i);
            String participantForm = fp.getString("participantForm" + i);
            String allowAnonymousSubmission = fp.getString("allowAnonymousSubmission" + i);
            String submissionUrl = fp.getString("submissionUrl" + i);
            String offline = fp.getString("offline" + i);
            System.out.println("submission :" + submissionUrl);
            if (!StringUtil.isBlank(hideCRF) && "yes".equalsIgnoreCase(hideCRF.trim())) {
                edcBean.setHideCrf(true);
            } else {
                edcBean.setHideCrf(false);
            }
            if (!StringUtil.isBlank(requiredCRF) && "yes".equalsIgnoreCase(requiredCRF.trim())) {
                edcBean.setRequiredCRF(true);
            } else {
                edcBean.setRequiredCRF(false);
            }
            if (!StringUtil.isBlank(doubleEntry) && "yes".equalsIgnoreCase(doubleEntry.trim())) {
                edcBean.setDoubleEntry(true);
            } else {
                edcBean.setDoubleEntry(false);
            }
            if (!StringUtil.isBlank(electronicSignature) && "yes".equalsIgnoreCase(electronicSignature.trim())) {
                edcBean.setElectronicSignature(true);
            } else {
                edcBean.setElectronicSignature(false);
            }
            if (!StringUtil.isBlank(decisionCondition) && "yes".equalsIgnoreCase(decisionCondition.trim())) {
                edcBean.setDecisionCondition(true);
            } else {
                edcBean.setDecisionCondition(false);
            }
            if (!StringUtil.isBlank(participantForm) && "yes".equalsIgnoreCase(participantForm.trim())) {
                edcBean.setParticipantForm(true);
            } else {
                edcBean.setParticipantForm(false);
            }
            if (!StringUtils.isBlank(allowAnonymousSubmission) && "yes".equalsIgnoreCase(allowAnonymousSubmission.trim())) {
                edcBean.setAllowAnonymousSubmission(true);
            } else {
                edcBean.setAllowAnonymousSubmission(false);
            }
            edcBean.setSubmissionUrl(submissionUrl.trim());
            if (!StringUtils.isBlank(offline) && "yes".equalsIgnoreCase(offline.trim())) {
                edcBean.setOffline(true);
            } else {
                edcBean.setOffline(false);
            }
            String nullString = "";
            // process null values
            ArrayList nulls = NullValue.toArrayList();
            for (int a = 0; a < nulls.size(); a++) {
                NullValue n = (NullValue) nulls.get(a);
                String myNull = fp.getString(n.getName().toLowerCase() + i);
                if (!StringUtil.isBlank(myNull) && "yes".equalsIgnoreCase(myNull.trim())) {
                    nullString = nullString + n.getName().toUpperCase() + ",";
                }
            }
            if (sdvId > 0 && (edcBean.getSourceDataVerification() == null || sdvId != edcBean.getSourceDataVerification().getCode())) {
                edcBean.setSourceDataVerification(SourceDataVerification.getByCode(sdvId));
            }
            edcBean.setNullValues(nullString);
            logger.info("found null values: " + nullString);
        }
    }
    validateSubmissionUrl(edcsInSession, eventDefCrfList, v);
    errors = v.validate();
    if (!errors.isEmpty()) {
        logger.info("has errors");
        session.setAttribute("eventDefinitionCRFs", edcs);
        request.setAttribute("formMessages", errors);
        forwardPage(Page.UPDATE_EVENT_DEFINITION1);
    }
    session.setAttribute("eventDefinitionCRFs", edcs);
    forwardPage(Page.UPDATE_EVENT_DEFINITION_CONFIRM);
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) Validator(org.akaza.openclinica.control.form.Validator) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 84 with CRFVersionDAO

use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.

the class CreateSubStudyServlet method submitSiteEventDefinitions.

private void submitSiteEventDefinitions(StudyBean site) throws MalformedURLException {
    FormProcessor fp = new FormProcessor(request);
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    seds = (ArrayList<StudyEventDefinitionBean>) session.getAttribute("definitions");
    HashMap<String, Boolean> changes = (HashMap<String, Boolean>) session.getAttribute("changed");
    for (StudyEventDefinitionBean sed : seds) {
        String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
        request.setAttribute("participateFormStatus", participateFormStatus);
        if (participateFormStatus.equals("enabled"))
            baseUrl();
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        ArrayList<EventDefinitionCRFBean> edcs = sed.getCrfs();
        for (EventDefinitionCRFBean edcBean : edcs) {
            int edcStatusId = edcBean.getStatus().getId();
            if (edcStatusId == 5 || edcStatusId == 7) {
            } else {
                boolean changed = changes.get(sed.getId() + "-" + edcBean.getId());
                if (changed) {
                    edcBean.setParentId(edcBean.getId());
                    edcBean.setStudyId(site.getId());
                    edcBean.setUpdater(ub);
                    edcBean.setUpdatedDate(new Date());
                    logger.debug("create for the site");
                    edcdao.create(edcBean);
                }
            }
        }
    }
    session.removeAttribute("definitions");
    session.removeAttribute("changed");
    session.removeAttribute("sdvOptions");
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) Date(java.util.Date) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 85 with CRFVersionDAO

use of org.akaza.openclinica.dao.submit.CRFVersionDAO in project OpenClinica by OpenClinica.

the class CreateSubStudyServlet method createSiteEventDefinitions.

private ArrayList<StudyEventDefinitionBean> createSiteEventDefinitions(StudyBean site, Validator v) throws MalformedURLException {
    FormProcessor fp = new FormProcessor(request);
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    ArrayList<EventDefinitionCRFBean> edcsInSession = new ArrayList<EventDefinitionCRFBean>();
    StudyBean parentStudyBean;
    if (site.getParentStudyId() == 0) {
        parentStudyBean = site;
    } else {
        StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
        parentStudyBean = (StudyBean) studyDAO.findByPK(site.getParentStudyId());
    }
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    ArrayList<EventDefinitionCRFBean> eventDefCrfList = (ArrayList<EventDefinitionCRFBean>) edcdao.findAllActiveSitesAndStudiesPerParentStudy(parentStudyBean.getId());
    ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
    StudyBean parentStudy = (StudyBean) new StudyDAO(sm.getDataSource()).findByPK(site.getParentStudyId());
    seds = (ArrayList<StudyEventDefinitionBean>) session.getAttribute("definitions");
    if (seds == null || seds.size() <= 0) {
        StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
        seds = sedDao.findAllByStudy(parentStudy);
    }
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    HashMap<String, Boolean> changes = new HashMap<String, Boolean>();
    for (StudyEventDefinitionBean sed : seds) {
        String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
        if (participateFormStatus.equals("enabled"))
            baseUrl();
        request.setAttribute("participateFormStatus", participateFormStatus);
        // EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        ArrayList<EventDefinitionCRFBean> edcs = sed.getCrfs();
        int start = 0;
        for (EventDefinitionCRFBean edcBean : edcs) {
            EventDefinitionCRFBean persistEventDefBean = (EventDefinitionCRFBean) edcdao.findByPK(edcBean.getId());
            int edcStatusId = edcBean.getStatus().getId();
            if (edcStatusId == 5 || edcStatusId == 7) {
            } else {
                String order = start + "-" + edcBean.getId();
                int defaultVersionId = fp.getInt("defaultVersionId" + order);
                String requiredCRF = fp.getString("requiredCRF" + order);
                String doubleEntry = fp.getString("doubleEntry" + order);
                String electronicSignature = fp.getString("electronicSignature" + order);
                String hideCRF = fp.getString("hideCRF" + order);
                int sdvId = fp.getInt("sdvOption" + order);
                String participantForm = fp.getString("participantForm" + order);
                String allowAnonymousSubmission = fp.getString("allowAnonymousSubmission" + order);
                String submissionUrl = fp.getString("submissionUrl" + order);
                String offline = fp.getString("offline" + order);
                ArrayList<String> selectedVersionIdList = fp.getStringArray("versionSelection" + order);
                int selectedVersionIdListSize = selectedVersionIdList.size();
                String selectedVersionIds = "";
                if (selectedVersionIdListSize > 0) {
                    for (String id : selectedVersionIdList) {
                        selectedVersionIds += id + ",";
                    }
                    selectedVersionIds = selectedVersionIds.substring(0, selectedVersionIds.length() - 1);
                }
                boolean changed = false;
                boolean isRequired = !StringUtil.isBlank(requiredCRF) && "yes".equalsIgnoreCase(requiredCRF.trim()) ? true : false;
                boolean isDouble = !StringUtil.isBlank(doubleEntry) && "yes".equalsIgnoreCase(doubleEntry.trim()) ? true : false;
                boolean hasPassword = !StringUtil.isBlank(electronicSignature) && "yes".equalsIgnoreCase(electronicSignature.trim()) ? true : false;
                boolean isHide = !StringUtil.isBlank(hideCRF) && "yes".equalsIgnoreCase(hideCRF.trim()) ? true : false;
                if (edcBean.getParentId() > 0) {
                    int dbDefaultVersionId = edcBean.getDefaultVersionId();
                    if (defaultVersionId != dbDefaultVersionId) {
                        changed = true;
                        CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(defaultVersionId);
                        edcBean.setDefaultVersionId(defaultVersionId);
                        edcBean.setDefaultVersionName(defaultVersion.getName());
                    }
                    if (isRequired != edcBean.isRequiredCRF()) {
                        changed = true;
                        edcBean.setRequiredCRF(isRequired);
                    }
                    if (isDouble != edcBean.isDoubleEntry()) {
                        changed = true;
                        edcBean.setDoubleEntry(isDouble);
                    }
                    if (hasPassword != edcBean.isElectronicSignature()) {
                        changed = true;
                        edcBean.setElectronicSignature(hasPassword);
                    }
                    if (isHide != edcBean.isHideCrf()) {
                        changed = true;
                        edcBean.setHideCrf(isHide);
                    }
                    if (!submissionUrl.equals(edcBean.getSubmissionUrl()) || !submissionUrl.equals(persistEventDefBean.getSubmissionUrl())) {
                        changed = true;
                        edcBean.setSubmissionUrl(submissionUrl);
                    }
                    if (!StringUtil.isBlank(selectedVersionIds) && !selectedVersionIds.equals(edcBean.getSelectedVersionIds())) {
                        changed = true;
                        String[] ids = selectedVersionIds.split(",");
                        ArrayList<Integer> idList = new ArrayList<Integer>();
                        for (String id : ids) {
                            idList.add(Integer.valueOf(id));
                        }
                        edcBean.setSelectedVersionIdList(idList);
                        edcBean.setSelectedVersionIds(selectedVersionIds);
                    }
                    if (sdvId > 0 && sdvId != edcBean.getSourceDataVerification().getCode()) {
                        changed = true;
                        edcBean.setSourceDataVerification(SourceDataVerification.getByCode(sdvId));
                    }
                } else {
                    // only if definition-crf has been modified, will it be
                    // saved for the site
                    int defaultId = defaultVersionId > 0 ? defaultVersionId : edcBean.getDefaultVersionId();
                    if (defaultId == defaultVersionId) {
                        if (isRequired == edcBean.isRequiredCRF()) {
                            if (isDouble == edcBean.isDoubleEntry()) {
                                if (hasPassword == edcBean.isElectronicSignature()) {
                                    if (isHide == edcBean.isHideCrf()) {
                                        if (submissionUrl.equals("")) {
                                            if (selectedVersionIdListSize > 0) {
                                                if (selectedVersionIdListSize == edcBean.getVersions().size()) {
                                                    if (sdvId > 0) {
                                                        if (sdvId != edcBean.getSourceDataVerification().getCode()) {
                                                            changed = true;
                                                            edcBean.setSourceDataVerification(SourceDataVerification.getByCode(sdvId));
                                                            edcBean.setSubmissionUrl(submissionUrl);
                                                        }
                                                    }
                                                } else {
                                                    changed = true;
                                                    String[] ids = selectedVersionIds.split(",");
                                                    ArrayList<Integer> idList = new ArrayList<Integer>();
                                                    for (String id : ids) {
                                                        idList.add(Integer.valueOf(id));
                                                    }
                                                    edcBean.setSelectedVersionIdList(idList);
                                                    edcBean.setSelectedVersionIds(selectedVersionIds);
                                                    edcBean.setSubmissionUrl(submissionUrl);
                                                }
                                            }
                                        } else {
                                            changed = true;
                                            edcBean.setSubmissionUrl(submissionUrl);
                                        }
                                    } else {
                                        changed = true;
                                        edcBean.setHideCrf(isHide);
                                        edcBean.setSubmissionUrl(submissionUrl);
                                    }
                                } else {
                                    changed = true;
                                    edcBean.setElectronicSignature(hasPassword);
                                    edcBean.setSubmissionUrl(submissionUrl);
                                }
                            } else {
                                changed = true;
                                edcBean.setDoubleEntry(isDouble);
                                edcBean.setSubmissionUrl(submissionUrl);
                            }
                        } else {
                            changed = true;
                            edcBean.setRequiredCRF(isRequired);
                            edcBean.setSubmissionUrl(submissionUrl);
                        }
                    } else {
                        changed = true;
                        CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(defaultVersionId);
                        edcBean.setDefaultVersionId(defaultVersionId);
                        edcBean.setDefaultVersionName(defaultVersion.getName());
                    }
                }
                changes.put(sed.getId() + "-" + edcBean.getId(), changed);
                ++start;
            }
            edcsInSession.add(edcBean);
        }
        sed.setPopulated(false);
        eventDefCrfList = validateSubmissionUrl(edcsInSession, eventDefCrfList, v, sed);
        edcsInSession.clear();
    }
    errors = v.validate();
    StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
    ArrayList<StudyBean> allStudies = (ArrayList<StudyBean>) studyDAO.findAll();
    for (StudyBean thisBean : allStudies) {
        if (fp.getString("uniqueProId").trim().equals(thisBean.getIdentifier())) {
            v.addError(errors, "uniqueProId", resexception.getString("unique_protocol_id_existed"));
        }
    }
    // << tbh #3999 08/2009
    if (fp.getString("name").trim().length() > 100) {
    // Validator.addError(errors, "name", resexception.getString("maximum_lenght_name_100"));
    }
    if (fp.getString("uniqueProId").trim().length() > 30) {
        Validator.addError(errors, "uniqueProId", resexception.getString("maximum_lenght_unique_protocol_30"));
    }
    if (fp.getString("description").trim().length() > 255) {
        Validator.addError(errors, "description", resexception.getString("maximum_lenght_brief_summary_255"));
    }
    if (fp.getString("prinInvestigator").trim().length() > 255) {
        Validator.addError(errors, "prinInvestigator", resexception.getString("maximum_lenght_principal_investigator_255"));
    }
    if (fp.getInt("expectedTotalEnrollment") <= 0) {
        Validator.addError(errors, "expectedTotalEnrollment", respage.getString("expected_total_enrollment_must_be_a_positive_number"));
    }
    if (!errors.isEmpty()) {
        // logger.info("has errors");
        StudyBean study = createStudyBean();
        session.setAttribute("newStudy", study);
        session.setAttribute("definitions", seds);
        request.setAttribute("formMessages", errors);
        /*   try {
               local_df.parse(fp.getString(INPUT_START_DATE));
               fp.addPresetValue(INPUT_START_DATE, local_df.format(fp.getDate(INPUT_START_DATE)));
           } catch (ParseException pe) {
               fp.addPresetValue(INPUT_START_DATE, fp.getString(INPUT_START_DATE));
           }
           try {
               local_df.parse(fp.getString(INPUT_END_DATE));
               fp.addPresetValue(INPUT_END_DATE, local_df.format(fp.getDate(INPUT_END_DATE)));
           } catch (ParseException pe) {
               fp.addPresetValue(INPUT_END_DATE, fp.getString(INPUT_END_DATE));
           }
           try {
               local_df.parse(fp.getString(INPUT_VER_DATE));
               fp.addPresetValue(INPUT_VER_DATE, local_df.format(fp.getDate(INPUT_VER_DATE)));
           } catch (ParseException pe) {
               fp.addPresetValue(INPUT_VER_DATE, fp.getString(INPUT_VER_DATE));
           }*/
        // setPresetValues(fp.getPresetValues());
        logger.info("has validation errors");
        // request.setAttribute("formMessages", errors);
        // request.setAttribute("facRecruitStatusMap",
        // CreateStudyServlet.facRecruitStatusMap);
        // request.setAttribute("statuses", Status.toActiveArrayList());
        // forwardPage(Page.CREATE_SUB_STUDY);
        forwardPage(Page.CREATE_SUB_STUDY);
    }
    session.setAttribute("changed", changes);
    return seds;
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Aggregations

CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)105 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)83 ArrayList (java.util.ArrayList)80 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)68 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)63 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)60 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)58 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)56 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)54 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)52 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)48 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)46 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)42 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)41 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)35 HashMap (java.util.HashMap)34 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)34 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)31 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)26 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)25