use of org.akaza.openclinica.domain.rule.expression.ExpressionBean in project OpenClinica by OpenClinica.
the class StratificationFactorBean method setExpressionAsString.
public void setExpressionAsString(String expressionAsString) {
stratificationFactor = new ExpressionBean(Context.OC_RULES_V1, expressionAsString);
this.expressionAsString = expressionAsString;
}
use of org.akaza.openclinica.domain.rule.expression.ExpressionBean in project OpenClinica by OpenClinica.
the class RuleSetBulkRuleRunner method runRulesBulkFromRuleSetScreenOLD.
public List<RuleSetBasedViewContainer> runRulesBulkFromRuleSetScreenOLD(List<RuleSetBean> ruleSets, Boolean dryRun, 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>();
for (RuleSetBean ruleSet : ruleSets) {
for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
ruleSet.setTarget(expressionBean);
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());
// HashMap<String, ArrayList<RuleActionBean>> actionsToBeExecuted = ruleSetRule.getAllActionsWithEvaluatesToAsKey(result);
List<RuleActionBean> actionListBasedOnRuleExecutionResult = ruleSetRule.getActions(result, Phase.BATCH);
ItemDataBean itemData = getExpressionService().getItemDataBeanFromDb(ruleSet.getTarget().getValue());
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();
}
}
}
logger.info("RuleSet with target : {} , Ran Rule : {} The Result was : {} , Based on that {} action will be executed ", new Object[] { ruleSet.getTarget().getValue(), rule.getName(), result, actionListBasedOnRuleExecutionResult.size() });
if (actionListBasedOnRuleExecutionResult.size() > 0) {
for (RuleActionBean ruleAction : actionListBasedOnRuleExecutionResult) {
ruleAction.setCuratedMessage(curateMessage(ruleAction, ruleSetRule));
// getDiscrepancyNoteService().saveFieldNotes(ruleAction.getSummary(), itemDataBeanId, "ItemData", currentStudy, ub);
ActionProcessor ap = ActionProcessorFacade.getActionProcessor(ruleAction.getActionType(), ds, getMailSender(), dynamicsMetadataService, ruleSet, getRuleActionRunLogDao(), ruleSetRule);
RuleActionBean rab = ap.execute(RuleRunnerMode.RULSET_BULK, ExecutionMode.SAVE, ruleAction, itemData, DiscrepancyNoteBean.ITEM_DATA, currentStudy, ub, prepareEmailContents(ruleSet, ruleSetRule, currentStudy, ruleAction));
if (rab != null) {
ruleSetBasedView = populateForRuleSetBasedView(ruleSetBasedView, ruleSet, rule, result, ruleAction);
}
}
}
} catch (OpenClinicaSystemException osa) {
String errorMessage = "RuleSet with target : " + ruleSet.getTarget().getValue() + " , Ran Rule : " + rule.getName() + " , It resulted in an error due to : " + osa.getMessage();
// log error
logger.warn(errorMessage);
}
}
}
}
return ruleSetBasedView;
}
use of org.akaza.openclinica.domain.rule.expression.ExpressionBean in project OpenClinica by OpenClinica.
the class RuleSetService method solidifyGroupOrdinalsUsingFormProperties.
/*
* (non-Javadoc)
* @see org.akaza.openclinica.service.rule.RuleSetServiceInterface#solidifyGroupOrdinalsUsingFormProperties(java.util.List, java.util.HashMap)
*/
public List<RuleSetBean> solidifyGroupOrdinalsUsingFormProperties(List<RuleSetBean> ruleSets, HashMap<String, Integer> grouped) {
for (RuleSetBean ruleSet : ruleSets) {
ArrayList<ExpressionBean> expressionsWithCorrectGroupOrdinal = new ArrayList<ExpressionBean>();
for (ExpressionBean expression : ruleSet.getExpressions()) {
logger.debug("solidifyGroupOrdinals: Expression Value : " + expression.getValue());
String groupOIDConcatItemOID = getExpressionService().getGroupOidConcatWithItemOid(expression.getValue());
String itemOID = getExpressionService().getItemOid(expression.getValue());
String groupOrdinal = getExpressionService().getGroupOrdninalCurated(expression.getValue());
if (grouped.containsKey(groupOIDConcatItemOID) && groupOrdinal.equals("")) {
for (int i = 0; i < grouped.get(groupOIDConcatItemOID); i++) {
ExpressionBean expBean = new ExpressionBean();
expBean.setValue(getExpressionService().replaceGroupOidOrdinalInExpression(expression.getValue(), i + 1));
expBean.setContext(expression.getContext());
expressionsWithCorrectGroupOrdinal.add(expBean);
}
} else if (grouped.containsKey(groupOIDConcatItemOID) && !groupOrdinal.equals("")) {
ExpressionBean expBean = new ExpressionBean();
expBean.setValue(expression.getValue());
expBean.setContext(expression.getContext());
expressionsWithCorrectGroupOrdinal.add(expBean);
} else if (grouped.containsKey(itemOID)) {
ExpressionBean expBean = new ExpressionBean();
expBean.setValue(getExpressionService().replaceGroupOidOrdinalInExpression(expression.getValue(), null));
expBean.setContext(expression.getContext());
expressionsWithCorrectGroupOrdinal.add(expBean);
}
}
ruleSet.setExpressions(expressionsWithCorrectGroupOrdinal);
for (ExpressionBean expressionBean : ruleSet.getExpressions()) {
logger.debug("expressionBean value : {} ", expressionBean.getValue());
}
}
return ruleSets;
}
use of org.akaza.openclinica.domain.rule.expression.ExpressionBean in project OpenClinica by OpenClinica.
the class JobTriggerService method triggerJob.
public void triggerJob() {
ResourceBundleProvider.updateLocale(new Locale("en_US"));
ArrayList<RuleSetBean> ruleSets = ruleSetDao.findAllRunOnSchedules(true);
for (RuleSetBean ruleSet : ruleSets) {
if (ruleSet.getStatus().AVAILABLE != null && ruleSet.isRunSchedule()) {
if (ruleSet.getItemId() != null) {
// item Specific Rule
ArrayList<RuleSetBean> ruleSetBeans = new ArrayList<>();
StudyBean currentStudy = (StudyBean) getStudyDao().findByPK(ruleSet.getStudyId());
ResourceBundleProvider.updateLocale(Locale.getDefault());
UserAccountBean ub = (UserAccountBean) getUserAccountDao().findByPK(1);
ruleSetBeans.add(ruleSet);
ruleSetService.runRulesInBulk(ruleSetBeans, false, currentStudy, ub, true);
} else {
// Event Specific Rule
StudyEventChangeDetails studyEventChangeDetails = new StudyEventChangeDetails(true, true);
ArrayList<RuleSetBean> ruleSetBeans = new ArrayList<>();
ExpressionBean eBean = new ExpressionBean();
eBean.setValue(ruleSet.getTarget().getValue() + ".A.B");
ruleSet.setTarget(eBean);
ruleSetBeans.add(ruleSet);
ruleSetService.runRulesInBeanProperty(ruleSetBeans, 1, studyEventChangeDetails);
}
}
}
}
use of org.akaza.openclinica.domain.rule.expression.ExpressionBean in project OpenClinica by OpenClinica.
the class RuleSetService method filterRuleSetsByGroupOrdinal.
/*
* (non-Javadoc)
* @see org.akaza.openclinica.service.rule.RuleSetServiceInterface#filterRuleSetsByGroupOrdinal(java.util.List)
*/
public List<RuleSetBean> filterRuleSetsByGroupOrdinal(List<RuleSetBean> ruleSets) {
for (RuleSetBean ruleSetBean : ruleSets) {
List<ExpressionBean> expressionsWithCorrectGroupOrdinal = new ArrayList<ExpressionBean>();
/**
* get the itemDataSize by studyEventId,itemGroupOid,itemOid for the whole study
* only run once
*/
String itemOid = getExpressionService().getItemOid(ruleSetBean.getExpressions().get(0).getValue());
String itemGroupOid = getExpressionService().getItemGroupOid(ruleSetBean.getExpressions().get(0).getValue());
HashMap itemDataCountHm = getItemDataDao().findCountByStudyEventAndOIDs(ruleSetBean.getStudyId(), itemOid, itemGroupOid);
int itemDataSize = 0;
for (ExpressionBean expression : ruleSetBean.getExpressions()) {
String studyEventId = getExpressionService().getStudyEventDefinitionOrdninalCurated(expression.getValue());
itemOid = getExpressionService().getItemOid(expression.getValue());
itemGroupOid = getExpressionService().getItemGroupOid(expression.getValue());
String groupOrdinal = getExpressionService().getGroupOrdninalCurated(expression.getValue());
String key = studyEventId + itemGroupOid + itemOid;
if (itemDataCountHm.containsKey(key)) {
itemDataSize = ((Integer) itemDataCountHm.get(key)).intValue();
logger.debug("studyEventId {} , itemOid {} , itemGroupOid {} , groupOrdinal {} , itemDatas {}", new Object[] { studyEventId, itemOid, itemGroupOid, groupOrdinal, itemDataSize });
}
// case 1 : group ordinal = ""
if (groupOrdinal.equals("") && itemDataSize > 0) {
for (int k = 0; k < itemDataSize; k++) {
ExpressionBean expBean = new ExpressionBean();
expBean.setValue(getExpressionService().replaceGroupOidOrdinalInExpression(expression.getValue(), k + 1));
expBean.setContext(expression.getContext());
expressionsWithCorrectGroupOrdinal.add(expBean);
}
}
// case 2 : group ordinal = x and itemDatas should be size >= x
if (!groupOrdinal.equals("") && itemDataSize >= Integer.valueOf(groupOrdinal)) {
ExpressionBean expBean = new ExpressionBean();
expBean.setValue(getExpressionService().replaceGroupOidOrdinalInExpression(expression.getValue(), null));
expBean.setContext(expression.getContext());
expressionsWithCorrectGroupOrdinal.add(expBean);
}
itemDataSize = 0;
}
ruleSetBean.setExpressions(expressionsWithCorrectGroupOrdinal);
}
logExpressions(ruleSets);
return ruleSets;
}
Aggregations