Search in sources :

Example 16 with StudyEventBean

use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.

the class ViewStudyEventsServlet method genTables.

/**
 * @param fp
 * @param definitions
 * @param startDate
 * @param endDate
 * @param sedId
 * @param definitionId
 * @param statusId
 * @return
 */
private ArrayList genTables(FormProcessor fp, ArrayList definitions, Date startDate, Date endDate, int sedId, int definitionId, int statusId) {
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ArrayList allEvents = new ArrayList();
    definitions = findDefinitionById(definitions, definitionId);
    // YW <<
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    ArrayList studySubjects = ssdao.findAllByStudyId(currentStudy.getId());
    // YW >>
    for (int i = 0; i < definitions.size(); i++) {
        ViewEventDefinitionBean ved = new ViewEventDefinitionBean();
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) definitions.get(i);
        ved.setDefinition(sed);
        // YW <<
        ArrayList events = new ArrayList();
        for (int s = 0; s < studySubjects.size(); ++s) {
            StudySubjectBean ssb = (StudySubjectBean) studySubjects.get(s);
            ArrayList evts = sedao.findAllWithSubjectLabelByStudySubjectAndDefinition(ssb, sed.getId());
            for (int v = 0; v < evts.size(); ++v) {
                StudyEventBean seb = (StudyEventBean) evts.get(v);
                if (!(currentRole.isDirector() || currentRole.isCoordinator()) && seb.getSubjectEventStatus().isLocked()) {
                    seb.setEditable(false);
                }
                events.add(seb);
            }
        }
        int subjectScheduled = 0;
        int subjectCompleted = 0;
        int subjectDiscontinued = 0;
        events = findEventByStatusAndDate(events, statusId, startDate, endDate);
        Date firstStartDateForScheduled = null;
        Date lastCompletionDate = null;
        // find the first firstStartDateForScheduled
        for (int k = 0; k < events.size(); k++) {
            StudyEventBean se = (StudyEventBean) events.get(k);
            if (se.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
                firstStartDateForScheduled = se.getDateStarted();
                break;
            }
        }
        // find the first lastCompletionDate
        for (int k = 0; k < events.size(); k++) {
            StudyEventBean se = (StudyEventBean) events.get(k);
            if (se.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED) && se.getDateEnded() != null) {
                lastCompletionDate = se.getDateEnded();
                break;
            }
        }
        for (int j = 0; j < events.size(); j++) {
            StudyEventBean se = (StudyEventBean) events.get(j);
            if (se.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
                subjectScheduled++;
                if (se.getDateStarted().before(new Date())) {
                    ArrayList eventCRFs = ecdao.findAllByStudyEvent(se);
                    if (eventCRFs.isEmpty()) {
                        se.setScheduledDatePast(true);
                    }
                }
                if (firstStartDateForScheduled == null) {
                    firstStartDateForScheduled = se.getDateStarted();
                } else if (se.getDateStarted().before(firstStartDateForScheduled)) {
                    firstStartDateForScheduled = se.getDateStarted();
                }
            } else if (se.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) {
                subjectCompleted++;
                if (lastCompletionDate == null) {
                    lastCompletionDate = se.getDateEnded();
                } else if (se.getDateEnded() != null && se.getDateEnded().after(lastCompletionDate)) {
                    lastCompletionDate = se.getDateEnded();
                }
            } else if (se.getSubjectEventStatus().getId() > 4) {
                // dropped out/stopped/skipped/relapse
                subjectDiscontinued++;
            }
        }
        ved.setSubjectCompleted(subjectCompleted);
        ved.setSubjectScheduled(subjectScheduled);
        ved.setSubjectDiscontinued(subjectDiscontinued);
        ved.setFirstScheduledStartDate(firstStartDateForScheduled);
        ved.setLastCompletionDate(lastCompletionDate);
        EntityBeanTable table;
        if (sedId == sed.getId()) {
            // apply finding function or ordering
            // function
            // to a specific table
            table = fp.getEntityBeanTable();
        } else {
            table = new EntityBeanTable();
        }
        // sort by event
        table.setSortingIfNotExplicitlySet(1, false);
        // start date,
        // desc
        ArrayList allEventRows = StudyEventRow.generateRowsFromBeans(events);
        String[] columns = { resword.getString("study_subject_ID"), resword.getString("event_date_started"), resword.getString("subject_event_status"), resword.getString("actions") };
        table.setColumns(new ArrayList(Arrays.asList(columns)));
        table.hideColumnLink(3);
        HashMap args = new HashMap();
        args.put("sedId", new Integer(sed.getId()).toString());
        args.put("definitionId", new Integer(definitionId).toString());
        args.put("statusId", new Integer(statusId).toString());
        args.put("startDate", local_df.format(startDate));
        args.put("endDate", local_df.format(endDate));
        table.setQuery("ViewStudyEvents", args);
        table.setRows(allEventRows);
        table.computeDisplay();
        ved.setStudyEventTable(table);
        if (!events.isEmpty()) {
            allEvents.add(ved);
        }
    }
    // A. Hamid.
    return allEvents;
}
Also used : HashMap(java.util.HashMap) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 17 with StudyEventBean

