Search in sources :

Example 16 with ItemGroupMetadataBean

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

the class FormBeanUtil method createDisplaySectionBWithFormGroups.

/**
     * Create a DisplaySectionBean with a list of ItemGroupBeans. This List will
     * include any ItemGroupBeans that are associated with ungrouped items; in
     * other words, the DisplaySectionBean will represent a section that has
     * both ungrouped and grouped tables.
     * 
     * @param sectionId
     *            The Section ID associated with the Items, which end up
     *            providing the content of the tables.
     * @param crfVersionId
     *            The CRF version ID associated with the Items.
     * @param dataSource
     * @param eventCRFDefId
     *            The id for the Event CRF Definition.
     * @return A DisplaySectionBean with sorted ItemGroupBeans, meaning the
     *         ItemGroupBeans should be listed in the order that they appear on
     *         the CRF section.
     * @return A DisplaySectionBean representing a CRF section.
     */
public DisplaySectionBean createDisplaySectionBWithFormGroups(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) {
        itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), crfVersionId);
        logger.debug("just ran find all by group id " + itemGroup.getId() + " found " + itBeans.size() + " item beans");
        List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(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 = getDisplayBeansFromItems(itBeans, dataSource, eventCrfBean, sectionId, nullValuesList, context);
        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 17 with ItemGroupMetadataBean

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

the class FormBeanUtil method createDisplaySectionBeanWithItemGroups.

/**
     * Create a DisplaySectionBean with a list of FormGroupBeans.
     * 
     * @param crfVersionId
     *            The CRF version ID associated with the Items.
     * @param sectionBean
     *            The SectionBean with an ID associated with the Items, which
     *            end up providing the content of the tables.
     * @param sm
     *            A SessionManager, from which DataSources are acquired for the
     *            DAO objects.
     * @return A DisplaySectionBean.
     */
public DisplaySectionBean createDisplaySectionBeanWithItemGroups(int sectionId, EventCRFBean eventCrfBean, SectionBean sectionBean, SessionManager sm, ServletContext context) {
    DisplaySectionBean dBean = new DisplaySectionBean();
    ItemGroupDAO formGroupDAO = new ItemGroupDAO(sm.getDataSource());
    ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(sm.getDataSource());
    ItemDAO itemDao = new ItemDAO(sm.getDataSource());
    // Get all items associated with this crfVersion ID; divide them up into
    // items with a group, and those without a group.
    // get all items associated with a section id, then split them up into
    // grouped
    // and non-grouped items
    List<ItemBean> allItems = itemDao.findAllParentsBySectionId(sectionId);
    // Get a List of FormGroupBeans for each group associated with
    // this crfVersionId.
    // List<ItemGroupBean> arrList =
    // formGroupDAO.findGroupByCRFVersionIDMap(crfVersionId);
    List<ItemGroupBean> arrList = formGroupDAO.findLegitGroupBySectionId(sectionId);
    if (arrList.isEmpty())
        return dBean;
    // Get the items associated with each group
    List<ItemBean> itBeans;
    List<DisplayItemBean> displayItems;
    List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
    DisplayItemGroupBean displayFormGBean;
    for (ItemGroupBean itemGroup : arrList) {
        itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), eventCrfBean.getCRFVersionId());
        List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(itemGroup.getId(), eventCrfBean.getCRFVersionId(), sectionId);
        // this requirement
        if (!metadata.isEmpty()) {
            // for a given crf version, all the items in the same group have
            // the same group metadata
            // so we can get one of them and set metadata for the group
            ItemGroupMetadataBean meta = metadata.get(0);
            itemGroup.setMeta(meta);
        }
        // TODO: the last arg is a list of null value strings
        displayItems = getDisplayBeansFromItems(itBeans, sm.getDataSource(), eventCrfBean, sectionBean.getId(), null, context);
        displayFormGBean = this.createDisplayFormGroup(displayItems, itemGroup);
        displayFormBeans.add(displayFormGBean);
    }
    // sort the list according to the ordinal of the contained
    // FormGroupBeans
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean disFormGroupBean, DisplayItemGroupBean disFormGroupBean1) {
            return disFormGroupBean.getGroupMetaBean().getOrdinal().compareTo(disFormGroupBean1.getGroupMetaBean().getOrdinal());
        }
    });
    dBean.setDisplayFormGroups(displayFormBeans);
    return dBean;
}
Also used : DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) 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) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean)

