Search in sources :

Example 71 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.

the class DefineStudyEventServlet method confirmDefinition1.

/**
     * Validates the first section of definition inputs
     * 
     * @throws Exception
     */
private void confirmDefinition1() throws Exception {
    Validator v = new Validator(request);
    FormProcessor fp = new FormProcessor(request);
    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);
    errors = v.validate();
    session.setAttribute("definition", createStudyEventDefinition());
    if (errors.isEmpty()) {
        logger.debug("no errors in the first section");
        // logger.debug("actionName*******" + fp.getString("actionName"));
        // debugger.debug("pageNum*******" + fp.getString("pageNum"));
        ArrayList crfArray = new ArrayList();
        /*
             * The tmpCRFIdMap will hold all the selected CRFs in the session
             * when the user is navigating through the list. This has been done
             * so that when the user moves to the next page of CRF list, the
             * selection made in the previous page doesn't get lost.
             */
        Map tmpCRFIdMap = (HashMap) session.getAttribute("tmpCRFIdMap");
        if (tmpCRFIdMap == null) {
            tmpCRFIdMap = new HashMap();
        }
        ArrayList crfsWithVersion = (ArrayList) session.getAttribute("crfsWithVersion");
        for (int i = 0; i < crfsWithVersion.size(); i++) {
            int id = fp.getInt("id" + i);
            String name = fp.getString("name" + i);
            String selected = fp.getString("selected" + i);
            if (!StringUtil.isBlank(selected) && "yes".equalsIgnoreCase(selected.trim())) {
                tmpCRFIdMap.put(id, name);
            } else {
                // deselected.
                if (tmpCRFIdMap.containsKey(id)) {
                    tmpCRFIdMap.remove(id);
                }
            }
        }
        session.setAttribute("tmpCRFIdMap", tmpCRFIdMap);
        EntityBeanTable table = fp.getEntityBeanTable();
        ArrayList allRows = CRFRow.generateRowsFromBeans(crfsWithVersion);
        String[] columns = { resword.getString("CRF_name"), resword.getString("date_created"), resword.getString("owner"), resword.getString("date_updated"), resword.getString("last_updated_by"), resword.getString("selected") };
        table.setColumns(new ArrayList(Arrays.asList(columns)));
        table.hideColumnLink(5);
        StudyEventDefinitionBean def1 = (StudyEventDefinitionBean) session.getAttribute("definition");
        HashMap args = new HashMap();
        args.put("actionName", "next");
        args.put("pageNum", "1");
        args.put("name", URLEncoder.encode(def1.getName(), "UTF-8"));
        args.put("repeating", new Boolean(def1.isRepeating()).toString());
        args.put("category", def1.getCategory());
        args.put("description", URLEncoder.encode(def1.getDescription(), "UTF-8"));
        args.put("type", def1.getType());
        table.setQuery("DefineStudyEvent", args, true);
        table.setRows(allRows);
        table.computeDisplay();
        request.setAttribute("table", table);
        forwardPage(Page.DEFINE_STUDY_EVENT2);
    } else {
        logger.debug("has validation errors in the first section");
        request.setAttribute("formMessages", errors);
        forwardPage(Page.DEFINE_STUDY_EVENT1);
    }
}
Also used : HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) HashMap(java.util.HashMap) Map(java.util.Map) Validator(org.akaza.openclinica.control.form.Validator)

Example 72 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.

the class DefineStudyEventServlet method createStudyEventDefinition.

/**
     * Constructs study bean from request-first section
     * 
     * @return
     */
private StudyEventDefinitionBean createStudyEventDefinition() {
    FormProcessor fp = new FormProcessor(request);
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
    try {
        String name = URLDecoder.decode(request.getParameter("name"), "UTF-8");
        String description = URLDecoder.decode(request.getParameter("description"), "UTF-8");
        sed.setName(name);
        sed.setDescription(description);
    } catch (Exception e) {
        // leaving old code here
        sed.setName(fp.getString("name"));
        sed.setDescription(fp.getString("description"));
    }
    // YW <<
    String temp = fp.getString("repeating");
    if ("true".equalsIgnoreCase(temp) || "1".equals(temp)) {
        sed.setRepeating(true);
    } else if ("false".equalsIgnoreCase(temp) || "0".equals(temp)) {
        sed.setRepeating(false);
    }
    // YW >>
    sed.setCategory(fp.getString("category"));
    sed.setType(fp.getString("type"));
    return sed;
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException)

Example 73 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.

the class CreateSubjectGroupClassServlet method confirmGroup.

/**
     * Validates the first section of study inputs and save it into study bean
     *
     * @param request
     * @param response
     * @throws Exception
     */
