Search in sources :

Example 1 with ItemDAO

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

the class ImportDataRuleRunnerContainer method initRuleSetsAndTargets.

/**
 * Populate importDataTrueRuleSets and variableAndValue.
 * Precondition: import data file passed validation which means all OIDs are not empty.
 * @param ds
 * @param studyBean
 * @param subjectDataBean
 * @param ruleSetService
 */
@Transactional
public void initRuleSetsAndTargets(DataSource ds, StudyBean studyBean, SubjectDataBean subjectDataBean, RuleSetServiceInterface ruleSetService) {
    this.shouldRunRules = this.shouldRunRules == null ? Boolean.FALSE : this.shouldRunRules;
    this.importDataTrueRuleSets = this.importDataTrueRuleSets == null ? new ArrayList<RuleSetBean>() : this.importDataTrueRuleSets;
    this.variableAndValue = this.variableAndValue == null ? new HashMap<String, String>() : this.variableAndValue;
    studyOid = studyBean.getOid();
    studySubjectOid = subjectDataBean.getSubjectOID();
    StudySubjectBean studySubject = new StudySubjectDAO<String, ArrayList>(ds).findByOid(studySubjectOid);
    HashMap<String, StudyEventDefinitionBean> seds = new HashMap<String, StudyEventDefinitionBean>();
    HashMap<String, CRFVersionBean> cvs = new HashMap<String, CRFVersionBean>();
    ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
    for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
        String sedOid = studyEventDataBean.getStudyEventOID();
        StudyEventDefinitionBean sed;
        if (seds.containsKey(sedOid))
            sed = seds.get(sedOid);
        else {
            sed = new StudyEventDefinitionDAO<String, ArrayList>(ds).findByOid(sedOid);
            seds.put(sedOid, sed);
        }
        ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
        for (FormDataBean formDataBean : formDataBeans) {
            String cvOid = formDataBean.getFormOID();
            CRFVersionBean crfVersion;
            if (cvs.containsKey(cvOid))
                crfVersion = cvs.get(cvOid);
            else {
                crfVersion = new CRFVersionDAO<String, ArrayList>(ds).findByOid(cvOid);
                cvs.put(cvOid, crfVersion);
            }
            String sedOrd = studyEventDataBean.getStudyEventRepeatKey();
            Integer sedOrdinal = sedOrd != null && !sedOrd.isEmpty() ? Integer.valueOf(sedOrd) : 1;
            StudyEventBean studyEvent = (StudyEventBean) new StudyEventDAO(ds).findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubject.getId(), sed.getId(), sedOrdinal);
            List<RuleSetBean> ruleSets = ruleSetService.getRuleSetsByCrfStudyAndStudyEventDefinition(studyBean, sed, crfVersion);
            // Set<String> targetItemOids = new HashSet<String>();
            if (ruleSets != null && !ruleSets.isEmpty()) {
                ruleSets = filterByImportDataEntryTrue(ruleSets);
                if (ruleSets != null && !ruleSets.isEmpty()) {
                    ruleSets = ruleSetService.filterByStatusEqualsAvailable(ruleSets);
                    ruleSets = ruleSetService.filterRuleSetsByStudyEventOrdinal(ruleSets, studyEvent, crfVersion, sed);
                    // ruleSets = ruleSetService.filterRuleSetsByHiddenItems(ruleSets, eventCrfBean, crfVersion, new ArrayList<ItemBean>());
                    shouldRunRules = ruleSetService.shouldRunRulesForRuleSets(ruleSets, Phase.IMPORT);
                    if (shouldRunRules != null && shouldRunRules == Boolean.TRUE) {
                        // targetItemOids = collectTargetItemOids(ruleSets);
                        HashMap<String, Integer> grouped = new HashMap<String, Integer>();
                        ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
                        for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
                            ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
                            for (ImportItemDataBean importItemDataBean : itemDataBeans) {
                                // if(targetItemOids.contains(importItemDataBean.getItemOID())) {
                                ItemBean item = new ItemDAO<String, ArrayList>(ds).findByOid(importItemDataBean.getItemOID()).get(0);
                                String igOid = itemGroupDataBean.getItemGroupOID();
                                String igOrd = itemGroupDataBean.getItemGroupRepeatKey();
                                Integer igOrdinal = igOrd != null && !igOrd.isEmpty() ? Integer.valueOf(igOrd) : 1;
                                // logic from DataEntryServlet method: populateRuleSpecificHashMaps()
                                if (isRepeatIGForSure(ds, crfVersion.getId(), igOid, igOrdinal, item.getId())) {
                                    String key1 = igOid + "[" + igOrdinal + "]." + importItemDataBean.getItemOID();
                                    String key = igOid + "." + importItemDataBean.getItemOID();
                                    variableAndValue.put(key1, importItemDataBean.getValue());
                                    if (grouped.containsKey(key)) {
                                        grouped.put(key, grouped.get(key) + 1);
                                    } else {
                                        grouped.put(key, 1);
                                    }
                                } else {
                                    variableAndValue.put(importItemDataBean.getItemOID(), importItemDataBean.getValue());
                                    grouped.put(importItemDataBean.getItemOID(), 1);
                                }
                            // 
                            // }
                            }
                        }
                        ruleSets = ruleSetService.solidifyGroupOrdinalsUsingFormProperties(ruleSets, grouped);
                        importDataTrueRuleSets.addAll(ruleSets);
                    }
                }
            }
        }
    }
}
Also used : ImportItemGroupDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemGroupDataBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ImportItemDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with ItemDAO

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

