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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations