Search in sources :

Example 56 with ItemDataDAO

use of org.akaza.openclinica.dao.submit.ItemDataDAO 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());
    CRFVersionDAO cvdao = new CRFVersionDAO(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.getCRFVersionId();
        CRFBean cb = cdao.findByVersionId(crfVersionId);
        logger.debug("1. found crf bean: " + cb.getName());
        ecb.setCrf(cb);
        CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
        logger.debug("2. found crf version bean: " + cvb.getName());
        ecb.setCrfVersion(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) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) 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) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 57 with ItemDataDAO

use of org.akaza.openclinica.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.

the class DataEntryServlet method prepareGroupSizes.

protected HashMap<Integer, Integer> prepareGroupSizes(HashMap<String, ItemBean> scoreItems, HttpServletRequest request) {
    HashMap<Integer, Integer> groupSizes = new HashMap<Integer, Integer>();
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    SectionDAO sdao = new SectionDAO(getDataSource());
    Iterator iter = scoreItems.keySet().iterator();
    while (iter.hasNext()) {
        int itemId = scoreItems.get(iter.next().toString()).getId();
        groupSizes.put(itemId, 1);
    }
    ArrayList<SectionBean> sbs = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
    for (SectionBean section : sbs) {
        ArrayList<ItemDataBean> idbs = iddao.findAllActiveBySectionIdAndEventCRFId(section.getId(), ecb.getId());
        for (ItemDataBean idb : idbs) {
            int itemId = idb.getItemId();
            if (groupSizes != null && groupSizes.containsKey(itemId)) {
                int groupsize = iddao.getGroupSize(itemId, ecb.getId());
                groupsize = groupsize > 0 ? groupsize : 1;
                groupSizes.put(itemId, groupsize);
            }
        }
    }
    return groupSizes;
}
Also used : SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) Iterator(java.util.Iterator) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 58 with ItemDataDAO

use of org.akaza.openclinica.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.

the class DataEntryServlet method prepareItemdataOrdinals.

protected HashMap<Integer, TreeSet<Integer>> prepareItemdataOrdinals(HttpServletRequest request) {
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    HashMap<Integer, TreeSet<Integer>> ordinals = new HashMap<Integer, TreeSet<Integer>>();
    SectionDAO sdao = new SectionDAO(getDataSource());
    ArrayList<SectionBean> sbs = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    for (SectionBean section : sbs) {
        ArrayList<ItemDataBean> idbs = iddao.findAllActiveBySectionIdAndEventCRFId(section.getId(), ecb.getId());
        if (idbs != null && idbs.size() > 0) {
            for (ItemDataBean idb : idbs) {
                int itemId = idb.getItemId();
                TreeSet<Integer> os = new TreeSet<Integer>();
                if (ordinals == null) {
                    os.add(idb.getOrdinal());
                    ordinals.put(itemId, os);
                } else if (ordinals.containsKey(itemId)) {
                    os = ordinals.get(itemId);
                    os.add(idb.getOrdinal());
                    ordinals.put(itemId, os);
                } else {
                    os.add(idb.getOrdinal());
                    ordinals.put(itemId, os);
                }
            }
        }
    }
    return ordinals;
}
Also used : HashMap(java.util.HashMap) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) TreeSet(java.util.TreeSet) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 59 with ItemDataDAO

use of org.akaza.openclinica.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.

the class DataEntryServlet method prepareSectionItemdataObject.

protected HashMap<String, ItemDataBean> prepareSectionItemdataObject(int sectionId, HttpServletRequest request) {
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    HashMap<String, ItemDataBean> itemdata = new HashMap<String, ItemDataBean>();
    ArrayList<ItemDataBean> idbs = iddao.findAllActiveBySectionIdAndEventCRFId(sectionId, ecb.getId());
    for (ItemDataBean idb : idbs) {
        itemdata.put(idb.getItemId() + "," + idb.getOrdinal(), idb);
    }
    return itemdata;
}
Also used : EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO)

Example 60 with ItemDataDAO

use of org.akaza.openclinica.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.

the class DataEntryServlet method markCRFComplete.

/**
 * The following methods are for 'mark CRF complete'
 * @param request TODO
 *
 * @return
 */
