Search in sources :

Example 11 with AuditableEntityBean

use of org.akaza.openclinica.bean.core.AuditableEntityBean in project OpenClinica by OpenClinica.

the class DiscrepancyNoteOutputServlet method populateRowsWithAttachedData.

private ArrayList<DiscrepancyNoteBean> populateRowsWithAttachedData(ArrayList<DiscrepancyNoteBean> noteRows) {
    Locale l = LocaleResolver.getLocale(request);
    resword = ResourceBundleProvider.getWordsBundle(l);
    resformat = ResourceBundleProvider.getFormatBundle(l);
    SimpleDateFormat sdf = new SimpleDateFormat(resformat.getString("date_format_string"), ResourceBundleProvider.getLocale());
    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(sm.getDataSource());
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    StudyDAO studyDao = new StudyDAO(sm.getDataSource());
    ItemGroupMetadataDAO<String, ArrayList> igmdao = new ItemGroupMetadataDAO<String, ArrayList>(sm.getDataSource());
    ItemGroupDAO<String, ArrayList> igdao = new ItemGroupDAO<String, ArrayList>(sm.getDataSource());
    ArrayList<DiscrepancyNoteBean> allNotes = new ArrayList<DiscrepancyNoteBean>();
    for (int i = 0; i < noteRows.size(); i++) {
        DiscrepancyNoteBean dnb = noteRows.get(i);
        dnb.setCreatedDateString(dnb.getCreatedDate() == null ? "" : sdf.format(dnb.getCreatedDate()));
        if (dnb.getParentDnId() == 0) {
            ArrayList children = dndao.findAllByStudyAndParent(currentStudy, dnb.getId());
            children = children == null ? new ArrayList() : children;
            dnb.setNumChildren(children.size());
            dnb.setChildren(children);
            int lastDnId = dnb.getId();
            int lastChild = 0;
            for (int j = 0; j < children.size(); j++) {
                DiscrepancyNoteBean child = (DiscrepancyNoteBean) children.get(j);
                child.setCreatedDateString(child.getCreatedDate() == null ? "" : sdf.format(child.getCreatedDate()));
                child.setUpdatedDateString(child.getCreatedDate() != null ? sdf.format(child.getCreatedDate()) : "");
                if (child.getId() > lastDnId) {
                    lastDnId = child.getId();
                    lastChild = j;
                }
            }
            if (children.size() > 0) {
                DiscrepancyNoteBean lastdn = (DiscrepancyNoteBean) children.get(lastChild);
                //dnb.setResStatus(ResolutionStatus.get(lastdn.getResolutionStatusId()));
                /*
                     * The update date is the date created of the latest child
                     * note
                     */
                dnb.setUpdatedDate(lastdn.getCreatedDate());
                dnb.setUpdatedDateString(dnb.getUpdatedDate() != null ? sdf.format(dnb.getUpdatedDate()) : "");
            }
        }
        String entityType = dnb.getEntityType();
        if (dnb.getEntityId() > 0 && !entityType.equals("")) {
            AuditableEntityBean aeb = dndao.findEntity(dnb);
            dnb.setEntityName(aeb.getName());
            if (entityType.equalsIgnoreCase("subject")) {
                //                    allNotes.add(dnb);
                SubjectBean sb = (SubjectBean) aeb;
                StudySubjectBean ssb = studySubjectDAO.findBySubjectIdAndStudy(sb.getId(), currentStudy);
                dnb.setStudySub(ssb);
                dnb.setSubjectName(ssb.getLabel());
                String column = dnb.getColumn().trim();
                if (!StringUtil.isBlank(column)) {
                    if ("gender".equalsIgnoreCase(column)) {
                        dnb.setEntityValue(sb.getGender() + "");
                        dnb.setEntityName(resword.getString("gender"));
                    } else if ("date_of_birth".equals(column)) {
                        if (sb.getDateOfBirth() != null) {
                            dnb.setEntityValue(sb.getDateOfBirth().toString());
                        }
                        dnb.setEntityName(resword.getString("date_of_birth"));
                    } else if ("unique_identifier".equalsIgnoreCase(column)) {
                        dnb.setEntityName(resword.getString("unique_identifier"));
                        dnb.setEntityValue(sb.getUniqueIdentifier());
                    }
                }
            } else if (entityType.equalsIgnoreCase("studySub")) {
                //                    allNotes.add(dnb);
                StudySubjectBean ssb = (StudySubjectBean) aeb;
                dnb.setStudySub(ssb);
                dnb.setSubjectName(ssb.getLabel());
                String column = dnb.getColumn().trim();
                if (!StringUtil.isBlank(column)) {
                    if ("enrollment_date".equals(column)) {
                        if (ssb.getEnrollmentDate() != null) {
                            dnb.setEntityValue(ssb.getEnrollmentDate().toString());
                        }
                        dnb.setEntityName(resword.getString("enrollment_date"));
                    }
                }
            } else if (entityType.equalsIgnoreCase("eventCRF")) {
                StudyEventBean se = (StudyEventBean) sedao.findByPK(dnb.getEntityId());
                StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
                EventCRFBean ecb = (EventCRFBean) aeb;
                CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
                CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
                dnb.setStageId(ecb.getStage().getId());
                dnb.setEntityName(cb.getName() + " (" + cvb.getName() + ")");
                StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(ecb.getStudySubjectId());
                dnb.setStudySub(ssub);
                dnb.setSubjectName(ssub.getLabel());
                if (se != null) {
                    dnb.setEventStart(se.getDateStarted());
                    dnb.setEventName(se.getName());
                }
                dnb.setCrfName(cb.getName());
                String crfStatus = resword.getString(ecb.getStage().getNameRaw());
                if (crfStatus.equals("Invalid")) {
                    crfStatus = "";
                } else if (crfStatus.equals("Data Entry Complete")) {
                    crfStatus = "Complete";
                }
                dnb.setCrfStatus(crfStatus);
                String column = dnb.getColumn().trim();
                if (!StringUtil.isBlank(column)) {
                    if ("date_interviewed".equals(column)) {
                        if (ecb.getDateInterviewed() != null) {
                            dnb.setEntityValue(ecb.getDateInterviewed().toString());
                        }
                        dnb.setEntityName(resword.getString("date_interviewed"));
                    } else if ("interviewer_name".equals(column)) {
                        dnb.setEntityValue(ecb.getInterviewerName());
                        dnb.setEntityName(resword.getString("interviewer_name"));
                    }
                }
                dnb.setEvent(se);
                dnb.setStudyEventDefinitionBean(sedb);
            // }
            } else if (entityType.equalsIgnoreCase("studyEvent")) {
                //                    allNotes.add(dnb);
                StudyEventBean se = (StudyEventBean) sedao.findByPK(dnb.getEntityId());
                StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
                se.setName(sedb.getName());
                dnb.setEntityName(sedb.getName());
                StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(se.getStudySubjectId());
                dnb.setStudySub(ssub);
                dnb.setEventStart(se.getDateStarted());
                dnb.setEventName(se.getName());
                dnb.setSubjectName(ssub.getLabel());
                String column = dnb.getColumn().trim();
                if (!StringUtil.isBlank(column)) {
                    if ("date_start".equals(column)) {
                        if (se.getDateStarted() != null) {
                            dnb.setEntityValue(se.getDateStarted().toString());
                        }
                        dnb.setEntityName(resword.getString("start_date"));
                    } else if ("date_end".equals(column)) {
                        if (se.getDateEnded() != null) {
                            dnb.setEntityValue(se.getDateEnded().toString());
                        }
                        dnb.setEntityName(resword.getString("end_date"));
                    } else if ("location".equals(column)) {
                        dnb.setEntityValue(se.getLocation());
                        dnb.setEntityName(resword.getString("location"));
                    }
                }
                dnb.setEvent(se);
                dnb.setStudyEventDefinitionBean(sedb);
            } else if (entityType.equalsIgnoreCase("itemData")) {
                ItemDataBean idb = (ItemDataBean) iddao.findByPK(dnb.getEntityId());
                ItemBean ib = (ItemBean) idao.findByPK(idb.getItemId());
                EventCRFBean ec = (EventCRFBean) ecdao.findByPK(idb.getEventCRFId());
                CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
                CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
                ItemGroupMetadataBean itemGroupMetadataBean = (ItemGroupMetadataBean) igmdao.findByItemAndCrfVersion(ib.getId(), cvb.getId());
                Boolean isRepeatForSure = itemGroupMetadataBean.isRepeatingGroup();
                if (isRepeatForSure) {
                    ItemGroupBean ig = (ItemGroupBean) igdao.findByPK(itemGroupMetadataBean.getItemGroupId());
                    dnb.setItemDataOrdinal(idb.getOrdinal());
                    dnb.setItemGroupName(ig.getName());
                }
                //                    allNotes.add(dnb);
                dnb.setStageId(ec.getStage().getId());
                dnb.setEntityName(ib.getName());
                dnb.setEntityValue(idb.getValue());
                StudyEventBean se = (StudyEventBean) sedao.findByPK(ec.getStudyEventId());
                StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
                se.setName(sedb.getName());
                StudySubjectBean ssub = (StudySubjectBean) studySubjectDAO.findByPK(ec.getStudySubjectId());
                dnb.setStudySub(ssub);
                dnb.setSubjectName(ssub.getLabel());
                dnb.setEventStart(se.getDateStarted());
                dnb.setEventName(se.getName());
                dnb.setCrfName(cb.getName());
                String crfStatus = resword.getString(ec.getStage().getNameRaw());
                if (crfStatus.equals("Invalid")) {
                    crfStatus = "";
                } else if (crfStatus.equals("Data Entry Complete")) {
                    crfStatus = "Complete";
                }
                dnb.setCrfStatus(crfStatus);
                dnb.setEvent(se);
                dnb.setStudyEventDefinitionBean(sedb);
            }
        }
        dnb.setStudy((StudyBean) studyDao.findByPK(dnb.getStudyId()));
        if (dnb.getParentDnId() == 0 && dnb.getChildren().size() > 0) {
            ArrayList<DiscrepancyNoteBean> children = dnb.getChildren();
            int childrenSize = children.size();
            for (int j = 0; j < childrenSize; j++) {
                DiscrepancyNoteBean child = children.get(j);
                child.setSubjectName(dnb.getSubjectName());
                child.setEventName(dnb.getEventName());
                child.setCrfName(dnb.getCrfName());
                child.setCrfStatus(dnb.getCrfStatus());
                child.setEntityName(dnb.getEntityName());
                child.setEntityValue(dnb.getEntityValue());
                child.setStudySub(dnb.getStudySub());
                child.setStudy(dnb.getStudy());
            }
        }
        allNotes.add(dnb);
    }
    return allNotes;
}
Also used : Locale(java.util.Locale) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

AuditableEntityBean (org.akaza.openclinica.bean.core.AuditableEntityBean)11 ArrayList (java.util.ArrayList)6 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)6 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)6 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)6 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)6 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)5 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)4 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)4 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)4 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)4 Date (java.util.Date)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 EntityBean (org.akaza.openclinica.bean.core.EntityBean)3 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)3 DisplayEventCRFBean (org.akaza.openclinica.bean.submit.DisplayEventCRFBean)2 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)2 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)2 InconsistentStateException (org.akaza.openclinica.web.InconsistentStateException)2