Search in sources :

Example 91 with ItemBean

use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.

the class CRFVersionDAO method findNotSharedItemsByVersion.

public ArrayList findNotSharedItemsByVersion(int versionId) {
    this.unsetTypeExpected();
    this.setTypeExpected(1, TypeNames.INT);
    this.setTypeExpected(2, TypeNames.STRING);
    this.setTypeExpected(3, TypeNames.INT);
    HashMap variables = new HashMap();
    variables.put(new Integer(1), new Integer(versionId));
    variables.put(new Integer(2), new Integer(versionId));
    String sql = digester.getQuery("findNotSharedItemsByVersion");
    ArrayList alist = this.select(sql, variables);
    ArrayList al = new ArrayList();
    Iterator it = alist.iterator();
    while (it.hasNext()) {
        ItemBean eb = new ItemBean();
        HashMap hm = (HashMap) it.next();
        eb.setId(((Integer) hm.get("item_id")).intValue());
        eb.setName((String) hm.get("name"));
        eb.setOwnerId(((Integer) hm.get("owner_id")).intValue());
        al.add(eb);
    }
    return al;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 92 with ItemBean

use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.

the class OpenClinicaVariableNode method testCalculate.

@Override
String testCalculate() throws OpenClinicaSystemException {
    validate();
    String variableValue = testCalculateVariable();
    boolean isEventStatusParamExist = number.endsWith(STATUS);
    boolean isEventStartDateParamExist = number.endsWith(STARTDATE);
    boolean isEventStartDateAndStatusParamExist = (number.endsWith(STARTDATE) || number.endsWith(STATUS));
    if (variableValue != null) {
        return variableValue;
    }
    ItemBean item = getExpressionService().getItemBeanFromExpression(number);
    String testString = "test";
    String testInt = "1";
    String testBoolean = "true";
    String testDate = "2008-01-01";
    String testPDate = "";
    if (item != null) {
        ItemDataType itemDataType = ItemDataType.get(item.getItemDataTypeId());
        switch(itemDataType.getId()) {
            case 1:
                {
                    return theTest(testBoolean);
                }
            case 2:
                {
                    return theTest(testBoolean);
                }
            case 3:
                {
                    return theTest(testString);
                }
            case 4:
                {
                    return theTest(testString);
                }
            case 5:
                {
                    return theTest(testString);
                }
            case 6:
                {
                    return theTest(testInt);
                }
            case 7:
                {
                    return theTest(testInt);
                }
            case 8:
                {
                    return theTest(testString);
                }
            case 9:
                {
                    return theTest(testDate);
                }
            case 10:
                {
                    return theTest(testPDate);
                }
            case 11:
                {
                    return theTest(testString + ".txt");
                }
            default:
                throw new OpenClinicaSystemException("OCRERR_0011");
        }
    } else if (isEventStartDateAndStatusParamExist) {
        if (isEventStatusParamExist)
            return theTest(testString);
        else if (isEventStartDateParamExist)
            return theTest(testDate);
        else
            return null;
    } else {
        throw new OpenClinicaSystemException("OCRERR_0012", new String[] { number });
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Example 93 with ItemBean

use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.

the class CreateCRFVersionServlet method isItemSame.

/**
     * Checks whether the item with same name has the same other fields: units, phi_status if no, they are two different
     * items, cannot have the same same
     * 
     * @param items
     *            items from excel
     * @return the items found
     */
private ArrayList isItemSame(HashMap items, CRFVersionBean version) {
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    ArrayList diffItems = new ArrayList();
    Set names = items.keySet();
    Iterator it = names.iterator();
    while (it.hasNext()) {
        String name = (String) it.next();
        ItemBean newItem = (ItemBean) idao.findByNameAndCRFId(name, version.getCrfId());
        ItemBean item = (ItemBean) items.get(name);
        if (newItem.getId() > 0) {
            if (!item.getUnits().equalsIgnoreCase(newItem.getUnits()) || item.isPhiStatus() != newItem.isPhiStatus() || item.getDataType().getId() != newItem.getDataType().getId() || !item.getDescription().equalsIgnoreCase(newItem.getDescription())) {
                logger.debug("found two items with same name but different units/phi/datatype/description");
                diffItems.add(newItem);
            }
        }
    }
    return diffItems;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) Set(java.util.Set) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator)

Example 94 with ItemBean

use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.

the class CreateCRFVersionServlet method canDeleteVersion.

/**
     * Checks whether the version can be deleted
     * 
     * @param previousVersionId
     * @return
     */
private boolean canDeleteVersion(int previousVersionId) {
    CRFVersionDAO cdao = new CRFVersionDAO(sm.getDataSource());
    ArrayList items = null;
    ArrayList itemsHaveData = new ArrayList();
    // boolean isItemUsedByOtherVersion =
    // cdao.isItemUsedByOtherVersion(previousVersionId);
    // if (isItemUsedByOtherVersion) {
    // ArrayList itemsUsedByOtherVersion = (ArrayList)
    // cdao.findItemUsedByOtherVersion(previousVersionId);
    // session.setAttribute("itemsUsedByOtherVersion",itemsUsedByOtherVersion);
    // return false;
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ArrayList events = ecdao.findAllByCRFVersion(previousVersionId);
    if (!events.isEmpty()) {
        session.setAttribute("eventsForVersion", events);
        return false;
    }
    items = cdao.findNotSharedItemsByVersion(previousVersionId);
    for (int i = 0; i < items.size(); i++) {
        ItemBean item = (ItemBean) items.get(i);
        if (ub.getId() != item.getOwner().getId()) {
            logger.debug("not owner" + item.getOwner().getId() + "<>" + ub.getId());
            return false;
        }
        if (cdao.hasItemData(item.getId())) {
            itemsHaveData.add(item);
            logger.debug("item has data");
            session.setAttribute("itemsHaveData", itemsHaveData);
            return false;
        }
    }
    // user is the owner and item not have data,
    // delete previous version with non-shared items
    NewCRFBean nib = (NewCRFBean) session.getAttribute("nib");
    nib.setDeleteQueries(cdao.generateDeleteQueries(previousVersionId, items));
    session.setAttribute("nib", nib);
    return true;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ArrayList(java.util.ArrayList) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 95 with ItemBean

use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.

the class ViewNoteServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    Locale locale = LocaleResolver.getLocale(request);
    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
    dndao.setFetchMapping(true);
    int noteId = fp.getInt(NOTE_ID, true);
    DiscrepancyNoteBean note = (DiscrepancyNoteBean) dndao.findByPK(noteId);
    String entityType = note.getEntityType();
    if (note.getEntityId() > 0 && !entityType.equals("")) {
        if (!StringUtil.isBlank(entityType)) {
            if ("itemData".equalsIgnoreCase(entityType)) {
                ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
                ItemDataBean itemData = (ItemDataBean) iddao.findByPK(note.getEntityId());
                ItemDAO idao = new ItemDAO(sm.getDataSource());
                ItemBean item = (ItemBean) idao.findByPK(itemData.getItemId());
                note.setEntityValue(itemData.getValue());
                note.setEntityName(item.getName());
                //Mantis Issue 5165. It should be itemData.getId() instead of item.getId()
                note.setEntityId(itemData.getId());
                EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
                EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
                StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
                StudyEventBean se = (StudyEventBean) sed.findByPK(ec.getStudyEventId());
                StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
                StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
                note.setStudySub(ssub);
                StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
                StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
                se.setName(sedb.getName());
                note.setEvent(se);
                CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
                CRFVersionBean cv = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
                CRFDAO cdao = new CRFDAO(sm.getDataSource());
                CRFBean crf = (CRFBean) cdao.findByPK(cv.getCrfId());
                note.setCrfName(crf.getName());
            } else if ("studySub".equalsIgnoreCase(entityType)) {
                StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
                StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(note.getEntityId());
                note.setStudySub(ssub);
                // System.out.println("column" + note.getColumn());
                SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
                SubjectBean sub = (SubjectBean) sdao.findByPK(ssub.getSubjectId());
                if (!StringUtil.isBlank(note.getColumn())) {
                    if ("enrollment_date".equalsIgnoreCase(note.getColumn())) {
                        if (ssub.getEnrollmentDate() != null) {
                            note.setEntityValue(dateFormatter.format(ssub.getEnrollmentDate()));
                        }
                        note.setEntityName(resword.getString("enrollment_date"));
                    } else if ("gender".equalsIgnoreCase(note.getColumn())) {
                        note.setEntityValue(sub.getGender() + "");
                        note.setEntityName(resword.getString("gender"));
                    } else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
                        if (sub.getDateOfBirth() != null) {
                            note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
                        }
                        note.setEntityName(resword.getString("date_of_birth"));
                    }
                }
            } else if ("subject".equalsIgnoreCase(entityType)) {
                SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
                SubjectBean sub = (SubjectBean) sdao.findByPK(note.getEntityId());
                StudySubjectBean ssub = new StudySubjectBean();
                ssub.setLabel(sub.getUniqueIdentifier());
                note.setStudySub(ssub);
                if (!StringUtil.isBlank(note.getColumn())) {
                    if ("gender".equalsIgnoreCase(note.getColumn())) {
                        note.setEntityValue(sub.getGender() + "");
                        note.setEntityName(resword.getString("gender"));
                    } else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
                        if (sub.getDateOfBirth() != null) {
                            note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
                        }
                        note.setEntityName(resword.getString("date_of_birth"));
                    } else if ("unique_identifier".equalsIgnoreCase(note.getColumn())) {
                        note.setEntityName(resword.getString("unique_identifier"));
                        note.setEntityValue(sub.getUniqueIdentifier());
                    }
                }
            } else if ("studyEvent".equalsIgnoreCase(entityType)) {
                StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
                StudyEventBean se = (StudyEventBean) sed.findByPK(note.getEntityId());
                StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
                StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
                note.setStudySub(ssub);
                StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
                StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
                se.setName(sedb.getName());
                note.setEvent(se);
                if (!StringUtil.isBlank(note.getColumn())) {
                    if ("location".equalsIgnoreCase(note.getColumn())) {
                        request.setAttribute("entityValue", se.getLocation());
                        request.setAttribute("entityName", resword.getString("location"));
                        note.setEntityName(resword.getString("location"));
                        note.setEntityValue(se.getLocation());
                    } else if ("date_start".equalsIgnoreCase(note.getColumn())) {
                        if (se.getDateStarted() != null) {
                            note.setEntityValue(dateFormatter.format(se.getDateStarted()));
                        }
                        note.setEntityName(resword.getString("start_date"));
                    } else if ("date_end".equalsIgnoreCase(note.getColumn())) {
                        if (se.getDateEnded() != null) {
                            note.setEntityValue(dateFormatter.format(se.getDateEnded()));
                        }
                        note.setEntityName(resword.getString("end_date"));
                    }
                }
            } else if ("eventCrf".equalsIgnoreCase(entityType)) {
                EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
                EventCRFBean ec = (EventCRFBean) ecdao.findByPK(note.getEntityId());
                StudySubjectBean ssub = (StudySubjectBean) new StudySubjectDAO(sm.getDataSource()).findByPK(ec.getStudySubjectId());
                note.setStudySub(ssub);
                StudyEventBean event = (StudyEventBean) new StudyEventDAO(sm.getDataSource()).findByPK(ec.getStudyEventId());
                note.setEvent(event);
                if (!StringUtil.isBlank(note.getColumn())) {
                    if ("date_interviewed".equals(note.getColumn())) {
                        if (ec.getDateInterviewed() != null) {
                            note.setEntityValue(dateFormatter.format(ec.getDateInterviewed()));
                        }
                        note.setEntityName(resword.getString("date_interviewed"));
                    } else if ("interviewer_name".equals(note.getColumn())) {
                        note.setEntityValue(ec.getInterviewerName());
                        note.setEntityName(resword.getString("interviewer_name"));
                    }
                }
            }
        }
    }
    // Mantis Issue 8495.
    if (note.getStudyId() != currentStudy.getId()) {
        if (currentStudy.getParentStudyId() > 0) {
            if (currentStudy.getId() != note.getStudySub().getStudyId()) {
                addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
                forwardPage(Page.MENU_SERVLET);
                return;
            }
        } else {
            // The SubjectStudy is not belong to currentstudy and current study is not a site.
            StudyDAO studydao = new StudyDAO(sm.getDataSource());
            Collection sites;
            sites = studydao.findOlnySiteIdsByStudy(currentStudy);
            if (!sites.contains(note.getStudySub().getStudyId())) {
                addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
                forwardPage(Page.MENU_SERVLET);
                return;
            }
        }
    }
    // Check end
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList<DiscrepancyNoteBean> notes = dndao.findAllEntityByPK(note.getEntityType(), noteId);
    Date lastUpdatedDate = note.getCreatedDate();
    UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
    /*
         * for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
         * (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
         * (pId == 0) { note = n; note.setLastUpdator((UserAccountBean)
         * udao.findByPK(n.getOwnerId()));
         * note.setLastDateUpdated(n.getCreatedDate()); lastUpdatedDate =
         * note.getLastDateUpdated(); lastUpdator = note.getLastUpdator(); } }
         */
    // BWP 3029 >> This algorithm needs to be changed to properly set
    // the parent note's status and updated date
    // First sort the notes on their ID; this will put the parent note
    // first; and
    // the note with the latest status and updated date last
    java.util.Collections.sort(notes);
    DiscrepancyNoteBean lastChild = notes.get(notes.size() - 1);
    lastUpdatedDate = lastChild.getCreatedDate();
    lastUpdator = (UserAccountBean) udao.findByPK(lastChild.getOwnerId());
    note.setLastUpdator(lastUpdator);
    note.setLastDateUpdated(lastUpdatedDate);
    note.setUpdatedDate(lastUpdatedDate);
    for (DiscrepancyNoteBean dnBean : notes) {
        if (dnBean.getParentDnId() > 0) {
            note.getChildren().add(dnBean);
        }
    }
    /*
         * for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
         * (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
         * (pId > 0) { note.getChildren().add(n);
         *
         * if (!n.getCreatedDate().before(lastUpdatedDate)) { lastUpdatedDate =
         * n.getCreatedDate(); lastUpdator = (UserAccountBean)
         * udao.findByPK(n.getOwnerId()); note.setLastUpdator(lastUpdator);
         * note.setLastDateUpdated(lastUpdatedDate);
         * note.setResolutionStatusId(n.getResolutionStatusId());
         * note.setResStatus(ResolutionStatus.get(n.getResolutionStatusId())); } } }
         */
    note.setNumChildren(note.getChildren().size());
    note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
    request.setAttribute(DIS_NOTE, note);
    forwardPage(Page.VIEW_SINGLE_NOTE);
}
Also used : Locale(java.util.Locale) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) DateFormat(java.text.DateFormat) Collection(java.util.Collection) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Aggregations

ItemBean (org.akaza.openclinica.bean.submit.ItemBean)132 ArrayList (java.util.ArrayList)77 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)56 HashMap (java.util.HashMap)50 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)43 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)42 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)36 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)26 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)25 Iterator (java.util.Iterator)23 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)22 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)22 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)21 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)20 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)15 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)15 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)15 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)13 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)13 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)13