Example 18 with ItemGroupMetadataBean

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

the class OpenRosaXmlGenerator method getItemGroupMetadata.

@SuppressWarnings({ "unchecked", "rawtypes" })
private ItemGroupMetadataBean getItemGroupMetadata(ItemGroupBean itemGroupBean, CRFVersionBean crfVersion, SectionBean section) throws Exception {
    ArrayList<ItemGroupMetadataBean> itemGroupMetadataBean = null;
    ItemGroupMetadataDAO itemGroupMetadataDAO = new ItemGroupMetadataDAO(dataSource);
    itemGroupMetadataBean = (ArrayList<ItemGroupMetadataBean>) itemGroupMetadataDAO.findMetaByGroupAndSection(itemGroupBean.getId(), crfVersion.getId(), section.getId());
    return itemGroupMetadataBean.get(0);
}
Also used : ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)

Example 19 with ItemGroupMetadataBean

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

the class OpenRosaXmlGenerator method getItemGroupMetadataByGroup.

@SuppressWarnings({ "unchecked", "rawtypes" })
private ItemGroupMetadataBean getItemGroupMetadataByGroup(ItemGroupBean itemGroupBean, CRFVersionBean crfVersion) throws Exception {
    ArrayList<ItemGroupMetadataBean> itemGroupMetadataBean = null;
    ItemGroupMetadataDAO itemGroupMetadataDAO = new ItemGroupMetadataDAO(dataSource);
    itemGroupMetadataBean = (ArrayList<ItemGroupMetadataBean>) itemGroupMetadataDAO.findMetaByGroupAndCrfVersion(itemGroupBean.getId(), crfVersion.getId());
    return itemGroupMetadataBean.get(0);
}
Also used : ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)

Example 20 with ItemGroupMetadataBean

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

the class ItemGroupMetadataDAO method findMetaByGroupAndCrfVersion.

public List<ItemGroupMetadataBean> findMetaByGroupAndCrfVersion(int itemGroupId, int crfVersionId) {
    this.setTypesExpected();
    HashMap<Integer, Integer> variables = new HashMap<Integer, Integer>();
    variables.put(1, itemGroupId);
    variables.put(2, crfVersionId);
    List listofMaps = this.select(digester.getQuery("findMetaByGroupAndCrfVersion"), variables);
    List<ItemGroupMetadataBean> beanList = new ArrayList<ItemGroupMetadataBean>();
    ItemGroupMetadataBean bean;
    for (Object map : listofMaps) {
        bean = (ItemGroupMetadataBean) this.getEntityFromHashMap((HashMap) map);
        beanList.add(bean);
    }
    return beanList;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)

Aggregations

ItemGroupMetadataBean (org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)36 ArrayList (java.util.ArrayList)20 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)16 HashMap (java.util.HashMap)14 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)13 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)13 ItemGroupMetadataDAO (org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO)12 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)10 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)10 DynamicsItemGroupMetadataBean (org.akaza.openclinica.domain.crfdata.DynamicsItemGroupMetadataBean)9 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)8 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)7 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)7 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)7 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)7 ItemGroupDAO (org.akaza.openclinica.dao.submit.ItemGroupDAO)7 DynamicsItemFormMetadataBean (org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean)4 List (java.util.List)3 Map (java.util.Map)3 DisplaySectionBean (org.akaza.openclinica.bean.submit.DisplaySectionBean)3