Search in sources :

Example 11 with ItemGroupMetadataDAO

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

the class OpenRosaXmlGenerator method getGroupInfo.

/**
     * @param itemGroupBean
     * @param crfVersion
     * @param section
     * @param factory
     * @param bindList
     * @return
     * @throws Exception
     */
private HashMap<String, Object> getGroupInfo(ItemGroupBean itemGroupBean, CRFVersionBean crfVersion, SectionBean section, WidgetFactory factory, ArrayList<Bind> bindList) throws Exception {
    boolean expressionEvaluate = true;
    igmdao = new ItemGroupMetadataDAO(dataSource);
    List<ItemGroupMetadataBean> itemGroupMetadata = igmdao.findMetaByGroupAndSection(itemGroupBean.getId(), crfVersion.getId(), section.getId());
    HashMap<String, Object> map = new HashMap<String, Object>();
    Group group = new Group();
    Repeat repeat = new Repeat();
    group.setUsercontrol(new ArrayList<UserControl>());
    repeat.setUsercontrol(new ArrayList<UserControl>());
    Label groupHeader = new Label();
    groupHeader.setLabel(itemGroupMetadata.get(0).getHeader());
    boolean isGroupRepeating = getItemGroupMetadata(itemGroupBean, crfVersion, section).isRepeatingGroup();
    String nodeset = "/" + crfVersion.getOid() + "/" + itemGroupBean.getOid();
    // repeat.setJrNoAddRemove("true()");
    repeat.setJrCount(nodeset);
    group.setRef(nodeset);
    repeat.setNodeset(nodeset);
    String groupExpression = null;
    ExpressionExpressionEvaluate eev = getSkipPattern(null, itemGroupBean);
    groupExpression = eev.getExpression();
    expressionEvaluate = eev.isExpressionEvaluate();
    if (groupExpression != null)
        groupExpression = getFullExpressionToParse(groupExpression, crfVersion, expressionEvaluate);
    setGroupWidget(section, crfVersion, groupExpression, bindList, factory, itemGroupBean, group, repeat, isGroupRepeating, groupHeader);
    map.put("group", group);
    map.put("repeat", repeat);
    map.put("isGroupRepeating", isGroupRepeating);
    return map;
}
Also used : Group(org.akaza.openclinica.web.pform.dto.Group) HashMap(java.util.HashMap) Label(org.akaza.openclinica.web.pform.dto.Label) Repeat(org.akaza.openclinica.web.pform.dto.Repeat) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) UserControl(org.akaza.openclinica.web.pform.dto.UserControl)

Example 12 with ItemGroupMetadataDAO

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

the class ChangeCRFVersionController method confirmCRFVersionChange.

/*
     * Displays two set of columns for user to confirm his decision to switch to a new version of CRF
     * field name | OID | field value
     */
