Search in sources :

Example 1 with StudyEventContainer

use of org.akaza.openclinica.patterns.ocobserver.StudyEventContainer in project OpenClinica by OpenClinica.

the class BeanPropertyService method executeAction.

/**
     * The Event action runs based on the values set in the rules.
     * @param result
     * @param propertyBean
     * @param eow
     * @param eventAction
     */
private void executeAction(Object result, PropertyBean propertyBean, ExpressionBeanObjectWrapper eow, EventActionBean eventAction, Integer userId, boolean isTransaction) {
    String oid = eventAction.getOc_oid_reference();
    String eventOID = null;
    DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
    int ordinal = 1;
    if (oid.startsWith(ExpressionService.STUDY_EVENT_OID_START_KEY)) {
        StudyEvent studyEvent = null;
        if (oid.contains("[")) {
            int leftBracketIndex = oid.indexOf("[");
            int rightBracketIndex = oid.indexOf("]");
            ordinal = Integer.valueOf(oid.substring(leftBracketIndex + 1, rightBracketIndex));
            eventOID = oid.substring(0, leftBracketIndex);
            studyEvent = getStudyEventDAO().fetchByStudyEventDefOIDAndOrdinal(eventOID, ordinal, eow.getStudySubjectBeanId());
        } else {
            eventOID = oid;
            studyEvent = getStudyEventDAO().fetchByStudyEventDefOIDAndOrdinal(oid, ordinal, eow.getStudySubjectBeanId());
        }
        StudyEventChangeDetails changeDetails = new StudyEventChangeDetails();
        if (studyEvent == null) {
            //the studyevent may not have been created.
            studyEvent = new StudyEvent();
            StudySubject ss = getStudySubjectDao().findById(eow.getStudySubjectBeanId());
            StudyEventDefinition sed = getStudyEventDefinitionDao().findByColumnName(eventOID, "oc_oid");
            studyEvent.setStudyEventDefinition(sed);
            studyEvent.setStudySubject(ss);
            studyEvent.setStatusId(1);
            studyEvent.setSampleOrdinal(getNewEventOrdinal(eventOID, eow.getStudySubjectBeanId(), sed));
            //The status is changed to started when it doesnt exist. In other cases, the status remains the same. The case of Signed and locked are prevented from validator and are not again checked here.
            studyEvent.setSubjectEventStatusId(new Integer(1));
            studyEvent.setStartTimeFlag(false);
            studyEvent.setEndTimeFlag(false);
            studyEvent.setDateCreated(new Date());
            studyEvent.setUserAccount(getUserAccountDao().findById(userId));
            changeDetails.setStartDateChanged(true);
            changeDetails.setStatusChanged(true);
        } else {
            studyEvent.setUpdateId(userId);
            studyEvent.setDateUpdated(new Date());
            changeDetails.setStatusChanged(false);
        }
        try {
            if (studyEvent.getDateStart() == null || studyEvent.getDateStart().compareTo(df.parse((String) result)) != 0)
                changeDetails.setStartDateChanged(true);
            studyEvent.setDateStart(df.parse((String) result));
        } catch (ParseException e) {
            e.printStackTrace();
            LOGGER.info(e.getMessage());
        }
        changeDetails.setRunningInTransaction(isTransaction);
        StudyEventContainer container = new StudyEventContainer(studyEvent, changeDetails);
        if (isTransaction)
            getStudyEventDAO().saveOrUpdateTransactional(container);
        else
            getStudyEventDAO().saveOrUpdate(container);
    }
}
Also used : StudyEventDefinition(org.akaza.openclinica.domain.datamap.StudyEventDefinition) StudyEventChangeDetails(org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails) StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) ParseException(java.text.ParseException) StudyEventContainer(org.akaza.openclinica.patterns.ocobserver.StudyEventContainer) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with StudyEventContainer

use of org.akaza.openclinica.patterns.ocobserver.StudyEventContainer in project OpenClinica by OpenClinica.

the class StudyEventController method completeData.

@Transactional
private void completeData(StudyEvent studyEvent, List<EventDefinitionCrf> eventDefCrfs, List<EventCrf> eventCrfs) throws Exception {
    boolean completeStudyEvent = true;
    // Loop thru event CRFs and complete all that are participant events.
    for (EventDefinitionCrf eventDefCrf : eventDefCrfs) {
        boolean foundEventCrfMatch = false;
        for (EventCrf eventCrf : eventCrfs) {
            if (eventDefCrf.getCrf().getCrfId() == eventCrf.getCrfVersion().getCrf().getCrfId()) {
                foundEventCrfMatch = true;
                if (eventDefCrf.getParicipantForm()) {
                    eventCrf.setStatusId(Status.UNAVAILABLE.getCode());
                    eventCrfDao.saveOrUpdate(eventCrf);
                } else if (eventCrf.getStatusId() != Status.UNAVAILABLE.getCode())
                    completeStudyEvent = false;
            }
        }
        if (!foundEventCrfMatch && !eventDefCrf.getParicipantForm())
            completeStudyEvent = false;
    }
    // Complete study event only if there are no uncompleted, non-participant forms.
    if (completeStudyEvent) {
        studyEvent.setSubjectEventStatusId(4);
        StudyEventChangeDetails changeDetails = new StudyEventChangeDetails(true, false);
        StudyEventContainer container = new StudyEventContainer(studyEvent, changeDetails);
        studyEventDao.saveOrUpdateTransactional(container);
    }
}
Also used : EventCrf(org.akaza.openclinica.domain.datamap.EventCrf) StudyEventChangeDetails(org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails) EventDefinitionCrf(org.akaza.openclinica.domain.datamap.EventDefinitionCrf) StudyEventContainer(org.akaza.openclinica.patterns.ocobserver.StudyEventContainer) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with StudyEventContainer

