Search in sources :

Example 51 with ItemFormMetadataBean

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

the class DynamicsMetadataService method showItem.

public boolean showItem(ItemFormMetadataBean metadataBean, EventCRFBean eventCrfBean, ItemDataBean itemDataBean) {
    ItemFormMetadataBean itemFormMetadataBean = metadataBean;
    itemFormMetadataBean.setShowItem(true);
    DynamicsItemFormMetadataBean dynamicsMetadataBean = new DynamicsItemFormMetadataBean(itemFormMetadataBean, eventCrfBean);
    dynamicsMetadataBean.setItemDataId(itemDataBean.getId());
    dynamicsMetadataBean.setShowItem(true);
    dynamicsMetadataBean.setPassedDde(0);
    getDynamicsItemFormMetadataDao().saveOrUpdate(dynamicsMetadataBean);
    logger.debug("just touched ifmb id " + metadataBean.getId() + " ecb id " + eventCrfBean.getId() + " item id " + metadataBean.getItemId() + " itemdata id " + itemDataBean.getId());
    return true;
}
Also used : DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 52 with ItemFormMetadataBean

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

the class DynamicsMetadataService method hide.

public boolean hide(Object metadataBean, EventCRFBean eventCrfBean) {
    // TODO -- interesting problem, where is the SpringServletAccess object going to live now? tbh 03/2010
    ItemFormMetadataBean itemFormMetadataBean = (ItemFormMetadataBean) metadataBean;
    itemFormMetadataBean.setShowItem(false);
    // DynamicsItemFormMetadataDao dynamicsMetadataDao = (DynamicsItemFormMetadataDao) metadataDao;
    // DynamicsItemFormMetadataDao metadataDao = (DynamicsItemFormMetadataDao) SpringServletAccess.getApplicationContext(context).getBean("dynamicsItemFormMetadataDao");
    DynamicsItemFormMetadataBean dynamicsMetadataBean = new DynamicsItemFormMetadataBean(itemFormMetadataBean, eventCrfBean);
    dynamicsMetadataBean.setShowItem(false);
    getDynamicsItemFormMetadataDao().saveOrUpdate(dynamicsMetadataBean);
    return true;
}
Also used : DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 53 with ItemFormMetadataBean

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

the class DynamicsMetadataService method isShown.

// deprecated?
public boolean isShown(Integer itemId, EventCRFBean eventCrfBean) {
    // do we check against the database, or just against the object? prob against the db
    // ItemFormMetadataBean itemFormMetadataBean = (ItemFormMetadataBean) metadataBean;
    // return itemFormMetadataBean.isShowItem();
    ItemFormMetadataBean itemFormMetadataBean = getItemFormMetadataDAO().findByItemIdAndCRFVersionId(itemId, eventCrfBean.getCRFVersionId());
    DynamicsItemFormMetadataBean dynamicsMetadataBean = getDynamicsItemFormMetadataBean(itemFormMetadataBean, eventCrfBean, null);
    // DynamicsItemFormMetadataBean dynamicsMetadataBean = getDynamicsItemFormMetadataDao().findByMetadataBean(itemFormMetadataBean, eventCrfBean);
    if (dynamicsMetadataBean != null) {
        return dynamicsMetadataBean.isShowItem();
    } else {
        logger.debug("did not find a row in the db for " + itemFormMetadataBean.getId());
        return false;
    }
// return false;
}
Also used : DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 54 with ItemFormMetadataBean

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

the class DynamicsMetadataService method hideItem.

