Search in sources :

Example 76 with OpenClinicaSystemException

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;
}
Also used : StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) HashMap(java.util.HashMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) OpenClinicaSystemException(org.akaza.openclinica.exception.OpenClinicaSystemException)

Aggregations

OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)76 IOException (java.io.IOException)19 File (java.io.File)13 HashMap (java.util.HashMap)11 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)11 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)11 ArrayList (java.util.ArrayList)10 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)10 FileNotFoundException (java.io.FileNotFoundException)8 MessageFormat (java.text.MessageFormat)8 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)7 RuleActionBean (org.akaza.openclinica.domain.rule.action.RuleActionBean)7 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)7 ExpressionObjectWrapper (org.akaza.openclinica.domain.rule.expression.ExpressionObjectWrapper)7 FileOutputStream (java.io.FileOutputStream)6 Date (java.util.Date)6 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)6 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)6 RuleBean (org.akaza.openclinica.domain.rule.RuleBean)6 RuleSetRuleBean (org.akaza.openclinica.domain.rule.RuleSetRuleBean)6