Search in sources :

Example 1 with FindSubjectsFilter

use of org.akaza.openclinica.dao.managestudy.FindSubjectsFilter in project OpenClinica by OpenClinica.

the class ListStudySubjectTableFactory method setDataAndLimitVariables.

@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
    Limit limit = tableFacade.getLimit();
    FindSubjectsFilter subjectFilter = getSubjectFilter(limit);
    if (!limit.isComplete()) {
        int totalRows = getStudySubjectDAO().getCountWithFilter(subjectFilter, getStudyBean());
        tableFacade.setTotalRows(totalRows);
    }
    FindSubjectsSort subjectSort = getSubjectSort(limit);
    int rowStart = limit.getRowSelect().getRowStart();
    int rowEnd = limit.getRowSelect().getRowEnd();
    Collection<StudySubjectBean> items = getStudySubjectDAO().getWithFilterAndSort(getStudyBean(), subjectFilter, subjectSort, rowStart, rowEnd);
    Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
    for (StudySubjectBean studySubjectBean : items) {
        HashMap<Object, Object> theItem = new HashMap<Object, Object>();
        theItem.put("studySubject", studySubjectBean);
        theItem.put("studySubject.label", studySubjectBean.getLabel());
        theItem.put("studySubject.status", studySubjectBean.getStatus());
        theItem.put("enrolledAt", ((StudyBean) getStudyDAO().findByPK(studySubjectBean.getStudyId())).getIdentifier());
        theItem.put("studySubject.oid", studySubjectBean.getOid());
        theItem.put("studySubject.secondaryLabel", studySubjectBean.getSecondaryLabel());
        SubjectBean subjectBean = (SubjectBean) getSubjectDAO().findByPK(studySubjectBean.getSubjectId());
        theItem.put("subject", subjectBean);
        theItem.put("subject.charGender", subjectBean.getGender());
        // Get All study events for this study subject and then put list in
        // HashMap with study event definition id as
        // key and a list of study events as the value.
        List<StudyEventBean> allStudyEventsForStudySubject = getStudyEventDAO().findAllByStudySubject(studySubjectBean);
        HashMap<Integer, List<StudyEventBean>> allStudyEventsForStudySubjectBySedId = new HashMap<Integer, List<StudyEventBean>>();
        theItem.put("isSignable", isSignable(allStudyEventsForStudySubject, studySubjectBean));
        for (StudyEventBean studyEventBean : allStudyEventsForStudySubject) {
            if (allStudyEventsForStudySubjectBySedId.get(studyEventBean.getStudyEventDefinitionId()) == null) {
                ArrayList<StudyEventBean> a = new ArrayList<StudyEventBean>();
                a.add(studyEventBean);
                allStudyEventsForStudySubjectBySedId.put(studyEventBean.getStudyEventDefinitionId(), a);
            } else {
                allStudyEventsForStudySubjectBySedId.get(studyEventBean.getStudyEventDefinitionId()).add(studyEventBean);
            }
        }
        SubjectGroupMapBean subjectGroupMapBean;
        for (StudyGroupClassBean studyGroupClass : getStudyGroupClasses()) {
            subjectGroupMapBean = getSubjectGroupMapDAO().findAllByStudySubjectAndStudyGroupClass(studySubjectBean.getId(), studyGroupClass.getId());
            if (null != subjectGroupMapBean) {
                theItem.put("sgc_" + studyGroupClass.getId(), subjectGroupMapBean.getStudyGroupId());
                theItem.put("grpName_sgc_" + studyGroupClass.getId(), subjectGroupMapBean.getStudyGroupName());
            }
        }
        subjectGroupMapBean = null;
        for (StudyEventDefinitionBean studyEventDefinition : getStudyEventDefinitions()) {
            List<StudyEventBean> studyEvents = allStudyEventsForStudySubjectBySedId.get(studyEventDefinition.getId());
            SubjectEventStatus subjectEventStatus = null;
            studyEvents = studyEvents == null ? new ArrayList<StudyEventBean>() : studyEvents;
            if (studyEvents.size() < 1) {
                subjectEventStatus = SubjectEventStatus.NOT_SCHEDULED;
            } else {
                for (StudyEventBean studyEventBean : studyEvents) {
                    if (studyEventBean.getSampleOrdinal() == 1) {
                        subjectEventStatus = studyEventBean.getSubjectEventStatus();
                        break;
                    }
                }
            }
            theItem.put("sed_" + studyEventDefinition.getId(), subjectEventStatus.getId());
            theItem.put("sed_" + studyEventDefinition.getId() + "_studyEvents", studyEvents);
            theItem.put("sed_" + studyEventDefinition.getId() + "_object", studyEventDefinition);
        }
        theItems.add(theItem);
    }
    // Do not forget to set the items back on the tableFacade.
    tableFacade.setItems(theItems);
}
Also used : SubjectGroupMapBean(org.akaza.openclinica.bean.submit.SubjectGroupMapBean) FindSubjectsSort(org.akaza.openclinica.dao.managestudy.FindSubjectsSort) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) List(java.util.List) ArrayList(java.util.ArrayList) Limit(org.jmesa.limit.Limit) FindSubjectsFilter(org.akaza.openclinica.dao.managestudy.FindSubjectsFilter)

Example 2 with FindSubjectsFilter

use of org.akaza.openclinica.dao.managestudy.FindSubjectsFilter in project OpenClinica by OpenClinica.

the class ListStudySubjectTableFactory method getSubjectFilter.

protected FindSubjectsFilter getSubjectFilter(Limit limit) {
    FindSubjectsFilter auditUserLoginFilter = new FindSubjectsFilter();
    FilterSet filterSet = limit.getFilterSet();
    Collection<Filter> filters = filterSet.getFilters();
    for (Filter filter : filters) {
        String property = filter.getProperty();
        String value = filter.getValue();
        if ("studySubject.status".equalsIgnoreCase(property)) {
            value = Status.getByName(value).getId() + "";
        } else if (property.startsWith("sgc_")) {
            int studyGroupClassId = property.endsWith("_") ? 0 : Integer.valueOf(property.split("_")[1]);
            value = studyGroupDAO.findByNameAndGroupClassID(value, studyGroupClassId).getId() + "";
        }
        auditUserLoginFilter.addFilter(property, value);
    }
    return auditUserLoginFilter;
}
Also used : FilterSet(org.jmesa.limit.FilterSet) FindSubjectsFilter(org.akaza.openclinica.dao.managestudy.FindSubjectsFilter) Filter(org.jmesa.limit.Filter) FindSubjectsFilter(org.akaza.openclinica.dao.managestudy.FindSubjectsFilter)

Aggregations

FindSubjectsFilter (org.akaza.openclinica.dao.managestudy.FindSubjectsFilter)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 SubjectEventStatus (org.akaza.openclinica.bean.core.SubjectEventStatus)1 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)1 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)1 StudyGroupClassBean (org.akaza.openclinica.bean.managestudy.StudyGroupClassBean)1 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)1 SubjectBean (org.akaza.openclinica.bean.submit.SubjectBean)1 SubjectGroupMapBean (org.akaza.openclinica.bean.submit.SubjectGroupMapBean)1 FindSubjectsSort (org.akaza.openclinica.dao.managestudy.FindSubjectsSort)1 Filter (org.jmesa.limit.Filter)1 FilterSet (org.jmesa.limit.FilterSet)1 Limit (org.jmesa.limit.Limit)1