Search in sources :

Example 11 with ItemFormMetadataBean

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

the class ItemFormMetadataDAO method findByItemIdAndFormLayoutIdNotInIGM.

public ItemFormMetadataBean findByItemIdAndFormLayoutIdNotInIGM(int itemId, int formLayoutId) {
    this.setTypesExpected();
    HashMap<Integer, Integer> variables = new HashMap<Integer, Integer>();
    variables.put(new Integer(1), new Integer(itemId));
    variables.put(new Integer(2), new Integer(formLayoutId));
    EntityBean eb = this.executeFindByPKQuery("findByItemIdAndFormLayoutIdNotInIGM", variables);
    if (!eb.isActive()) {
        return new ItemFormMetadataBean();
    } else {
        return (ItemFormMetadataBean) eb;
    }
}
Also used : HashMap(java.util.HashMap) EntityBean(org.akaza.openclinica.bean.core.EntityBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 12 with ItemFormMetadataBean

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

the class ItemFormMetadataDAO method findSCDItemsBySectionId.

/**
     * Find all ItemFormMetadataBean which is simple_conditional_display
     * 
     * @param sectionId
     * @return
     */
public ArrayList<ItemFormMetadataBean> findSCDItemsBySectionId(Integer sectionId) {
    ArrayList<ItemFormMetadataBean> answer = new ArrayList<ItemFormMetadataBean>();
    this.unsetTypeExpected();
    this.setTypesExpected();
    HashMap<Integer, Object> variables = new HashMap<Integer, Object>();
    variables.put(new Integer(1), sectionId);
    String sql = digester.getQuery("findSCDItemsBySectionId");
    ArrayList alist = this.select(sql, variables);
    Iterator it = alist.iterator();
    while (it.hasNext()) {
        ItemFormMetadataBean ifmb = (ItemFormMetadataBean) this.getEntityFromHashMap((HashMap) it.next());
        answer.add(ifmb);
    }
    return answer;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 13 with ItemFormMetadataBean

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

the class ItemFormMetadataDAO method findAllBySectionId.

public ArrayList<ItemFormMetadataBean> findAllBySectionId(int sectionId) throws OpenClinicaException {
    ArrayList<ItemFormMetadataBean> answer = new ArrayList<ItemFormMetadataBean>();
    this.setTypesExpected();
    HashMap<Integer, Object> variables = new HashMap<Integer, Object>();
    variables.put(new Integer(1), new Integer(sectionId));
    String sql = digester.getQuery("findAllBySectionId");
    ArrayList alist = this.select(sql, variables);
    Iterator it = alist.iterator();
    while (it.hasNext()) {
        ItemFormMetadataBean ifmb = (ItemFormMetadataBean) this.getEntityFromHashMap((HashMap) it.next());
        answer.add(ifmb);
    }
    return answer;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 14 with ItemFormMetadataBean

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

the class ItemFormMetadataDAO method findAllByCRFIdItemIdAndHasValidations.

public ArrayList<ItemFormMetadataBean> findAllByCRFIdItemIdAndHasValidations(int crfId, int itemId) {
    ArrayList<ItemFormMetadataBean> answer = new ArrayList<ItemFormMetadataBean>();
    this.setTypesExpected();
    HashMap<Integer, Object> variables = new HashMap<Integer, Object>();
    variables.put(new Integer(1), new Integer(crfId));
    variables.put(new Integer(2), new Integer(itemId));
    String sql = digester.getQuery("findAllByCRFIdItemIdAndHasValidations");
    ArrayList alist = this.select(sql, variables);
    Iterator it = alist.iterator();
    while (it.hasNext()) {
        ItemFormMetadataBean ifmb = (ItemFormMetadataBean) this.getEntityFromHashMap((HashMap) it.next());
        answer.add(ifmb);
    }
    return answer;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 15 with ItemFormMetadataBean

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

the class ScoreCalculator method redoCalculations.

/**
     * Re-do calculations if funcs include changed item(s) and funcs are not
     * included in the current section. If calculation can not sucessfully redo,
     * old value will be erased and "<erased>" will be saved in database. <br>
     * The parameter 'itemdata' might be overwritten.
     * 
     * @param itemGroupSizes
     * @param items
     * @param itemdata
     * @param oldItemdata
     * @param updatedData
     * @param sectionId
     * @return ArrayList<String> which records left_item_text of items who
     *         failed to be updated into database.
     */
public ArrayList<String> redoCalculations(HashMap<String, ItemBean> items, HashMap<String, String> itemdata, TreeSet<String> changedItems, HashMap<Integer, TreeSet<Integer>> itemOrdinals, int sectionId) {
    ArrayList<String> updateFailedItems = new ArrayList<String>();
    if (itemdata == null) {
        logger.error("In ScoreCalculator redoCalculations(), itemdata is empty!");
        errors.add("In ScoreCalculator redoCalculations(), 'itemdata' map is empty!");
        return updateFailedItems;
    }
    if (changedItems == null) {
        logger.error("In ScoreCalculator redoCalculations(), 'changeItems' set is empty!");
        errors.add("In ScoreCalculator redoCalculations(), 'changeItems' set is empty!");
        return updateFailedItems;
    }
    ItemFormMetadataDAO ifmdao = new ItemFormMetadataDAO(sm.getDataSource());
    ItemDAO idao = new ItemDAO(sm.getDataSource());
    ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
    NumberFormat nf = NumberFormat.getInstance();
    Parser parser = new Parser(items, itemdata);
    try {
        // for calculation type
        List<ItemFormMetadataBean> derivedItemList = ifmdao.findAllByCRFVersionIdAndResponseTypeId(ecb.getCRFVersionId(), ResponseType.CALCULATION.getId());
        if (derivedItemList.size() > 0) {
            Collections.sort(derivedItemList);
            for (ItemFormMetadataBean ifmb : derivedItemList) {
                if (ifmb.getSectionId() != sectionId) {
                    ItemBean ib = (ItemBean) idao.findByPK(ifmb.getItemId());
                    ResponseOptionBean rob = (ResponseOptionBean) ifmb.getResponseSet().getOptions().get(0);
                    int groupsize = 1;
                    if (itemOrdinals.containsKey(ib.getId())) {
                        groupsize = itemOrdinals.get(ib.getId()).size();
                    }
                    String value = "";
                    ArrayList<ScoreToken> parsedExp = new ArrayList<ScoreToken>();
                    for (int i = 0; i < groupsize; ++i) {
                        ItemDataBean idb = iddao.findByItemIdAndEventCRFIdAndOrdinal(ifmb.getItemId(), ecb.getId(), i + 1);
                        // is there any changed item
                        Parser p = new Parser(items, itemdata);
                        parsedExp = parser.parseScoreTokens(rob.getValue());
                        if (p.isChanged(changedItems, parsedExp)) {
                            StringBuffer err = new StringBuffer();
                            parsedExp = parser.assignVariables(parsedExp, i + 1);
                            // before, set "<erased>"
                            if (parser.getErrors().length() > 0) {
                                err.append(parser.getErrors());
                                if (idb.isActive()) {
                                    idb.setValue("<erased>");
                                    idb.setStatus(Status.UNAVAILABLE);
                                    idb = (ItemDataBean) iddao.update(idb);
                                    if (!idb.isActive()) {
                                        String key = i + 1 > 1 ? ifmb.getLeftItemText() + "_" + (i + 1) : ifmb.getLeftItemText();
                                        updateFailedItems.add(key);
                                    }
                                }
                                parser.setErrors(new StringBuffer());
                            } else // otherwise do calculation
                            {
                                try {
                                    value = ScoreUtil.eval(parsedExp);
                                } catch (ScoreException se) {
                                    logger.error(se.getMessage());
                                }
                                String exp = rob.getValue();
                                exp = exp.replace("##", ",");
                                if (writeToDB(ib, ifmb, idb, exp, value, err)) {
                                    changedItems.add(ib.getName());
                                    itemdata.put(ib.getId() + "_" + (i + 1), idb.getValue());
                                } else {
                                    String key = i + 1 > 1 ? ifmb.getLeftItemText() + "_" + (i + 1) : ifmb.getLeftItemText();
                                    updateFailedItems.add(key);
                                }
                            }
                            if (err.length() > 0) {
                                String key = i + 1 > 1 ? ifmb.getLeftItemText() + "_" + (i + 1) : ifmb.getLeftItemText();
                                errors.add("Item " + key + " contains calculation errors: " + err.toString());
                            }
                        }
                    }
                }
            }
        }
        List<ItemFormMetadataBean> itemList = ifmdao.findAllByCRFVersionIdAndResponseTypeId(ecb.getCRFVersionId(), ResponseType.GROUP_CALCULATION.getId());
        if (itemList.size() > 0) {
            Collections.sort(itemList);
            for (ItemFormMetadataBean ifmb : itemList) {
                if (ifmb.getSectionId() != sectionId) {
                    ItemBean ib = (ItemBean) idao.findByPK(ifmb.getItemId());
                    ResponseOptionBean rob = (ResponseOptionBean) ifmb.getResponseSet().getOptions().get(0);
                    String value = "";
                    Parser p = new Parser(items, itemdata);
                    ArrayList<ScoreToken> parsedExp = parser.parseScoreTokens(rob.getValue());
                    if (p.isChanged(changedItems, parsedExp)) {
                        StringBuffer err = new StringBuffer();
                        parser.setErrors(err);
                        parsedExp = parser.assignVariables(parsedExp, itemOrdinals);
                        ItemDataBean idb = iddao.findByItemIdAndEventCRFIdAndOrdinal(ifmb.getItemId(), ecb.getId(), 1);
                        if (parser.getErrors().length() > 0) {
                            err.append(parser.getErrors());
                            if (idb.isActive()) {
                                idb.setValue("<erased>");
                                idb.setStatus(Status.UNAVAILABLE);
                                idb = (ItemDataBean) iddao.update(idb);
                                if (!idb.isActive()) {
                                    updateFailedItems.add(ifmb.getLeftItemText());
                                }
                            }
                        } else {
                            try {
                                value = ScoreUtil.eval(parsedExp);
                            } catch (ScoreException se) {
                                logger.error(se.getMessage());
                            }
                            String exp = rob.getValue();
                            exp = exp.replace("##", ",");
                            if (writeToDB(ib, ifmb, idb, exp, value, err)) {
                                changedItems.add(ib.getName());
                                itemdata.put(ib.getId() + "_" + idb.getOrdinal(), idb.getValue());
                            } else {
                                updateFailedItems.add(ifmb.getLeftItemText());
                            }
                        }
                        if (err.length() > 0) {
                            errors.add("Item " + ifmb.getLeftItemText() + " contains calculation errors: " + err.toString());
                        }
                    }
                }
            }
        }
    } catch (OpenClinicaException e) {
        logger.error(e.getMessage());
    }
    return updateFailedItems;
}
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) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ScoreException(org.akaza.openclinica.exception.ScoreException) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) NumberFormat(java.text.NumberFormat)

Aggregations

ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)93 ArrayList (java.util.ArrayList)57 HashMap (java.util.HashMap)36 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)36 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)29 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)26 ItemFormMetadataDAO (org.akaza.openclinica.dao.submit.ItemFormMetadataDAO)25 DynamicsItemFormMetadataBean (org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean)25 Iterator (java.util.Iterator)21 ItemDAO (org.akaza.openclinica.dao.submit.ItemDAO)18 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)16 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)14 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)14 ItemGroupMetadataBean (org.akaza.openclinica.bean.submit.ItemGroupMetadataBean)13 DisplayItemGroupBean (org.akaza.openclinica.bean.submit.DisplayItemGroupBean)12 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)12 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)10 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)9 ResponseSetBean (org.akaza.openclinica.bean.submit.ResponseSetBean)9 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)9