the class CreateCRFVersionServlet method isResponseValid.

private ItemBean isResponseValid(HashMap items, CRFVersionBean version) {
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    ItemFormMetadataDAO metadao = new ItemFormMetadataDAO(sm.getDataSource());
    Set names = items.keySet();
    Iterator it = names.iterator();
    while (it.hasNext()) {
        String name = (String) it.next();
        ItemBean oldItem = (ItemBean) idao.findByNameAndCRFId(name, version.getCrfId());
        ItemBean item = (ItemBean) items.get(name);
        if (oldItem.getId() > 0) {
            // found same item in DB
            ArrayList metas = metadao.findAllByItemId(oldItem.getId());
            for (int i = 0; i < metas.size(); i++) {
                ItemFormMetadataBean ifmb = (ItemFormMetadataBean) metas.get(i);
                ResponseSetBean rsb = ifmb.getResponseSet();
                if (hasDifferentOption(rsb, item.getItemMeta().getResponseSet()) != null) {
                    return item;
                }
            }
        }
    }
    return null;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) Set(java.util.Set) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) ResponseSetBean(org.akaza.openclinica.bean.submit.ResponseSetBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 3 with ItemDAO

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

the class DataEntryServlet method getDisplayBean.

/**
 * Retrieve the DisplaySectionBean which will be used to display the Event CRF Section on the JSP, and also is used to controll processRequest.
 * @param request TODO
 * @param isSubmitted TODO
 */
protected DisplaySectionBean getDisplayBean(boolean hasGroup, boolean includeUngroupedItems, HttpServletRequest request, boolean isSubmitted) throws Exception {
    DisplaySectionBean section = new DisplaySectionBean();
    FormProcessor fp = new FormProcessor(request);
    HttpSession session = request.getSession();
    Locale loc = this.locale == null ? LocaleResolver.getLocale(request) : this.locale;
    StudyBean study = (StudyBean) session.getAttribute("study");
    SessionManager sm = (SessionManager) request.getSession().getAttribute("sm");
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    EventDefinitionCRFBean edcb = (EventDefinitionCRFBean) request.getAttribute(EVENT_DEF_CRF_BEAN);
    SectionDAO sdao;
    // Find out whether there are ungrouped items in this section
    boolean hasUngroupedItems = false;
    int eventDefinitionCRFId = fp.getInt("eventDefinitionCRFId");
    if (eventDefinitionCRFId <= 0) {
        // TODO: this block of code repeats
        // many times, need to clean up
        // synchronized(this)
        {
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
            EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, ecb.getStudyEventId(), ecb.getCRFVersionId());
            eventDefinitionCRFId = edcBean.getId();
        }
    }
    LOGGER.trace("eventDefinitionCRFId " + eventDefinitionCRFId);
    // Use this class to find out whether there are ungrouped items in this
    // section
    FormBeanUtil formBeanUtil = new FormBeanUtil();
    List<DisplayItemGroupBean> itemGroups = new ArrayList<DisplayItemGroupBean>();
    if (hasGroup) {
        DisplaySectionBean newDisplayBean = new DisplaySectionBean();
        if (includeUngroupedItems) {
            // Null values: this method adds null values to the
            // displayitembeans
            newDisplayBean = formBeanUtil.createDisplaySectionBWithFormGroups(sb.getId(), ecb.getCRFVersionId(), getDataSource(), eventDefinitionCRFId, ecb, getServletContext());
        } else {
            newDisplayBean = formBeanUtil.createDisplaySectionWithItemGroups(study, sb.getId(), ecb, ecb.getStudyEventId(), sm, eventDefinitionCRFId, getServletContext());
        }
        itemGroups = newDisplayBean.getDisplayFormGroups();
        // setDataForDisplayItemGroups(itemGroups, sb,ecb,sm);
        LOGGER.trace("found item group size: " + itemGroups.size() + " and to string: " + itemGroups.toString());
        section.setDisplayFormGroups(itemGroups);
    }
    // Find out whether any display items are *not* grouped; see issue 1689
    hasUngroupedItems = formBeanUtil.sectionHasUngroupedItems(getDataSource(), sb.getId(), itemGroups);
    sdao = new SectionDAO(getDataSource());
    // 
    sb.setHasSCDItem(hasUngroupedItems ? sdao.hasSCDItem(sb.getId()) : false);
    section.setEventCRF(ecb);
    if (sb.getParentId() > 0) {
        SectionBean parent = (SectionBean) sdao.findByPK(sb.getParentId());
        sb.setParent(parent);
    }
    section.setSection(sb);
    CRFVersionDAO cvdao = new CRFVersionDAO(getDataSource());
    CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(ecb.getCRFVersionId());
    section.setCrfVersion(cvb);
    CRFDAO cdao = new CRFDAO(getDataSource());
    CRFBean cb = (CRFBean) cdao.findByPK(cvb.getCrfId());
    section.setCrf(cb);
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(getDataSource());
    // EventDefinitionCRFBean edcb =
    // edcdao.findByStudyEventIdAndCRFVersionId(study,
    // ecb.getStudyEventId(), cvb.getId());
    section.setEventDefinitionCRF(edcb);
    // setup DAO's here to avoid creating too many objects
    ItemDAO idao = new ItemDAO(getDataSource());
    ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), loc);
    // Use itemGroups to determine if there are any ungrouped items
    // get all the parent display item beans not in group
    logMe("Entering getParentDisplayItems::: Thread is? " + Thread.currentThread());
    ArrayList displayItems = getParentDisplayItems(hasGroup, sb, edcb, idao, ifmdao, iddao, hasUngroupedItems, request);
    logMe("Entering getParentDisplayItems::: Done and Thread is? " + Thread.currentThread());
    LOGGER.debug("just ran get parent display, has group " + hasGroup + " has ungrouped " + hasUngroupedItems);
    // now sort them by ordinal,
    // JN: Commenting out this logic, its wrong and will give erroneous results.
    Collections.sort(displayItems);
    // now get the child DisplayItemBeans
    for (int i = 0; i < displayItems.size(); i++) {
        DisplayItemBean dib = (DisplayItemBean) displayItems.get(i);
        dib.setChildren(getChildrenDisplayItems(dib, edcb, request));
        // 
        if (ecb.getStage() == DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE || ecb.getStage() == DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) {
            if (shouldLoadDBValues(dib) && !isSubmitted) {
                dib.loadDBValue();
            }
        } else {
            if (shouldLoadDBValues(dib)) {
                LOGGER.trace("should load db values is true, set value");
                dib.loadDBValue();
                LOGGER.trace("just got data loaded: " + dib.getData().getValue());
            }
        }
        displayItems.set(i, dib);
    }
    section.setItems(displayItems);
    return section;
}
Also used : Locale(java.util.Locale) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormBeanUtil(org.akaza.openclinica.view.form.FormBeanUtil) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) HttpSession(javax.servlet.http.HttpSession) SessionManager(org.akaza.openclinica.core.SessionManager) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Example 4 with ItemDAO

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

