Search in sources :

Example 1 with NullValue

use of org.akaza.openclinica.bean.core.NullValue in project OpenClinica by OpenClinica.

the class DefineStudyEventServlet method confirmWholeDefinition.

/**
     * Validates the entire definition
     * 
     * @throws Exception
     */
private void confirmWholeDefinition() throws Exception {
    Validator v = new Validator(request);
    FormProcessor fp = new FormProcessor(request);
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) session.getAttribute("definition");
    ArrayList eventDefinitionCRFs = new ArrayList();
    FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
    for (int i = 0; i < sed.getCrfs().size(); i++) {
        EventDefinitionCRFBean edcBean = new EventDefinitionCRFBean();
        int crfId = fp.getInt("crfId" + i);
        int defaultVersionId = fp.getInt("defaultVersionId" + i);
        edcBean.setCrfId(crfId);
        edcBean.setDefaultVersionId(defaultVersionId);
        FormLayoutBean defaultVersion = (FormLayoutBean) fldao.findByPK(edcBean.getDefaultVersionId());
        edcBean.setDefaultVersionName(defaultVersion.getName());
        String crfName = fp.getString("crfName" + i);
        edcBean.setCrfName(crfName);
        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 participantForm = fp.getString("participantForm" + i);
        String allowAnonymousSubmission = fp.getString("allowAnonymousSubmission" + i);
        String submissionUrl = fp.getString("submissionUrl" + i);
        String offline = fp.getString("offline" + i);
        // issue 312 BWP<<
        String hiddenCrf = fp.getString("hiddenCrf" + i);
        // hideCRF is false by default in the bean
        if (!StringUtil.isBlank(hiddenCrf) && "yes".equalsIgnoreCase(hiddenCrf.trim())) {
            edcBean.setHideCrf(true);
        } else {
            edcBean.setHideCrf(false);
        }
        // >>
        String sdvOption = fp.getString("sdvOption" + i);
        if (!StringUtils.isBlank(sdvOption)) {
            int id = Integer.valueOf(sdvOption);
            edcBean.setSourceDataVerification(SourceDataVerification.getByCode(id));
        }
        if (!StringUtils.isBlank(requiredCRF) && "yes".equalsIgnoreCase(requiredCRF.trim())) {
            edcBean.setRequiredCRF(true);
        } else {
            edcBean.setRequiredCRF(false);
        }
        if (!StringUtils.isBlank(participantForm) && "yes".equalsIgnoreCase(participantForm.trim())) {
            edcBean.setParticipantForm(true);
        } else {
            edcBean.setParticipantForm(false);
        }
        // when participant form is not selected, force allow anonymous to be not selected
        if (edcBean.isParticipantForm() && !StringUtils.isBlank(allowAnonymousSubmission) && "yes".equalsIgnoreCase(allowAnonymousSubmission.trim())) {
            edcBean.setAllowAnonymousSubmission(true);
        } else {
            edcBean.setAllowAnonymousSubmission(false);
        }
        if (!StringUtils.isBlank(offline) && "yes".equalsIgnoreCase(offline.trim())) {
            edcBean.setOffline(true);
        } else {
            edcBean.setOffline(false);
        }
        if (!StringUtils.isBlank(doubleEntry) && "yes".equalsIgnoreCase(doubleEntry.trim())) {
            edcBean.setDoubleEntry(true);
        } else {
            edcBean.setDoubleEntry(false);
        }
        if (!StringUtils.isBlank(decisionCondition) && "yes".equalsIgnoreCase(decisionCondition.trim())) {
            edcBean.setDecisionCondition(true);
        } else {
            edcBean.setDecisionCondition(false);
        }
        if (!StringUtils.isBlank(electronicSignature) && "yes".equalsIgnoreCase(electronicSignature.trim())) {
            edcBean.setElectronicSignature(true);
        } else {
            edcBean.setElectronicSignature(false);
        }
        // also useful to protect from naughty submission not coming from our html form
        if (edcBean.isParticipantForm() && edcBean.isAllowAnonymousSubmission()) {
            edcBean.setSubmissionUrl(submissionUrl.trim());
        }
        ArrayList<CRFVersionBean> versions = fldao.findAllByCRFId(crfId);
        edcBean.setVersions(versions);
        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 (!StringUtils.isBlank(myNull) && "yes".equalsIgnoreCase(myNull.trim())) {
                nullString = nullString + n.getName().toUpperCase() + ",";
            }
        }
        edcBean.setNullValues(nullString);
        edcBean.setStudyId(ub.getActiveStudyId());
        eventDefinitionCRFs.add(edcBean);
    }
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
    request.setAttribute("participateFormStatus", participateFormStatus);
    if (participateFormStatus.equals("enabled"))
        baseUrl();
    request.setAttribute("participateFormStatus", participateFormStatus);
    request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
    // not used on page
    session.setAttribute("edCRFs", eventDefinitionCRFs);
    ArrayList<EventDefinitionCRFBean> edcsInSession = (ArrayList<EventDefinitionCRFBean>) session.getAttribute("edCRFs");
    int parentStudyId = sed.getStudyId();
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    ArrayList<EventDefinitionCRFBean> eventDefCrfList = (ArrayList<EventDefinitionCRFBean>) edcdao.findAllActiveSitesAndStudiesPerParentStudy(parentStudyId);
    if (eventDefCrfList.size() != 0)
        validateSubmissionUrl(edcsInSession, eventDefCrfList, v);
    errors = v.validate();
    if (!errors.isEmpty()) {
        ArrayList<String> sdvOptions = new ArrayList<String>();
        sdvOptions.add(SourceDataVerification.AllREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.PARTIALREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.NOTREQUIRED.toString());
        sdvOptions.add(SourceDataVerification.NOTAPPLICABLE.toString());
        request.setAttribute("sdvOptions", sdvOptions);
        logger.info("has errors");
        session.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
        request.setAttribute("formMessages", errors);
        forwardPage(Page.DEFINE_STUDY_EVENT4);
    }
    forwardPage(Page.DEFINE_STUDY_EVENT_CONFIRM);
}
Also used : 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) NullValue(org.akaza.openclinica.bean.core.NullValue) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) Validator(org.akaza.openclinica.control.form.Validator)

