Search in sources :

Example 51 with EventCRFDAO

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

the class DiscrepancyNoteUtil method getDNotesForStudy.

/**
     * Acquire the DiscrepancyNoteBeans for a specific study.
     *
     * @param currentStudy
     *            A StudyBean object.
     * @param resolutionStatus
     *            An int resolution status; only DiscrepancyNoteBeans will be
     *            returned if they have this resolutionStatus id.
     * @param dataSource
     *            A DataSource used for various DAO methods.
     * @param discNoteType
     *            An int discrepancy note type id; only DiscrepancyNoteBeans
     *            will be returned if they have this discrepancyNoteTypeId.
     * @return A List of DiscrepancyNoteBeans.
     */
public List<DiscrepancyNoteBean> getDNotesForStudy(StudyBean currentStudy, int resolutionStatus, DataSource dataSource, int discNoteType) {
    List<DiscrepancyNoteBean> allDiscNotes = new ArrayList<DiscrepancyNoteBean>();
    if (currentStudy == null)
        return allDiscNotes;
    // Do the returned DN's have to be filtered? A valid resolution status
    // has to be between 1 and 5; 0 is "invalid";
    // -1 means that no resolutionStatus parameter was passed into the
    // servlet
    boolean filterDiscNotes = resolutionStatus >= 1 && resolutionStatus <= 5;
    boolean filterforDiscNoteType = discNoteType >= 1 && discNoteType <= 4;
    DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(dataSource);
    // what is the purpose of this data member?
    discrepancyNoteDAO.setFetchMapping(true);
    EventCRFDAO ecdao = new EventCRFDAO(dataSource);
    ArrayList itemDataNotes = discrepancyNoteDAO.findAllItemDataByStudy(currentStudy);
    ArrayList subjectNotes = discrepancyNoteDAO.findAllSubjectByStudy(currentStudy);
    ArrayList studySubjectNotes = discrepancyNoteDAO.findAllStudySubjectByStudy(currentStudy);
    ArrayList studyEventNotes = discrepancyNoteDAO.findAllStudyEventByStudy(currentStudy);
    ArrayList eventCRFNotes = discrepancyNoteDAO.findAllEventCRFByStudy(currentStudy);
    allDiscNotes.addAll(itemDataNotes);
    allDiscNotes.addAll(subjectNotes);
    allDiscNotes.addAll(studySubjectNotes);
    allDiscNotes.addAll(studyEventNotes);
    allDiscNotes.addAll(eventCRFNotes);
    if (filterDiscNotes) {
        // filter for the resolution status
        allDiscNotes = filterDiscNotes(allDiscNotes, resolutionStatus);
    }
    if (filterforDiscNoteType) {
        // filter for the ddiscrepancyNoteTypeId
        allDiscNotes = filterforDiscNoteType(allDiscNotes, discNoteType);
    }
    return allDiscNotes;
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) ArrayList(java.util.ArrayList) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 52 with EventCRFDAO

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

the class DiscrepancyNoteUtil method getDNotesForStudy.

/**
     * An overloaded version of the prior method, the difference being a HashSet
     * of resolution status ids, instead of a single id.
     *
     * @param currentStudy
     *            A StudyBean object.
     * @param resolutionStatusIds
     *            A HashSet object consisting of resolution status ids (i.e.,
     *            1,2,3).
     * @param dataSource
     *            A DataSource used for various DAO methods.
     * @param discNoteType
     *            An int discrepancy note type id; only DiscrepancyNoteBeans
     *            will be returned if they have this discrepancyNoteTypeId.
     * @return A List of DiscrepancyNoteBeans.
     */
public List<DiscrepancyNoteBean> getDNotesForStudy(StudyBean currentStudy, Set<Integer> resolutionStatusIds, DataSource dataSource, int discNoteType) {
    List<DiscrepancyNoteBean> allDiscNotes = new ArrayList<DiscrepancyNoteBean>();
    if (currentStudy == null)
        return allDiscNotes;
    // Do the returned DN's have to be filtered? A valid resolution status
    // has to be between 1 and 5; 0 is "invalid";
    // -1 means that no resolutionStatus parameter was passed into the
    // servlet
    boolean filterDiscNotes = checkResolutionStatus(resolutionStatusIds);
    boolean filterforDiscNoteType = discNoteType >= 1 && discNoteType <= 4;
    DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(dataSource);
    // what is the purpose of this data member?
    discrepancyNoteDAO.setFetchMapping(true);
    EventCRFDAO ecdao = new EventCRFDAO(dataSource);
    ArrayList itemDataNotes = discrepancyNoteDAO.findAllItemDataByStudy(currentStudy);
    ArrayList subjectNotes = discrepancyNoteDAO.findAllSubjectByStudy(currentStudy);
    ArrayList studySubjectNotes = discrepancyNoteDAO.findAllStudySubjectByStudy(currentStudy);
    ArrayList studyEventNotes = discrepancyNoteDAO.findAllStudyEventByStudy(currentStudy);
    ArrayList eventCRFNotes = discrepancyNoteDAO.findAllEventCRFByStudy(currentStudy);
    allDiscNotes.addAll(itemDataNotes);
    allDiscNotes.addAll(subjectNotes);
    allDiscNotes.addAll(studySubjectNotes);
    allDiscNotes.addAll(studyEventNotes);
    allDiscNotes.addAll(eventCRFNotes);
    if (filterDiscNotes) {
        // filter for the resolution status
        allDiscNotes = filterDiscNotes(allDiscNotes, resolutionStatusIds);
    }
    if (filterforDiscNoteType) {
        // filter for the ddiscrepancyNoteTypeId
        allDiscNotes = filterforDiscNoteType(allDiscNotes, discNoteType);
    }
    return allDiscNotes;
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) ArrayList(java.util.ArrayList) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 53 with EventCRFDAO