the class DataEntryServlet method loadItemsWithGroupRows.

protected void loadItemsWithGroupRows(DisplayItemWithGroupBean itemWithGroup, SectionBean sb, EventDefinitionCRFBean edcb, EventCRFBean ecb, HttpServletRequest request) {
    // this method is a copy of the method: createItemWithGroups ,
    // only modified for load one DisplayItemWithGroupBean.
    // 
    ItemDAO idao = new ItemDAO(getDataSource());
    // For adding null values to display items
    FormBeanUtil formBeanUtil = new FormBeanUtil();
    List<String> nullValuesList = new ArrayList<String>();
    // BWP>> Get a List<String> of any null values such as NA or NI
    // method returns null values as a List<String>
    nullValuesList = formBeanUtil.getNullValuesByEventCRFDefId(edcb.getId(), getDataSource());
    // >>BWP
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    ArrayList data = iddao.findAllActiveBySectionIdAndEventCRFId(sb.getId(), ecb.getId());
    DisplayItemGroupBean itemGroup = itemWithGroup.getItemGroup();
    // to arrange item groups and other single items, the ordinal of
    // a item group will be the ordinal of the first item in this
    // group
    DisplayItemBean firstItem = itemGroup.getItems().get(0);
    DisplayItemBean checkItem = firstItem;
    // does not work if there is not any data in the first item of the group
    // i.e. imports.
    // does it make a difference if we take a last item?
    boolean noNeedToSwitch = false;
    for (int i = 0; i < data.size(); i++) {
        ItemDataBean idb = (ItemDataBean) data.get(i);
        if (idb.getItemId() == firstItem.getItem().getId()) {
            noNeedToSwitch = true;
        }
    }
    if (!noNeedToSwitch) {
        checkItem = itemGroup.getItems().get(itemGroup.getItems().size() - 1);
    }
    // so we are either checking the first or the last item, BUT ONLY ONCE
    itemWithGroup.setPageNumberLabel(firstItem.getMetadata().getPageNumberLabel());
    itemWithGroup.setItemGroup(itemGroup);
    itemWithGroup.setInGroup(true);
    itemWithGroup.setOrdinal(itemGroup.getGroupMetaBean().getOrdinal());
    List<ItemBean> itBeans = idao.findAllItemsByGroupId(itemGroup.getItemGroupBean().getId(), sb.getCRFVersionId());
    boolean hasData = false;
    int checkAllColumns = 0;
    // first item should be same as the row number
    for (int i = 0; i < data.size(); i++) {
        ItemDataBean idb = (ItemDataBean) data.get(i);
        LOGGER.debug("check all columns: " + checkAllColumns);
        if (idb.getItemId() == checkItem.getItem().getId()) {
            hasData = true;
            LOGGER.debug("set has data to --TRUE--");
            checkAllColumns = 0;
            // so that we only fire once a row
            LOGGER.debug("has data set to true");
            DisplayItemGroupBean digb = new DisplayItemGroupBean();
            // always get a fresh copy for items, may use other
            // better way to
            // do deep copy, like clone
            List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), edcb, 0, getServletContext());
            digb.setItems(dibs);
            LOGGER.trace("set with dibs list of : " + dibs.size());
            digb.setGroupMetaBean(runDynamicsCheck(itemGroup.getGroupMetaBean(), request));
            digb.setItemGroupBean(itemGroup.getItemGroupBean());
            itemWithGroup.getItemGroups().add(digb);
            itemWithGroup.getDbItemGroups().add(digb);
        }
    }
    List<DisplayItemGroupBean> groupRows = itemWithGroup.getItemGroups();
    LOGGER.trace("how many group rows:" + groupRows.size());
    LOGGER.trace("how big is the data:" + data.size());
    if (hasData) {
        // the group
        for (int i = 0; i < groupRows.size(); i++) {
            DisplayItemGroupBean displayGroup = groupRows.get(i);
            for (DisplayItemBean dib : displayGroup.getItems()) {
                for (int j = 0; j < data.size(); j++) {
                    ItemDataBean idb = (ItemDataBean) data.get(j);
                    if (idb.getItemId() == dib.getItem().getId() && !idb.isSelected()) {
                        idb.setSelected(true);
                        dib.setData(idb);
                        LOGGER.debug("--> set data " + idb.getId() + ": " + idb.getValue());
                        if (shouldLoadDBValues(dib)) {
                            LOGGER.debug("+++should load db values is true, set value");
                            dib.loadDBValue();
                            LOGGER.debug("+++data loaded: " + idb.getName() + ": " + idb.getOrdinal() + " " + idb.getValue());
                            LOGGER.debug("+++try dib OID: " + dib.getItem().getOid());
                        }
                        break;
                    }
                }
            }
        }
    } else {
        // no data, still add a blank row for displaying
        DisplayItemGroupBean digb2 = new DisplayItemGroupBean();
        List<DisplayItemBean> dibs = FormBeanUtil.getDisplayBeansFromItems(itBeans, getDataSource(), ecb, sb.getId(), nullValuesList, getServletContext());
        digb2.setItems(dibs);
        LOGGER.trace("set with nullValuesList of : " + nullValuesList);
        digb2.setEditFlag("initial");
        digb2.setGroupMetaBean(itemGroup.getGroupMetaBean());
        digb2.setItemGroupBean(itemGroup.getItemGroupBean());
        itemWithGroup.getItemGroups().add(digb2);
        itemWithGroup.getDbItemGroups().add(digb2);
    }
}
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) FormBeanUtil(org.akaza.openclinica.view.form.FormBeanUtil) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean)