Example 2 with NullValue

use of org.akaza.openclinica.bean.core.NullValue in project OpenClinica by OpenClinica.

the class DisplayItemBean method setMetadata.

/**
     * @param metadata
     *            The metadata to set.
     */
public void setMetadata(ItemFormMetadataBean metadata) {
    this.metadata = metadata;
    ResponseSetBean rsb = getMetadata().getResponseSet();
    // BWP 09/18/07 >> rsb cannot be null here because I added this line to
    // ItemFormMetadataBean's
    // constructor: responseSet=new ResponseSetBean();
    // logger.info("rsb = " + rsb);
    org.akaza.openclinica.bean.core.ResponseType rt = rsb.getResponseType();
    if (rt.equals(org.akaza.openclinica.bean.core.ResponseType.CHECKBOX) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.RADIO) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.SELECT) || rt.equals(org.akaza.openclinica.bean.core.ResponseType.SELECTMULTI)) {
        if (eventDefinitionCRF != null) {
            ArrayList nullValues = eventDefinitionCRF.getNullValuesList();
            for (int i = 0; i < nullValues.size(); i++) {
                NullValue nv = (NullValue) nullValues.get(i);
                ResponseOptionBean ro = new ResponseOptionBean();
                ro.setValue(nv.getName());
                ro.setText(nv.getDescription());
                rsb.addOption(ro);
            }
        }
    }
    getMetadata().setResponseSet(rsb);
}
Also used : NullValue(org.akaza.openclinica.bean.core.NullValue) ArrayList(java.util.ArrayList)

Example 3 with NullValue

use of org.akaza.openclinica.bean.core.NullValue in project OpenClinica by OpenClinica.

the class DataEntryServlet method validateDisplayItemBeanText.

/**
     * Peform validation on a item which has a TEXT or TEXTAREA response type. If the item has a null value, it's automatically validated. Otherwise, it's
     * checked against its data type.
     *
     * @param v
     *            The Validator to add validations to.
     * @param dib
     *            The DisplayItemBean to validate.
     * @param request TODO
     * @return The DisplayItemBean which is validated.
     */
