use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class EventService method scheduleEvent.
public HashMap<String, String> scheduleEvent(UserAccountBean user, Date startDateTime, Date endDateTime, String location, String studyUniqueId, String siteUniqueId, String eventDefinitionOID, String studySubjectId) throws OpenClinicaSystemException {
// Business Validation
StudyBean study = getStudyDao().findByUniqueIdentifier(studyUniqueId);
int parentStudyId = study.getId();
if (siteUniqueId != null) {
study = getStudyDao().findSiteByUniqueIdentifier(studyUniqueId, siteUniqueId);
}
StudyEventDefinitionBean studyEventDefinition = getStudyEventDefinitionDao().findByOidAndStudy(eventDefinitionOID, study.getId(), parentStudyId);
StudySubjectBean studySubject = getStudySubjectDao().findByLabelAndStudy(studySubjectId, study);
Integer studyEventOrdinal = null;
if (canSubjectScheduleAnEvent(studyEventDefinition, studySubject)) {
StudyEventBean studyEvent = new StudyEventBean();
studyEvent.setStudyEventDefinitionId(studyEventDefinition.getId());
studyEvent.setStudySubjectId(studySubject.getId());
studyEvent.setLocation(location);
studyEvent.setDateStarted(startDateTime);
studyEvent.setDateEnded(endDateTime);
studyEvent.setOwner(user);
studyEvent.setStatus(Status.AVAILABLE);
studyEvent.setSubjectEventStatus(SubjectEventStatus.SCHEDULED);
studyEvent.setSampleOrdinal(getStudyEventDao().getMaxSampleOrdinal(studyEventDefinition, studySubject) + 1);
studyEvent = (StudyEventBean) getStudyEventDao().create(studyEvent, true);
studyEventOrdinal = studyEvent.getSampleOrdinal();
} else {
throw new OpenClinicaSystemException("Cannot schedule an event for this Subject");
}
HashMap<String, String> h = new HashMap<String, String>();
h.put("eventDefinitionOID", eventDefinitionOID);
h.put("studyEventOrdinal", studyEventOrdinal.toString());
h.put("studySubjectOID", studySubject.getOid());
return h;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean 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);
FormLayoutDAO formLayoutDAO = new FormLayoutDAO(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, FormLayoutBean> formLayoutById = formLayoutDAO.buildFormLayoutById(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, formLayoutById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, formLayoutById, crfById);
populateUncompletedCRFsWithCRFAndVersions(al, formLayoutById, 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.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class OdmExtractDAO method getEventDefCRF.
private EventDefinitionCRFBean getEventDefCRF(StudyEventDefBean studyEventDefBean, ElementRefBean formRef, int studyId) {
StudyBean studyBean = (StudyBean) sdao.findByPK(studyId);
StudyEventDefinitionBean sedBean = seddao.findByOid(studyEventDefBean.getOid());
CRFBean crfBean = crfdao.findByOid(formRef.getElementDefOID());
return edcdao.findByStudyEventDefinitionIdAndCRFId(studyBean, sedBean.getId(), crfBean.getId());
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class RandomizeActionValidator 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().isRandomizeActionExpressionValid(propertyBean.getOid(), getRuleSetBean(), 3) || item == null) {
e.rejectValue(p + "oid", "oid.invalid", "OID: " + propertyBean.getOid() + " is Invalid.");
}
}
}
use of org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean in project OpenClinica by OpenClinica.
the class StudyEventDefinitionDAO method findByName.
/*
* added tbh, 02/2008 (non-Javadoc)
*
* @see org.akaza.openclinica.dao.core.DAOInterface#findByPK(int)
*/
public EntityBean findByName(String name) {
StudyEventDefinitionBean eb = new StudyEventDefinitionBean();
this.setTypesExpected();
HashMap variables = new HashMap();
variables.put(new Integer(1), name);
String sql = digester.getQuery("findByName");
ArrayList alist = this.select(sql, variables);
Iterator it = alist.iterator();
if (it.hasNext()) {
eb = (StudyEventDefinitionBean) this.getEntityFromHashMap((HashMap) it.next());
}
return eb;
}
Aggregations