use of org.akaza.openclinica.bean.submit.ItemBean 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.ItemBean 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.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class ExpressionService method isExpressionValidOLD.
/**
* Given a Complete Expression check business logic validity of each
* component. Will throw OpenClinicaSystemException with correct
* explanation. This might allow immediate communication of message to user
* .
*
* @param expression
*/
@Deprecated
public void isExpressionValidOLD(String expression) {
StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(expression);
CRFBean crf = getCRFFromExpression(expression);
if (studyEventDefinition == null || crf == null)
throw new OpenClinicaSystemException("OCRERR_0020");
EventDefinitionCRFBean eventDefinitionCrf = getEventDefinitionCRFDao().findByStudyEventDefinitionIdAndCRFId(this.expressionWrapper.getStudyBean(), studyEventDefinition.getId(), crf.getId());
if (eventDefinitionCrf == null || eventDefinitionCrf.getId() == 0 || eventDefinitionCrf.getStatus() != Status.AVAILABLE)
throw new OpenClinicaSystemException("OCRERR_0021");
ItemGroupBean itemGroup = getItemGroupExpression(expression, crf);
if (itemGroup == null)
throw new OpenClinicaSystemException("OCRERR_0022");
ItemBean item = getItemExpression(expression, itemGroup);
if (item == null)
throw new OpenClinicaSystemException("OCRERR_0023");
logger.debug("Study Event Definition ID : " + studyEventDefinition.getId());
logger.debug("Crf ID : " + crf.getId());
logger.debug("Event Definition CRF ID : " + eventDefinitionCrf.getId());
logger.debug("Item ID : " + item.getId());
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class ExpressionService method isExpressionValid.
public String isExpressionValid(String oid, RuleSetBean ruleSet) {
StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(ruleSet.getTarget().getValue());
String[] theOid = oid.split(ESCAPED_SEPERATOR);
if (theOid.length == 3) {
ItemGroupBean itemGroup = getItemGroupDao().findByOid(theOid[0]);
if (itemGroup != null && itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
ItemBean item = getItemDao().findItemByGroupIdandItemOid(itemGroup.getId(), theOid[1]);
if (item != null) {
return "OK";
}
}
}
if (theOid.length == 2) {
ItemGroupBean itemGroup = getItemGroupDao().findByOid(theOid[0]);
if (itemGroup != null && itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
ItemBean item = getItemDao().findItemByGroupIdandItemOid(itemGroup.getId(), theOid[1]);
if (item != null) {
return "OK";
}
}
}
if (theOid.length == 1) {
ItemGroupBean itemGroup = getItemGroupDao().findByOid(oid);
if (itemGroup != null && itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
return "OK";
}
ItemBean item = getItemDao().findItemByGroupIdandItemOid(getItemGroupExpression(ruleSet.getTarget().getValue()).getId(), oid);
if (item != null) {
return "OK";
}
}
return oid;
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class ExpressionService method getValueFromDbb.
public HashMap<String, String> getValueFromDbb(String expression) throws OpenClinicaSystemException {
HashMap<String, String> map = new HashMap<>();
if (isExpressionPartial(expression)) {
throw new OpenClinicaSystemException("getValueFromDb:We cannot get the Value of a PARTIAL expression : " + expression);
}
try {
// Get the studyEventId from RuleSet Target so we can know which
// StudySubject we are dealing with.
String ruleSetExpression = expressionWrapper.getRuleSet().getTarget().getValue();
String ruleSetExpressionStudyEventId = getStudyEventDefinitionOidOrdinalFromExpression(ruleSetExpression);
StudyEventBean studyEvent = (StudyEventBean) getStudyEventDao().findByPK(Integer.valueOf(ruleSetExpressionStudyEventId));
// Prepare Method arguments
String studyEventDefinitionOid = getStudyEventDefinitionOidFromExpression(expression);
String crfOrCrfVersionOid = getCrfOidFromExpression(expression);
String studyEventDefinitionOrdinal = getStudyEventDefinitionOidOrdinalFromExpression(expression);
studyEventDefinitionOrdinal = studyEventDefinitionOrdinal.equals("") ? "1" : studyEventDefinitionOrdinal;
String studySubjectId = String.valueOf(studyEvent.getStudySubjectId());
System.out.println("studySubjectId: " + studySubjectId);
logger.debug("ruleSet studyEventId {} , studyEventDefinitionOid {} , crfOrCrfVersionOid {} , studyEventDefinitionOrdinal {} ,studySubjectId {}", new Object[] { studyEvent.getId(), studyEventDefinitionOid, crfOrCrfVersionOid, studyEventDefinitionOrdinal, studySubjectId });
StudyEventBean studyEventofThisExpression = getStudyEventDao().findAllByStudyEventDefinitionAndCrfOidsAndOrdinal(studyEventDefinitionOid, crfOrCrfVersionOid, studyEventDefinitionOrdinal, studySubjectId);
if (studyEvent.getId() == studyEventofThisExpression.getId())
map.put("match", "true");
logger.debug("studyEvent : {} , itemOid {} , itemGroupOid {}", new Object[] { studyEventofThisExpression.getId(), getItemOidFromExpression(expression), getItemGroupOidFromExpression(expression) });
List<ItemDataBean> itemData = getItemDataDao().findByStudyEventAndOids(Integer.valueOf(studyEventofThisExpression.getId()), getItemOidFromExpression(expression), getItemGroupOidFromExpression(expression));
expression = fixGroupOrdinal(expression, ruleSetExpression, itemData, expressionWrapper.getEventCrf());
Integer index = getItemGroupOidOrdinalFromExpression(expression).equals("") ? 0 : Integer.valueOf(getItemGroupOidOrdinalFromExpression(expression)) - 1;
ItemDataBean itemDataBean = itemData.get(index);
ItemBean itemBean = (ItemBean) getItemDao().findByPK(itemDataBean.getItemId());
String value = itemData.get(index).getValue();
value = ifValueIsDate(itemBean, value);
map.put("value", value);
return map;
} catch (Exception e) {
return map;
}
}
Aggregations