use of org.akaza.openclinica.domain.rule.action.EventActionBean in project OpenClinica by OpenClinica.
the class RulesPostImportContainerServiceTest method createRuleSetRule.
private RuleSetRuleBean createRuleSetRule(RuleSetBean ruleSet, String ruleOid, String oidRef) {
RuleSetRuleBean ruleSetRule = new RuleSetRuleBean();
// DiscrepancyNoteActionBean ruleAction = new DiscrepancyNoteActionBean();
EventActionBean ruleAction = new EventActionBean();
ruleAction.setOc_oid_reference(oidRef);
ruleAction.setExpressionEvaluatesTo(true);
ruleSetRule.addAction(ruleAction);
ruleSetRule.setRuleSetBean(ruleSet);
ruleSetRule.setOid(ruleOid);
return ruleSetRule;
}
use of org.akaza.openclinica.domain.rule.action.EventActionBean in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method isRuleActionValid.
private void isRuleActionValid(RuleActionBean ruleActionBean, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, EventDefinitionCRFBean eventDefinitionCRFBean, List<RuleSetBean> eventActionsRuleSetBean) {
RuleActionRunBean ruleActionRun = ruleActionBean.getRuleActionRun();
if (ruleActionBean.getActionType().getCode() != 6 && !ruleActionRun.getInitialDataEntry() && !ruleActionRun.getAdministrativeDataEntry() && !ruleActionRun.getBatch() && !ruleActionRun.getDoubleDataEntry() && !ruleActionRun.getImportDataEntry())
ruleSetBeanWrapper.error(createError("OCRERR_0050"));
String message = "";
String emailSubject = "";
if (ruleActionBean instanceof org.akaza.openclinica.domain.rule.action.NotificationActionBean) {
message = ((NotificationActionBean) ruleActionBean).getMessage();
emailSubject = ((NotificationActionBean) ruleActionBean).getSubject();
if (emailSubject.length() > 330)
ruleSetBeanWrapper.error(createError("OCRERR_0048"));
if (message.length() > 2040)
ruleSetBeanWrapper.error(createError("OCRERR_0049"));
}
if (ruleActionBean instanceof org.akaza.openclinica.domain.rule.action.EmailActionBean)
isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper);
if (ruleActionBean instanceof DiscrepancyNoteActionBean)
isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper);
if (ruleActionBean instanceof ShowActionBean) {
if (!isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper)) {
List<PropertyBean> properties = ((ShowActionBean) ruleActionBean).getProperties();
// if (ruleActionBean.getRuleActionRun().getBatch() == true || ruleActionBean.getRuleActionRun().getImportDataEntry() == true) {
if (ruleActionBean.getRuleActionRun().getBatch() == true) {
ruleSetBeanWrapper.error("ShowAction " + ((ShowActionBean) ruleActionBean).toString() + " is not Valid. You cannot have Batch=\"true\". ");
// + " is not Valid. You cannot have ImportDataEntry=\"true\" Batch=\"true\". ");
}
for (PropertyBean propertyBean : properties) {
String result = getExpressionService().checkValidityOfItemOrItemGroupOidInCrf(propertyBean.getOid(), ruleSetBeanWrapper.getAuditableBean());
// String result = getExpressionService().isExpressionValid(oid, ruleSetBeanWrapper.getAuditableBean(), 2) ? "OK" : "";
if (!result.equals("OK")) {
ruleSetBeanWrapper.error("ShowAction OID " + result + " is not Valid. ");
}
}
}
}
if (ruleActionBean instanceof HideActionBean) {
if (!isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper)) {
List<PropertyBean> properties = ((HideActionBean) ruleActionBean).getProperties();
// if (ruleActionBean.getRuleActionRun().getBatch() == true || ruleActionBean.getRuleActionRun().getImportDataEntry() == true) {
if (ruleActionBean.getRuleActionRun().getBatch() == true) {
ruleSetBeanWrapper.error("HideAction " + ((HideActionBean) ruleActionBean).toString() + " is not Valid. You cannot have Batch=\"true\". ");
// + " is not Valid. You cannot have ImportDataEntry=\"true\" Batch=\"true\". ");
}
for (PropertyBean propertyBean : properties) {
String result = getExpressionService().checkValidityOfItemOrItemGroupOidInCrf(propertyBean.getOid(), ruleSetBeanWrapper.getAuditableBean());
// String result = getExpressionService().isExpressionValid(oid, ruleSetBeanWrapper.getAuditableBean(), 2) ? "OK" : "";
if (!result.equals("OK")) {
ruleSetBeanWrapper.error("HideAction OID " + result + " is not Valid. ");
}
}
}
}
if (ruleActionBean instanceof InsertActionBean) {
if (!isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper)) {
DataBinder dataBinder = new DataBinder(ruleActionBean);
Errors errors = dataBinder.getBindingResult();
InsertActionValidator insertActionValidator = getInsertActionValidator();
insertActionValidator.setEventDefinitionCRFBean(eventDefinitionCRFBean);
insertActionValidator.setRuleSetBean(ruleSetBeanWrapper.getAuditableBean());
insertActionValidator.setExpressionService(expressionService);
insertActionValidator.validate(ruleActionBean, errors);
if (errors.hasErrors()) {
ruleSetBeanWrapper.error("InsertAction is not valid: " + errors.getAllErrors().get(0).getCode());
}
}
}
if (ruleActionBean instanceof RandomizeActionBean) {
if (!isUploadedRuleSupportedForEventAction(ruleSetBeanWrapper)) {
DataBinder dataBinder = new DataBinder(ruleActionBean);
Errors errors = dataBinder.getBindingResult();
RandomizeActionValidator randomizeActionValidator = getRandomizeActionValidator();
randomizeActionValidator.setEventDefinitionCRFBean(eventDefinitionCRFBean);
randomizeActionValidator.setRuleSetBean(ruleSetBeanWrapper.getAuditableBean());
randomizeActionValidator.setExpressionService(expressionService);
randomizeActionValidator.validate(ruleActionBean, errors);
RandomizeActionBean randomizeActionBean = (RandomizeActionBean) ruleActionBean;
// ruleSetBeanWrapper.error(createError("OCRERR_0050"));
if (randomizeActionBean.getStratificationFactors() != null) {
for (StratificationFactorBean factor : randomizeActionBean.getStratificationFactors()) {
if (factor.getStratificationFactor() != null && factor.getStratificationFactor().getValue() != null && factor.getStratificationFactor().getValue().length() != 0) {
String expressionContextName = factor.getStratificationFactor().getContextName();
Context context = expressionContextName != null ? Context.getByName(expressionContextName) : Context.OC_RULES_V1;
factor.getStratificationFactor().setContext(context);
ExpressionBean expBean = factor.getStratificationFactor();
String expValue = expBean.getValue();
String prefix = "STUDYGROUPCLASSLIST";
boolean sgcExist = false;
if (expValue.startsWith("SS.")) {
String param = expValue.split("\\.", -1)[1].trim();
if (param.startsWith(prefix)) {
String gcName = param.substring(21, param.indexOf("\"]"));
StudyGroupClassDAO studyGroupClassDAO = new StudyGroupClassDAO(ds);
ArrayList<StudyGroupClassBean> studyGroupClasses = studyGroupClassDAO.findAllByStudy(currentStudy);
for (StudyGroupClassBean studyGroupClass : studyGroupClasses) {
if (studyGroupClass.getName().equalsIgnoreCase(gcName.trim())) {
sgcExist = true;
break;
}
}
}
if (!param.equalsIgnoreCase("BIRTHDATE") && !param.equalsIgnoreCase("SEX") && !sgcExist) {
ruleSetBeanWrapper.error(createError("OCRERR_0051", expBean.getValue()));
}
} else {
isStratificationExpressionValid(expBean, ruleSetBeanWrapper);
}
}
}
}
if (errors.hasErrors())
ruleSetBeanWrapper.error("Randomize Action is not valid: " + errors.getAllErrors().get(0).getCode());
}
}
if (ruleActionBean instanceof EventActionBean) {
DataBinder dataBinder = new DataBinder(ruleActionBean);
Errors errors = dataBinder.getBindingResult();
eventActionValidator.setRuleSetBeanWrapper(ruleSetBeanWrapper);
eventActionValidator.setExpressionService(expressionService);
eventActionValidator.setRespage(respage);
eventActionValidator.validate(ruleActionBean, errors);
String currentTarget = null;
currentTarget = ruleSetBeanWrapper.getAuditableBean().getOriginalTarget().getValue();
if (currentTarget.contains(".STARTDATE") || currentTarget.contains(".STATUS")) {
if (ruleActionBean.getActionType().getCode() == 6)
// Validation , move to Validate Rule page under eventActinValidator
inValidateInfiniteLoop(ruleActionBean, ruleSetBeanWrapper, eventActionsRuleSetBean);
} else {
ruleSetBeanWrapper.error(createError("OCRERR_0044"));
}
if (errors.hasErrors()) {
ruleSetBeanWrapper.error("EventAction is not valid: " + errors.getAllErrors().get(0).getDefaultMessage());
}
}
}
use of org.akaza.openclinica.domain.rule.action.EventActionBean in project OpenClinica by OpenClinica.
the class EventActionValidator method validate.
public void validate(Object obj, Errors e) {
EventActionBean eventActionBean = (EventActionBean) obj;
validateOidInAction(eventActionBean.getOc_oid_reference(), e);
boolean foundStartDate = false;
for (int i = 0; i < eventActionBean.getProperties().size(); i++) {
PropertyBean propertyBean = eventActionBean.getProperties().get(i);
if (!foundStartDate && propertyBean.getProperty().equals("STARTDATE")) {
foundStartDate = true;
if (!isEventActionValueExpressionValid(propertyBean, ruleSetBeanWrapper))
getRuleSetBeanWrapper().error(createError("OCRERR_0035"));
} else // Throw error for getting more than one STARTDATE property
if (propertyBean.getProperty().equals("STARTDATE") && foundStartDate)
getRuleSetBeanWrapper().error(createError("OCRERR_0037"));
else
// Throw error for unknown Property value
getRuleSetBeanWrapper().error(createError("OCRERR_0036"));
}
}
use of org.akaza.openclinica.domain.rule.action.EventActionBean in project OpenClinica by OpenClinica.
the class BeanPropertyService method runAction.
/**
* Complete adding to this Service to evaluate Event action
* @param ruleActionBean
* @param eow
* @param isTransaction
*/
public void runAction(RuleActionBean ruleActionBean, ExpressionBeanObjectWrapper eow, Integer userId, Boolean isTransaction) {
boolean statusMatch = false;
OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow);
ExpressionBeanService ebs = new ExpressionBeanService(eow);
StudyEvent studyEvent = ebs.getStudyEventFromOID(((EventActionBean) ruleActionBean).getOc_oid_reference());
RuleActionRunBean runOnStatuses = ruleActionBean.getRuleActionRun();
if (studyEvent != null) {
switch(SubjectEventStatus.getByCode(studyEvent.getSubjectEventStatusId())) {
case NOT_SCHEDULED:
if (runOnStatuses.getNot_started())
statusMatch = true;
break;
case SCHEDULED:
if (runOnStatuses.getScheduled())
statusMatch = true;
break;
case DATA_ENTRY_STARTED:
if (runOnStatuses.getData_entry_started())
statusMatch = true;
break;
case COMPLETED:
if (runOnStatuses.getComplete())
statusMatch = true;
break;
case SKIPPED:
if (runOnStatuses.getSkipped())
statusMatch = true;
break;
case STOPPED:
if (runOnStatuses.getStopped())
statusMatch = true;
break;
case SIGNED:
case LOCKED:
default:
statusMatch = false;
break;
}
} else // Special case if destination study event doesn't exist yet, ie not scheduled.
{
if (runOnStatuses.getNot_started())
statusMatch = true;
}
if (statusMatch) {
for (PropertyBean propertyBean : ((EventActionBean) ruleActionBean).getProperties()) {
// This will execute the contents of <ValueExpression>SS.ENROLLMENT_DATE + 2</ValueExpression>
LOGGER.debug("Values:expression??::" + propertyBean.getValueExpression().getValue());
Object result = oep.parseAndEvaluateExpression(propertyBean.getValueExpression().getValue());
executeAction(result, propertyBean, eow, (EventActionBean) ruleActionBean, userId, isTransaction);
}
}
}
use of org.akaza.openclinica.domain.rule.action.EventActionBean in project OpenClinica by OpenClinica.
the class RulesPostImportContainerService method runValidationInList.
public void runValidationInList(String target, String destination, AuditableBeanWrapper<RuleSetBean> ruleSetBeanWrapper, List<RuleSetBean> eventActionsRuleSetBean) {
// eventActionsRuleSetBean is the list of all events from rule set table
Boolean isDestinationATarget = false;
RuleSetBean isDestination = null;
for (RuleSetBean ruleSetBean : eventActionsRuleSetBean) {
if (isDestinationAndTargetMatch(parseTarget(ruleSetBean.getOriginalTarget().getValue()), parseDestination(destination)) || isDestinationAndTargetAcceptable(parseTarget(ruleSetBean.getOriginalTarget().getValue()), parseDestination(destination))) {
isDestinationATarget = true;
isDestination = ruleSetBean;
break;
}
}
if (isDestinationATarget == true && isDestination != null) {
List<RuleActionBean> ruleActions = getAllRuleActions(isDestination);
for (RuleActionBean ruleActionBean : ruleActions) {
if (ruleActionBean.getActionType().getCode() == 6) {
if (isDestinationAndTargetMatch(parseTarget(target), parseDestination(((EventActionBean) ruleActionBean).getOc_oid_reference() + ".STARTDATE"))) {
ruleSetBeanWrapper.error(createError("OCRERR_0042"));
break;
}
if (isDestinationAndTargetAcceptable(parseTarget(target), parseDestination(((EventActionBean) ruleActionBean).getOc_oid_reference()))) {
ruleSetBeanWrapper.error(createError("OCRERR_0043"));
break;
}
runValidationInList(target, ((EventActionBean) ruleActionBean).getOc_oid_reference(), ruleSetBeanWrapper, eventActionsRuleSetBean);
}
}
} else {
addNewRuleSetBeanInList(target, destination, eventActionsRuleSetBean);
}
}
Aggregations