Search in sources :

Example 51 with ItemDAO

use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.

the class SecureController method getNoteInfo.

public DiscrepancyNoteBean getNoteInfo(DiscrepancyNoteBean note) {
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    if ("itemData".equalsIgnoreCase(note.getEntityType())) {
        int itemDataId = note.getEntityId();
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        ItemDataBean itemData = (ItemDataBean) iddao.findByPK(itemDataId);
        ItemDAO idao = new ItemDAO(sm.getDataSource());
        if (StringUtil.isBlank(note.getEntityName())) {
            ItemBean item = (ItemBean) idao.findByPK(itemData.getItemId());
            note.setEntityName(item.getName());
            request.setAttribute("item", item);
        }
        EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
        StudyEventDAO svdao = new StudyEventDAO(sm.getDataSource());
        EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
        StudyEventBean event = (StudyEventBean) svdao.findByPK(ec.getStudyEventId());
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
        note.setEventName(sed.getName());
        note.setEventStart(event.getDateStarted());
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        CRFBean crf = cdao.findByVersionId(ec.getCRFVersionId());
        note.setCrfName(crf.getName());
        note.setEventCRFId(ec.getId());
        if (StringUtil.isBlank(note.getSubjectName())) {
            StudySubjectBean ss = (StudySubjectBean) ssdao.findByPK(ec.getStudySubjectId());
            note.setSubjectName(ss.getName());
        }
        if (note.getDiscrepancyNoteTypeId() == 0) {
            // default
            note.setDiscrepancyNoteTypeId(DiscrepancyNoteType.FAILEDVAL.getId());
        // value
        }
    } else if ("eventCrf".equalsIgnoreCase(note.getEntityType())) {
        int eventCRFId = note.getEntityId();
        EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
        StudyEventDAO svdao = new StudyEventDAO(sm.getDataSource());
        EventCRFBean ec = (EventCRFBean) ecdao.findByPK(eventCRFId);
        StudyEventBean event = (StudyEventBean) svdao.findByPK(ec.getStudyEventId());
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
        note.setEventName(sed.getName());
        note.setEventStart(event.getDateStarted());
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        CRFBean crf = cdao.findByVersionId(ec.getCRFVersionId());
        note.setCrfName(crf.getName());
        StudySubjectBean ss = (StudySubjectBean) ssdao.findByPK(ec.getStudySubjectId());
        note.setSubjectName(ss.getName());
        note.setEventCRFId(ec.getId());
    } else if ("studyEvent".equalsIgnoreCase(note.getEntityType())) {
        int eventId = note.getEntityId();
        StudyEventDAO svdao = new StudyEventDAO(sm.getDataSource());
        StudyEventBean event = (StudyEventBean) svdao.findByPK(eventId);
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
        note.setEventName(sed.getName());
        note.setEventStart(event.getDateStarted());
        StudySubjectBean ss = (StudySubjectBean) ssdao.findByPK(event.getStudySubjectId());
        note.setSubjectName(ss.getName());
    } else if ("studySub".equalsIgnoreCase(note.getEntityType())) {
        int studySubjectId = note.getEntityId();
        StudySubjectBean ss = (StudySubjectBean) ssdao.findByPK(studySubjectId);
        note.setSubjectName(ss.getName());
    } else if ("Subject".equalsIgnoreCase(note.getEntityType())) {
        int subjectId = note.getEntityId();
        StudySubjectBean ss = ssdao.findBySubjectIdAndStudy(subjectId, currentStudy);
        note.setSubjectName(ss.getName());
    }
    return note;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) 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) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 52 with ItemDAO

use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.

the class VariableSubstitutionHelper method buildTokensMap.

