Search in sources :

Example 76 with CRFBean

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

the class RuleSetDaoTest method testFindByCrfEmptyResultSet.

// @pgawade 09-NOV-2010 Commented out the test "testFindByCrf" temporarily
// public void testFindByCrf() {
// CRFBean crfBean = new CRFBean();
// crfBean.setId(2);
// StudyBean studyBean = new StudyBean();
// studyBean.setId(1);
// RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
// List<RuleSetBean> persistentRuleSets = ruleSetDao.findByCrf(crfBean,
// studyBean);
// assertNotNull("The returned ruleSet was null", persistentRuleSets);
// assertEquals("The List size of ruleset objects should be 2 ",
// persistentRuleSets.size(), 2);
// }
public void testFindByCrfEmptyResultSet() {
    CRFBean crfBean = new CRFBean();
    crfBean.setId(4);
    StudyBean studyBean = new StudyBean();
    studyBean.setId(1);
    // RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
    crfBean.setId(4);
    List<RuleSetBean> persistentRuleSets = ruleSetDao.findByCrf(crfBean, studyBean);
    assertNotNull("The returned ruleSet was null", persistentRuleSets);
    assertEquals("The List size of ruleset objects should be 0 ", persistentRuleSets.size(), 0);
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 77 with CRFBean

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

the class InsertActionValidator method validateValueExpressionInPropertyBean.

public void validateValueExpressionInPropertyBean(PropertyBean propertyBean, Errors e, String p) {
    if (getExpressionService().isExpressionPartial(getRuleSetBean().getTarget().getValue())) {
        if (getExpressionService().getExpressionSize(propertyBean.getValueExpression().getValue()).intValue() > 2) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
        try {
            getExpressionService().isExpressionValid(propertyBean.getValueExpression().getValue());
        } catch (OpenClinicaSystemException ose) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
        // Use ValueExression in destinationProperty to get CRF
        ItemBean item = getExpressionService().getItemBeanFromExpression(propertyBean.getValueExpression().getValue());
        if (item == null)
            return;
        CRFBean destinationPropertyValueExpressionCrf = getCrfDAO().findByItemOid(item.getOid());
        // Use Target to get CRF
        CRFBean targetCrf = getExpressionService().getCRFFromExpression(getRuleSetBean().getTarget().getValue());
        if (targetCrf == null) {
            ItemBean targetItem = getExpressionService().getItemBeanFromExpression(getRuleSetBean().getTarget().getValue());
            targetCrf = getCrfDAO().findByItemOid(targetItem.getOid());
        }
        if (destinationPropertyValueExpressionCrf.getId() != targetCrf.getId()) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
    } else {
        String valueExpression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getValueExpression().getValue(), getRuleSetBean().getTarget().getValue());
        ItemBean item = getExpressionService().getItemBeanFromExpression(valueExpression);
        if (!getExpressionService().isExpressionValid(propertyBean.getValueExpression().getValue(), getRuleSetBean(), 2) || item == null) {
            e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 78 with CRFBean

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

the class StudySubjectServiceImpl method getDisplayStudyEventsForStudySubject.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(StudySubjectBean studySubject, UserAccountBean userAccount, StudyUserRoleBean currentRole) {
    StudyEventDAO studyEventDao = new StudyEventDAO(dataSource);
    StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
    StudyDAO studyDao = new StudyDAO(dataSource);
    EventDefinitionCRFDAO eventDefinitionCrfDao = new EventDefinitionCRFDAO(dataSource);
    EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
    CRFDAO crfDao = new CRFDAO(dataSource);
    CRFVersionDAO crfVersionDao = new CRFVersionDAO(dataSource);
    ArrayList events = studyEventDao.findAllByStudySubject(studySubject);
    Map<Integer, StudyEventDefinitionBean> eventDefinitionByEvent = studyEventDefinitionDao.findByStudySubject(studySubject.getId());
    StudyBean study = (StudyBean) studyDao.findByPK(studySubject.getStudyId());
    Map<Integer, SortedSet<EventDefinitionCRFBean>> eventDefinitionCrfByStudyEventDefinition;
    if (study.getParentStudyId() < 1) {
        // Is a study
        eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinitionForStudy(studySubject.getId());
    } else {
        // Is a site
        eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinition(studySubject.getId(), study.getId(), study.getParentStudyId());
    }
    Map<Integer, SortedSet<EventCRFBean>> eventCrfListByStudyEvent = eventCrfDao.buildEventCrfListByStudyEvent(studySubject.getId());
    Map<Integer, Integer> maxOrdinalByStudyEvent = studyEventDefinitionDao.buildMaxOrdinalByStudyEvent(studySubject.getId());
    Set<Integer> nonEmptyEventCrf = eventCrfDao.buildNonEmptyEventCrfIds(studySubject.getId());
    Map<Integer, CRFVersionBean> crfVersionById = crfVersionDao.buildCrfVersionById(studySubject.getId());
    Map<Integer, CRFBean> crfById = crfDao.buildCrfById(studySubject.getId());
    ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
    for (int i = 0; i < events.size(); i++) {
        StudyEventBean event = (StudyEventBean) events.get(i);
        StudyEventDefinitionBean sed = eventDefinitionByEvent.get(event.getStudyEventDefinitionId());
        event.setStudyEventDefinition(sed);
        List eventDefinitionCRFs = new ArrayList((eventDefinitionCrfByStudyEventDefinition.containsKey(sed.getId()) ? eventDefinitionCrfByStudyEventDefinition.get(sed.getId()) : Collections.EMPTY_LIST));
        List eventCRFs = new ArrayList((eventCrfListByStudyEvent.containsKey(event.getId())) ? eventCrfListByStudyEvent.get(event.getId()) : Collections.EMPTY_LIST);
        // construct info needed on view study event page
        DisplayStudyEventBean de = new DisplayStudyEventBean();
        de.setStudyEvent(event);
        de.setDisplayEventCRFs((ArrayList<DisplayEventCRFBean>) getDisplayEventCRFs(eventCRFs, userAccount, currentRole, event.getSubjectEventStatus(), study, nonEmptyEventCrf, crfVersionById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
        ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, crfVersionById, crfById);
        populateUncompletedCRFsWithCRFAndVersions(al, crfVersionById, crfById);
        de.setUncompletedCRFs(al);
        // de.setMaximumSampleOrdinal(studyEventDao.getMaxSampleOrdinal(sed,
        // studySubject));
        de.setMaximumSampleOrdinal(maxOrdinalByStudyEvent.get(event.getStudyEventDefinitionId()));
        displayEvents.add(de);
    // event.setEventCRFs(createAllEventCRFs(eventCRFs,
    // eventDefinitionCRFs));
    }
    return displayEvents;
}
Also used : ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) SortedSet(java.util.SortedSet) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) List(java.util.List) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) 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) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) 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) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean)

