Search in sources :

Example 16 with DisplayEventCRFBean

use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.

the class EnterDataForStudyEventServlet method getDisplayEventCRFs.

/**
     * Each of the event CRFs with its corresponding CRFBean. Then generates a
     * list of DisplayEventCRFBeans, one for each event CRF.
     *
     * @param eventCRFs
     *            The list of event CRFs for this study event.
     * @param eventDefinitionCRFs
     *            The list of event definition CRFs for this study event.
     * @return The list of DisplayEventCRFBeans for this study event.
     */
private ArrayList getDisplayEventCRFs(ArrayList eventCRFs, ArrayList eventDefinitionCRFs, SubjectEventStatus status) {
    ArrayList answer = new ArrayList();
    HashMap definitionsByCRFId = new HashMap();
    int i;
    for (i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        definitionsByCRFId.put(new Integer(edc.getCrfId()), edc);
    }
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    for (i = 0; i < eventCRFs.size(); i++) {
        EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
        logger.debug("0. found event crf bean: " + ecb.getName());
        // populate the event CRF with its crf bean
        int crfVersionId = ecb.getFormLayoutId();
        CRFBean cb = cdao.findByVersionId(crfVersionId);
        logger.debug("1. found crf bean: " + cb.getName());
        ecb.setCrf(cb);
        FormLayoutBean cvb = (FormLayoutBean) fldao.findByPK(crfVersionId);
        logger.debug("2. found crf version bean: " + cvb.getName());
        ecb.setFormLayout(cvb);
        logger.debug("found subj event status: " + status.getName() + " cb status: " + cb.getStatus().getName() + " cvb status: " + cvb.getStatus().getName());
        // below added tbh 092007
        boolean invalidate = false;
        if (status.isLocked()) {
            ecb.setStage(DataEntryStage.LOCKED);
        } else if (status.isInvalid()) {
            ecb.setStage(DataEntryStage.LOCKED);
        // invalidate = true;
        } else if (!cb.getStatus().equals(Status.AVAILABLE)) {
            logger.debug("got to the CB version of the logic");
            ecb.setStage(DataEntryStage.LOCKED);
        // invalidate= true;
        } else if (!cvb.getStatus().equals(Status.AVAILABLE)) {
            logger.debug("got to the CVB version of the logic");
            ecb.setStage(DataEntryStage.LOCKED);
        // invalidate = true;
        }
        logger.debug("found ecb stage of " + ecb.getStage().getName());
        // above added tbh, 092007-102007
        try {
            // event crf collection will pull up events that have
            // been started, but contain no data
            // this creates problems if we remove CRFs from
            // event definitions
            EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) definitionsByCRFId.get(new Integer(cb.getId()));
            logger.debug("3. found event def crf bean: " + edcb.getName());
            DisplayEventCRFBean dec = new DisplayEventCRFBean();
            dec.setFlags(ecb, ub, currentRole, edcb.isDoubleEntry());
            ArrayList idata = iddao.findAllByEventCRFId(ecb.getId());
            if (!idata.isEmpty()) {
                // consider an event crf started only if item data get
                // created
                answer.add(dec);
            }
        } catch (NullPointerException npe) {
            logger.debug("5. got to NPE on this time around!");
        }
    }
    return answer;
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) 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) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 17 with DisplayEventCRFBean

use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.

the class EnterDataForStudyEventServlet method getDisplayEventCRFs.

/**
     * Generate a list of DisplayEventCRFBean objects for a study event. Some of
     * the DisplayEventCRFBeans will represent uncompleted Event CRFs; others
     * will represent Event CRFs which are in initial data entry, have completed
     * initial data entry, are in double data entry, or have completed double
     * data entry.
     *
     * The list is sorted using the DisplayEventCRFBean's compareTo method (that
     * is, using the event definition crf bean's ordinal value.) Also, the
     * setFlags method of each DisplayEventCRFBean object will have been called
     * once.
     *
     * @param studyEvent
     *            The study event for which we want the Event CRFs.
     * @param ecdao
     *            An EventCRFDAO from which to grab the study event's Event
     *            CRFs.
     * @param edcdao
     *            An EventDefinitionCRFDAO from which to grab the Event CRF
     *            Definitions which apply to the study event.
     * @return A list of DisplayEventCRFBean objects releated to the study
     *         event, ordered by the EventDefinitionCRF ordinal property, and
     *         with flags already set.
     */
