Search in sources :

Example 41 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class RuleSetService method filterRuleSetsByStudyEventOrdinal.

@SuppressWarnings("unchecked")
public List<RuleSetBean> filterRuleSetsByStudyEventOrdinal(List<RuleSetBean> ruleSets, String crfVersionId) {
    ArrayList<RuleSetBean> validRuleSets = new ArrayList<RuleSetBean>();
    for (RuleSetBean ruleSetBean : ruleSets) {
        String studyEventDefinitionOrdinal = getExpressionService().getStudyEventDefinitionOrdninalCurated(ruleSetBean.getTarget().getValue());
        String studyEventDefinitionOid = getExpressionService().getStudyEventDefenitionOid(ruleSetBean.getTarget().getValue());
        String crfOrCrfVersionOid = getExpressionService().getCrfOid(ruleSetBean.getTarget().getValue());
        // whole expression is provided in target
        if (studyEventDefinitionOid != null && crfOrCrfVersionOid != null) {
            List<StudyEventBean> studyEvents = null;
            if (crfOrCrfVersionOid.equals("STARTDATE") || crfOrCrfVersionOid.equals("STATUS")) {
                StudyEventDefinitionBean sedBean = getStudyEventDefinitionDao().findByOid(studyEventDefinitionOid);
                studyEvents = (List<StudyEventBean>) getStudyEventDao().findAllByDefinition(sedBean.getId());
                logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionOid, crfOrCrfVersionOid, studyEvents.size() });
            } else {
                studyEvents = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOids(studyEventDefinitionOid, crfOrCrfVersionOid);
                logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionOid, crfOrCrfVersionOid, studyEvents.size() });
            }
            if (studyEventDefinitionOrdinal.equals("") && studyEvents.size() > 0) {
                for (StudyEventBean studyEvent : studyEvents) {
                    ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent));
                }
                validRuleSets.add(ruleSetBean);
            } else {
                for (StudyEventBean studyEvent : studyEvents) {
                    if (studyEventDefinitionOrdinal.equals(String.valueOf(studyEvent.getSampleOrdinal()))) {
                        ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent));
                    }
                }
                validRuleSets.add(ruleSetBean);
            }
        } else {
            // partial expression is provided in target
            CRFBean crf = null;
            List<CRFVersionBean> crfVersions = new ArrayList<CRFVersionBean>();
            CRFVersionBean crfVersion = null;
            if (crfOrCrfVersionOid == null) {
                crf = getCrfDao().findByItemOid(getExpressionService().getItemOid(ruleSetBean.getTarget().getValue()));
                if (crfVersionId != null) {
                    crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(Integer.valueOf(crfVersionId));
                    crfVersions.add(crfVersion);
                } else {
                    crfVersions = (List<CRFVersionBean>) getCrfVersionDao().findAllByCRF(crf.getId());
                }
            } else {
                crf = getExpressionService().getCRFFromExpression(ruleSetBean.getTarget().getValue());
                if (crfVersionId != null) {
                    crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(Integer.valueOf(crfVersionId));
                } else {
                    crfVersion = getExpressionService().getCRFVersionFromExpression(ruleSetBean.getTarget().getValue());
                }
                if (crfVersion != null) {
                    crfVersions.add(crfVersion);
                } else {
                    crfVersions = (List<CRFVersionBean>) getCrfVersionDao().findAllByCRF(crf.getId());
                }
            }
            List<StudyEventDefinitionBean> studyEventDefinitions = getStudyEventDefinitionDao().findAllByCrf(crf);
            for (StudyEventDefinitionBean studyEventDefinitionBean : studyEventDefinitions) {
                for (CRFVersionBean crfVersionBean : crfVersions) {
                    String expression = getExpressionService().constructFullExpressionIfPartialProvided(ruleSetBean.getTarget().getValue(), crfVersionBean, studyEventDefinitionBean);
                    List<StudyEventBean> studyEvents = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOids(studyEventDefinitionBean.getOid(), crfVersionBean.getOid());
                    logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionBean.getOid(), crfVersionBean.getOid(), studyEvents.size() });
                    for (StudyEventBean studyEvent : studyEvents) {
                        ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent, expression));
                    }
                }
            }
            validRuleSets.add(ruleSetBean);
        }
    }
    logExpressions(validRuleSets);
    logger.debug("Size of RuleSets post filterRuleSetsByStudyEventOrdinal() {} ", validRuleSets.size());
    return validRuleSets;
}
Also used : ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 42 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class InsertActionValidator method validateOidInPropertyBean.