Example 79 with CRFBean

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

the class StudySubjectServiceImpl method getDisplayEventCRFs.

private List<DisplayEventCRFBean> getDisplayEventCRFs(List eventCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status, StudyBean study, Set<Integer> nonEmptyEventCrf, Map<Integer, CRFVersionBean> crfVersionById, Map<Integer, CRFBean> crfById, Integer studyEventDefinitionId, List eventDefinitionCRFs) {
    ArrayList<DisplayEventCRFBean> answer = new ArrayList<DisplayEventCRFBean>();
    for (int i = 0; i < eventCRFs.size(); i++) {
        EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
        // populate the event CRF with its crf bean
        int crfVersionId = ecb.getCRFVersionId();
        // CRFVersionBean cvb = crfVersionById.get(ecb.getCRFVersionId());
        CRFVersionBean cvb = crfVersionById.get(crfVersionId);
        ecb.setCrfVersion(cvb);
        // CRFBean cb = crfDao.findByVersionId(crfVersionId);
        CRFBean cb = crfById.get(cvb.getCrfId());
        ecb.setCrf(cb);
        EventDefinitionCRFBean edc = null;
        Iterator it = eventDefinitionCRFs.iterator();
        while (it.hasNext()) {
            EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) it.next();
            if (edcBean.getCrfId() == cb.getId()) {
                edc = edcBean;
                break;
            }
        }
        // rules updated 112007 tbh
        if (status.equals(SubjectEventStatus.LOCKED) || status.equals(SubjectEventStatus.SKIPPED) || status.equals(SubjectEventStatus.STOPPED)) {
            ecb.setStage(DataEntryStage.LOCKED);
        // we need to set a SED-wide flag here, because other edcs
        // in this event can be filled in and change the status, tbh
        } else if (status.equals(SubjectEventStatus.INVALID)) {
            ecb.setStage(DataEntryStage.LOCKED);
        } else if (!cb.getStatus().equals(Status.AVAILABLE)) {
            ecb.setStage(DataEntryStage.LOCKED);
        } else if (!cvb.getStatus().equals(Status.AVAILABLE)) {
            ecb.setStage(DataEntryStage.LOCKED);
        }
        // TODO need to refactor since this is similar to other code, tbh
        if (edc != null) {
            // System.out.println("edc is not null, need to set flags");
            DisplayEventCRFBean dec = new DisplayEventCRFBean();
            dec.setEventDefinitionCRF(edc);
            // System.out.println("edc.isDoubleEntry()" +
            // edc.isDoubleEntry() + ecb.getId());
            dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
            if (dec.isLocked()) {
            // System.out.println("*** found a locked DEC:
            // "+edc.getCrfName());
            }
            if (nonEmptyEventCrf.contains(ecb.getId())) {
                // consider an event crf started only if item data get
                // created
                answer.add(dec);
            }
        }
    }
    return answer;
}
Also used : DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) 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) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 80 with CRFBean

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