@SuppressWarnings("unchecked")
private static Map<String, String> buildTokensMap(DisplaySectionBean section, StudySubjectBean studySubject, StudyBean study, StudyEventDefinitionBean eventDef, StudyEventBean event, DataSource dataSource) {
    ItemDAO itemDAO = new ItemDAO(dataSource);
    List<ItemBean> items = itemDAO.findAllWithItemDataByFormLayoutId(section.getCrfVersion().getId(), section.getEventCRF().getId());
    Map<String, String> tokensMap = new HashMap<String, String>();
    tokensMap.put("studySubject", encode(studySubject.getName()));
    if (studySubject.getOid() != null && !studySubject.getOid().isEmpty()) {
        tokensMap.put("studySubjectOID", encode(studySubject.getOid()));
    } else
        tokensMap.put("studySubjectOID", "");
    tokensMap.put("studyName", encode(study.getName()));
    tokensMap.put("eventName", encode(eventDef.getName()));
    if (event == null)
        tokensMap.put("eventOrdinal", "");
    else
        tokensMap.put("eventOrdinal", encode(Integer.toString(event.getSampleOrdinal())));
    tokensMap.put("crfName", encode(section.getCrf().getName()));
    tokensMap.put("crfVersion", encode(section.getCrfVersion().getName()));
    // Render a set of "item['ITEM_NAME']" tokens for existing item data
    for (ItemBean item : items) {
        // If the item has multiple values, combine them in a comma-separated list
        List<String> values = new ArrayList<String>();
        for (ItemDataBean itemData : item.getItemDataElements()) {
            values.add(itemData.getValue());
        }
        String value = StringUtils.join(values, ',');
        tokensMap.put("item['" + item.getName() + "']", encode(value));
    }
    if (LOG.isDebugEnabled()) {
        for (String key : tokensMap.keySet()) {
            LOG.debug("Substitution context: {} = {}", key, tokensMap.get(key));
        }
    }
    return tokensMap;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ArrayList(java.util.ArrayList)

Example 53 with ItemDAO

use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.

the class ViewRuleAssignmentNewServlet method createStudyEventForInfoPanel.

private void createStudyEventForInfoPanel() {
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ItemDAO itemdao = new ItemDAO(sm.getDataSource());
    StudyBean studyWithEventDefinitions = currentStudy;
    if (currentStudy.getParentStudyId() > 0) {
        studyWithEventDefinitions = new StudyBean();
        studyWithEventDefinitions.setId(currentStudy.getParentStudyId());
    }
    CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    ArrayList seds = seddao.findAllActiveByStudy(studyWithEventDefinitions);
    HashMap events = new LinkedHashMap();
    for (int i = 0; i < seds.size(); i++) {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seds.get(i);
        ArrayList<CRFBean> crfs = (ArrayList<CRFBean>) crfdao.findAllActiveByDefinition(sed);
        if (currentStudy.getParentStudyId() > 0) {
            // sift through these CRFs and see which ones are hidden
            HideCRFManager hideCRFs = HideCRFManager.createHideCRFManager();
            crfs = hideCRFs.removeHiddenCRFBeans(studyWithEventDefinitions, sed, crfs, sm.getDataSource());
        }
        if (!crfs.isEmpty()) {
            events.put(sed, crfs);
        }
    }
    request.setAttribute("eventlist", events);
    request.setAttribute("crfCount", crfdao.getCountofActiveCRFs());
    request.setAttribute("itemCount", itemdao.getCountofActiveItems());
    request.setAttribute("ruleSetCount", getRuleSetService().getRuleSetDao().count(currentStudy));
}
Also used : EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) HideCRFManager(org.akaza.openclinica.service.crfdata.HideCRFManager) LinkedHashMap(java.util.LinkedHashMap) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 54 with ItemDAO

use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.

the class FormBeanUtil method createDisplaySectionBWithFormGroupsForPrint.