Example 5 with ItemDAO

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

the class DataEntryServlet method saveItemsToMarkComplete.

/**
 * 06/13/2007- jxu Since we don't require users to review each section before mark a CRF as complete, we need to create item data in the database because
 * items will not be created unless the section which contains the items is reviewed by users
 * @param request TODO
 */
private boolean saveItemsToMarkComplete(Status completeStatus, HttpServletRequest request) throws Exception {
    EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
    SectionDAO sdao = new SectionDAO(getDataSource());
    ArrayList sections = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
    UserAccountBean ub = (UserAccountBean) request.getSession().getAttribute(USER_BEAN_NAME);
    ItemDataDAO iddao = new ItemDataDAO(getDataSource(), locale);
    ItemDAO idao = new ItemDAO(getDataSource());
    for (int i = 0; i < sections.size(); i++) {
        SectionBean sb = (SectionBean) sections.get(i);
        if (!isCreateItemReqd(sb, request)) {
            // ArrayList requiredItems =
            // idao.findAllRequiredBySectionId(sb.getId());
            // if (!requiredItems.isEmpty()) {
            // return false;
            // }
            ArrayList items = idao.findAllBySectionId(sb.getId());
            for (int j = 0; j < items.size(); j++) {
                ItemBean item = (ItemBean) items.get(j);
                ArrayList<ItemDataBean> itemBean = iddao.findAllByEventCRFIdAndItemIdNoStatus(ecb.getId(), item.getId());
                ItemDataBean idb = new ItemDataBean();
                idb.setItemId(item.getId());
                idb.setEventCRFId(ecb.getId());
                idb.setCreatedDate(new Date());
                idb.setOrdinal(1);
                idb.setOwner(ub);
                if (completeStatus != null) {
                    // to avoid null exception
                    idb.setStatus(completeStatus);
                } else {
                    idb.setStatus(Status.UNAVAILABLE);
                }
                idb.setValue("");
                boolean save = true;
                if (itemBean.size() > 0)
                    save = false;
                /* while(itemBean.iterator().hasNext())
                    {

                        ItemDataBean temp = itemBean.iterator().next();
                       if(idb.getEventCRFId()==(temp.getEventCRFId()))
                       {
                           if(idb.getItemId()==(temp.getItemId())){
                              save = false;
                           }
                       }


                    }*/
                if (save) {
                    iddao.create(idb);
                }
            }
        }
    }
    return true;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) Date(java.util.Date) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Aggregations

ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)57 ArrayList (java.util.ArrayList)45 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)42 HashMap (java.util.HashMap)26 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)21 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)21 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)21 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)20 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)19 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)18 ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)18 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)16 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)16 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)15 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)14 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)14 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)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