the class ExpressionService method isExpressionValid.

/**
 * 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
 */
public void isExpressionValid(String expression) {
    int length = expression.split(ESCAPED_SEPERATOR).length;
    ItemBean item = null;
    ItemGroupBean itemGroup = null;
    CRFBean crf = null;
    boolean isEventStartDateAndStatusParamExist = (expression.endsWith(STARTDATE) || expression.endsWith(STATUS));
    if (length > 0 && !isEventStartDateAndStatusParamExist) {
        item = getItemFromExpression(expression);
        if (item == null)
            throw new OpenClinicaSystemException("OCRERR_0023");
    // throw new OpenClinicaSystemException("item is Invalid");
    }
    if (length > 1 && !isEventStartDateAndStatusParamExist) {
        String itemGroupOid = getItemGroupOidFromExpression(expression);
        itemGroup = getItemGroupDao().findByOid(itemGroupOid);
        ArrayList<ItemGroupBean> igBean = (ArrayList<ItemGroupBean>) getItemGroupDao().findGroupsByItemID(item.getId());
        if (itemGroup == null || itemGroup.getId() != igBean.get(0).getId())
            throw new OpenClinicaSystemException("OCRERR_0022");
    // throw new OpenClinicaSystemException("itemGroup is Invalid");
    }
    if (length > 2 && !isEventStartDateAndStatusParamExist) {
        crf = getCRFFromExpression(expression);
        if (crf == null || crf.getId() != itemGroup.getCrfId())
            throw new OpenClinicaSystemException("OCRERR_0033");
    // throw new OpenClinicaSystemException("CRF is Invalid");
    }
    if (length > 3 && !isEventStartDateAndStatusParamExist) {
        StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(expression);
        crf = getCRFFromExpression(expression);
        if (studyEventDefinition == null || crf == null)
            throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
        // throw new
        // OpenClinicaSystemException("StudyEventDefinition is Invalid");
        EventDefinitionCRFBean eventDefinitionCrf = getEventDefinitionCRFDao().findByStudyEventDefinitionIdAndCRFId(this.expressionWrapper.getStudyBean(), studyEventDefinition.getId(), crf.getId());
        if (eventDefinitionCrf == null || eventDefinitionCrf.getId() == 0)
            throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
    // throw new
    // OpenClinicaSystemException("StudyEventDefinition is Invalid");
    }
    if (length == 2 && isEventStartDateAndStatusParamExist) {
        StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpressionForEventScheduling(expression);
        // studyEventDefinition.getOid());
        if (studyEventDefinition == null)
            throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
    }
    if (length != 2 && isEventStartDateAndStatusParamExist) {
        throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

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