Search in sources :

Example 1 with DisplayStudySubjectBean

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

the class ListStudySubjectServlet method processRequest.

// >>
// < ResourceBundleresword;
@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    locale = LocaleResolver.getLocale(request);
    // < resword =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.words",locale);
    // BWP 3098 << close the info side panel and show icons
    request.setAttribute("closeInfoShowIcons", true);
    // >>
    // BWP 3195, 3330 : designed to address pagination issues
    String pageNumber = fp.getString(SUBJECT_PAGE_NUMBER);
    StringBuilder paginatingQuery = new StringBuilder("");
    String filterKeyword = fp.getString(FILTER_KEYWORD);
    String tmpSearch = fp.getString(SEARCH_SUBMITTED);
    boolean searchSubmitted = !(tmpSearch == null || "".equalsIgnoreCase(tmpSearch)) && !"".equalsIgnoreCase(filterKeyword) && !"+".equalsIgnoreCase(filterKeyword);
    if (pageNumber != null && !"".equalsIgnoreCase(pageNumber)) {
        int tempNum = 0;
        try {
            tempNum = Integer.parseInt(pageNumber);
        } catch (NumberFormatException nfe) {
        // tempNum is already initialized to 0
        }
        if (tempNum > 0) {
            paginatingQuery = new StringBuilder(SUBJECT_PAGE_NUMBER).append("=").append(pageNumber);
            paginatingQuery.append("&ebl_paginated=1");
        }
    }
    // URL encode the search keyword, since it will be a parameter in the
    // URL
    String filterKeywordURLEncode = java.net.URLEncoder.encode(filterKeyword, "UTF-8");
    if (searchSubmitted) {
        paginatingQuery.append("&ebl_sortColumnInd=0&submitted=1&ebl_sortAscending=1&ebl_filtered=1");
        paginatingQuery.append("&").append(FILTER_KEYWORD).append("=").append(filterKeywordURLEncode);
    }
    request.setAttribute(PAGINATING_QUERY, paginatingQuery.toString());
    StudyDAO stdao = new StudyDAO(sm.getDataSource());
    StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
    StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
    StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    // YW << update study parameters of current study.
    // "collectDob" and "genderRequired" are set as the same as the parent
    // study
    // tbh, also add the params "subjectPersonIdRequired",
    // "subjectIdGeneration", "subjectIdPrefixSuffix"
    int parentStudyId = currentStudy.getParentStudyId();
    ArrayList studyGroupClasses = new ArrayList();
    ArrayList allDefs = new ArrayList();
    // tbh
    if (parentStudyId > 0) {
        StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId);
        studyGroupClasses = sgcdao.findAllActiveByStudy(parentStudy);
        allDefs = seddao.findAllActiveByStudy(parentStudy);
    } else {
        parentStudyId = currentStudy.getId();
        studyGroupClasses = sgcdao.findAllActiveByStudy(currentStudy);
        allDefs = seddao.findAllActiveByStudy(currentStudy);
    }
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    StudyParameterValueBean parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "collectDob");
    currentStudy.getStudyParameterConfig().setCollectDob(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "genderRequired");
    currentStudy.getStudyParameterConfig().setGenderRequired(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectPersonIdRequired");
    currentStudy.getStudyParameterConfig().setSubjectPersonIdRequired(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdGeneration");
    currentStudy.getStudyParameterConfig().setSubjectIdGeneration(parentSPV.getValue());
    parentSPV = spvdao.findByHandleAndStudy(parentStudyId, "subjectIdPrefixSuffix");
    currentStudy.getStudyParameterConfig().setSubjectIdPrefixSuffix(parentSPV.getValue());
    // for all the study groups for each group class
    for (int i = 0; i < studyGroupClasses.size(); i++) {
        StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
        ArrayList groups = sgdao.findAllByGroupClass(sgc);
        sgc.setStudyGroups(groups);
    }
    request.setAttribute("studyGroupClasses", studyGroupClasses);
    // information for the event tabs
    session.setAttribute("allDefsArray", allDefs);
    session.setAttribute("allDefsNumber", new Integer(allDefs.size()));
    session.setAttribute("groupSize", new Integer(studyGroupClasses.size()));
    // find all the subjects in current study
    ArrayList subjects = sdao.findAllByStudyId(currentStudy.getId());
    ArrayList<DisplayStudySubjectBean> displayStudySubs = new ArrayList<DisplayStudySubjectBean>();
    // BEGIN LOOPING THROUGH SUBJECTS
    for (int i = 0; i < subjects.size(); i++) {
        StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
        ArrayList groups = (ArrayList) sgmdao.findAllByStudySubject(studySub.getId());
        ArrayList subGClasses = new ArrayList();
        for (int j = 0; j < studyGroupClasses.size(); j++) {
            StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(j);
            boolean hasClass = false;
            for (int k = 0; k < groups.size(); k++) {
                SubjectGroupMapBean sgmb = (SubjectGroupMapBean) groups.get(k);
                if (sgmb.getGroupClassName().equalsIgnoreCase(sgc.getName())) {
                    subGClasses.add(sgmb);
                    hasClass = true;
                    break;
                }
            }
            if (!hasClass) {
                subGClasses.add(new SubjectGroupMapBean());
            }
        }
        ArrayList subEvents = new ArrayList();
        // find all events order by definition ordinal
        ArrayList events = sedao.findAllByStudySubject(studySub);
        for (int j = 0; j < allDefs.size(); j++) {
            StudyEventDefinitionBean sed = (StudyEventDefinitionBean) allDefs.get(j);
            boolean hasDef = false;
            // logger.info("...set blank to "+blankid);
            for (int k = 0; k < events.size(); k++) {
                StudyEventBean se = (StudyEventBean) events.get(k);
                if (se.getStudyEventDefinitionId() == sed.getId()) {
                    se.setStudyEventDefinition(sed);
                    // logger.info(">>>found assigned id "+sed.getId()+" sed
                    // name: "+sed.getName()+" "+se.getId());
                    subEvents.add(se);
                    hasDef = true;
                }
            }
            if (!hasDef) {
                StudyEventBean blank = new StudyEventBean();
                blank.setSubjectEventStatus(SubjectEventStatus.NOT_SCHEDULED);
                blank.setStudyEventDefinitionId(sed.getId());
                // how can we set the following:
                // logger.info("...resetting blank id: "+blank.getId()+" to
                // "+blankid);
                // blank.setId(blankid);
                blank.setStudyEventDefinition(sed);
                // logger.info(">>>blank id: "+blank.getId());
                // logger.info(">>>found unassigned id "+sed.getId()+" sed
                // name: "+sed.getName()+" ");
                subEvents.add(blank);
            }
        }
        // logger.info("subevents size after all adds: "+subEvents.size());
        // reorganize the events and find the repeating ones
        // subEvents:[aa bbb cc d ee]
        // finalEvents:[a(2) b(3) c(2) d e(2)]
        int prevDefId = 0;
        int currDefId = 0;
        ArrayList finalEvents = new ArrayList();
        int repeatingNum = 1;
        int count = 0;
        StudyEventBean event = new StudyEventBean();
        // begin looping through subject events
        for (int j = 0; j < subEvents.size(); j++) {
            StudyEventBean se = (StudyEventBean) subEvents.get(j);
            currDefId = se.getStudyEventDefinitionId();
            if (currDefId != prevDefId) {
                // find a new event
                if (repeatingNum > 1) {
                    event.setRepeatingNum(repeatingNum);
                    repeatingNum = 1;
                }
                // add current event to final
                finalEvents.add(se);
                event = se;
                count++;
            // logger.info("event id? "+event.getId());
            } else {
                // repeating event
                repeatingNum++;
                event.getRepeatEvents().add(se);
                // event.getRepeatEvents().size());
                if (j == subEvents.size() - 1) {
                    event.setRepeatingNum(repeatingNum);
                    repeatingNum = 1;
                }
            }
            prevDefId = currDefId;
        }
        // end looping through subject events
        DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
        // logger.info("final events size: "+finalEvents.size());
        dssb.setStudyEvents(finalEvents);
        dssb.setStudySubject(studySub);
        dssb.setStudyGroups(subGClasses);
        displayStudySubs.add(dssb);
    }
    // END LOOPING THROUGH SUBJECTS
    // Set a subject property to determine whether to show a signed-type
    // icon (electronic signature)
    // in the JSP view or not
    // Get all event crfs by studyevent id; then use
    // EventDefinitionCRFDAO.isRequired to
    // determine whether any uncompleted CRFs are required.
    boolean isRequiredUncomplete = false;
    for (DisplayStudySubjectBean subject : displayStudySubs) {
        for (Iterator it = subject.getStudyEvents().iterator(); it.hasNext(); ) {
            StudyEventBean event = (StudyEventBean) it.next();
            if (event.getSubjectEventStatus() != null && event.getSubjectEventStatus().getId() == 3) {
                // disallow the subject from signing any studies
                subject.setStudySignable(false);
                break;
            } else {
                // determine whether the subject has any required,
                // uncompleted event CRFs
                isRequiredUncomplete = eventHasRequiredUncompleteCRFs(event);
                if (isRequiredUncomplete) {
                    subject.setStudySignable(false);
                    break;
                }
            }
        }
    }
    fp = new FormProcessor(request);
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allStudyRows = DisplayStudySubjectRow.generateRowsFromBeans(displayStudySubs);
    ArrayList columnArray = new ArrayList();
    columnArray.add(resword.getString("study_subject_ID"));
    columnArray.add(resword.getString("subject_status"));
    columnArray.add(resword.getString("OID"));
    columnArray.add(resword.getString("gender"));
    // new
    columnArray.add(resword.getString("secondary_ID"));
    for (int i = 0; i < studyGroupClasses.size(); i++) {
        StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
        columnArray.add(sgc.getName());
    }
    for (int i = 0; i < allDefs.size(); i++) {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) allDefs.get(i);
        columnArray.add(sed.getName());
    }
    columnArray.add(resword.getString("actions"));
    String[] columns = new String[columnArray.size()];
    columnArray.toArray(columns);
    // String[] columns = {"ID", "Subject Status", "Gender", "Enrollment
    // Date",
    // "Study Events", "Actions" };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.setQuery(getBaseURL(), new HashMap());
    table.hideColumnLink(columnArray.size() - 1);
    // table.addLink("Enroll a new subject",
    // "javascript:leftnavExpand('addSubjectRowExpress');");
    table.setRows(allStudyRows);
    if (filterKeyword != null && !"".equalsIgnoreCase(filterKeyword)) {
        table.setKeywordFilter(filterKeyword);
    }
    table.computeDisplay();
    request.setAttribute("table", table);
    // request.setAttribute("subjects", subjects);
    String idSetting = currentStudy.getStudyParameterConfig().getSubjectIdGeneration();
    // set up auto study subject id
    if (idSetting.equals("auto editable") || idSetting.equals("auto non-editable")) {
        //Shaoyu Su
        //int nextLabel = ssdao.findTheGreatestLabel() + 1;
        //request.setAttribute("label", new Integer(nextLabel).toString());
        request.setAttribute("label", resword.getString("id_generated_Save_Add"));
    }
    FormDiscrepancyNotes discNotes = new FormDiscrepancyNotes();
    session.setAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME, discNotes);
    forwardPage(getJSP());
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) HashMap(java.util.HashMap) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudyParameterValueBean(org.akaza.openclinica.bean.service.StudyParameterValueBean) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) Iterator(java.util.Iterator) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO)