private void confirmGroup() throws Exception {
    Validator v = new Validator(request);
    FormProcessor fp = new FormProcessor(request);
    v.addValidation("name", Validator.NO_BLANKS);
    v.addValidation("subjectAssignment", Validator.NO_BLANKS);
    v.addValidation("name", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 30);
    v.addValidation("subjectAssignment", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 30);
    ArrayList studyGroups = new ArrayList();
    for (int i = 0; i < 10; i++) {
        String name = fp.getString("studyGroup" + i);
        String description = fp.getString("studyGroupDescription" + i);
        if (!StringUtil.isBlank(name)) {
            StudyGroupBean group = new StudyGroupBean();
            group.setName(name);
            group.setDescription(description);
            studyGroups.add(group);
            if (name.length() > 255) {
                request.setAttribute("studyGroupError", respage.getString("group_name_cannot_be_more_255"));
                break;
            }
            if (description.length() > 1000) {
                request.setAttribute("studyGroupError", respage.getString("group_description_cannot_be_more_100"));
                break;
            }
        }
    }
    errors = v.validate();
    if (fp.getInt("groupClassTypeId") == 0) {
        Validator.addError(errors, "groupClassTypeId", resexception.getString("group_class_type_is_required"));
    }
    StudyGroupClassBean group = new StudyGroupClassBean();
    group.setName(fp.getString("name"));
    group.setGroupClassTypeId(fp.getInt("groupClassTypeId"));
    group.setSubjectAssignment(fp.getString("subjectAssignment"));
    session.setAttribute("group", group);
    session.setAttribute("studyGroups", studyGroups);
    if (errors.isEmpty()) {
        logger.info("no errors in the first section");
        group.setGroupClassTypeName(GroupClassType.get(group.getGroupClassTypeId()).getName());
        forwardPage(Page.CREATE_SUBJECT_GROUP_CLASS_CONFIRM);
    } else {
        logger.info("has validation errors in the first section");
        request.setAttribute("formMessages", errors);
        request.setAttribute("groupTypes", GroupClassType.toArrayList());
        forwardPage(Page.CREATE_SUBJECT_GROUP_CLASS);
    }
}
Also used : FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) Validator(org.akaza.openclinica.control.form.Validator) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean)

Example 74 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.

the class ListEventDefinitionServlet method processRequest.

/**
     * Processes the request
     */
@Override
public void processRequest() throws Exception {
    StudyEventDefinitionDAO edao = new StudyEventDefinitionDAO(sm.getDataSource());
    UserAccountDAO sdao = new UserAccountDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    CRFDAO crfDao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO crfVersionDao = new CRFVersionDAO(sm.getDataSource());
    ArrayList seds = edao.findAllByStudy(currentStudy);
    // request.setAttribute("seds", seds);
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    for (int i = 0; i < seds.size(); i++) {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
        Collection eventDefinitionCRFlist = edcdao.findAllParentsByDefinition(sed.getId());
        Map crfWithDefaultVersion = new LinkedHashMap();
        for (Iterator it = eventDefinitionCRFlist.iterator(); it.hasNext(); ) {
            EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) it.next();
            CRFBean crfBean = (CRFBean) crfDao.findByPK(edcBean.getCrfId());
            CRFVersionBean crfVersionBean = (CRFVersionBean) crfVersionDao.findByPK(edcBean.getDefaultVersionId());
            logger.info("ED[" + sed.getName() + "]crf[" + crfBean.getName() + "]dv[" + crfVersionBean.getName() + "]");
            crfWithDefaultVersion.put(crfBean.getName(), crfVersionBean.getName());
        }
        sed.setCrfsWithDefaultVersion(crfWithDefaultVersion);
        logger.info("CRF size [" + sed.getCrfs().size() + "]");
        if (sed.getUpdater().getId() == 0) {
            sed.setUpdater(sed.getOwner());
            sed.setUpdatedDate(sed.getCreatedDate());
        }
        if (isPopulated(sed, sedao)) {
            sed.setPopulated(true);
        }
    }
    FormProcessor fp = new FormProcessor(request);
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allStudyRows = StudyEventDefinitionRow.generateRowsFromBeans(seds);
    String[] columns = { resword.getString("order"), resword.getString("name"), resword.getString("OID"), resword.getString("repeating"), resword.getString("type"), resword.getString("category"), resword.getString("populated"), resword.getString("date_created"), resword.getString("date_updated"), resword.getString("CRFs"), resword.getString("default_version"), resword.getString("actions") };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    // >> tbh #4169 09/2009
    table.hideColumnLink(2);
    table.hideColumnLink(3);
    table.hideColumnLink(4);
    table.hideColumnLink(6);
    table.hideColumnLink(7);
    table.hideColumnLink(8);
    table.hideColumnLink(9);
    // crfs, tbh
    table.hideColumnLink(10);
    table.hideColumnLink(11);
    table.hideColumnLink(12);
    // << tbh 09/2009
    table.setQuery("ListEventDefinition", new HashMap());
    // if (!currentStudy.getStatus().isLocked()) {
    // table.addLink(resworkflow.getString(
    // "create_a_new_study_event_definition"), "DefineStudyEvent");
    // }
    table.setRows(allStudyRows);
    table.setPaginated(false);
    table.computeDisplay();
    request.setAttribute("table", table);
    request.setAttribute("defSize", new Integer(seds.size()));
    if (request.getParameter("read") != null && request.getParameter("read").equals("true")) {
        request.setAttribute("readOnly", true);
    }
    forwardPage(Page.STUDY_EVENT_DEFINITION_LIST);
}
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) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) LinkedHashMap(java.util.LinkedHashMap) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) Iterator(java.util.Iterator) Collection(java.util.Collection) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 75 with FormProcessor