public boolean hideItem(ItemFormMetadataBean metadataBean, EventCRFBean eventCrfBean, ItemDataBean itemDataBean) {
    ItemFormMetadataBean itemFormMetadataBean = metadataBean;
    DynamicsItemFormMetadataBean dynamicsMetadataBean = this.getDynamicsItemFormMetadataDao().findByItemDataBean(itemDataBean);
    dynamicsMetadataBean = dynamicsMetadataBean != null && dynamicsMetadataBean.getId() > 0 ? dynamicsMetadataBean : new DynamicsItemFormMetadataBean(itemFormMetadataBean, eventCrfBean);
    dynamicsMetadataBean.setShowItem(false);
    getDynamicsItemFormMetadataDao().saveOrUpdate(dynamicsMetadataBean);
    return true;
}
Also used : DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) DynamicsItemFormMetadataBean(org.akaza.openclinica.domain.crfdata.DynamicsItemFormMetadataBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 55 with ItemFormMetadataBean

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

the class ScoreCalculator method doCalculation.

/*
     * Perform all calculations in a CRFVersion. The parameter 'itemdata' might
     * be overwritten.
     * 
     * @param calcItemGroupSizes @param items @param itemdata @param
     * itemGroupSizes @param databaseErrors @return ArrayList<String> which
     * records left_item_text of items who failed to be updated into database.
     * 
     * 
     * //this method has not been fully tested yet
     * 
     * 
     * public ArrayList<String> doCalculations( HashMap<String,ItemBean>
     * items, HashMap<String,String> itemdata, HashMap<Integer,TreeSet<Integer>>
     * itemOrdinals) { ArrayList<String> updateFailedItems = new ArrayList<String>();
     * if(itemdata==null) { //here, actually only record errors but doesn't
     * return errors. logger.error("In scoreCalculator doCalculations(), items
     * are empty!"); errors.add("Calculation cannot be started because needed
     * items are 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) { ItemBean ib =
     * (ItemBean)idao.findByPK(ifmb.getItemId()); ResponseOptionBean rob =
     * (ResponseOptionBean)ifmb.getResponseSet().getOptions().get(0); //YW,
     * 1-16-2008, << enable: 1. evaluate combination of expression and
     * functions 2. scoring for group items. //int groupsize =
     * iddao.getMaxOrdinalForGroup(ecb,
     * (SectionBean)sdao.findByPK(ifmb.getSectionId()), //
     * (ItemGroupBean)igdao.findByName(ifmb.getGroupLabel())); int groupsize =
     * 1; if(itemOrdinals.containsKey(ib.getId())) { groupsize =
     * (itemOrdinals.get(ib.getId())).size(); } String value = ""; String
     * parsedExp = ""; for(int i=0; i<groupsize; ++i) { ItemDataBean idb =
     * (ItemDataBean)iddao.findByItemIdAndEventCRFIdAndOrdinal(ifmb
     * .getItemId(), ecb.getId(), i+1); StringBuffer err = new StringBuffer();
     * parsedExp = parser.parse(rob.getValue(), i+1);
     * if(parser.getErrors().length()>0) { err.append(parser.getErrors());
     * parser.setErrors(new StringBuffer()); } else { value =
     * ScoreUtil.eval(parsedExp, err); //YW >> String exp = rob.getValue(); exp =
     * exp.replace("##", ","); if(writeToDB(ib,idb,exp,value,err)) {
     * 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()); } } } }
     * 
     * //YW, 1-16-2008, for group-calculation type. Current restrictions: //1.
     * an item with group-calculation type is not repeatable. //2. only
     * calculate sum(), avg(), min(), max(), median(), stdev() //3. formula
     * arguments only contain item beans //4. only one item bean per argument
     * List<ItemFormMetadataBean> itemList =
     * ifmdao.findAllByCRFVersionIdAndResponseTypeId( ecb.getCRFVersionId(),
     * ResponseType.GROUP_CALCULATION.getId()); if(itemList.size()>0) {
     * Collections.sort(itemList); for (ItemFormMetadataBean ifmb: itemList) {
     * ItemBean ib = (ItemBean)idao.findByPK(ifmb.getItemId());
     * ResponseOptionBean rob =
     * (ResponseOptionBean)ifmb.getResponseSet().getOptions().get(0);
     * StringBuffer err = new StringBuffer(); parser.setErrors(err); String
     * parsedExp = parser.parse(rob.getValue(),itemOrdinals); String value = "";
     * if(parser.getErrors().length()>0) { err.append(parser.getErrors()); }else {
     * value = ScoreUtil.eval(parsedExp,err);
     * 
     * ItemDataBean idb =
     * (ItemDataBean)iddao.findByItemIdAndEventCRFIdAndOrdinal(ifmb
     * .getItemId(), ecb.getId(), 1); String exp = rob.getValue(); exp =
     * exp.replace("##", ","); if(writeToDB(ib,idb,exp,value,err)) {
     * 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()); }
     * //ecb.setNeedsRecalc(false); //EventCRFDAO ecdao = new
     * EventCRFDAO(sm.getDataSource()); //ecb = ecdao.update(ecb);
     * 
     * return updateFailedItems; }
     */
/**
 * Performs calculation. <br>
 * Notice: both parameter 'itemdata' and parameter 'errs' might be updated
 * in this method.
 *
 * @param displayItems
 * @param items
 * @param itemdata
 * @param errs
 * @return
 *
 * @author ywang (Jan. 2008)
 */
public String doCalculation(DisplayItemBean displayItem, HashMap<String, ItemBean> items, HashMap<String, String> itemdata, HashMap<Integer, TreeSet<Integer>> itemOrdinals, StringBuffer errs, int ordinal) {
    if (itemdata == null) {
        logger.error("In DataEntryServlet doCalculation(), itemdata map is empty!");
        errs.append("Calculation cannot be started because needed items are empty" + "; ");
        return "";
    }
    String value = "";
    NumberFormat nf = NumberFormat.getInstance();
    Parser parser = new Parser(items, itemdata);
    ItemBean ib = displayItem.getItem();
    ItemFormMetadataBean ifm = displayItem.getMetadata();
    ResponseOptionBean rob = (ResponseOptionBean) ifm.getResponseSet().getOptions().get(0);
    ArrayList<ScoreToken> parsedExp = new ArrayList<ScoreToken>();
    int type = ifm.getResponseSet().getResponseTypeId();
    if (type == 8) {
        parsedExp = parser.assignVariables(parser.parseScoreTokens(rob.getValue()), ordinal);
    } else if (type == 9) {
        // YW, 1-16-2008, for group-calculation type. Current restrictions:
        // 1. only calculate sum(), avg(), min(), max(), median(), stdev()
        // 2. formula arguments only contain item beans
        // 3. only one item bean per argument
        parsedExp = parser.assignVariables(parser.parseScoreTokens(rob.getValue()), itemOrdinals);
    }
    if (parser.getErrors().length() > 0) {
        errs.append(parser.getErrors());
    } else {
        try {
            value = ScoreUtil.eval(parsedExp);
        } catch (ScoreException se) {
            logger.error(se.getMessage());
        }
        ItemDataType idt = ib.getDataType();
        if (value == null || value.length() == 0) {
            value = "";
            String exp = rob.getValue();
            exp = exp.replace("##", ",");
            errs.append("Result is empty in" + " " + exp + "; ");
        // errors.append(resexception.getString("result_is_empty_in") +
        // " " + exp + "; ");
        } else {
            value = this.getMathContextValue(value, ifm, idt, errs);
        }
        // idb.setStatus(Status.UNAVAILABLE);
        itemdata.put(ib.getId() + "_" + ordinal, value);
    }
    return value;
}
Also used : ScoreException(org.akaza.openclinica.exception.ScoreException) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDataType(org.akaza.openclinica.bean.core.ItemDataType) ArrayList(java.util.ArrayList) ResponseOptionBean(org.akaza.openclinica.bean.submit.ResponseOptionBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean) NumberFormat(java.text.NumberFormat)

Aggregations

ItemFormMetadataBean (org.akaza.openclinica.bean.submit.ItemFormMetadataBean)93 ArrayList (java.util.ArrayList)58 HashMap (java.util.HashMap)36 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)36 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)28 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 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)16 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)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)9 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)9 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)8 ResponseSetBean (org.akaza.openclinica.bean.submit.ResponseSetBean)8