use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class ScoreCalculator method writeToDB.
protected boolean writeToDB(ItemBean ib, ItemFormMetadataBean ifm, ItemDataBean idb, String exp, String value, StringBuffer err) {
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
NumberFormat nf = NumberFormat.getInstance();
if (idb == null) {
idb = new ItemDataBean();
}
ItemDataType idt = ib.getDataType();
if (value == null || value.length() == 0) {
if (idb.isActive() && !"".equals(idb.getValue())) {
idb.setValue("<erased>");
} else {
idb.setValue("");
}
err.append("Result is empty in" + " " + exp + "; ");
} else {
idb.setValue(this.getMathContextValue(value, ifm, idt, err));
}
idb.setStatus(Status.UNAVAILABLE);
// idb.setNeedsRecalc(false);
if (!idb.isActive()) {
// will this need to change for double data entry?
idb.setCreatedDate(new Date());
idb.setOwner(ub);
idb.setItemId(ib.getId());
idb.setEventCRFId(ecb.getId());
idb = (ItemDataBean) iddao.create(idb);
} else {
idb = (ItemDataBean) iddao.update(idb);
}
return idb.isActive();
}
use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class RuleSetBulkRuleRunner method runRulesBulkFromRuleSetScreen.
public List<RuleSetBasedViewContainer> runRulesBulkFromRuleSetScreen(List<RuleSetBean> ruleSets, ExecutionMode executionMode, StudyBean currentStudy, HashMap<String, String> variableAndValue, UserAccountBean ub) {
if (variableAndValue == null || variableAndValue.isEmpty()) {
logger.warn("You must be executing Rules in Batch");
variableAndValue = new HashMap<String, String>();
}
List<RuleSetBasedViewContainer> ruleSetBasedView = new ArrayList<RuleSetBasedViewContainer>();
HashMap<String, ArrayList<RuleActionContainer>> toBeExecuted = new HashMap<String, ArrayList<RuleActionContainer>>();
for (RuleSetBean ruleSet : ruleSets) {
String key = getExpressionService().getItemOid(ruleSet.getOriginalTarget().getValue());
List<RuleActionContainer> allActionContainerListBasedOnRuleExecutionResult = null;
if (toBeExecuted.containsKey(key)) {
allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
} else {
toBeExecuted.put(key, new ArrayList<RuleActionContainer>());
allActionContainerListBasedOnRuleExecutionResult = toBeExecuted.get(key);
}
ItemDataBean itemData = null;
for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
ruleSet.setTarget(expressionBean);
System.out.println("tg expression:" + ruleSet.getTarget().getValue());
for (RuleSetRuleBean ruleSetRule : ruleSet.getRuleSetRules()) {
String result = null;
RuleBean rule = ruleSetRule.getRuleBean();
ExpressionObjectWrapper eow = new ExpressionObjectWrapper(ds, currentStudy, rule.getExpression(), ruleSet, variableAndValue);
try {
OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow);
result = (String) oep.parseAndEvaluateExpression(rule.getExpression().getValue());
itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue());
System.out.println("The result: " + result);
List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, Phase.BATCH);
if (itemData != null) {
Iterator<RuleActionBean> itr = actionListBasedOnRuleExecutionResult.iterator();
while (itr.hasNext()) {
RuleActionBean ruleActionBean = itr.next();
RuleActionRunLogBean ruleActionRunLog = new RuleActionRunLogBean(ruleActionBean.getActionType(), itemData, itemData.getValue(), ruleSetRule.getRuleBean().getOid());
if (getRuleActionRunLogDao().findCountByRuleActionRunLogBean(ruleActionRunLog) > 0) {
itr.remove();
}
}
}
for (RuleActionBean ruleActionBean : actionListBasedOnRuleExecutionResult) {
RuleActionContainer ruleActionContainer = new RuleActionContainer(ruleActionBean, expressionBean, itemData, ruleSet);
allActionContainerListBasedOnRuleExecutionResult.add(ruleActionContainer);
}
logger.info("RuleSet with target : {} , Ran Rule : {} The Result was : {} , Based on that {} action will be executed in {} mode. ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size(), executionMode.name() });
} catch (OpenClinicaSystemException osa) {
// TODO: report something useful
}
}
}
}
for (Map.Entry<String, ArrayList<RuleActionContainer>> entry : toBeExecuted.entrySet()) {
// Sort the list of actions
Collections.sort(entry.getValue(), new RuleActionContainerComparator());
for (RuleActionContainer ruleActionContainer : entry.getValue()) {
ruleActionContainer.getRuleSetBean().setTarget(ruleActionContainer.getExpressionBean());
ruleActionContainer.getRuleAction().setCuratedMessage(curateMessage(ruleActionContainer.getRuleAction(), ruleActionContainer.getRuleAction().getRuleSetRule()));
ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleActionContainer.getRuleAction().getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleActionContainer.getRuleSetBean(), getRuleActionRunLogDao(), ruleActionContainer.getRuleAction().getRuleSetRule());
RuleActionBean rab = ap.execute(RuleRunnerMode.RULSET_BULK, executionMode, ruleActionContainer.getRuleAction(), ruleActionContainer.getItemDataBean(), DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule(), currentStudy, ruleActionContainer.getRuleAction()));
System.out.println(" Action Trigger: " + ap.toString());
if (rab != null) {
ruleSetBasedView = populateForRuleSetBasedView(ruleSetBasedView, ruleActionContainer.getRuleSetBean(), ruleActionContainer.getRuleAction().getRuleSetRule().getRuleBean(), ruleActionContainer.getRuleAction().getExpressionEvaluatesTo().toString(), ruleActionContainer.getRuleAction());
}
}
}
return ruleSetBasedView;
}
use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class ItemDAO method findAllWithItemDataByFormLayoutId.
// select name, ordinal, oc_oid, item_data_id, i.item_id as item_id, value
//
// from item_data id, item i
// where id.item_id=i.item_id and event_crf_id = ? order by i.item_id,ordinal;
public ArrayList<ItemBean> findAllWithItemDataByFormLayoutId(int crfVersionId, int eventCRFId) {
this.unsetTypeExpected();
// (item)name
this.setTypeExpected(1, TypeNames.STRING);
// ordinal
this.setTypeExpected(2, TypeNames.INT);
// oc_oid
this.setTypeExpected(3, TypeNames.STRING);
// item_data_id
this.setTypeExpected(4, TypeNames.INT);
// item_id
this.setTypeExpected(5, TypeNames.INT);
// (item)value
this.setTypeExpected(6, TypeNames.STRING);
ArrayList<ItemBean> answer = new ArrayList<ItemBean>();
HashMap variables = new HashMap();
variables.put(new Integer(1), new Integer(crfVersionId));
variables.put(new Integer(2), new Integer(eventCRFId));
String sql = digester.getQuery("findAllWithItemDataByFormLayoutId");
ArrayList rows = super.select(sql, variables);
Iterator it = rows.iterator();
int cur_item_id = 0;
ItemBean item_bean = null;
ItemDataBean item_data_bean = null;
while (it.hasNext()) {
HashMap row = (HashMap) it.next();
Integer id = (Integer) row.get("item_id");
if (cur_item_id != id.intValue()) {
item_bean = new ItemBean();
answer.add(item_bean);
cur_item_id = id.intValue();
item_bean.setId(cur_item_id);
item_bean.setName((String) row.get("name"));
item_bean.setOid((String) row.get("oc_oid"));
}
item_data_bean = new ItemDataBean();
item_data_bean.setValue((String) row.get("value"));
item_data_bean.setOrdinal(((Integer) row.get("ordinal")).intValue());
item_data_bean.setId(((Integer) row.get("item_data_id")).intValue());
item_data_bean.setItemId(cur_item_id);
item_bean.addItemDataElement(item_data_bean);
}
return answer;
}
use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class ItemDataDAO method findByItemIdAndEventCRFIdAndOrdinal.
// YW, 1-25-2008, for repeating item
public ItemDataBean findByItemIdAndEventCRFIdAndOrdinal(int itemId, int eventCRFId, int ordinal) {
setTypesExpected();
ItemDataBean answer = new ItemDataBean();
HashMap<Integer, Integer> variables = new HashMap<Integer, Integer>();
variables.put(new Integer(1), new Integer(itemId));
variables.put(new Integer(2), new Integer(eventCRFId));
variables.put(new Integer(3), new Integer(ordinal));
EntityBean eb = this.executeFindByPKQuery("findByItemIdAndEventCRFIdAndOrdinal", variables);
if (!eb.isActive()) {
// hmm, return null instead?
return new ItemDataBean();
} else {
return (ItemDataBean) eb;
}
}
use of org.akaza.openclinica.bean.submit.ItemDataBean in project OpenClinica by OpenClinica.
the class ItemDataDAO method updateUser.
public EntityBean updateUser(EntityBean eb) {
ItemDataBean idb = (ItemDataBean) eb;
idb.setActive(false);
HashMap<Integer, Comparable> variables = new HashMap<Integer, Comparable>();
variables.put(new Integer(1), new Integer(idb.getUpdaterId()));
variables.put(new Integer(2), new Integer(idb.getId()));
this.execute(digester.getQuery("updateUser"), variables);
if (isQuerySuccessful()) {
idb.setActive(true);
}
return idb;
}
Aggregations