use of org.akaza.openclinica.exception.OpenClinicaSystemException 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;
}
Aggregations