@RequestMapping(value = "/managestudy/confirmCRFVersionChange", method = RequestMethod.POST)
public // @RequestMapping("/managestudy/confirmCRFVersionChange")
ModelMap confirmCRFVersionChange(HttpServletRequest request, HttpServletResponse response, @RequestParam(value = "crfId", required = false) int crfId, @RequestParam(value = "crfName", required = false) String crfName, @RequestParam(value = "formLayoutId", required = false) int formLayoutId, @RequestParam(value = "formLayoutName", required = false) String formLayoutName, @RequestParam(value = "studySubjectLabel", required = false) String studySubjectLabel, @RequestParam(value = "studySubjectId", required = false) int studySubjectId, @RequestParam(value = "eventCRFId", required = false) int eventCRFId, @RequestParam(value = "eventDefinitionCRFId", required = false) int eventDefinitionCRFId, @RequestParam(value = "selectedVersionId", required = false) int selectedVersionId, @RequestParam(value = "selectedVersionName", required = false) String selectedVersionName, @RequestParam(value = "eventName", required = false) String eventName, @RequestParam(value = "eventCreateDate", required = false) String eventCreateDate, @RequestParam(value = "eventOrdinal", required = false) String eventOrdinal, @RequestParam("confirmCRFVersionSubmit") String as) {
    // to be removed for aquamarine
    if (!mayProceed(request)) {
        if (redirect(request, response, "/MainMenu?message=authentication_failed") == null)
            return null;
    }
    FormLayoutDAO formLayoutDao = new FormLayoutDAO(dataSource);
    selectedVersionName = (formLayoutDao.findByPK(selectedVersionId)).getName().trim();
    resetPanel(request);
    request.setAttribute("eventCRFId", eventCRFId);
    request.setAttribute("studySubjectLabel", studySubjectLabel);
    request.setAttribute("eventDefinitionCRFId", eventDefinitionCRFId);
    request.setAttribute("studySubjectId", studySubjectId);
    request.setAttribute("crfId", crfId);
    request.setAttribute("crfName", crfName);
    request.setAttribute("formLayoutId", formLayoutId);
    request.setAttribute("formLayoutName", formLayoutName.trim());
    request.setAttribute("selectedVersionId", selectedVersionId);
    if (selectedVersionName != null) {
        selectedVersionName = selectedVersionName.trim();
    }
    request.setAttribute("selectedVersionName", selectedVersionName);
    request.setAttribute("eventName", eventName);
    request.setAttribute("eventCreateDate", eventCreateDate);
    request.setAttribute("eventOrdinal", eventOrdinal);
    ModelMap gridMap = new ModelMap();
    ArrayList<String> pageMessages = initPageMessages(request);
    setupResource(request);
    if (selectedVersionId == -1) {
        // "Please select CRF
        String errorMessage = resword.getString("confirm_crf_version_em_select_version");
        // version";
        StringBuffer params = new StringBuffer();
        params.append("/pages/managestudy/chooseCRFVersion?crfId=" + crfId);
        params.append("&crfName=" + crfName);
        params.append("&formLayoutId=" + formLayoutId);
        params.append("&formLayoutName=" + formLayoutName);
        params.append("&selectedVersionName=" + selectedVersionName);
        params.append("&studySubjectLabel=" + studySubjectLabel);
        params.append("&studySubjectId=" + studySubjectId);
        params.append("&eventCRFId=" + eventCRFId);
        params.append("&eventDefinitionCRFId=" + eventDefinitionCRFId);
        params.append("&errorMessage=" + errorMessage);
        if (redirect(request, response, params.toString()) == null) {
            return null;
        }
    }
    request.getSession().removeAttribute("pageMessages");
    // get dATa for current crf version display
    // select name, ordinal, oc_oid, item_data_id, i.item_id, value from item_data id, item i
    // where id.item_id=i.item_id and event_crf_id = 171 order by i.item_id,ordinal;
    ArrayList<String[]> rows = new ArrayList<String[]>();
    int cur_counter = 0;
    int new_counter = 0;
    try {
        ItemDAO item_dao = new ItemDAO(dataSource);
        ItemDataBean d_bean = null;
        // get metadata to find repeat group or not
        ItemGroupMetadataDAO dao_item_form_mdata = new ItemGroupMetadataDAO(dataSource);
        HashMap<Integer, ItemGroupMetadataBean> hash_item_form_mdata = new HashMap<Integer, ItemGroupMetadataBean>();
        HashMap<Integer, ItemGroupMetadataBean> hash_new_item_form_mdata = new HashMap<Integer, ItemGroupMetadataBean>();
        List<ItemBean> cur_items = new ArrayList<>();
        List<ItemBean> new_items = new ArrayList<>();
        List<VersioningMap> origFormLayoutItems = versioningMapDao.findByFormLayoutId(formLayoutId);
        for (VersioningMap vm : origFormLayoutItems) {
            ItemGroupMetadataBean beans_item_form_mdata = (ItemGroupMetadataBean) dao_item_form_mdata.findByItemAndCrfVersion(vm.getVersionMapId().getItemId(), vm.getVersionMapId().getCrfVersionId());
            hash_item_form_mdata.put(new Integer(vm.getVersionMapId().getItemId()), beans_item_form_mdata);
            ItemBean itemBean = (ItemBean) item_dao.findByPK(vm.getVersionMapId().getItemId());
            cur_items.add(itemBean);
        }
        List<VersioningMap> newFormLayoutItems = versioningMapDao.findByFormLayoutId(selectedVersionId);
        for (VersioningMap vm : newFormLayoutItems) {
            ItemGroupMetadataBean bn_new_item_form_mdata = (ItemGroupMetadataBean) dao_item_form_mdata.findByItemAndCrfVersion(vm.getVersionMapId().getItemId(), vm.getVersionMapId().getCrfVersionId());
            hash_new_item_form_mdata.put(new Integer(vm.getVersionMapId().getItemId()), bn_new_item_form_mdata);
            ItemBean itemBean = (ItemBean) item_dao.findByPK(vm.getVersionMapId().getItemId());
            new_items.add(itemBean);
        }
        // get items description
        List<ItemBean> cur_items_with_data = item_dao.findAllWithItemDataByFormLayoutId(formLayoutId, eventCRFId);
        HashMap<String, ItemBean> hash_items_with_data = new HashMap<String, ItemBean>(cur_items_with_data.size());
        for (ItemBean item : cur_items_with_data) {
            hash_items_with_data.put(item.getOid(), item);
        }
        ItemBean temp = null;
        for (ItemBean item : cur_items) {
            temp = hash_items_with_data.get(item.getOid());
            if (temp != null) {
                item.setItemDataElements(temp.getItemDataElements());
            }
        }
        List<ItemBean> new_items_with_data = item_dao.findAllWithItemDataByFormLayoutId(selectedVersionId, eventCRFId);
        hash_items_with_data = new HashMap<String, ItemBean>(new_items_with_data.size());
        for (ItemBean item : new_items_with_data) {
            hash_items_with_data.put(item.getOid(), item);
        }
        for (ItemBean item : new_items) {
            temp = hash_items_with_data.get(item.getOid());
            if (temp != null) {
                item.setItemDataElements(temp.getItemDataElements());
            }
        }
        ItemBean cur_element = null;
        ItemBean new_element = null;
        ItemGroupMetadataBean bn_mdata = null;
        ItemGroupMetadataBean bn_new_mdata = null;
        while (cur_counter < cur_items.size() || new_counter < new_items.size()) {
            if (cur_counter < cur_items.size()) {
                cur_element = cur_items.get(cur_counter);
                bn_mdata = hash_item_form_mdata.get(new Integer(cur_element.getId()));
            }
            if (new_counter < new_items.size()) {
                new_element = new_items.get(new_counter);
                bn_new_mdata = hash_new_item_form_mdata.get(new Integer(new_element.getId()));
            }
            if (cur_counter < cur_items.size() && new_counter < new_items.size() && new_element.getId() == cur_element.getId()) {
                buildRecord(cur_element, new_element, bn_mdata, bn_new_mdata, rows);
                cur_counter++;
                new_counter++;
            } else if (cur_counter < cur_items.size() && (new_counter >= new_items.size() || new_element.getId() > cur_element.getId())) {
                buildRecord(cur_element, null, bn_mdata, null, rows);
                cur_counter++;
            } else if (new_counter < new_items.size() && (cur_counter >= cur_items.size() || new_element.getId() < cur_element.getId())) {
                buildRecord(null, new_element, null, bn_new_mdata, rows);
                new_counter++;
            }
        }
    } catch (Exception e) {
        logger.error(cur_counter + " " + new_counter);
        pageMessages.add(resword.getString("confirm_crf_version_em_dataextraction"));
    }
    request.setAttribute("pageMessages", pageMessages);
    gridMap.addAttribute("rows", rows);
    return gridMap;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) ModelMap(org.springframework.ui.ModelMap) ArrayList(java.util.ArrayList) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) VersioningMap(org.akaza.openclinica.domain.datamap.VersioningMap) HttpSessionRequiredException(org.springframework.web.HttpSessionRequiredException) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with ItemGroupMetadataDAO

use of org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO 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)

Aggregations

ItemGroupMetadataDAO (org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO)13 ItemGroupMetadataBean (org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)12 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)9 ArrayList (java.util.ArrayList)8 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)8 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)7 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)7 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)6 ItemGroupDAO (org.akaza.openclinica.dao.submit.ItemGroupDAO)6 HashMap (java.util.HashMap)4 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)4 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)4 DisplaySectionBean (org.akaza.openclinica.bean.submit.DisplaySectionBean)4 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)4 SectionDAO (org.akaza.openclinica.dao.submit.SectionDAO)4 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)3 OpenClinicaException (org.akaza.openclinica.exception.OpenClinicaException)3 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)2 FormLayoutDAO (org.akaza.openclinica.dao.submit.FormLayoutDAO)2 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)2