public void validateOidInPropertyBean(PropertyBean propertyBean, Errors e, String p) {
    if (getExpressionService().isExpressionPartial(getRuleSetBean().getTarget().getValue())) {
        if (getExpressionService().getExpressionSize(propertyBean.getOid()).intValue() > 3) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
        try {
            getExpressionService().isExpressionValid(propertyBean.getOid());
        } catch (OpenClinicaSystemException ose) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
        // Use OID in destinationProperty to get CRF
        CRFBean destinationPropertyOidCrf = getExpressionService().getCRFFromExpression(propertyBean.getOid());
        if (destinationPropertyOidCrf == null) {
            ItemBean item = getExpressionService().getItemBeanFromExpression(propertyBean.getOid());
            destinationPropertyOidCrf = getCrfDAO().findByItemOid(item.getOid());
        }
        // Use Target get CRF
        CRFBean targetCrf = getExpressionService().getCRFFromExpression(getRuleSetBean().getTarget().getValue());
        if (targetCrf == null) {
            ItemBean item = getExpressionService().getItemBeanFromExpression(getRuleSetBean().getTarget().getValue());
            targetCrf = getCrfDAO().findByItemOid(item.getOid());
        }
        // Get All event definitions the selected CRF belongs to
        List<StudyEventDefinitionBean> destinationPropertyStudyEventDefinitions = getStudyEventDefinitionDAO().findAllByCrf(destinationPropertyOidCrf);
        List<StudyEventDefinitionBean> targetStudyEventDefinitions = getStudyEventDefinitionDAO().findAllByCrf(targetCrf);
        Collection intersection = CollectionUtils.intersection(destinationPropertyStudyEventDefinitions, targetStudyEventDefinitions);
        if (intersection.size() == 0) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
    } else {
        String expression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getOid(), getRuleSetBean().getTarget().getValue());
        ItemBean item = getExpressionService().getItemBeanFromExpression(expression);
        if (!getExpressionService().isInsertActionExpressionValid(propertyBean.getOid(), getRuleSetBean(), 3) || item == null) {
            e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) Collection(java.util.Collection) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 43 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class ExpressionService method isExpressionValidOLD.

/**
 * Given a Complete Expression check business logic validity of each
 * component. Will throw OpenClinicaSystemException with correct
 * explanation. This might allow immediate communication of message to user
 * .
 *
 * @param expression
 */
@Deprecated
public void isExpressionValidOLD(String expression) {
    StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(expression);
    CRFBean crf = getCRFFromExpression(expression);
    if (studyEventDefinition == null || crf == null)
        throw new OpenClinicaSystemException("OCRERR_0020");
    EventDefinitionCRFBean eventDefinitionCrf = getEventDefinitionCRFDao().findByStudyEventDefinitionIdAndCRFId(this.expressionWrapper.getStudyBean(), studyEventDefinition.getId(), crf.getId());
    if (eventDefinitionCrf == null || eventDefinitionCrf.getId() == 0 || eventDefinitionCrf.getStatus() != Status.AVAILABLE)
        throw new OpenClinicaSystemException("OCRERR_0021");
    ItemGroupBean itemGroup = getItemGroupExpression(expression, crf);
    if (itemGroup == null)
        throw new OpenClinicaSystemException("OCRERR_0022");
    ItemBean item = getItemExpression(expression, itemGroup);
    if (item == null)
        throw new OpenClinicaSystemException("OCRERR_0023");
    logger.debug("Study Event Definition ID : " + studyEventDefinition.getId());
    logger.debug("Crf ID : " + crf.getId());
    logger.debug("Event Definition CRF ID : " + eventDefinitionCrf.getId());
    logger.debug("Item ID : " + item.getId());
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 44 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class ExpressionService method getCRFFromExpression.

public CRFBean getCRFFromExpression(String expression) {
    if (expression.split(ESCAPED_SEPERATOR).length < 3) {
        return null;
    }
    CRFBean crf;
    logger.debug("Expression : " + expression);
    logger.debug("Expression : " + getCrfOidFromExpression(expression));
    CRFVersionBean crfVersion = getCrfVersionDao().findByOid(getCrfOidFromExpression(expression));
    if (crfVersion != null) {
        int crfId = getCrfVersionDao().getCRFIdFromCRFVersionId(crfVersion.getId());
        crf = (CRFBean) getCrfDao().findByPK(crfId);
    } else {
        crf = getCrfDao().findByOid(getCrfOidFromExpression(expression));
    }
    return crf;
// return crfVersions.size() > 0 ? crfVersions.get(0) : null;
}
Also used : CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 45 with CRFBean

use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.

the class StudySubjectServiceImpl method populateUncompletedCRFsWithCRFAndVersions.

@SuppressWarnings({ "rawtypes", "unchecked" })
public void populateUncompletedCRFsWithCRFAndVersions(ArrayList<DisplayEventDefinitionCRFBean> uncompletedEventDefinitionCRFs, Map<Integer, CRFVersionBean> crfVersionById, Map<Integer, CRFBean> crfById) {
    CRFVersionDAO crfVersionDao = new CRFVersionDAO(dataSource);
    int size = uncompletedEventDefinitionCRFs.size();
    for (int i = 0; i < size; i++) {
        DisplayEventDefinitionCRFBean dedcrf = uncompletedEventDefinitionCRFs.get(i);
        // CRFBean cb = (CRFBean)
        // crfDao.findByPK(dedcrf.getEdc().getCrfId());
        CRFBean cb = crfById.get(dedcrf.getEdc().getCrfId());
        dedcrf.getEdc().setCrf(cb);
        ArrayList<CRFVersionBean> theVersions = (ArrayList<CRFVersionBean>) crfVersionDao.findAllActiveByCRF(dedcrf.getEdc().getCrfId());
        ArrayList<CRFVersionBean> versions = new ArrayList<CRFVersionBean>();
        HashMap<String, CRFVersionBean> crfVersionIds = new HashMap<String, CRFVersionBean>();
        for (int j = 0; j < theVersions.size(); j++) {
            CRFVersionBean crfVersion = theVersions.get(j);
            crfVersionIds.put(String.valueOf(crfVersion.getId()), crfVersion);
        }
        if (!dedcrf.getEdc().getSelectedVersionIds().equals("")) {
            String[] kk = dedcrf.getEdc().getSelectedVersionIds().split(",");
            for (String string : kk) {
                if (crfVersionIds.get(string) != null) {
                    versions.add(crfVersionIds.get(string));
                }
            }
        } else {
            versions = theVersions;
        }
        dedcrf.getEdc().setVersions(versions);
        uncompletedEventDefinitionCRFs.set(i, dedcrf);
    }
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Aggregations

CRFBean (org.akaza.openclinica.bean.admin.CRFBean)138 ArrayList (java.util.ArrayList)95 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)78 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)78 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)70 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)67 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)63 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)56 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)44 HashMap (java.util.HashMap)43 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)43 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)40 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)37 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)29 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)27 Iterator (java.util.Iterator)26 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)26 DisplayEventCRFBean (org.akaza.openclinica.bean.submit.DisplayEventCRFBean)22 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)21 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)20