public DisplaySectionBean createDisplaySectionBWithFormGroupsForPrint(int sectionId, int crfVersionId, DataSource dataSource, int eventCRFDefId, EventCRFBean eventCrfBean, ServletContext context) {
    DisplaySectionBean displaySectionBean = new DisplaySectionBean();
    ItemGroupDAO formGroupDAO = new ItemGroupDAO(dataSource);
    ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(dataSource);
    ItemDAO itemDao = new ItemDAO(dataSource);
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(dataSource);
    SectionDAO sectionDao = new SectionDAO(dataSource);
    // Give the DisplaySectionBean a legitimate SectionBean
    SectionBean secBean = (SectionBean) sectionDao.findByPK(sectionId);
    displaySectionBean.setSection(secBean);
    // changed from: findGroupBySectionId
    List<ItemGroupBean> itemGroupBeans = formGroupDAO.findLegitGroupAllBySectionId(sectionId);
    // all items associated with the section, including those not in a group
    List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
    try {
        allMetas = metaDao.findAllBySectionId(sectionId);
    } catch (OpenClinicaException oce) {
        logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
    }
    // Sort these items according to their position on the CRF; their
    // ordinal
    Collections.sort(allMetas);
    // The DisplayItemGroupBean(s) for "nongrouped" items
    List<DisplayItemGroupBean> nonGroupBeans = null;
    // if(itemGroupBeans.isEmpty()) return displaySectionBean;
    // Find out whether there are any checkboxes/radios/select elements
    // and if so, get any null values
    // associated with them
    List<String> nullValuesList = new ArrayList<String>();
    boolean itemsHaveChecksRadios = itemsIncludeChecksRadiosSelects(allMetas);
    if (itemsHaveChecksRadios && eventCRFDefId > 0) {
        // method returns null values as a List<String>
        nullValuesList = this.getNullValuesByEventCRFDefId(eventCRFDefId, dataSource);
    }
    // Get the items associated with each group
    List<ItemBean> itBeans;
    List<DisplayItemBean> displayItems;
    List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
    DisplayItemGroupBean displayItemGBean;
    for (ItemGroupBean itemGroup : itemGroupBeans) {
        //TODO:fix me!
        itBeans = itemDao.findAllItemsByGroupIdForPrint(itemGroup.getId(), crfVersionId, sectionId);
        logger.debug("just ran find all by group id " + itemGroup.getId() + " found " + itBeans.size() + " item beans");
        //TODO:fix me add item_form_metadata.section_id to the query
        List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSectionForPrint(itemGroup.getId(), crfVersionId, sectionId);
        if (!metadata.isEmpty()) {
            // for a given crf version, all the items in the same group
            // have the same group metadata info
            // so we can get one of the metadata and set the metadata for
            // the group
            ItemGroupMetadataBean meta = metadata.get(0);
            itemGroup.setMeta(meta);
        }
        displayItems = getDisplayBeansFromItemsForPrint(itBeans, dataSource, eventCrfBean, sectionId, nullValuesList, context, crfVersionId);
        displayItemGBean = this.createDisplayFormGroup(displayItems, itemGroup);
        displayFormBeans.add(displayItemGBean);
    }
    // We still have to sort these display item group beans on their
    // ItemGroupMetadataBean?
    // then number their ordinals accordingly
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean displayItemGroupBean, DisplayItemGroupBean displayItemGroupBean1) {
            return displayItemGroupBean.getGroupMetaBean().compareTo(displayItemGroupBean1.getGroupMetaBean());
        }
    });
    // Now provide the display item group beans with an ordinal
    int digOrdinal = 0;
    for (DisplayItemGroupBean digBean : displayFormBeans) {
        digBean.setOrdinal(++digOrdinal);
    }
    // find out whether there are any ungrouped items by comparing the
    // number of
    // grouped items to allMetas.size()
    // List<DisplayItemGroupBean> nonGroupBeans=null;
    int tempCount = 0;
    for (DisplayItemGroupBean groupBean : displayFormBeans) {
        tempCount += groupBean.getItems().size();
    }
    if (tempCount < allMetas.size()) {
        nonGroupBeans = createGroupBeansForNongroupedItems(allMetas, displayFormBeans, sectionId, dataSource, nullValuesList, eventCrfBean, context);
    }
    if (nonGroupBeans != null) {
        displayFormBeans.addAll(nonGroupBeans);
    }
    // sort the list according to the ordinal of the contained
    // DisplayItemGroupBeans
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean disFormGroupBean, DisplayItemGroupBean disFormGroupBean1) {
            Integer compInt = disFormGroupBean1.getOrdinal();
            Integer compInt2 = disFormGroupBean.getOrdinal();
            return compInt2.compareTo(compInt);
        }
    });
    displaySectionBean.setDisplayFormGroups(displayFormBeans);
    return displaySectionBean;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) ArrayList(java.util.ArrayList) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 55 with ItemDAO

use of org.akaza.openclinica.dao.submit.ItemDAO in project OpenClinica by OpenClinica.

the class FormBeanUtil method getDisplayBeanFromSingleItem.

public DisplayItemBean getDisplayBeanFromSingleItem(ItemFormMetadataBean itemFBean, int sectionId, DataSource dataSource, EventCRFBean eventCrfBean, List<String> nullValuesList, ServletContext context) {
    DisplayItemBean disBean = new DisplayItemBean();
    ItemBean itemBean = new ItemBean();
    ItemDAO itemDAO = new ItemDAO(dataSource);
    ItemDataDAO itemDataDao = new ItemDataDAO(dataSource);
    if (itemFBean == null)
        return disBean;
    itemBean = (ItemBean) itemDAO.findByPK(itemFBean.getItemId());
    if (itemBean == null) {
        itemBean = new ItemBean();
    }
    // Add any null values to checks or radios
    String responseName;
    List<ResponseOptionBean> respOptions;
    ResponseOptionBean respBean;
    boolean hasNullValues = nullValuesList != null && !nullValuesList.isEmpty();
    // Only include Items that belong to the associated section
    if (itemFBean.getSectionId() == sectionId) {
        ItemDataBean itemDataBean = itemDataDao.findByItemIdAndEventCRFId(itemBean.getId(), eventCrfBean.getId());
        disBean.setItem(itemBean);
        disBean.setMetadata(runDynamicsCheck(itemFBean, eventCrfBean, itemDataBean, context));
        disBean.setData(itemDataBean);
        logger.debug("3. just set: " + itemDataBean.getValue());
        responseName = disBean.getMetadata().getResponseSet().getResponseType().getName();
        respOptions = disBean.getMetadata().getResponseSet().getOptions();
        if (hasNullValues && respOptions != null && ("checkbox".equalsIgnoreCase(responseName) || "radio".equalsIgnoreCase(responseName) || "single-select".equalsIgnoreCase(responseName) || "multi-select".equalsIgnoreCase(responseName))) {
            this.addBeansToResponseOptions(nullValuesList, respOptions);
        }
    }
    return disBean;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO)

Aggregations

ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)56 ArrayList (java.util.ArrayList)43 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)43 HashMap (java.util.HashMap)25 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)22 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)22 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)21 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)21 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)20 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)19 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)18 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)16 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)15 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)14 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)14 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)14 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)13 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)12 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)12 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)12