Example 2 with DisplayStudySubjectBean

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

the class DisplayStudySubjectEventsRow method compareColumn.

@Override
protected int compareColumn(Object row, int sortingColumn) {
    if (!row.getClass().equals(DisplayStudySubjectEventsRow.class)) {
        return 0;
    }
    DisplayStudySubjectBean thisStudy = (DisplayStudySubjectBean) bean;
    DisplayStudySubjectBean argStudy = (DisplayStudySubjectBean) ((DisplayStudySubjectEventsRow) row).bean;
    int answer = 0;
    // YW <<
    int groupSize = thisStudy.getStudyGroups().size();
    int code;
    if (sortingColumn > 4 + groupSize) {
        code = COL_STUDYCRF;
    } else if (sortingColumn > 4 && sortingColumn <= 4 + groupSize) {
        code = COL_STUDYGROUP;
    } else {
        code = sortingColumn;
    }
    switch(code) {
        case COL_SUBJECT_LABEL:
            answer = thisStudy.getStudySubject().getLabel().toLowerCase().compareTo(argStudy.getStudySubject().getLabel().toLowerCase());
            break;
        case COL_GENDER:
            answer = (thisStudy.getStudySubject().getGender() + "").compareTo(argStudy.getStudySubject().getGender() + "");
            break;
        case COL_STATUS:
            answer = thisStudy.getStudySubject().getStatus().compareTo(argStudy.getStudySubject().getStatus());
            break;
        case COL_EVENT_STATUS:
            if (thisStudy.getStudyEvents() == null || thisStudy.getStudyEvents().isEmpty()) {
                answer = -1;
                break;
            }
            if (argStudy.getStudyEvents() == null || argStudy.getStudyEvents().isEmpty()) {
                answer = 1;
                break;
            }
            answer = ((DisplayStudyEventBean) thisStudy.getStudyEvents().get(0)).getStudyEvent().getSubjectEventStatus().compareTo(((DisplayStudyEventBean) argStudy.getStudyEvents().get(0)).getStudyEvent().getSubjectEventStatus());
            break;
        case COL_EVENT_DATE:
            if (thisStudy.getStudyEvents() == null || thisStudy.getStudyEvents().isEmpty()) {
                answer = -1;
                break;
            }
            if (argStudy.getStudyEvents() == null || argStudy.getStudyEvents().isEmpty()) {
                answer = 1;
                break;
            }
            answer = ((DisplayStudyEventBean) thisStudy.getStudyEvents().get(0)).getStudyEvent().getDateStarted().compareTo(((DisplayStudyEventBean) argStudy.getStudyEvents().get(0)).getStudyEvent().getDateStarted());
            break;
        case COL_STUDYGROUP:
            answer = ((SubjectGroupMapBean) thisStudy.getStudyGroups().get(sortingColumn - 5)).getStudyGroupName().toLowerCase().compareTo(((SubjectGroupMapBean) argStudy.getStudyGroups().get(sortingColumn - 5)).getStudyGroupName().toLowerCase());
            break;
        case COL_STUDYCRF:
            if (thisStudy.getStudyEvents() == null || thisStudy.getStudyEvents().isEmpty()) {
                answer = -1;
                break;
            }
            if (argStudy.getStudyEvents() == null || argStudy.getStudyEvents().isEmpty()) {
                answer = 1;
                break;
            }
            ArrayList thisAllEventCRFs = ((DisplayStudyEventBean) thisStudy.getStudyEvents().get(0)).getAllEventCRFs();
            ArrayList argAllEventCRFs = ((DisplayStudyEventBean) argStudy.getStudyEvents().get(0)).getAllEventCRFs();
            if (thisAllEventCRFs == null || thisAllEventCRFs.isEmpty()) {
                answer = -1;
                break;
            }
            if (argAllEventCRFs == null || argAllEventCRFs.isEmpty()) {
                answer = 1;
                break;
            }
            // Event crf status comparision
            DataEntryStage thisDes = ((DisplayEventCRFBean) thisAllEventCRFs.get(sortingColumn - 5)).getEventCRF().getStage();
            DataEntryStage argDes = ((DisplayEventCRFBean) argAllEventCRFs.get(sortingColumn - 5)).getEventCRF().getStage();
            /*Event crf status is ordered in this sequence, Not Started=1,Data Entry Started=2,Initial Data Entry Completed=3,
                Double Data Entry Started=4,Double Data Entry Complete=5,Complete=6,Locked=7,Invalid/Removed=0*/
            switch(thisDes.getId()) {
                //DataEntryStage.INVALID
                case 0:
                    if (thisDes.getId() == argDes.getId()) {
                        answer = 0;
                    } else {
                        answer = 1;
                    }
                    break;
                //DataEntryStage.UNCOMPLETED
                case 1:
                    if (thisDes.getId() == argDes.getId()) {
                        answer = 0;
                    } else {
                        answer = -1;
                    }
                    break;
                //DataEntryStage.INITIAL_DATA_ENTRY
                case 2:
                    if (thisDes.getId() == argDes.getId()) {
                        answer = 0;
                    } else if (argDes.getId() == 1) {
                        answer = 1;
                    } else {
                        answer = -1;
                    }
                    break;
                //DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE
                case 3:
                    if (thisDes.getId() == argDes.getId()) {
                        answer = 0;
                    } else if (argDes.getId() == 1 || argDes.getId() == 2) {
                        answer = 1;
                    } else {
                        answer = -1;
                    }
                    break;
                //DataEntryStage.DOUBLE_DATA_ENTRY
                case 4:
                    if (thisDes.getId() == argDes.getId()) {
                        answer = 0;
                    } else if (argDes.getId() == 1 || argDes.getId() == 2 || argDes.getId() == 3) {
                        answer = 1;
                    } else {
                        answer = -1;
                    }
                    break;
                //DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE
                case 5:
                    if (thisDes.getId() == argDes.getId()) {
                        answer = 0;
                    } else if (argDes.getId() == 0 || argDes.getId() == 7) {
                        answer = -1;
                    } else {
                        answer = 1;
                    }
                    break;
                //DataEntryStage.ADMINISTRATIVE_EDITING
                case 6:
                    if (thisDes.getId() == argDes.getId()) {
                        answer = 0;
                    } else if (argDes.getId() == 7 || argDes.getId() == 0) {
                        answer = -1;
                    } else {
                        answer = 1;
                    }
                    break;
                //DataEntryStage.LOCKED
                case 7:
                    if (thisDes.getId() == argDes.getId()) {
                        answer = 0;
                    } else if (argDes.getId() == 0) {
                        answer = -1;
                    } else {
                        answer = 1;
                    }
                    break;
                default:
                    answer = 1;
            }
    }
    return answer;
}
Also used : DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) ArrayList(java.util.ArrayList) DataEntryStage(org.akaza.openclinica.bean.core.DataEntryStage)