use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.

the class ViewStudySubjectServlet method getDisplayStudyEventsForStudySubject.

public static ArrayList<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(StudySubjectBean studySub, DataSource ds, UserAccountBean ub, StudyUserRoleBean currentRole) {
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
    StudyEventDAO sedao = new StudyEventDAO(ds);
    EventCRFDAO ecdao = new EventCRFDAO(ds);
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
    StudySubjectDAO ssdao = new StudySubjectDAO(ds);
    StudyDAO sdao = new StudyDAO(ds);
    ArrayList events = sedao.findAllByStudySubject(studySub);
    ArrayList displayEvents = new ArrayList();
    for (int i = 0; i < events.size(); i++) {
        StudyEventBean event = (StudyEventBean) events.get(i);
        StudySubjectBean studySubject = (StudySubjectBean) ssdao.findByPK(event.getStudySubjectId());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
        event.setStudyEventDefinition(sed);
        // find all active crfs in the definition
        StudyBean study = (StudyBean) sdao.findByPK(studySubject.getStudyId());
        ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, sed.getId());
        ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
        // construct info needed on view study event page
        DisplayStudyEventBean de = new DisplayStudyEventBean();
        de.setStudyEvent(event);
        de.setDisplayEventCRFs(getDisplayEventCRFs(ds, eventCRFs, eventDefinitionCRFs, ub, currentRole, event.getSubjectEventStatus(), study));
        ArrayList al = getUncompletedCRFs(ds, eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus());
        populateUncompletedCRFsWithCRFAndVersions(ds, al);
        de.setUncompletedCRFs(al);
        de.setMaximumSampleOrdinal(sedao.getMaxSampleOrdinal(sed, studySubject));
        displayEvents.add(de);
    // event.setEventCRFs(createAllEventCRFs(eventCRFs,
    // eventDefinitionCRFs));
    }
    return displayEvents;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) 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) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 18 with StudyEventBean

use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.

the class EnterDataForStudyEventServlet method processRequest.

