use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class DynamicsMetadataService method insert.
private void insert(Integer itemDataId, List<PropertyBean> properties, UserAccountBean ub, RuleSetBean ruleSet, Status itemDataStatus, List<StratificationFactorBean> stratificationFactorBeans) {
ItemDataBean itemDataBeanA = (ItemDataBean) getItemDataDAO().findByPK(itemDataId);
EventCRFBean eventCrfBeanA = (EventCRFBean) getEventCRFDAO().findByPK(itemDataBeanA.getEventCRFId());
StudyEventBean studyEventBeanA = (StudyEventBean) getStudyEventDAO().findByPK(eventCrfBeanA.getStudyEventId());
ItemGroupMetadataBean itemGroupMetadataBeanA = (ItemGroupMetadataBean) getItemGroupMetadataDAO().findByItemAndCrfVersion(itemDataBeanA.getItemId(), eventCrfBeanA.getCRFVersionId());
Boolean isGroupARepeating = isGroupRepeating(itemGroupMetadataBeanA);
String itemGroupAOrdinal = getExpressionService().getGroupOrdninalCurated(ruleSet.getTarget().getValue());
for (PropertyBean propertyBean : properties) {
String expression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getOid(), ruleSet.getTarget().getValue());
ItemBean itemBeanB = getExpressionService().getItemBeanFromExpression(expression);
ItemGroupBean itemGroupBeanB = getExpressionService().getItemGroupExpression(expression);
ItemGroupMetadataBean itemGroupMetadataBeanB = null;
Boolean isGroupBRepeating = null;
String itemGroupBOrdinal = null;
EventCRFBean eventCrfBeanB = null;
Boolean isItemInSameForm = getItemFormMetadataDAO().findByItemIdAndCRFVersionId(itemBeanB.getId(), eventCrfBeanA.getCRFVersionId()).getId() != 0 ? true : false;
// Item Does not below to same form
if (!isItemInSameForm) {
List<EventCRFBean> eventCrfs = getEventCRFDAO().findAllByStudyEventAndCrfOrCrfVersionOid(studyEventBeanA, getExpressionService().getCrfOid(expression));
if (eventCrfs.size() == 0) {
CRFVersionBean crfVersion = getExpressionService().getCRFVersionFromExpression(expression);
CRFBean crf = getExpressionService().getCRFFromExpression(expression);
int crfVersionId = 0;
EventDefinitionCRFBean eventDefinitionCRFBean = getEventDefinitionCRfDAO().findByStudyEventDefinitionIdAndCRFId(studyEventBeanA.getStudyEventDefinitionId(), crf.getId());
if (eventDefinitionCRFBean.getId() != 0) {
crfVersionId = crfVersion != null ? crfVersion.getId() : eventDefinitionCRFBean.getDefaultVersionId();
}
// Create new event crf
eventCrfBeanB = eventCrfBeanA.copy();
eventCrfBeanB.setStatus(Status.AVAILABLE);
eventCrfBeanB.setId(0);
eventCrfBeanB.setCRFVersionId(crfVersionId);
eventCrfBeanB = (EventCRFBean) getEventCRFDAO().create(eventCrfBeanB);
} else {
eventCrfBeanB = eventCrfs.get(0);
}
}
if (isItemInSameForm) {
eventCrfBeanB = eventCrfBeanA;
}
itemGroupMetadataBeanB = (ItemGroupMetadataBean) getItemGroupMetadataDAO().findByItemAndCrfVersion(itemBeanB.getId(), eventCrfBeanB.getCRFVersionId());
isGroupBRepeating = isGroupRepeating(itemGroupMetadataBeanB);
itemGroupBOrdinal = getExpressionService().getGroupOrdninalCurated(expression);
// If A and B are both non repeating groups
if (!isGroupARepeating && !isGroupBRepeating) {
ItemDataBean oidBasedItemData = oneToOne(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, 1);
oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
if (itemDataStatus != null)
oidBasedItemData.setStatus(itemDataStatus);
getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
}
// If A is not repeating group & B is a repeating group with no index selected
if (!isGroupARepeating && isGroupBRepeating && itemGroupBOrdinal.equals("")) {
List<ItemDataBean> oidBasedItemDatas = oneToMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub);
for (ItemDataBean oidBasedItemData : oidBasedItemDatas) {
oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
if (itemDataStatus != null)
oidBasedItemData.setStatus(itemDataStatus);
getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
}
}
// If A is not repeating group & B is a repeating group with index selected
if (!isGroupARepeating && isGroupBRepeating && !itemGroupBOrdinal.equals("")) {
ItemDataBean oidBasedItemData = oneToIndexedMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, Integer.valueOf(itemGroupBOrdinal));
oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
if (itemDataStatus != null)
oidBasedItemData.setStatus(itemDataStatus);
getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
}
// If A is repeating/ non repeating group & B is a repeating group with index selected as END
if (isGroupBRepeating && itemGroupBOrdinal.equals("END")) {
ItemDataBean oidBasedItemData = oneToEndMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub);
oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
if (itemDataStatus != null)
oidBasedItemData.setStatus(itemDataStatus);
getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
}
// If A is repeating group with index & B is a repeating group with index selected
if (isGroupARepeating && isGroupBRepeating && !itemGroupBOrdinal.equals("") && !itemGroupBOrdinal.equals("END")) {
ItemDataBean oidBasedItemData = oneToIndexedMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, Integer.valueOf(itemGroupBOrdinal));
oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
if (itemDataStatus != null)
oidBasedItemData.setStatus(itemDataStatus);
getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
}
// If A is repeating group with index & B is a repeating group with no index selected
if (isGroupARepeating && isGroupBRepeating && itemGroupBOrdinal.equals("")) {
ItemDataBean oidBasedItemData = oneToIndexedMany(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, Integer.valueOf(itemGroupAOrdinal));
oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA, stratificationFactorBeans));
if (itemDataStatus != null)
oidBasedItemData.setStatus(itemDataStatus);
getItemDataDAO().updateValue(oidBasedItemData, getDateFormat(propertyBean));
}
// // If A is repeating group with index & B is none-repeating group
// if (isGroupARepeating && !isGroupBRepeating ) {
// ItemDataBean oidBasedItemData =
// oneToOne(itemDataBeanA, eventCrfBeanA, itemGroupMetadataBeanA, itemBeanB, itemGroupMetadataBeanB, eventCrfBeanB, ub, 1);
//
// oidBasedItemData.setValue(getValue(propertyBean, ruleSet, eventCrfBeanA));
// getItemDataDAO().updateValue(oidBasedItemData, "yyyy-MM-dd");
// }
}
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean 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.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class ExpressionService method ruleExpressionChecker.
public boolean ruleExpressionChecker(String expression) {
boolean result = false;
boolean isRuleExpressionValid = false;
isExpressionValid(expression);
if (checkIfExpressionIsForScheduling(expression)) {
if (checkSyntax(expression))
return true;
else
return false;
}
if (expressionWrapper.getRuleSet() != null) {
if (isExpressionPartial(expressionWrapper.getRuleSet().getTarget().getValue())) {
return true;
}
String fullExpression = constructFullExpressionIfPartialProvided(expression, expressionWrapper.getRuleSet().getTarget().getValue());
if (isExpressionPartial(expression)) {
isRuleExpressionValid = checkSyntax(fullExpression);
} else {
isRuleExpressionValid = checkRuleExpressionSyntax(fullExpression);
}
if (isRuleExpressionValid) {
isExpressionValid(fullExpression);
result = true;
}
String targetGroupOid = getItemGroupOid(expressionWrapper.getRuleSet().getTarget().getValue());
String ruleGroupOid = getItemGroupOid(fullExpression);
CRFVersionBean targetCrfVersion = getCRFVersionFromExpression(expressionWrapper.getRuleSet().getTarget().getValue());
CRFVersionBean ruleCrfVersion = getCRFVersionFromExpression(fullExpression);
Boolean isTargetGroupRepeating = targetCrfVersion == null ? getItemGroupDao().isItemGroupRepeatingBasedOnAllCrfVersions(targetGroupOid) : getItemGroupDao().isItemGroupRepeatingBasedOnCrfVersion(targetGroupOid, targetCrfVersion.getId());
Boolean isRuleGroupRepeating = ruleCrfVersion == null ? getItemGroupDao().isItemGroupRepeatingBasedOnAllCrfVersions(ruleGroupOid) : getItemGroupDao().isItemGroupRepeatingBasedOnCrfVersion(ruleGroupOid, ruleCrfVersion.getId());
if (!isTargetGroupRepeating && isRuleGroupRepeating) {
String ordinal = getItemGroupOidOrdinalFromExpression(fullExpression);
if (ordinal.equals("") || ordinal.equals("ALL")) {
result = false;
}
}
} else {
if (checkSyntax(expression) && getItemBeanFromExpression(expression) != null) {
result = true;
}
}
return result;
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class ExpressionService method getCRFFromExpression.
public CRFBean getCRFFromExpression(String expression) {
if (expression.split(ESCAPED_SEPERATOR).length < 3) {
return null;
}
CRFBean crf;
logger.debug("Expression : " + expression);
logger.debug("Expression : " + getCrfOidFromExpression(expression));
CRFVersionBean crfVersion = getCrfVersionDao().findByOid(getCrfOidFromExpression(expression));
if (crfVersion != null) {
int crfId = getCrfVersionDao().getCRFIdFromCRFVersionId(crfVersion.getId());
crf = (CRFBean) getCrfDao().findByPK(crfId);
} else {
crf = getCrfDao().findByOid(getCrfOidFromExpression(expression));
}
return crf;
// return crfVersions.size() > 0 ? crfVersions.get(0) : null;
}
use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.
the class RuleSetService method getRuleSetBeanByRuleSetRuleAndSubstituteCrfVersion.
// TODO: look into the commented line make sure logic doesn't break
private RuleSetBean getRuleSetBeanByRuleSetRuleAndSubstituteCrfVersion(String ruleSetRuleId, String crfVersionId, StudyBean currentStudy) {
RuleSetBean ruleSetBean = null;
if (ruleSetRuleId != null && crfVersionId != null && ruleSetRuleId.length() > 0 && crfVersionId.length() > 0) {
RuleSetRuleBean ruleSetRule = getRuleSetRuleDao().findById(Integer.valueOf(ruleSetRuleId));
// ruleSetBean = getRuleSetById(currentStudy, String.valueOf(ruleSetRule.getRuleSetBean().getId()), ruleSetRule.getRuleBean());
ruleSetBean = ruleSetRule.getRuleSetBean();
filterByRules(ruleSetBean, ruleSetRule.getRuleBean().getId());
CRFVersionBean crfVersion = (CRFVersionBean) getCrfVersionDao().findByPK(Integer.valueOf(crfVersionId));
ruleSetBean = replaceCrfOidInTargetExpression(ruleSetBean, crfVersion.getOid());
}
return ruleSetBean;
}
Aggregations