protected boolean markCRFComplete(HttpServletRequest request) throws Exception {
    locale = LocaleResolver.getLocale(request);
    HttpSession session = request.getSession();
    UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    // < respage =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.page_messages",
    // locale);
    // < restext =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.notes",locale);
    // <
    // resexception=ResourceBundle.getBundle(
    // "org.akaza.openclinica.i18n.exceptions",locale);
    getEventCRFBean(request);
    getEventDefinitionCRFBean(request);
    DataEntryStage stage = ecb.getStage();
    // request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN,
    // ecb);
    // request.setAttribute(INPUT_EVENT_CRF_ID, new Integer(ecb.getId()));
    LOGGER.trace("inout_event_crf_id:" + ecb.getId());
    if (stage.equals(DataEntryStage.UNCOMPLETED) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.LOCKED)) {
        addPageMessage(respage.getString("not_mark_CRF_complete1"), request);
        return false;
    }
    if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
        if (!edcb.isDoubleEntry()) {
            addPageMessage(respage.getString("not_mark_CRF_complete2"), request);
            return false;
        }
    }
    if (isEachRequiredFieldFillout(request) == false) {
        addPageMessage(respage.getString("not_mark_CRF_complete4"), request);
        return false;
    }
    /*
         * if (ecb.getInterviewerName().trim().equals("")) { throw new InconsistentStateException(errorPage, "You may not mark this Event CRF complete, because
         * the interviewer name is blank."); }
         */
    Status newStatus = ecb.getStatus();
    boolean ide = true;
    if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && edcb.isDoubleEntry()) {
        newStatus = Status.PENDING;
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecb.setDateCompleted(new Date());
    } else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && !edcb.isDoubleEntry()) {
        newStatus = Status.UNAVAILABLE;
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecb.setDateCompleted(new Date());
        ecb.setDateValidateCompleted(new Date());
    } else if (stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) && edcb.isDoubleEntry()) {
        newStatus = Status.UNAVAILABLE;
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ecb.setUpdatedDate(new Date());
        ecb.setDateCompleted(new Date());
        ecb.setDateValidateCompleted(new Date());
        ide = false;
    } else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
        newStatus = Status.UNAVAILABLE;
        ecb.setDateValidateCompleted(new Date());
        ecb.setUpdaterId(ub.getId());
        ecb.setUpdater(ub);
        ide = false;
    }
    // create them
    if (!isEachSectionReviewedOnce(request)) {
        boolean canSave = saveItemsToMarkComplete(newStatus, request);
        if (canSave == false) {
            addPageMessage(respage.getString("not_mark_CRF_complete3"), request);
            return false;
        }
    }
    ecb.setStatus(newStatus);
    /*
         * Marking the data entry as signed if the corresponding EventDefinitionCRF is being enabled for electronic signature.
         */
    if (edcb.isElectronicSignature()) {
        ecb.setElectronicSignatureStatus(true);
    }
    ecb = (EventCRFBean) ecdao.update(ecb);
    // note the below statement only updates the DATES, not the STATUS
    ecdao.markComplete(ecb, ide);
    // update all the items' status to complete
    iddao.updateStatusByEventCRF(ecb, newStatus);
    // change status for study event
    StudyEventDAO sedao = new StudyEventDAO(getDataSource());
    StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
    seb.setUpdatedDate(new Date());
    seb.setUpdater(ub);
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
    ArrayList allCRFs = ecdao.findAllByStudyEventAndStatus(seb, Status.UNAVAILABLE);
    StudyBean study = (StudyBean) session.getAttribute("study");
    ArrayList allEDCs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, seb.getStudyEventDefinitionId());
    CRFVersionDAO crfversionDao = new CRFVersionDAO(getDataSource());
    boolean eventCompleted = true;
    boolean allRequired = true;
    // JN Adding another flag
    boolean allCrfsCompleted = false;
    int allEDCsize = allEDCs.size();
    ArrayList nonRequiredCrfIds = new ArrayList();
    ArrayList requiredCrfIds = new ArrayList();
    if (allCRFs.size() == allEDCs.size()) {
        // was
        // JN: all crfs are completed and then set the subject event status as complete
        seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
    }
    seb = (StudyEventBean) sedao.update(seb);
    request.setAttribute(INPUT_EVENT_CRF, ecb);
    request.setAttribute(EVENT_DEF_CRF_BEAN, edcb);
    return true;
}
Also used : Status(org.akaza.openclinica.bean.core.Status) ResolutionStatus(org.akaza.openclinica.bean.core.ResolutionStatus) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HttpSession(javax.servlet.http.HttpSession) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) Date(java.util.Date) DataEntryStage(org.akaza.openclinica.bean.core.DataEntryStage) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Aggregations

ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)83 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)64 ArrayList (java.util.ArrayList)61 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)61 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)52 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)40 Date (java.util.Date)38 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)37 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)31 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)30 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)29 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)29 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)28 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)27 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)26 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)24 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)23 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)22 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)21 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)21