/*
     * (non-Javadoc)
     *
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
@Override
protected void processRequest() throws Exception {
    // removeLockedCRF(ub.getId());
    getCrfLocker().unlockAllForUser(ub.getId());
    FormProcessor fp = new FormProcessor(request);
    int eventId = fp.getInt(INPUT_EVENT_ID, true);
    request.setAttribute("eventId", eventId + "");
    // so we can display the event for which we're entering data
    StudyEventBean seb = getStudyEvent(eventId);
    // so we can display the subject's label
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    StudySubjectBean studySubjectBean = (StudySubjectBean) ssdao.findByPK(seb.getStudySubjectId());
    int studyId = studySubjectBean.getStudyId();
    StudyDAO studydao = new StudyDAO(sm.getDataSource());
    StudyBean study = (StudyBean) studydao.findByPK(studyId);
    // If the study subject derives from a site, and is being viewed from a
    // parent study,
    // then the study IDs will be different. However, since each note is
    // saved with the specific
    // study ID, then its study ID may be different than the study subject's
    // ID.
    boolean subjectStudyIsCurrentStudy = studyId == currentStudy.getId();
    boolean isParentStudy = study.getParentStudyId() < 1;
    // Get any disc notes for this study event
    DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(sm.getDataSource());
    ArrayList<DiscrepancyNoteBean> allNotesforSubjectAndEvent = new ArrayList<DiscrepancyNoteBean>();
    // These methods return only parent disc notes
    if (subjectStudyIsCurrentStudy && isParentStudy) {
        allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudyAndId(currentStudy, studySubjectBean.getId());
    } else {
        // findAllStudyEventByStudiesAndSubjectId
        if (!isParentStudy) {
            StudyBean stParent = (StudyBean) studydao.findByPK(study.getParentStudyId());
            allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(stParent, study, studySubjectBean.getId());
        } else {
            allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(currentStudy, study, studySubjectBean.getId());
        }
    }
    if (!allNotesforSubjectAndEvent.isEmpty()) {
        setRequestAttributesForNotes(allNotesforSubjectAndEvent);
    }
    // prepare to figure out what the display should look like
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ArrayList<EventCRFBean> eventCRFs = ecdao.findAllByStudyEvent(seb);
    ArrayList<Boolean> doRuleSetsExist = new ArrayList<Boolean>();
    RuleSetDAO ruleSetDao = new RuleSetDAO(sm.getDataSource());
    for (EventCRFBean eventCrfBean : eventCRFs) {
    // Boolean result = ruleSetDao.findByEventCrf(eventCrfBean) != null
    // ? Boolean.TRUE : Boolean.FALSE;
    // doRuleSetsExist.add(result);
    }
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, seb.getStudyEventDefinitionId());
    // get the event definition CRFs for which no event CRF exists
    // the event definition CRFs must be populated with versions so we can
    // let the user choose which version he will enter data for
    // However, this method seems to be returning DisplayEventDefinitionCRFs
    // that contain valid eventCRFs??
    ArrayList uncompletedEventDefinitionCRFs = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs);
    populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
    // BWP 2816 << Attempt to provide the DisplayEventDefinitionCRF with a
    // valid owner
    // only if its container eventCRf has a valid id
    populateUncompletedCRFsWithAnOwner(uncompletedEventDefinitionCRFs);
    // >>BWP
    // for the event definition CRFs for which event CRFs exist, get
    // DisplayEventCRFBeans, which the JSP will use to determine what
    // the user will see for each event CRF
    // removing the below row in exchange for the ViewStudySubjectServlet
    // version, for two
    // reasons:
    // 1. concentrate all business logic in one place
    // 2. VSSS seems to handle the javascript creation correctly
    // ArrayList displayEventCRFs = getDisplayEventCRFs(eventCRFs,
    // eventDefinitionCRFs, seb.getSubjectEventStatus());
    ArrayList displayEventCRFs = ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(), eventCRFs, eventDefinitionCRFs, ub, currentRole, seb.getSubjectEventStatus(), study);
    // Issue 3212 BWP << hide certain CRFs at the site level
    if (currentStudy.getParentStudyId() > 0) {
        HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
        uncompletedEventDefinitionCRFs = hideCRFManager.removeHiddenEventDefinitionCRFBeans(uncompletedEventDefinitionCRFs);
        displayEventCRFs = hideCRFManager.removeHiddenEventCRFBeans(displayEventCRFs);
    }
    // >>
    request.setAttribute(BEAN_STUDY_EVENT, seb);
    request.setAttribute("doRuleSetsExist", doRuleSetsExist);
    request.setAttribute(BEAN_STUDY_SUBJECT, studySubjectBean);
    request.setAttribute(BEAN_UNCOMPLETED_EVENTDEFINITIONCRFS, uncompletedEventDefinitionCRFs);
    request.setAttribute(BEAN_DISPLAY_EVENT_CRFS, displayEventCRFs);
    // @pgawade 31-Aug-2012 fix for issue #15315: Reverting to set the request variable "beans" back
    // this is for generating side info panel
    ArrayList beans = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySubjectBean, sm.getDataSource(), ub, currentRole);
    request.setAttribute("beans", beans);
    EventCRFBean ecb = new EventCRFBean();
    ecb.setStudyEventId(eventId);
    request.setAttribute("eventCRF", ecb);
    // Make available the study
    request.setAttribute("study", currentStudy);
    forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT);
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) RuleSetDAO(org.akaza.openclinica.dao.rule.RuleSetDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) 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) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) HideCRFManager(org.akaza.openclinica.service.crfdata.HideCRFManager) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 19 with StudyEventBean

use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.

the class CreateDiscrepancyNoteServlet method getStudyEvent.

private StudyEventBean getStudyEvent(int eventCRFId) {
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventBean event = (StudyEventBean) sedao.findByPK(getEventCrf(eventCRFId).getStudyEventId());
    return event;
}
Also used : StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean)

Example 20 with StudyEventBean

use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.

the class CreateDiscrepancyNoteServlet method updateStudySubjectStatus.

/**
 * Pulls the note related information from database according to note type
 *
 * @param note
 */
private void updateStudySubjectStatus(String entityType, int entityId) {
    if ("itemData".equalsIgnoreCase(entityType)) {
        int itemDataId = entityId;
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        ItemDataBean itemData = (ItemDataBean) iddao.findByPK(itemDataId);
        EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
        StudyEventDAO svdao = new StudyEventDAO(sm.getDataSource());
        StudySubjectDAO studySubjectDAO = new StudySubjectDAO(sm.getDataSource());
        EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
        StudyEventBean event = (StudyEventBean) svdao.findByPK(ec.getStudyEventId());
        StudySubjectBean studySubject = (StudySubjectBean) studySubjectDAO.findByPK(event.getStudySubjectId());
        if (studySubject.getStatus() != null && studySubject.getStatus().equals(Status.SIGNED)) {
            studySubject.setStatus(Status.AVAILABLE);
            studySubject.setUpdater(ub);
            studySubject.setUpdatedDate(new Date());
            studySubjectDAO.update(studySubject);
        }
        if (ec.isSdvStatus()) {
            studySubject.setStatus(Status.AVAILABLE);
            studySubject.setUpdater(ub);
            studySubject.setUpdatedDate(new Date());
            studySubjectDAO.update(studySubject);
            ec.setSdvStatus(false);
            ec.setSdvUpdateId(ub.getId());
            ecdao.update(ec);
        }
    }
}
Also used : EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) Date(java.util.Date)

Aggregations

StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)162 ArrayList (java.util.ArrayList)103 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)91 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)90 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)74 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)71 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)62 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)62 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)60 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)58 Date (java.util.Date)52 HashMap (java.util.HashMap)50 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)47 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)43 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)37 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)37 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)36 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)34 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)34 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)31