Example 3 with DisplayStudySubjectBean

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

the class DisplayStudySubjectEventsRow method getSearchString.

@Override
public String getSearchString() {
    DisplayStudySubjectBean thisStudy = (DisplayStudySubjectBean) bean;
    String searchString = thisStudy.getStudySubject().getLabel();
    String secondaryLabel = thisStudy.getStudySubject().getSecondaryLabel();
    if (!"".equalsIgnoreCase(secondaryLabel)) {
        searchString += " ";
        searchString += secondaryLabel;
    }
    return searchString;
}
Also used : DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean)

Example 4 with DisplayStudySubjectBean

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

the class ListEventsForSubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);
    String pageNumber = fp.getString(ListStudySubjectServlet.SUBJECT_PAGE_NUMBER);
    String filterKeyword = fp.getString(ListStudySubjectServlet.FILTER_KEYWORD);
    String tmpSearch = fp.getString(ListStudySubjectServlet.SEARCH_SUBMITTED);
    boolean searchSubmitted = !(tmpSearch == null || "".equalsIgnoreCase(tmpSearch)) && !"".equalsIgnoreCase(filterKeyword);
    SubjectMatrixUtil matrixUtil = new SubjectMatrixUtil();
    String query = matrixUtil.createPaginatingQuery(pageNumber);
    StringBuilder extendedQuery = new StringBuilder(query);
    // URL encode the search keyword, since it will be a parameter in the
    // URL
    String filterKeywordURLEncode = java.net.URLEncoder.encode(filterKeyword, "UTF-8");
    if (searchSubmitted) {
        extendedQuery.append("&ebl_sortColumnInd=0&submitted=1&ebl_sortAscending=1&ebl_filtered=1");
        extendedQuery.append("&").append(ListStudySubjectServlet.FILTER_KEYWORD).append("=").append(filterKeywordURLEncode);
    }
    request.setAttribute(ListStudySubjectServlet.PAGINATING_QUERY, extendedQuery.toString());
    int definitionId = fp.getInt("defId");
    int tabId = fp.getInt("tab");
    if (definitionId <= 0) {
        addPageMessage(respage.getString("please_choose_an_ED_ta_to_vies_details"));
        forwardPage(Page.LIST_STUDY_SUBJECTS);
        return;
    }
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(definitionId);
    StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
    StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    // find all the groups in the current study
    ArrayList studyGroupClasses = sgcdao.findAllActiveByStudy(currentStudy);
    // information for the event tabs
    ArrayList allDefs = seddao.findAllActiveByStudy(currentStudy);
    boolean isASite = false;
    if (currentStudy.getParentStudyId() > 0) {
        StudyDAO stdao = new StudyDAO(sm.getDataSource());
        StudyBean parent = (StudyBean) stdao.findByPK(currentStudy.getParentStudyId());
        allDefs = seddao.findAllActiveByStudy(parent);
    }
    ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(this.currentStudy, definitionId);
    for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        CRFBean crf = (CRFBean) crfdao.findByPK(edc.getCrfId());
        edc.setCrf(crf);
    }
    request.setAttribute("studyGroupClasses", studyGroupClasses);
    request.setAttribute("allDefsArray", allDefs);
    request.setAttribute("allDefsNumber", new Integer(allDefs.size()));
    request.setAttribute("groupSize", new Integer(studyGroupClasses.size()));
    request.setAttribute("eventDefCRFSize", new Integer(eventDefinitionCRFs.size()));
    request.setAttribute("tabId", new Integer(tabId));
    request.setAttribute("studyEventDef", sed);
    request.setAttribute("eventDefCRFs", eventDefinitionCRFs);
    // find all the subjects in current study
    ArrayList subjects = sdao.findAllByStudyId(currentStudy.getId());
    ArrayList displayStudySubs = new ArrayList();
    for (int i = 0; i < subjects.size(); i++) {
        StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
        ArrayList groups = (ArrayList) sgmdao.findAllByStudySubject(studySub.getId());
        ArrayList subGClasses = new ArrayList();
        for (int j = 0; j < studyGroupClasses.size(); j++) {
            StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(j);
            boolean hasClass = false;
            for (int k = 0; k < groups.size(); k++) {
                SubjectGroupMapBean sgmb = (SubjectGroupMapBean) groups.get(k);
                if (sgmb.getGroupClassName().equalsIgnoreCase(sgc.getName())) {
                    subGClasses.add(sgmb);
                    hasClass = true;
                    break;
                }
            }
            if (!hasClass) {
                subGClasses.add(new SubjectGroupMapBean());
            }
        }
        // find all eventcrfs for each event, for each event tab
        ArrayList displaySubjectEvents = new ArrayList();
        ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
        ArrayList events = sedao.findAllByStudySubjectAndDefinition(studySub, sed);
        for (int k = 0; k < events.size(); k++) {
            StudyEventBean seb = (StudyEventBean) events.get(k);
            DisplayStudyEventBean dseb = ListStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, seb, sm.getDataSource(), ub, currentRole, this.currentStudy);
            // ArrayList eventCRFs = ecdao.findAllByStudyEvent(seb);
            // ArrayList al =
            // ViewStudySubjectServlet.getUncompletedCRFs(sm.getDataSource(),
            // eventDefinitionCRFs, eventCRFs);
            // dseb.getUncompletedCRFs().add(al);
            displayEvents.add(dseb);
        }
        ArrayList al = new ArrayList();
        for (int k = 0; k < displayEvents.size(); k++) {
            DisplayStudyEventBean dseb = displayEvents.get(k);
            ArrayList eventCRFs = dseb.getDisplayEventCRFs();
            for (int a = 0; a < eventDefinitionCRFs.size(); a++) {
                EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(a);
                int crfId = edc.getCrfId();
                boolean hasCRF = false;
                for (int b = 0; b < eventCRFs.size(); b++) {
                    DisplayEventCRFBean decb = (DisplayEventCRFBean) eventCRFs.get(b);
                    // decb.getStage().getName() );
                    if (decb.getEventCRF().getCrf().getId() == crfId) {
                        dseb.getAllEventCRFs().add(decb);
                        // logger.info("hasCRf" + crfId +
                        // decb.getEventCRF().getCrf().getName());
                        hasCRF = true;
                        break;
                    }
                }
                if (hasCRF == false) {
                    DisplayEventCRFBean db = new DisplayEventCRFBean();
                    db.setEventDefinitionCRF(edc);
                    db.getEventDefinitionCRF().setCrf(edc.getCrf());
                    dseb.getAllEventCRFs().add(db);
                // logger.info("noCRf" + crfId);
                }
            }
            // Issue 3212 BWP <<
            if (currentStudy.getParentStudyId() > 0) {
                // check each eventDefCRFBean and set its isHidden property
                // to true, if its
                // persistent/database-derived hideCrf is true (domain rule:
                // hide the CRF from users logged into a site)
                HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
                hideCRFManager.optionallyCheckHideCRFProperty(dseb);
                // remove a DisplayEventCRFBean from a DisplayStudyEventBean
                // in the list
                // if it contains a hidden CRF in its event definition
                hideCRFManager.removeHiddenEventCRF(dseb);
                // generate a boolean request attribute indicating whether
                // any of the CRFs
                // should be hidden
                boolean hideCRFs = hideCRFManager.studyEventHasAHideCRFProperty(dseb);
                request.setAttribute("hideCRFs", hideCRFs);
            }
        // >>
        }
        DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
        dssb.setStudySubject(studySub);
        dssb.setStudyGroups(subGClasses);
        dssb.setStudyEvents(displayEvents);
        if (definitionId > 0) {
            dssb.setSedId(definitionId);
        } else {
            dssb.setSedId(-1);
        }
        displayStudySubs.add(dssb);
    }
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allStudyRows = DisplayStudySubjectEventsRow.generateRowsFromBeans(displayStudySubs);
    ArrayList columnArray = new ArrayList();
    columnArray.add(resword.getString("ID"));
    columnArray.add(resword.getString("subject_status"));
    columnArray.add(resword.getString("gender"));
    for (int i = 0; i < studyGroupClasses.size(); i++) {
        StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
        columnArray.add(sgc.getName());
    }
    // columnArray.add("Event Sequence");
    columnArray.add(resword.getString("event_status"));
    columnArray.add(resword.getString("event_date"));
    // Issue 3212 BWP <<
    HideCRFManager hideCRFMgr = HideCRFManager.createHideCRFManager();
    hideCRFMgr.hideSpecifiedEventCRFDefBeans(eventDefinitionCRFs);
    for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
        EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
        // Issue 3212 BWP <<
        if (!(currentStudy.getParentStudyId() > 0)) {
            columnArray.add(edc.getCrf().getName());
        } else {
            if (!edc.isHideCrf()) {
                columnArray.add(edc.getCrf().getName());
            }
        }
    // >>
    }
    columnArray.add(resword.getString("actions"));
    String[] columns = new String[columnArray.size()];
    columnArray.toArray(columns);
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.setQuery("ListEventsForSubject?module=" + module + "&defId=" + definitionId + "&tab=" + tabId, new HashMap());
    table.hideColumnLink(columnArray.size() - 1);
    // if(currentStudy.getStatus().isAvailable()){
    // table.addLink(resword.getString("add_new_subject"), "AddNewSubject");
    // }
    table.setRows(allStudyRows);
    if (filterKeyword != null && !"".equalsIgnoreCase(filterKeyword)) {
        table.setKeywordFilter(filterKeyword);
    }
    table.computeDisplay();
    request.setAttribute("table", table);
    forwardPage(Page.LIST_EVENTS_FOR_SUBJECT);
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) HashMap(java.util.HashMap) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) 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) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) 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) SubjectGroupMapDAO(org.akaza.openclinica.dao.submit.SubjectGroupMapDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) HideCRFManager(org.akaza.openclinica.service.crfdata.HideCRFManager) 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) DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 5 with DisplayStudySubjectBean

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

