use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class ExpressionService method isExpressionValid.
/**
* 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
*/
public void isExpressionValid(String expression) {
int length = expression.split(ESCAPED_SEPERATOR).length;
ItemBean item = null;
ItemGroupBean itemGroup = null;
CRFBean crf = null;
boolean isEventStartDateAndStatusParamExist = (expression.endsWith(STARTDATE) || expression.endsWith(STATUS));
if (length > 0 && !isEventStartDateAndStatusParamExist) {
item = getItemFromExpression(expression);
if (item == null)
throw new OpenClinicaSystemException("OCRERR_0023");
// throw new OpenClinicaSystemException("item is Invalid");
}
if (length > 1 && !isEventStartDateAndStatusParamExist) {
String itemGroupOid = getItemGroupOidFromExpression(expression);
itemGroup = getItemGroupDao().findByOid(itemGroupOid);
ArrayList<ItemGroupBean> igBean = (ArrayList<ItemGroupBean>) getItemGroupDao().findGroupsByItemID(item.getId());
if (itemGroup == null || itemGroup.getId() != igBean.get(0).getId())
throw new OpenClinicaSystemException("OCRERR_0022");
// throw new OpenClinicaSystemException("itemGroup is Invalid");
}
if (length > 2 && !isEventStartDateAndStatusParamExist) {
crf = getCRFFromExpression(expression);
if (crf == null || crf.getId() != itemGroup.getCrfId())
throw new OpenClinicaSystemException("OCRERR_0033");
// throw new OpenClinicaSystemException("CRF is Invalid");
}
if (length > 3 && !isEventStartDateAndStatusParamExist) {
StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpression(expression);
crf = getCRFFromExpression(expression);
if (studyEventDefinition == null || crf == null)
throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
// throw new
// OpenClinicaSystemException("StudyEventDefinition is Invalid");
EventDefinitionCRFBean eventDefinitionCrf = getEventDefinitionCRFDao().findByStudyEventDefinitionIdAndCRFId(this.expressionWrapper.getStudyBean(), studyEventDefinition.getId(), crf.getId());
if (eventDefinitionCrf == null || eventDefinitionCrf.getId() == 0)
throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
// throw new
// OpenClinicaSystemException("StudyEventDefinition is Invalid");
}
if (length == 2 && isEventStartDateAndStatusParamExist) {
StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionFromExpressionForEventScheduling(expression);
// studyEventDefinition.getOid());
if (studyEventDefinition == null)
throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
}
if (length != 2 && isEventStartDateAndStatusParamExist) {
throw new OpenClinicaSystemException("OCRERR_0034", new String[] { expression });
}
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class ExpressionService method getValueFromForm.
public String getValueFromForm(String expression, Map<String, ItemBean> itemBeans) {
if (itemBeans == null)
logger.debug("The Map that stores ItemBeans is null. Item Date value cannot be processed.");
String result = null;
HashMap<String, String> formValues = expressionWrapper.getItemsAndTheirValues();
if (formValues != null && !formValues.isEmpty()) {
String withGroup = getItemGroupPLusItem(expression);
String withoutGroup = getItemOidFromExpression(expression);
result = formValues.containsKey(withGroup) ? formValues.get(withGroup) : formValues.containsKey(withoutGroup) ? formValues.get(withoutGroup) : null;
if (itemBeans != null) {
ItemBean itemBean = itemBeans.containsKey(withGroup) ? itemBeans.get(withGroup) : itemBeans.containsKey(withoutGroup) ? itemBeans.get(withoutGroup) : null;
result = ifValueIsDate(itemBean, result);
}
} else {
logger.warn("The HashMap that stores form values was null, Better this be a Bulk operation");
}
return result;
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class ExpressionService method checkValidityOfItemOrItemGroupOidInCrf.
public String checkValidityOfItemOrItemGroupOidInCrf(String oid, RuleSetBean ruleSet) {
oid = oid.trim();
String[] theOid = oid.split(ESCAPED_SEPERATOR);
if (theOid.length == 2) {
ItemGroupBean itemGroup = getItemGroupDao().findByOid(theOid[0]);
Boolean isItemGroupBePartOfCrfOrNull = ruleSet.getCrfId() != null ? itemGroup.getCrfId().equals(ruleSet.getCrfId()) : true;
if (itemGroup != null && isItemGroupBePartOfCrfOrNull) {
if (ruleSet.getCrfId() != null && itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
return "OK";
}
if (ruleSet.getCrfId() != null && !itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
return oid;
}
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) {
if (ruleSet.getCrfId() != null && itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
return "OK";
}
if (ruleSet.getCrfId() != null && !itemGroup.getCrfId().equals(ruleSet.getCrfId())) {
return oid;
}
return "OK";
}
// ItemBean item =
// getItemDao().findItemByGroupIdandItemOid(getItemGroupExpression(ruleSet.getTarget().getValue()).getId(),
// oid);
ArrayList<ItemBean> items = (ArrayList<ItemBean>) getItemDao().findByOid(oid);
if (items == null || items.size() != 0) {
return "OK";
}
}
return oid;
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class ExpressionService method getItemFromExpression.
public ItemBean getItemFromExpression(String expression) {
String itemKey = getItemOidFromExpression(expression);
logger.debug("Expression : {} , Item OID : {}", expression, itemKey);
if (items.containsKey(itemKey)) {
return items.get(itemKey);
} else {
List<ItemBean> persistentItems = getItemDao().findByOid(itemKey);
ItemBean item = persistentItems.size() > 0 ? persistentItems.get(0) : null;
if (item != null) {
items.put(itemKey, item);
return item;
} else {
return null;
}
}
}
use of org.akaza.openclinica.bean.submit.ItemBean in project OpenClinica by OpenClinica.
the class ExpressionService method deContextualizeExpression.
@SuppressWarnings("unchecked")
private String deContextualizeExpression(int j, String ruleExpression, String ruleSetTargetExpression) {
String ruleSetExpression = ruleSetTargetExpression;
String[] splitRuleSetExpression = ruleSetExpression.split(ESCAPED_SEPERATOR);
String buildExpression = "";
ItemBean item = null;
String groupOidWithoutOrdinal = "";
String groupOidFromItem = "";
String repeatOrdinal = "";
if (j == 3) {
item = getItemFromExpression(ruleExpression);
int indexOfOpenBrack = splitRuleSetExpression[2].indexOf("[");
if (indexOfOpenBrack != -1) {
groupOidWithoutOrdinal = splitRuleSetExpression[2].substring(0, indexOfOpenBrack);
} else {
groupOidWithoutOrdinal = splitRuleSetExpression[2];
}
ArrayList<ItemGroupBean> igBean = (ArrayList<ItemGroupBean>) getItemGroupDao().findGroupsByItemID(item.getId());
groupOidFromItem = igBean.get(0).getOid();
}
for (int i = 0; i < j; i++) {
if (j == 3 && i == 2 && !groupOidFromItem.equalsIgnoreCase(groupOidWithoutOrdinal)) {
ArrayList<ItemFormMetadataBean> itemFormMetadataBeans = getItemFormMetadataDao().findAllByItemId(item.getId());
List<ItemGroupMetadataBean> itemGroupMetadataBeans = getItemGroupMetadataDao().findByCrfVersion(itemFormMetadataBeans.get(0).getCrfVersionId());
if (!itemGroupMetadataBeans.get(0).isRepeatingGroup()) {
repeatOrdinal = "[1]";
}
buildExpression = buildExpression + groupOidFromItem + repeatOrdinal + SEPERATOR;
} else {
buildExpression = buildExpression + splitRuleSetExpression[i] + SEPERATOR;
}
}
return buildExpression + ruleExpression;
}
Aggregations