public static ArrayList getDisplayEventCRFs(StudyEventBean studyEvent, EventCRFDAO ecdao, EventDefinitionCRFDAO edcdao, FormLayoutDAO fldao, UserAccountBean user, StudyUserRoleBean surb) {
    ArrayList answer = new ArrayList();
    HashMap indexByCRFId = new HashMap();
    ArrayList eventCRFs = ecdao.findAllByStudyEvent(studyEvent);
    ArrayList eventDefinitionCRFs = edcdao.findAllByEventDefinitionId(studyEvent.getStudyEventDefinitionId());
    // TODO: map this out to another function
    ArrayList crfVersions = (ArrayList) fldao.findAll();
    HashMap crfIdByCRFVersionId = new HashMap();
    for (int i = 0; i < crfVersions.size(); i++) {
        FormLayoutBean cvb = (FormLayoutBean) crfVersions.get(i);
        crfIdByCRFVersionId.put(new Integer(cvb.getId()), new Integer(cvb.getCrfId()));
    }
    // put the event definition crfs inside DisplayEventCRFs
    for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        DisplayEventCRFBean decb = new DisplayEventCRFBean();
        decb.setEventDefinitionCRF(edcb);
        answer.add(decb);
        indexByCRFId.put(new Integer(edcb.getCrfId()), new Integer(answer.size() - 1));
    }
    // attach EventCRFs to the DisplayEventCRFs
    for (int i = 0; i < eventCRFs.size(); i++) {
        EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
        Integer crfVersionId = new Integer(ecb.getFormLayoutId());
        if (crfIdByCRFVersionId.containsKey(crfVersionId)) {
            Integer crfId = (Integer) crfIdByCRFVersionId.get(crfVersionId);
            if (crfId != null && indexByCRFId.containsKey(crfId)) {
                Integer indexObj = (Integer) indexByCRFId.get(crfId);
                if (indexObj != null) {
                    int index = indexObj.intValue();
                    if (index > 0 && index < answer.size()) {
                        DisplayEventCRFBean decb = (DisplayEventCRFBean) answer.get(index);
                        decb.setEventCRF(ecb);
                        answer.set(index, decb);
                    }
                }
            }
        }
    }
    for (int i = 0; i < answer.size(); i++) {
        DisplayEventCRFBean decb = (DisplayEventCRFBean) answer.get(i);
        decb.setFlags(decb.getEventCRF(), user, surb, decb.getEventDefinitionCRF().isDoubleEntry());
        answer.set(i, decb);
    }
    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) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 18 with DisplayEventCRFBean

use of org.akaza.openclinica.bean.submit.DisplayEventCRFBean in project OpenClinica by OpenClinica.

the class SignStudySubjectServlet method getDisplayEventCRFs.

/**
     * Each of the event CRFs with its corresponding CRFBean. Then generates a
     * list of DisplayEventCRFBeans, one for each event CRF.
     *
     * @param eventCRFs
     *            The list of event CRFs for this study event.
     * @return The list of DisplayEventCRFBeans for this study event.
     */
public static ArrayList getDisplayEventCRFs(StudyBean study, DataSource ds, ArrayList eventCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status) {
    ArrayList answer = new ArrayList();
    // HashMap definitionsById = new HashMap();
    int i;
    /*
         * for (i = 0; i < eventDefinitionCRFs.size(); i++) {
         * EventDefinitionCRFBean edc = (EventDefinitionCRFBean)
         * eventDefinitionCRFs.get(i); definitionsById.put(new
         * Integer(edc.getStudyEventDefinitionId()), edc); }
         */
    StudyEventDAO sedao = new StudyEventDAO(ds);
    CRFDAO cdao = new CRFDAO(ds);
    CRFVersionDAO cvdao = new CRFVersionDAO(ds);
    ItemDataDAO iddao = new ItemDataDAO(ds);
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
    for (i = 0; i < eventCRFs.size(); i++) {
        EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
        // populate the event CRF with its crf bean
        int crfVersionId = ecb.getCRFVersionId();
        CRFBean cb = cdao.findByVersionId(crfVersionId);
        ecb.setCrf(cb);
        CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
        ecb.setCrfVersion(cvb);
        // then get the definition so we can call
        // DisplayEventCRFBean.setFlags
        int studyEventId = ecb.getStudyEventId();
        int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
        // EventDefinitionCRFBean edc = (EventDefinitionCRFBean)
        // definitionsById.get(new Integer(
        // studyEventDefinitionId));
        // fix problem of the above code(commented out), find the correct
        // edc, note that on definitionId can be related to multiple
        // eventdefinitioncrfBeans
        EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
        // 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();
            // 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());
            //                }
            ArrayList idata = iddao.findAllByEventCRFId(ecb.getId());
            if (!idata.isEmpty()) {
                // 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) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) 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)

Aggregations

DisplayEventCRFBean (org.akaza.openclinica.bean.submit.DisplayEventCRFBean)18 ArrayList (java.util.ArrayList)15 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)13 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)12 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)11 DisplayEventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean)11 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)10 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)10 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)9 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)8 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)7 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)7 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)7 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)6 HashMap (java.util.HashMap)5 DisplayStudyEventBean (org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean)5 FormLayoutBean (org.akaza.openclinica.bean.submit.FormLayoutBean)5 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)4 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)4 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)4