use of org.akaza.openclinica.patterns.ocobserver.StudyEventContainer in project OpenClinica by OpenClinica.

the class EventProcessor method createStudyEvent.

private StudyEvent createStudyEvent(StudySubject studySubject, StudyEventDefinition studyEventDefinition, Integer ordinal, UserAccount user) {
    Date currentDate = new Date();
    StudyEvent studyEvent = new StudyEvent();
    studyEvent.setStudySubject(studySubject);
    studyEvent.setStudyEventDefinition(studyEventDefinition);
    studyEvent.setSampleOrdinal(ordinal);
    studyEvent.setStatusId(Status.AVAILABLE.getCode());
    studyEvent.setUserAccount(user);
    studyEvent.setDateStart(currentDate);
    studyEvent.setSubjectEventStatusId(SubjectEventStatus.SCHEDULED.getCode());
    studyEvent.setStartTimeFlag(false);
    studyEvent.setEndTimeFlag(false);
    studyEvent.setDateCreated(currentDate);
    studyEvent.setLocation("");
    StudyEventChangeDetails changeDetails = new StudyEventChangeDetails(true, true);
    StudyEventContainer container = new StudyEventContainer(studyEvent, changeDetails);
    studyEventDao.saveOrUpdateTransactional(container);
    studyEvent = studyEventDao.fetchByStudyEventDefOIDAndOrdinal(studyEventDefinition.getOc_oid(), ordinal, studySubject.getStudySubjectId());
    return studyEvent;
}
Also used : StudyEventChangeDetails(org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) StudyEventContainer(org.akaza.openclinica.patterns.ocobserver.StudyEventContainer) Date(java.util.Date)

Example 4 with StudyEventContainer

use of org.akaza.openclinica.patterns.ocobserver.StudyEventContainer in project OpenClinica by OpenClinica.

the class EventProcessor method updateStudyEvent.

private StudyEvent updateStudyEvent(StudyEvent studyEvent, StudyEventDefinition studyEventDefinition, Study study, StudySubject studySubject, UserAccount user, boolean isAnonymous) {
    SubjectEventStatus newStatus = null;
    int crfCount = 0;
    int hiddenSiteCrfCount = 0;
    int completedCrfCount = 0;
    if (!isAnonymous) {
        if (studyEvent.getSubjectEventStatusId().intValue() == SubjectEventStatus.SCHEDULED.getCode().intValue())
            newStatus = SubjectEventStatus.DATA_ENTRY_STARTED;
    } else {
        // get the crf count
        if (study.getStudy() != null) {
            hiddenSiteCrfCount = eventDefinitionCrfDao.findSiteHiddenByStudyEventDefStudy(studyEventDefinition.getStudyEventDefinitionId(), study.getStudyId()).size();
            crfCount = eventDefinitionCrfDao.findAvailableByStudyEventDefStudy(studyEventDefinition.getStudyEventDefinitionId(), study.getStudy().getStudyId()).size();
        } else
            crfCount = eventDefinitionCrfDao.findAvailableByStudyEventDefStudy(studyEventDefinition.getStudyEventDefinitionId(), study.getStudyId()).size();
        // Get a count of completed CRFs for the event
        completedCrfCount = eventCrfDao.findByStudyEventStatus(studyEvent.getStudyEventId(), Status.UNAVAILABLE.getCode()).size();
        if ((crfCount - hiddenSiteCrfCount) == completedCrfCount) {
            if (studyEvent.getSubjectEventStatusId().intValue() == SubjectEventStatus.SCHEDULED.getCode().intValue() || studyEvent.getSubjectEventStatusId().intValue() == SubjectEventStatus.DATA_ENTRY_STARTED.getCode().intValue()) {
                newStatus = SubjectEventStatus.COMPLETED;
            }
        } else if (studyEvent.getSubjectEventStatusId().intValue() == SubjectEventStatus.SCHEDULED.getCode().intValue()) {
            newStatus = SubjectEventStatus.DATA_ENTRY_STARTED;
        }
    }
    if (newStatus != null) {
        studyEvent.setUpdateId(user.getUserId());
        studyEvent.setDateUpdated(new Date());
        studyEvent.setSubjectEventStatusId(newStatus.getCode());
        StudyEventChangeDetails changeDetails = new StudyEventChangeDetails(true, false);
        StudyEventContainer container = new StudyEventContainer(studyEvent, changeDetails);
        studyEvent = studyEventDao.saveOrUpdateTransactional(container);
        logger.debug("*********UPDATED STUDY EVENT ");
    }
    return studyEvent;
}
Also used : StudyEventChangeDetails(org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails) StudyEventContainer(org.akaza.openclinica.patterns.ocobserver.StudyEventContainer) Date(java.util.Date) SubjectEventStatus(org.akaza.openclinica.domain.datamap.SubjectEventStatus)

Aggregations

StudyEventChangeDetails (org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails)4 StudyEventContainer (org.akaza.openclinica.patterns.ocobserver.StudyEventContainer)4 Date (java.util.Date)3 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)2 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)1 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)1 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)1 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)1 SubjectEventStatus (org.akaza.openclinica.domain.datamap.SubjectEventStatus)1 Transactional (org.springframework.transaction.annotation.Transactional)1