protected DisplayItemBean validateDisplayItemBeanText(DiscrepancyValidator v, DisplayItemBean dib, String inputName, HttpServletRequest request) {
    FormProcessor fp = new FormProcessor(request);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    if (StringUtil.isBlank(inputName)) {
        // for single items
        inputName = getInputName(dib);
    }
    ItemBean ib = dib.getItem();
    ItemFormMetadataBean ibMeta = dib.getMetadata();
    ItemDataType idt = ib.getDataType();
    ItemDataBean idb = dib.getData();
    boolean isNull = false;
    ArrayList nullValues = edcb.getNullValuesList();
    for (int i = 0; i < nullValues.size(); i++) {
        NullValue nv = (NullValue) nullValues.get(i);
        if (nv.getName().equals(fp.getString(inputName))) {
            isNull = true;
        }
    }
    if (!isNull) {
        if (StringUtil.isBlank(idb.getValue())) {
            // check required first
            if (ibMeta.isRequired() && ibMeta.isShowItem()) {
                v.addValidation(inputName, Validator.IS_REQUIRED);
            }
        } else {
            if (idt.equals(ItemDataType.ST)) {
                // a string's size could be more than 3999, which is more
                // than
                // the db field length
                v.addValidation(inputName, Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 3999);
            } else if (idt.equals(ItemDataType.INTEGER)) {
                v.addValidation(inputName, Validator.IS_AN_INTEGER);
                v.alwaysExecuteLastValidation(inputName);
            } else if (idt.equals(ItemDataType.REAL)) {
                v.addValidation(inputName, Validator.IS_A_NUMBER);
                v.alwaysExecuteLastValidation(inputName);
            } else if (idt.equals(ItemDataType.BL)) {
            // there is no validation here since this data type is
            // explicitly
            // allowed to be null
            // if the string input for this field parses to a non-zero
            // number, the
            // value will be true; otherwise, 0
            } else if (idt.equals(ItemDataType.BN)) {
            } else if (idt.equals(ItemDataType.SET)) {
                // v.addValidation(inputName, Validator.NO_BLANKS_SET);
                v.addValidation(inputName, Validator.IN_RESPONSE_SET_SINGLE_VALUE, dib.getMetadata().getResponseSet());
            } else if (idt.equals(ItemDataType.DATE)) {
                v.addValidation(inputName, Validator.IS_A_DATE);
                v.alwaysExecuteLastValidation(inputName);
            } else if (idt.equals(ItemDataType.PDATE)) {
                v.addValidation(inputName, Validator.IS_PARTIAL_DATE);
                v.alwaysExecuteLastValidation(inputName);
            }
            if (ibMeta.getWidthDecimal().length() > 0) {
                ArrayList<String> params = new ArrayList<String>();
                params.add(0, idt.getName());
                params.add(1, ibMeta.getWidthDecimal());
                v.addValidation(inputName, Validator.IS_VALID_WIDTH_DECIMAL, params);
                v.alwaysExecuteLastValidation(inputName);
            }
            // >> tbh 4/30/2010 #4963 removing custom validations firing during AE
            customValidation(v, dib, inputName);
        /*
                 * if (!StringUtil.isBlank(customValidationString)) { Validation customValidation = null; if (customValidationString.startsWith("func:")) { try
                 * { customValidation = Validator.processCRFValidationFunction(customValidationString ); } catch (Exception e) { e.printStackTrace(); } } else
                 * if (customValidationString.startsWith("regexp:")) { try { customValidation = Validator.processCRFValidationRegex(customValidationString); }
                 * catch (Exception e) { } } if (customValidation != null) { customValidation .setErrorMessage(dib.getMetadata().getRegexpErrorMsg());
                 * v.addValidation(inputName, customValidation); } }
                 */
        }
    }
    return dib;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) NullValue(org.akaza.openclinica.bean.core.NullValue) ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 4 with NullValue

use of org.akaza.openclinica.bean.core.NullValue in project OpenClinica by OpenClinica.

the class FormBeanUtil method getNullValuesByEventCRFDefId.

public List<String> getNullValuesByEventCRFDefId(int eventDefinitionCRFId, DataSource dataSource) {
    if (eventDefinitionCRFId < 1 || dataSource == null) {
        return new ArrayList<String>();
    }
    List<String> nullValuesList = new ArrayList<String>();
    // hold the bean's return value
    List<NullValue> nullObjectList = new ArrayList<NullValue>();
    EventDefinitionCRFBean eventCRFDefBean;
    EventDefinitionCRFDAO eventDefinitionCRFDAO = new EventDefinitionCRFDAO(dataSource);
    eventCRFDefBean = (EventDefinitionCRFBean) eventDefinitionCRFDAO.findByPK(eventDefinitionCRFId);
    nullObjectList = eventCRFDefBean.getNullValuesList();
    if (nullObjectList == null) {
        return new ArrayList<String>();
    }
    for (NullValue nullVal : nullObjectList) {
        nullValuesList.add(nullVal.getName());
    }
    return nullValuesList;
}
Also used : NullValue(org.akaza.openclinica.bean.core.NullValue) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 5 with NullValue

use of org.akaza.openclinica.bean.core.NullValue in project OpenClinica by OpenClinica.

the class FormBeanUtil method getNullValuesListAsOptionBeans.

public List<ResponseOptionBean> getNullValuesListAsOptionBeans(List<NullValue> nullValues) {
    List<ResponseOptionBean> responseOptionBeans = new ArrayList<ResponseOptionBean>();
    if (nullValues == null || nullValues.isEmpty()) {
        return responseOptionBeans;
    }
    ResponseOptionBean respBean;
    String name;
    for (NullValue nullVal : nullValues) {
        name = nullVal.getName();
        respBean = new ResponseOptionBean();
        respBean.setText(name);
        respBean.setValue(name);
        responseOptionBeans.add(respBean);
    }
    return responseOptionBeans;
}
Also used : NullValue(org.akaza.openclinica.bean.core.NullValue) ArrayList(java.util.ArrayList) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean)

Aggregations

NullValue (org.akaza.openclinica.bean.core.NullValue)9 ArrayList (java.util.ArrayList)8 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)4 ResponseOptionBean (org.akaza.openclinica.bean.submit.ResponseOptionBean)3 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)3 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)3 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)2 FormLayoutBean (org.akaza.openclinica.bean.submit.FormLayoutBean)2 Validator (org.akaza.openclinica.control.form.Validator)2 StudyParameterValueDAO (org.akaza.openclinica.dao.service.StudyParameterValueDAO)2 FormLayoutDAO (org.akaza.openclinica.dao.submit.FormLayoutDAO)2 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 ItemDataType (org.akaza.openclinica.bean.core.ItemDataType)1 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)1 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)1 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)1 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)1