Search in sources :

Example 51 with StudySubjectBean

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

the class ViewNotesServlet method filterForOneSubject.

public ArrayList<DiscrepancyNoteBean> filterForOneSubject(ArrayList<DiscrepancyNoteBean> allNotes, int subjectId, int resolutionStatus) {
    if (allNotes == null || allNotes.isEmpty() || subjectId == 0)
        return allNotes;
    // Are the D Notes filtered by resolution?
    boolean filterByRes = resolutionStatus >= 1 && resolutionStatus <= 5;
    ArrayList<DiscrepancyNoteBean> filteredNotes = new ArrayList<DiscrepancyNoteBean>();
    StudySubjectDAO subjectDao = new StudySubjectDAO(sm.getDataSource());
    StudySubjectBean studySubjBean = (StudySubjectBean) subjectDao.findByPK(subjectId);
    for (DiscrepancyNoteBean discBean : allNotes) {
        if (discBean.getSubjectName().equalsIgnoreCase(studySubjBean.getLabel())) {
            if (!filterByRes) {
                filteredNotes.add(discBean);
            } else {
                if (discBean.getResolutionStatusId() == resolutionStatus) {
                    filteredNotes.add(discBean);
                }
            }
        }
    }
    return filteredNotes;
}
Also used : StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) ArrayList(java.util.ArrayList) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Example 52 with StudySubjectBean

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

the class ViewStudyEventsServlet method genEventsForPrint.

/**
     * Generates an arraylist of study events for printing
     *
     * @param fp
     * @param definitions
     * @param startDate
     * @param endDate
     * @param sedId
     * @param definitionId
     * @param statusId
     * @return
     */
private ArrayList genEventsForPrint(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) {
                events.add(evts.get(v));
            }
        }
        // YW >>
        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)) {
                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().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);
        ved.setStudyEvents(events);
        if (!events.isEmpty()) {
            allEvents.add(ved);
        }
    }
    return allEvents;
}
Also used : StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) 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) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) Date(java.util.Date)

Example 53 with StudySubjectBean

use of org.akaza.openclinica.bean.managestudy.StudySubjectBean 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 54 with StudySubjectBean

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

the class ViewEventCRFServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int eventCRFId = fp.getInt("id", true);
    int studySubId = fp.getInt("studySubId", true);
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    SectionDAO secdao = new SectionDAO(sm.getDataSource());
    if (eventCRFId == 0) {
        addPageMessage(respage.getString("please_choose_an_event_CRF_to_view"));
        forwardPage(Page.LIST_STUDY_SUBJECTS);
    } else {
        StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
        request.setAttribute("studySub", studySub);
        EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
        CRFBean crf = cdao.findByVersionId(eventCRF.getCRFVersionId());
        request.setAttribute("crf", crf);
        ArrayList sections = secdao.findAllByCRFVersionId(eventCRF.getCRFVersionId());
        for (int j = 0; j < sections.size(); j++) {
            SectionBean section = (SectionBean) sections.get(j);
            ArrayList itemData = iddao.findAllByEventCRFId(eventCRFId);
            ArrayList displayItemData = new ArrayList();
            for (int i = 0; i < itemData.size(); i++) {
                ItemDataBean id = (ItemDataBean) itemData.get(i);
                DisplayItemBean dib = new DisplayItemBean();
                ItemBean item = (ItemBean) idao.findByPK(id.getItemId());
                ItemFormMetadataBean ifm = ifmdao.findByItemIdAndCRFVersionId(item.getId(), eventCRF.getCRFVersionId());
                item.setItemMeta(ifm);
                dib.setItem(item);
                dib.setData(id);
                dib.setMetadata(ifm);
                displayItemData.add(dib);
            }
            section.setItems(displayItemData);
        }
        request.setAttribute("sections", sections);
        request.setAttribute("studySubId", new Integer(studySubId).toString());
        forwardPage(Page.VIEW_EVENT_CRF);
    }
}
Also used : EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 55 with StudySubjectBean

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

the class AddNewSubjectServlet method displaySubjects.

/**
     * Find study subject id for each subject, and construct displaySubjectBean
     * 
     * @param displayArray
     * @param subjects
     */
public static void displaySubjects(ArrayList displayArray, ArrayList subjects, StudySubjectDAO ssdao, StudyDAO stdao) {
    for (int i = 0; i < subjects.size(); i++) {
        SubjectBean subject = (SubjectBean) subjects.get(i);
        ArrayList studySubs = ssdao.findAllBySubjectId(subject.getId());
        String protocolSubjectIds = "";
        for (int j = 0; j < studySubs.size(); j++) {
            StudySubjectBean studySub = (StudySubjectBean) studySubs.get(j);
            int studyId = studySub.getStudyId();
            StudyBean stu = (StudyBean) stdao.findByPK(studyId);
            String protocolId = stu.getIdentifier();
            if (j == studySubs.size() - 1) {
                protocolSubjectIds = protocolId + "-" + studySub.getLabel();
            } else {
                protocolSubjectIds = protocolId + "-" + studySub.getLabel() + ", ";
            }
        }
        DisplaySubjectBean dsb = new DisplaySubjectBean();
        dsb.setSubject(subject);
        dsb.setStudySubjectIds(protocolSubjectIds);
        displayArray.add(dsb);
    }
}
Also used : SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) DisplaySubjectBean(org.akaza.openclinica.bean.submit.DisplaySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DisplaySubjectBean(org.akaza.openclinica.bean.submit.DisplaySubjectBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList)

Aggregations

StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)155 ArrayList (java.util.ArrayList)102 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)86 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)71 HashMap (java.util.HashMap)66 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)66 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)57 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)52 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)52 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)49 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)43 Date (java.util.Date)42 Iterator (java.util.Iterator)38 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)35 SubjectBean (org.akaza.openclinica.bean.submit.SubjectBean)29 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)26 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)26 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)26 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)23