use of org.akaza.openclinica.dao.submit.EventCRFDAO 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);
    FormLayoutDAO formLayoutDAO = new FormLayoutDAO(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, FormLayoutBean> formLayoutById = formLayoutDAO.buildFormLayoutById(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, formLayoutById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
        ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, formLayoutById, crfById);
        populateUncompletedCRFsWithCRFAndVersions(al, formLayoutById, 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) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) 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) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean)

Example 54 with EventCRFDAO

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

the class DeleteCRFVersionServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int versionId = fp.getInt(VERSION_ID, true);
    String action = request.getParameter("action");
    if (versionId == 0) {
        addPageMessage(respage.getString("please_choose_a_CRF_version_to_delete"));
        forwardPage(Page.CRF_LIST_SERVLET);
    } else {
        CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDAO seDao = new StudyEventDAO(sm.getDataSource());
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId);
        // find definitions using this version
        ArrayList definitions = edcdao.findByDefaultVersion(version.getId());
        for (Object edcBean : definitions) {
            StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(((EventDefinitionCRFBean) edcBean).getStudyEventDefinitionId());
            ((EventDefinitionCRFBean) edcBean).setEventName(sedBean.getName());
        }
        // find event crfs using this version
        ArrayList<ItemDataBean> idBeans = iddao.findByCRFVersion(version);
        ArrayList<EventCRFBean> eCRFs = ecdao.findAllByCRF(version.getCrfId());
        for (EventCRFBean eCRF : eCRFs) {
            StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eCRF.getStudySubjectId());
            eCRF.setStudySubject(ssBean);
            StudyEventBean seBean = (StudyEventBean) seDao.findByPK(eCRF.getStudyEventId());
            StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(seBean.getStudyEventDefinitionId());
            seBean.setStudyEventDefinition(sedBean);
            eCRF.setStudyEvent(seBean);
        }
        ArrayList eventCRFs = ecdao.findAllByCRFVersion(versionId);
        boolean canDelete = true;
        if (!definitions.isEmpty()) {
            // used in definition
            canDelete = false;
            request.setAttribute("definitions", definitions);
            addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_study_events_definitions_cannot_delete"));
        } else if (!idBeans.isEmpty()) {
            canDelete = false;
            request.setAttribute("eventCRFs", eCRFs);
            request.setAttribute("itemDataForVersion", idBeans);
            addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_item_data_cannot_delete"));
        } else if (!eventCRFs.isEmpty()) {
            canDelete = false;
            request.setAttribute("eventsForVersion", eventCRFs);
            addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_study_events_cannot_delete"));
        }
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute(VERSION_TO_DELETE, version);
            forwardPage(Page.DELETE_CRF_VERSION);
        } else {
            // submit
            if (canDelete) {
                ArrayList items = cvdao.findNotSharedItemsByVersion(versionId);
                NewCRFBean nib = new NewCRFBean(sm.getDataSource(), version.getCrfId());
                nib.setDeleteQueries(cvdao.generateDeleteQueries(versionId, items));
                nib.deleteFromDB();
                addPageMessage(respage.getString("the_CRF_version_has_been_deleted_succesfully"));
            } else {
                addPageMessage(respage.getString("the_CRF_version_cannot_be_deleted"));
            }
            forwardPage(Page.CRF_LIST_SERVLET);
        }
    }
}
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) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 55 with EventCRFDAO

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

the class CreateCRFVersionServlet method canDeleteVersion.

/**
     * Checks whether the version can be deleted
     * 
     * @param previousVersionId
     * @return
     */
private boolean canDeleteVersion(int previousVersionId) {
    CRFVersionDAO cdao = new CRFVersionDAO(sm.getDataSource());
    ArrayList items = null;
    ArrayList itemsHaveData = new ArrayList();
    // boolean isItemUsedByOtherVersion =
    // cdao.isItemUsedByOtherVersion(previousVersionId);
    // if (isItemUsedByOtherVersion) {
    // ArrayList itemsUsedByOtherVersion = (ArrayList)
    // cdao.findItemUsedByOtherVersion(previousVersionId);
    // session.setAttribute("itemsUsedByOtherVersion",itemsUsedByOtherVersion);
    // return false;
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ArrayList events = ecdao.findAllByCRFVersion(previousVersionId);
    if (!events.isEmpty()) {
        session.setAttribute("eventsForVersion", events);
        return false;
    }
    items = cdao.findNotSharedItemsByVersion(previousVersionId);
    for (int i = 0; i < items.size(); i++) {
        ItemBean item = (ItemBean) items.get(i);
        if (ub.getId() != item.getOwner().getId()) {
            logger.debug("not owner" + item.getOwner().getId() + "<>" + ub.getId());
            return false;
        }
        if (cdao.hasItemData(item.getId())) {
            itemsHaveData.add(item);
            logger.debug("item has data");
            session.setAttribute("itemsHaveData", itemsHaveData);
            return false;
        }
    }
    // user is the owner and item not have data,
    // delete previous version with non-shared items
    NewCRFBean nib = (NewCRFBean) session.getAttribute("nib");
    nib.setDeleteQueries(cdao.generateDeleteQueries(previousVersionId, items));
    session.setAttribute("nib", nib);
    return true;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ArrayList(java.util.ArrayList) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Aggregations

EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)106 ArrayList (java.util.ArrayList)80 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)76 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)73 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)71 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)57 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)51 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)51 Date (java.util.Date)50 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)49 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)49 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)47 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)45 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)43 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)41 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)37 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)34 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)32 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)24