Search in sources :

Example 1 with WidgetFactory

use of org.akaza.openclinica.web.pform.widget.WidgetFactory in project OpenClinica by OpenClinica.

the class OpenRosaXmlGenerator method mapBeansToDTO.

/**
     * @param html
     * @param crf
     * @param crfVersion
     * @param crfSections
     * @return
     * @throws Exception
     */
private Integer mapBeansToDTO(Html html, CRFBean crf, CRFVersionBean crfVersion, ArrayList<SectionBean> crfSections) throws Exception {
    boolean expressionEvaluate = true;
    int sectionCount = 0;
    ItemFormMetadataBean itemFormMetadataBean = null;
    Body body = html.getBody();
    ArrayList<Group> allSections = new ArrayList<Group>();
    ArrayList<Bind> bindList = new ArrayList<Bind>();
    WidgetFactory factory = new WidgetFactory(crfVersion);
    html.getHead().setTitle(crf.getName());
    for (SectionBean section : crfSections) {
        ArrayList<Group> groups = new ArrayList<Group>();
        Group singleSection = new Group();
        singleSection.setUsercontrol(new ArrayList<UserControl>());
        String ref = "/" + crfVersion.getOid() + "/" + "SECTION_" + section.getLabel().replaceAll("\\W", "_");
        singleSection.setRef(ref);
        String sectionExpression = null;
        igdao = new ItemGroupDAO(dataSource);
        ArrayList<ItemGroupBean> groupBeans = (ArrayList<ItemGroupBean>) igdao.findGroupBySectionId(section.getId());
        int count = 0;
        if (groupBeans.size() > 0) {
            for (ItemGroupBean groupBean : groupBeans) {
                ExpressionExpressionEvaluate eev = getSkipPattern(null, groupBean);
                String expr = eev.getExpression();
                expressionEvaluate = eev.isExpressionEvaluate();
                if (expr != null) {
                    if (sectionExpression != null) {
                        sectionExpression = sectionExpression + " and " + expr;
                        count++;
                    } else {
                        sectionExpression = expr;
                        count++;
                    }
                }
            }
            if (sectionExpression != null && groupBeans.size() == count) {
                sectionExpression = getFullExpressionToParse(sectionExpression, crfVersion, expressionEvaluate);
            } else {
                sectionExpression = null;
            }
            setSectionWidget(section, crfVersion, sectionExpression, bindList, factory, singleSection);
            HashMap<String, Object> groupMap = null;
            boolean isGroupRepeating = false;
            Group group = null;
            Repeat repeat = null;
            idao = new ItemDAO(dataSource);
            ArrayList<ItemBean> items = (ArrayList<ItemBean>) idao.findAllBySectionIdOrderedByItemFormMetadataOrdinal(section.getId());
            Integer itemGroupId = 0;
            for (ItemBean item : items) {
                ItemGroupBean itemGroupBean = getItemGroupBeanByItemId(item.getId());
                if (itemGroupId != itemGroupBean.getId()) {
                    groupMap = getGroupInfo(itemGroupBean, crfVersion, section, factory, bindList);
                    isGroupRepeating = (Boolean) groupMap.get("isGroupRepeating");
                    group = (Group) groupMap.get("group");
                    repeat = (Repeat) groupMap.get("repeat");
                }
                itemFormMetadataBean = getItemFormMetadata(item, crfVersion);
                int responseTypeId = itemFormMetadataBean.getResponseSet().getResponseTypeId();
                boolean isItemRequired = itemFormMetadataBean.isRequired();
                String responseLayout = itemFormMetadataBean.getResponseLayout();
                String itemExpression = null;
                ExpressionExpressionEvaluate eev = getSkipPattern(item, itemGroupBean);
                itemExpression = eev.getExpression();
                expressionEvaluate = eev.isExpressionEvaluate();
                if (itemExpression != null)
                    itemExpression = getFullExpressionToParse(itemExpression, crfVersion, expressionEvaluate);
                // Add the Item Header
                setHeaderWidget(item, itemFormMetadataBean, itemGroupBean, bindList, factory, isGroupRepeating, repeat, group, itemExpression);
                // Add the Item SubHeader
                setSubHeaderWidget(item, itemFormMetadataBean, itemGroupBean, bindList, factory, isGroupRepeating, repeat, group, itemExpression);
                // Add the Item itself
                setItemWidget(item, responseTypeId, itemFormMetadataBean, itemGroupBean, bindList, factory, isGroupRepeating, repeat, group, isItemRequired, responseLayout, itemExpression);
                if (itemGroupId != itemGroupBean.getId()) {
                    groups.add(group);
                    itemGroupId = itemGroupBean.getId();
                }
            }
            // end of item loop
            singleSection.setGroup(groups);
            allSections.add(singleSection);
        }
        // end of groups per section if exist
        sectionCount = allSections.size();
    }
    // end of section loop
    body.setGroup(allSections);
    html.getHead().getModel().setBind(bindList);
    return sectionCount;
}
Also used : Group(org.akaza.openclinica.web.pform.dto.Group) Bind(org.akaza.openclinica.web.pform.dto.Bind) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) Repeat(org.akaza.openclinica.web.pform.dto.Repeat) UserControl(org.akaza.openclinica.web.pform.dto.UserControl) Body(org.akaza.openclinica.web.pform.dto.Body) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) WidgetFactory(org.akaza.openclinica.web.pform.widget.WidgetFactory) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Aggregations

ArrayList (java.util.ArrayList)1 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)1 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)1 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)1 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)1 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)1 ItemGroupDAO (org.akaza.openclinica.dao.submit.ItemGroupDAO)1 Bind (org.akaza.openclinica.web.pform.dto.Bind)1 Body (org.akaza.openclinica.web.pform.dto.Body)1 Group (org.akaza.openclinica.web.pform.dto.Group)1 Repeat (org.akaza.openclinica.web.pform.dto.Repeat)1 UserControl (org.akaza.openclinica.web.pform.dto.UserControl)1 WidgetFactory (org.akaza.openclinica.web.pform.widget.WidgetFactory)1