use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.
the class RuleSetService method runRulesInBulk.
/*
* (non-Javadoc)
* @see org.akaza.openclinica.service.rule.RuleSetServiceInterface#runRulesInBulk(java.lang.String, java.lang.Boolean,
* org.akaza.openclinica.bean.managestudy.StudyBean, org.akaza.openclinica.bean.login.UserAccountBean)
*/
public HashMap<RuleBulkExecuteContainer, HashMap<RuleBulkExecuteContainerTwo, Set<String>>> runRulesInBulk(String crfId, ExecutionMode executionMode, StudyBean currentStudy, UserAccountBean ub) {
CRFBean crf = new CRFBean();
crf.setId(Integer.valueOf(crfId));
List<RuleSetBean> ruleSets = getRuleSetsByCrfAndStudy(crf, currentStudy);
ruleSets = filterByStatusEqualsAvailable(ruleSets);
ruleSets = filterRuleSetsByStudyEventOrdinal(ruleSets, null);
ruleSets = filterRuleSetsByGroupOrdinal(ruleSets);
CrfBulkRuleRunner ruleRunner = new CrfBulkRuleRunner(dataSource, requestURLMinusServletPath, contextPath, mailSender);
dynamicsMetadataService.setExpressionService(getExpressionService());
ruleRunner.setDynamicsMetadataService(dynamicsMetadataService);
ruleRunner.setRuleActionRunLogDao(ruleActionRunLogDao);
return ruleRunner.runRulesBulk(ruleSets, executionMode, currentStudy, null, ub);
// return runRulesBulk(ruleSets, dryRun, currentStudy, null, ub);
}
use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.
the class RuleSetService method filterRuleSetsByStudyEventOrdinal.
@SuppressWarnings("unchecked")
public List<RuleSetBean> filterRuleSetsByStudyEventOrdinal(List<RuleSetBean> ruleSets, String crfVersionId) {
ArrayList<RuleSetBean> validRuleSets = new ArrayList<RuleSetBean>();
for (RuleSetBean ruleSetBean : ruleSets) {
String studyEventDefinitionOrdinal = getExpressionService().getStudyEventDefinitionOrdninalCurated(ruleSetBean.getTarget().getValue());
String studyEventDefinitionOid = getExpressionService().getStudyEventDefenitionOid(ruleSetBean.getTarget().getValue());
String crfOrCrfVersionOid = getExpressionService().getCrfOid(ruleSetBean.getTarget().getValue());
// whole expression is provided in target
if (studyEventDefinitionOid != null && crfOrCrfVersionOid != null) {
List<StudyEventBean> studyEvents = null;
if (crfOrCrfVersionOid.equals("STARTDATE") || crfOrCrfVersionOid.equals("STATUS")) {
StudyEventDefinitionBean sedBean = getStudyEventDefinitionDao().findByOid(studyEventDefinitionOid);
studyEvents = (List<StudyEventBean>) getStudyEventDao().findAllByDefinition(sedBean.getId());
logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionOid, crfOrCrfVersionOid, studyEvents.size() });
} else {
studyEvents = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOids(studyEventDefinitionOid, crfOrCrfVersionOid);
logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionOid, crfOrCrfVersionOid, studyEvents.size() });
}
if (studyEventDefinitionOrdinal.equals("") && studyEvents.size() > 0) {
for (StudyEventBean studyEvent : studyEvents) {
ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent));
}
validRuleSets.add(ruleSetBean);
} else {
for (StudyEventBean studyEvent : studyEvents) {
if (studyEventDefinitionOrdinal.equals(String.valueOf(studyEvent.getSampleOrdinal()))) {
ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent));
}
}
validRuleSets.add(ruleSetBean);
}
} else {
// partial expression is provided in target
CRFBean crf = null;
List<CRFVersionBean> crfVersions = new ArrayList<CRFVersionBean>();
CRFVersionBean crfVersion = null;
if (crfOrCrfVersionOid == null) {
crf = getCrfDao().findByItemOid(getExpressionService().getItemOid(ruleSetBean.getTarget().getValue()));
if (crfVersionId != null) {
crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(Integer.valueOf(crfVersionId));
crfVersions.add(crfVersion);
} else {
crfVersions = (List<CRFVersionBean>) getCrfVersionDao().findAllByCRF(crf.getId());
}
} else {
crf = getExpressionService().getCRFFromExpression(ruleSetBean.getTarget().getValue());
if (crfVersionId != null) {
crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(Integer.valueOf(crfVersionId));
} else {
crfVersion = getExpressionService().getCRFVersionFromExpression(ruleSetBean.getTarget().getValue());
}
if (crfVersion != null) {
crfVersions.add(crfVersion);
} else {
crfVersions = (List<CRFVersionBean>) getCrfVersionDao().findAllByCRF(crf.getId());
}
}
List<StudyEventDefinitionBean> studyEventDefinitions = getStudyEventDefinitionDao().findAllByCrf(crf);
for (StudyEventDefinitionBean studyEventDefinitionBean : studyEventDefinitions) {
for (CRFVersionBean crfVersionBean : crfVersions) {
String expression = getExpressionService().constructFullExpressionIfPartialProvided(ruleSetBean.getTarget().getValue(), crfVersionBean, studyEventDefinitionBean);
List<StudyEventBean> studyEvents = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOids(studyEventDefinitionBean.getOid(), crfVersionBean.getOid());
logger.debug("studyEventDefinitionOrdinal {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEvents {}", new Object[] { studyEventDefinitionOrdinal, studyEventDefinitionBean.getOid(), crfVersionBean.getOid(), studyEvents.size() });
for (StudyEventBean studyEvent : studyEvents) {
ruleSetBean.addExpression(replaceSEDOrdinal(ruleSetBean.getTarget(), studyEvent, expression));
}
}
}
validRuleSets.add(ruleSetBean);
}
}
logExpressions(validRuleSets);
logger.debug("Size of RuleSets post filterRuleSetsByStudyEventOrdinal() {} ", validRuleSets.size());
return validRuleSets;
}
use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.
the class RuleSetService method filterRuleSetsByHiddenItems.
public List<RuleSetBean> filterRuleSetsByHiddenItems(List<RuleSetBean> ruleSets, EventCRFBean eventCrf, CRFVersionBean crfVersion, List<ItemBean> itemBeansWithSCDShown) {
ArrayList<RuleSetBean> shownRuleSets = new ArrayList<RuleSetBean>();
for (RuleSetBean ruleSetBean : ruleSets) {
logMe("Entering the filterRuleSetsBy HiddenItems? Thread::" + Thread.currentThread() + "eventCrf?" + eventCrf + "crfVersion??" + crfVersion + "ruleSets?" + ruleSets);
ItemBean target = ruleSetBean.getItem();
ItemFormMetadataBean metadataBean = this.getItemFormMetadataDao().findByItemIdAndCRFVersionId(target.getId(), crfVersion.getId());
ItemDataBean itemData = this.getItemDataDao().findByItemIdAndEventCRFId(target.getId(), eventCrf.getId());
DynamicsItemFormMetadataBean dynamicsBean = this.getDynamicsItemFormMetadataDao().findByMetadataBean(metadataBean, eventCrf, itemData);
if (itemBeansWithSCDShown == null)
itemBeansWithSCDShown = new ArrayList<ItemBean>();
if (dynamicsBean == null) {
if (metadataBean.isShowItem() || itemBeansWithSCDShown.contains(target)) {
logger.debug("just added rule set bean");
shownRuleSets.add(ruleSetBean);
}
} else {
if (metadataBean.isShowItem() || dynamicsBean.isShowItem()) {
logger.debug("just added rule set bean 2, with dyn bean");
shownRuleSets.add(ruleSetBean);
}
}
}
return shownRuleSets;
}
use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.
the class RuleSetService method filterRuleSetsByStudySubject.
/*
* (non-Javadoc)
* @see org.akaza.openclinica.service.rule.RuleSetServiceInterface#filterRuleSetsByStudyEventOrdinal(java.util.List)
*/
@SuppressWarnings("unchecked")
public List<RuleSetBean> filterRuleSetsByStudySubject(List<RuleSetBean> ruleSets) throws NumberFormatException, ParseException {
for (RuleSetBean ruleSet : ruleSets) {
List<ExpressionBean> filteredExpressions = new ArrayList<ExpressionBean>();
if (ruleSet.getExpressions() != null) {
for (ExpressionBean expression : ruleSet.getExpressions()) {
String studyEventId = getExpressionService().getStudyEventDefinitionOrdninalCurated(expression.getValue());
StudyEventBean studyEvent = (StudyEventBean) getStudyEventDao().findByPK(Integer.valueOf(studyEventId));
StudySubjectBean studySubject = (StudySubjectBean) getStudySubjecdao().findByPK(studyEvent.getStudySubjectId());
if (doTriggerRule(ruleSet, studySubject)) {
ExpressionBean expBean = new ExpressionBean();
expBean.setValue(expression.getValue());
expBean.setContext(expression.getContext());
filteredExpressions.add(expBean);
}
}
ruleSet.setExpressions(filteredExpressions);
} else {
ruleSet.setExpressions(filteredExpressions);
}
}
logExpressions(ruleSets);
return ruleSets;
}
use of org.akaza.openclinica.domain.rule.RuleSetBean in project OpenClinica by OpenClinica.
the class RuleSetService method runIndividualRulesInBeanProperty.
public void runIndividualRulesInBeanProperty(List<RuleSetBean> ruleSets, Integer userId, StudyEventChangeDetails changeDetails, Integer studyEventOrdinal) {
ArrayList<RuleSetBean> ruleSetBeans = new ArrayList<>();
for (RuleSetBean ruleSet : ruleSets) {
String studyEventDefinitionOrdinal = getExpressionService().getStudyEventDefinitionOrdninalCurated(ruleSet.getOriginalTarget().getValue() + ".A.B");
if (studyEventDefinitionOrdinal.equals("") || studyEventDefinitionOrdinal.equals(String.valueOf(studyEventOrdinal))) {
ruleSetBeans.add(ruleSet);
}
}
BeanPropertyRuleRunner ruleRunner = new BeanPropertyRuleRunner(dataSource, requestURLMinusServletPath, contextPath, mailSender);
ruleRunner.runRules(ruleSetBeans, dataSource, beanPropertyService, getStudyEventDomainDao(), getStudyEventDefDomainDao(), changeDetails, userId, mailSender);
}
Aggregations