use of org.akaza.openclinica.bean.admin.CRFBean 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.admin.CRFBean in project OpenClinica by OpenClinica.
the class InsertActionValidator method validateOidInPropertyBean.
public void validateOidInPropertyBean(PropertyBean propertyBean, Errors e, String p) {
if (getExpressionService().isExpressionPartial(getRuleSetBean().getTarget().getValue())) {
if (getExpressionService().getExpressionSize(propertyBean.getOid()).intValue() > 3) {
e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
}
try {
getExpressionService().isExpressionValid(propertyBean.getOid());
} catch (OpenClinicaSystemException ose) {
e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
}
// Use OID in destinationProperty to get CRF
CRFBean destinationPropertyOidCrf = getExpressionService().getCRFFromExpression(propertyBean.getOid());
if (destinationPropertyOidCrf == null) {
ItemBean item = getExpressionService().getItemBeanFromExpression(propertyBean.getOid());
destinationPropertyOidCrf = getCrfDAO().findByItemOid(item.getOid());
}
// Use Target get CRF
CRFBean targetCrf = getExpressionService().getCRFFromExpression(getRuleSetBean().getTarget().getValue());
if (targetCrf == null) {
ItemBean item = getExpressionService().getItemBeanFromExpression(getRuleSetBean().getTarget().getValue());
targetCrf = getCrfDAO().findByItemOid(item.getOid());
}
// Get All event definitions the selected CRF belongs to
List<StudyEventDefinitionBean> destinationPropertyStudyEventDefinitions = getStudyEventDefinitionDAO().findAllByCrf(destinationPropertyOidCrf);
List<StudyEventDefinitionBean> targetStudyEventDefinitions = getStudyEventDefinitionDAO().findAllByCrf(targetCrf);
Collection intersection = CollectionUtils.intersection(destinationPropertyStudyEventDefinitions, targetStudyEventDefinitions);
if (intersection.size() == 0) {
e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
}
} else {
String expression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getOid(), getRuleSetBean().getTarget().getValue());
ItemBean item = getExpressionService().getItemBeanFromExpression(expression);
if (!getExpressionService().isInsertActionExpressionValid(propertyBean.getOid(), getRuleSetBean(), 3) || item == null) {
e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
}
}
}
use of org.akaza.openclinica.bean.admin.CRFBean 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.admin.CRFBean 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.admin.CRFBean in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method populateUncompletedCRFsWithCRFAndVersions.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void populateUncompletedCRFsWithCRFAndVersions(ArrayList<DisplayEventDefinitionCRFBean> uncompletedEventDefinitionCRFs, Map<Integer, CRFVersionBean> crfVersionById, Map<Integer, CRFBean> crfById) {
CRFVersionDAO crfVersionDao = new CRFVersionDAO(dataSource);
int size = uncompletedEventDefinitionCRFs.size();
for (int i = 0; i < size; i++) {
DisplayEventDefinitionCRFBean dedcrf = uncompletedEventDefinitionCRFs.get(i);
// CRFBean cb = (CRFBean)
// crfDao.findByPK(dedcrf.getEdc().getCrfId());
CRFBean cb = crfById.get(dedcrf.getEdc().getCrfId());
dedcrf.getEdc().setCrf(cb);
ArrayList<CRFVersionBean> theVersions = (ArrayList<CRFVersionBean>) crfVersionDao.findAllActiveByCRF(dedcrf.getEdc().getCrfId());
ArrayList<CRFVersionBean> versions = new ArrayList<CRFVersionBean>();
HashMap<String, CRFVersionBean> crfVersionIds = new HashMap<String, CRFVersionBean>();
for (int j = 0; j < theVersions.size(); j++) {
CRFVersionBean crfVersion = theVersions.get(j);
crfVersionIds.put(String.valueOf(crfVersion.getId()), crfVersion);
}
if (!dedcrf.getEdc().getSelectedVersionIds().equals("")) {
String[] kk = dedcrf.getEdc().getSelectedVersionIds().split(",");
for (String string : kk) {
if (crfVersionIds.get(string) != null) {
versions.add(crfVersionIds.get(string));
}
}
} else {
versions = theVersions;
}
dedcrf.getEdc().setVersions(versions);
uncompletedEventDefinitionCRFs.set(i, dedcrf);
}
}
Aggregations