the class DisplayStudySubjectRow method compareColumn.

// YW >>
/*
     * (non-Javadoc)
     *
     * @see org.akaza.openclinica.core.EntityBeanRow#compareColumn(java.lang.Object,
     *      int)
     */
@Override
protected int compareColumn(Object row, int sortingColumn) {
    if (!row.getClass().equals(DisplayStudySubjectRow.class)) {
        return 0;
    }
    DisplayStudySubjectBean thisStudy = (DisplayStudySubjectBean) bean;
    DisplayStudySubjectBean argStudy = (DisplayStudySubjectBean) ((DisplayStudySubjectRow) row).bean;
    int answer = 0;
    // YW <<
    int groupSize = thisStudy.getStudyGroups().size();
    int code;
    if (sortingColumn > 4 + groupSize) {
        if (thisStudy.getSedId() <= 0) {
            code = COL_STUDYEVENT;
        } else {
            code = -1;
        }
    } else if (sortingColumn > 4 && sortingColumn <= 4 + groupSize) {
        code = COL_STUDYGROUP;
    } else {
        code = sortingColumn;
    }
    switch(code) {
        // break;
        case COL_SUBJECT_LABEL:
            answer = thisStudy.getStudySubject().getLabel().toLowerCase().compareTo(argStudy.getStudySubject().getLabel().toLowerCase());
            break;
        case COL_GENDER:
            answer = (thisStudy.getStudySubject().getGender() + "").compareTo(argStudy.getStudySubject().getGender() + "");
            break;
        case COL_OID:
            answer = thisStudy.getStudySubject().getOid().toLowerCase().compareTo(argStudy.getStudySubject().getOid().toLowerCase());
            break;
        case COL_SECONDARY_LABEL:
            answer = thisStudy.getStudySubject().getSecondaryLabel().toLowerCase().compareTo(argStudy.getStudySubject().getSecondaryLabel().toLowerCase());
            break;
        /*
         * case COL_ENROLLMENTDATE: answer =
         * compareDate(thisStudy.getStudySubject().getEnrollmentDate(),argStudy.getStudySubject().getEnrollmentDate());
         * break;
         */
        case COL_STATUS:
            answer = thisStudy.getStudySubject().getStatus().compareTo(argStudy.getStudySubject().getStatus());
            break;
        // YW <<
        case COL_STUDYGROUP:
            answer = ((SubjectGroupMapBean) thisStudy.getStudyGroups().get(sortingColumn - 5)).getStudyGroupName().toLowerCase().compareTo(((SubjectGroupMapBean) argStudy.getStudyGroups().get(sortingColumn - 5)).getStudyGroupName().toLowerCase());
            break;
        case COL_STUDYEVENT:
            // studyEvent status comparision
            SubjectEventStatus thisSes = ((StudyEventBean) thisStudy.getStudyEvents().get(sortingColumn - 5 - groupSize)).getSubjectEventStatus();
            SubjectEventStatus argSes = ((StudyEventBean) argStudy.getStudyEvents().get(sortingColumn - 5 - groupSize)).getSubjectEventStatus();
            /*Subject event status is ordered in this sequence Not Started=2,Scheduled=1,Data Entry Started=3,
              Stopped=5,Skipped=6, Completed=4,Locked=7,Signed=8*/
            switch(thisSes.getId()) {
                //SubjectEventStatus.SCHEDULED
                case 1:
                    if (thisSes.getId() == argSes.getId()) {
                        answer = 0;
                    } else if (argSes.getId() == 2) {
                        answer = 1;
                    } else {
                        answer = -1;
                    }
                    break;
                //SubjectEventStatus.NOT_SCHEDULED
                case 2:
                    if (thisSes.getId() == argSes.getId()) {
                        answer = 0;
                    } else {
                        answer = -1;
                    }
                    break;
                //SubjectEventStatus.DATA_ENTRY_STARTED
                case 3:
                    if (thisSes.getId() == argSes.getId()) {
                        answer = 0;
                    } else if (argSes.getId() == 1 || argSes.getId() == 2) {
                        answer = 1;
                    } else {
                        answer = -1;
                    }
                    break;
                //SubjectEventStatus.COMPLETED
                case 4:
                    if (thisSes.getId() == argSes.getId()) {
                        answer = 0;
                    } else if (argSes.getId() == 7 || argSes.getId() == 8) {
                        answer = -1;
                    } else {
                        answer = 1;
                    }
                    break;
                //SubjectEventStatus.STOPPED
                case 5:
                    if (thisSes.getId() == argSes.getId()) {
                        answer = 0;
                    } else if (argSes.getId() == 1 || argSes.getId() == 2 || argSes.getId() == 3) {
                        answer = 1;
                    } else {
                        answer = -1;
                    }
                    break;
                //SubjectEventStatus.SKIPPED
                case 6:
                    if (thisSes.getId() == argSes.getId()) {
                        answer = 0;
                    } else if (argSes.getId() == 4 || argSes.getId() == 7 || argSes.getId() == 8) {
                        answer = -1;
                    } else {
                        answer = 1;
                    }
                    break;
                //SubjectEventStatus.LOCKED
                case 7:
                    if (thisSes.getId() == argSes.getId()) {
                        answer = 0;
                    } else if (argSes.getId() == 8) {
                        answer = -1;
                    } else {
                        answer = 1;
                    }
                    break;
                //SubjectEventStatus.SIGNED
                case 8:
                    if (thisSes.getId() == argSes.getId()) {
                        answer = 0;
                    } else {
                        answer = 1;
                    }
                default:
                    answer = 1;
            }
    }
    return answer;
}
Also used : DisplayStudySubjectBean(org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus)

Aggregations

DisplayStudySubjectBean (org.akaza.openclinica.bean.managestudy.DisplayStudySubjectBean)6 ArrayList (java.util.ArrayList)3 DisplayStudyEventBean (org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean)3 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)3 HashMap (java.util.HashMap)2 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)2 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)2 StudyGroupClassBean (org.akaza.openclinica.bean.managestudy.StudyGroupClassBean)2 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)2 SubjectGroupMapBean (org.akaza.openclinica.bean.submit.SubjectGroupMapBean)2 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)2 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)2 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)2 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)2 StudyGroupClassDAO (org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO)2 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)2 SubjectGroupMapDAO (org.akaza.openclinica.dao.submit.SubjectGroupMapDAO)2 EntityBeanTable (org.akaza.openclinica.web.bean.EntityBeanTable)2 Iterator (java.util.Iterator)1 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)1