use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.

the class InitUpdateSubStudyServlet method createEventDefinitions.

private void createEventDefinitions(StudyBean parentStudy) throws MalformedURLException {
    FormProcessor fp = new FormProcessor(request);
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    int siteId = Integer.valueOf(request.getParameter("id").trim());
    ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
    StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    // CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    seds = sedDao.findAllByStudy(parentStudy);
    int start = 0;
    for (StudyEventDefinitionBean sed : seds) {
        String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
        if (participateFormStatus.equals("enabled"))
            baseUrl();
        request.setAttribute("participateFormStatus", participateFormStatus);
        int defId = sed.getId();
        ArrayList<EventDefinitionCRFBean> edcs = (ArrayList<EventDefinitionCRFBean>) edcdao.findAllByDefinitionAndSiteIdAndParentStudyId(defId, siteId, parentStudy.getId());
        ArrayList<EventDefinitionCRFBean> defCrfs = new ArrayList<EventDefinitionCRFBean>();
        // sed.setCrfNum(edcs.size());
        for (EventDefinitionCRFBean edcBean : edcs) {
            CRFBean cBean = (CRFBean) cdao.findByPK(edcBean.getCrfId());
            String crfPath = sed.getOid() + "." + cBean.getOid();
            edcBean.setOffline(getEventDefinitionCrfTagService().getEventDefnCrfOfflineStatus(2, crfPath, true));
            int edcStatusId = edcBean.getStatus().getId();
            CRFBean crf = (CRFBean) cdao.findByPK(edcBean.getCrfId());
            int crfStatusId = crf.getStatusId();
            if (edcStatusId == 5 || edcStatusId == 7 || crfStatusId == 5 || crfStatusId == 7) {
            } else {
                // ArrayList<CRFVersionBean> versions = (ArrayList<CRFVersionBean>)
                // cvdao.findAllActiveByCRF(edcBean.getCrfId());
                ArrayList<FormLayoutBean> versions = (ArrayList<FormLayoutBean>) fldao.findAllActiveByCRF(edcBean.getCrfId());
                edcBean.setVersions(versions);
                edcBean.setCrfName(crf.getName());
                if (edcBean.getParentId() == 0)
                    edcBean.setSubmissionUrl("");
                // CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edcBean.getDefaultVersionId());
                FormLayoutBean defaultVersion = (FormLayoutBean) fldao.findByPK(edcBean.getDefaultVersionId());
                edcBean.setDefaultVersionName(defaultVersion.getName());
                String sversionIds = edcBean.getSelectedVersionIds();
                ArrayList<Integer> idList = new ArrayList<Integer>();
                if (sversionIds.length() > 0) {
                    String[] ids = sversionIds.split("\\,");
                    for (String id : ids) {
                        idList.add(Integer.valueOf(id));
                    }
                }
                edcBean.setSelectedVersionIdList(idList);
                defCrfs.add(edcBean);
                ++start;
            }
        }
        logger.debug("definitionCrfs size=" + defCrfs.size() + " total size=" + edcs.size());
        sed.setCrfs(defCrfs);
        sed.setCrfNum(defCrfs.size());
    }
    // not sure if request is better, since not sure if there is another
    // process using this.
    session.setAttribute("definitions", seds);
    session.setAttribute("sdvOptions", this.setSDVOptions());
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Aggregations

FormProcessor (org.akaza.openclinica.control.form.FormProcessor)224 ArrayList (java.util.ArrayList)139 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)92 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)73 HashMap (java.util.HashMap)69 Date (java.util.Date)49 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)48 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)46 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)46 Validator (org.akaza.openclinica.control.form.Validator)44 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)44 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)42 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)41 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)41 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)40 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)36 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)36 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)35 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)35 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)35