use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class RuleSetDaoTest method testFindByCrfEmptyResultSet.
// @pgawade 09-NOV-2010 Commented out the test "testFindByCrf" temporarily
// public void testFindByCrf() {
// CRFBean crfBean = new CRFBean();
// crfBean.setId(2);
// StudyBean studyBean = new StudyBean();
// studyBean.setId(1);
// RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
// List<RuleSetBean> persistentRuleSets = ruleSetDao.findByCrf(crfBean,
// studyBean);
// assertNotNull("The returned ruleSet was null", persistentRuleSets);
// assertEquals("The List size of ruleset objects should be 2 ",
// persistentRuleSets.size(), 2);
// }
public void testFindByCrfEmptyResultSet() {
CRFBean crfBean = new CRFBean();
crfBean.setId(4);
StudyBean studyBean = new StudyBean();
studyBean.setId(1);
// RuleSetDao ruleSetDao = (RuleSetDao) getContext().getBean("ruleSetDao");
crfBean.setId(4);
List<RuleSetBean> persistentRuleSets = ruleSetDao.findByCrf(crfBean, studyBean);
assertNotNull("The returned ruleSet was null", persistentRuleSets);
assertEquals("The List size of ruleset objects should be 0 ", persistentRuleSets.size(), 0);
}
use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class InsertActionValidator method validateValueExpressionInPropertyBean.
public void validateValueExpressionInPropertyBean(PropertyBean propertyBean, Errors e, String p) {
if (getExpressionService().isExpressionPartial(getRuleSetBean().getTarget().getValue())) {
if (getExpressionService().getExpressionSize(propertyBean.getValueExpression().getValue()).intValue() > 2) {
e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
}
try {
getExpressionService().isExpressionValid(propertyBean.getValueExpression().getValue());
} catch (OpenClinicaSystemException ose) {
e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
}
// Use ValueExression in destinationProperty to get CRF
ItemBean item = getExpressionService().getItemBeanFromExpression(propertyBean.getValueExpression().getValue());
if (item == null)
return;
CRFBean destinationPropertyValueExpressionCrf = getCrfDAO().findByItemOid(item.getOid());
// Use Target to get CRF
CRFBean targetCrf = getExpressionService().getCRFFromExpression(getRuleSetBean().getTarget().getValue());
if (targetCrf == null) {
ItemBean targetItem = getExpressionService().getItemBeanFromExpression(getRuleSetBean().getTarget().getValue());
targetCrf = getCrfDAO().findByItemOid(targetItem.getOid());
}
if (destinationPropertyValueExpressionCrf.getId() != targetCrf.getId()) {
e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
}
} else {
String valueExpression = getExpressionService().constructFullExpressionIfPartialProvided(propertyBean.getValueExpression().getValue(), getRuleSetBean().getTarget().getValue());
ItemBean item = getExpressionService().getItemBeanFromExpression(valueExpression);
if (!getExpressionService().isExpressionValid(propertyBean.getValueExpression().getValue(), getRuleSetBean(), 2) || item == null) {
e.rejectValue(p + "valueExpression", "valueExpression.invalid", "Value provided for ValueExpression is Invalid");
}
}
}
use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method getDisplayStudyEventsForStudySubject.
@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(StudySubjectBean studySubject, UserAccountBean userAccount, StudyUserRoleBean currentRole) {
StudyEventDAO studyEventDao = new StudyEventDAO(dataSource);
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
StudyDAO studyDao = new StudyDAO(dataSource);
EventDefinitionCRFDAO eventDefinitionCrfDao = new EventDefinitionCRFDAO(dataSource);
EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
CRFDAO crfDao = new CRFDAO(dataSource);
CRFVersionDAO crfVersionDao = new CRFVersionDAO(dataSource);
ArrayList events = studyEventDao.findAllByStudySubject(studySubject);
Map<Integer, StudyEventDefinitionBean> eventDefinitionByEvent = studyEventDefinitionDao.findByStudySubject(studySubject.getId());
StudyBean study = (StudyBean) studyDao.findByPK(studySubject.getStudyId());
Map<Integer, SortedSet<EventDefinitionCRFBean>> eventDefinitionCrfByStudyEventDefinition;
if (study.getParentStudyId() < 1) {
// Is a study
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinitionForStudy(studySubject.getId());
} else {
// Is a site
eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinition(studySubject.getId(), study.getId(), study.getParentStudyId());
}
Map<Integer, SortedSet<EventCRFBean>> eventCrfListByStudyEvent = eventCrfDao.buildEventCrfListByStudyEvent(studySubject.getId());
Map<Integer, Integer> maxOrdinalByStudyEvent = studyEventDefinitionDao.buildMaxOrdinalByStudyEvent(studySubject.getId());
Set<Integer> nonEmptyEventCrf = eventCrfDao.buildNonEmptyEventCrfIds(studySubject.getId());
Map<Integer, CRFVersionBean> crfVersionById = crfVersionDao.buildCrfVersionById(studySubject.getId());
Map<Integer, CRFBean> crfById = crfDao.buildCrfById(studySubject.getId());
ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
for (int i = 0; i < events.size(); i++) {
StudyEventBean event = (StudyEventBean) events.get(i);
StudyEventDefinitionBean sed = eventDefinitionByEvent.get(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
List eventDefinitionCRFs = new ArrayList((eventDefinitionCrfByStudyEventDefinition.containsKey(sed.getId()) ? eventDefinitionCrfByStudyEventDefinition.get(sed.getId()) : Collections.EMPTY_LIST));
List eventCRFs = new ArrayList((eventCrfListByStudyEvent.containsKey(event.getId())) ? eventCrfListByStudyEvent.get(event.getId()) : Collections.EMPTY_LIST);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs((ArrayList<DisplayEventCRFBean>) getDisplayEventCRFs(eventCRFs, userAccount, currentRole, event.getSubjectEventStatus(), study, nonEmptyEventCrf, crfVersionById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, crfVersionById, crfById);
populateUncompletedCRFsWithCRFAndVersions(al, crfVersionById, crfById);
de.setUncompletedCRFs(al);
// de.setMaximumSampleOrdinal(studyEventDao.getMaxSampleOrdinal(sed,
// studySubject));
de.setMaximumSampleOrdinal(maxOrdinalByStudyEvent.get(event.getStudyEventDefinitionId()));
displayEvents.add(de);
// event.setEventCRFs(createAllEventCRFs(eventCRFs,
// eventDefinitionCRFs));
}
return displayEvents;
}
use of org.akaza.openclinica.bean.admin.CRFBean in project OpenClinica by OpenClinica.
the class StudySubjectServiceImpl method getDisplayEventCRFs.
private List<DisplayEventCRFBean> getDisplayEventCRFs(List eventCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status, StudyBean study, Set<Integer> nonEmptyEventCrf, Map<Integer, CRFVersionBean> crfVersionById, Map<Integer, CRFBean> crfById, Integer studyEventDefinitionId, List eventDefinitionCRFs) {
ArrayList<DisplayEventCRFBean> answer = new ArrayList<DisplayEventCRFBean>();
for (int i = 0; i < eventCRFs.size(); i++) {
EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
// populate the event CRF with its crf bean
int crfVersionId = ecb.getCRFVersionId();
// CRFVersionBean cvb = crfVersionById.get(ecb.getCRFVersionId());
CRFVersionBean cvb = crfVersionById.get(crfVersionId);
ecb.setCrfVersion(cvb);
// CRFBean cb = crfDao.findByVersionId(crfVersionId);
CRFBean cb = crfById.get(cvb.getCrfId());
ecb.setCrf(cb);
EventDefinitionCRFBean edc = null;
Iterator it = eventDefinitionCRFs.iterator();
while (it.hasNext()) {
EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) it.next();
if (edcBean.getCrfId() == cb.getId()) {
edc = edcBean;
break;
}
}
// rules updated 112007 tbh
if (status.equals(SubjectEventStatus.LOCKED) || status.equals(SubjectEventStatus.SKIPPED) || status.equals(SubjectEventStatus.STOPPED)) {
ecb.setStage(DataEntryStage.LOCKED);
// we need to set a SED-wide flag here, because other edcs
// in this event can be filled in and change the status, tbh
} else if (status.equals(SubjectEventStatus.INVALID)) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (!cb.getStatus().equals(Status.AVAILABLE)) {
ecb.setStage(DataEntryStage.LOCKED);
} else if (!cvb.getStatus().equals(Status.AVAILABLE)) {
ecb.setStage(DataEntryStage.LOCKED);
}
// TODO need to refactor since this is similar to other code, tbh
if (edc != null) {
// System.out.println("edc is not null, need to set flags");
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventDefinitionCRF(edc);
// System.out.println("edc.isDoubleEntry()" +
// edc.isDoubleEntry() + ecb.getId());
dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
if (dec.isLocked()) {
// System.out.println("*** found a locked DEC:
// "+edc.getCrfName());
}
if (nonEmptyEventCrf.contains(ecb.getId())) {
// consider an event crf started only if item data get
// created
answer.add(dec);
}
}
}
return answer;
}
use of org.akaza.openclinica.bean.admin.CRFBean 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 });
}
}
Aggregations