Search in sources :

Example 6 with StudyEventChangeDetails

use of org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails 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)

Example 7 with StudyEventChangeDetails

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

the class StudyEventDAO method update.

/* this function allows to run transactional updates for an action*/
public EntityBean update(EntityBean eb, Connection con, boolean isTransaction) {
    StudyEventBean sb = (StudyEventBean) eb;
    StudyEventBean oldStudyEventBean = (StudyEventBean) findByPK(sb.getId());
    HashMap nullVars = new HashMap();
    HashMap variables = new HashMap();
    // UPDATE study_event SET
    // STUDY_EVENT_DEFINITION_ID=?,SUBJECT_ID=?,LOCATION=?,
    // SAMPLE_ORDINAL=?, DATE_START=?,DATE_END=?,STATUS_ID=?,DATE_UPDATED=?,
    // UPDATE_ID=?, subject_event_status_id=?, end_time_flag=? WHERE
    // STUDY_EVENT_ID=?
    sb.setActive(false);
    variables.put(Integer.valueOf(1), Integer.valueOf(sb.getStudyEventDefinitionId()));
    variables.put(Integer.valueOf(2), Integer.valueOf(sb.getStudySubjectId()));
    variables.put(Integer.valueOf(3), sb.getLocation());
    variables.put(Integer.valueOf(4), Integer.valueOf(sb.getSampleOrdinal()));
    // YW 08-17-2007, data type changed from DATE to TIMESTAMP
    variables.put(Integer.valueOf(5), new Timestamp(sb.getDateStarted().getTime()));
    if (sb.getDateEnded() == null) {
        nullVars.put(Integer.valueOf(6), Integer.valueOf(TypeNames.TIMESTAMP));
        variables.put(Integer.valueOf(6), null);
    } else {
        variables.put(Integer.valueOf(6), new Timestamp(sb.getDateEnded().getTime()));
    }
    variables.put(Integer.valueOf(7), Integer.valueOf(sb.getStatus().getId()));
    // changing date_updated from java.util.Date() into postgres now() statement
    // variables.put(Integer.valueOf(8), new java.util.Date());// DATE_Updated
    variables.put(Integer.valueOf(8), Integer.valueOf(sb.getUpdater().getId()));
    variables.put(Integer.valueOf(9), Integer.valueOf(sb.getSubjectEventStatus().getId()));
    // YW
    variables.put(Integer.valueOf(10), sb.getStartTimeFlag());
    // 08-17-2007,
    // start_time_flag
    // YW
    variables.put(Integer.valueOf(11), sb.getEndTimeFlag());
    // 08-17-2007,
    // end_time_flag
    variables.put(Integer.valueOf(12), Integer.valueOf(sb.getId()));
    String sql = digester.getQuery("update");
    if (con == null) {
        this.execute(sql, variables, nullVars);
    } else {
        this.execute(sql, variables, nullVars, con);
    }
    if (isQuerySuccessful()) {
        sb.setActive(true);
    }
    StudyEventChangeDetails changeDetails = new StudyEventChangeDetails();
    if (oldStudyEventBean.getDateStarted().compareTo(sb.getDateStarted()) != 0)
        changeDetails.setStartDateChanged(true);
    if (oldStudyEventBean.getSubjectEventStatus().getId() != sb.getSubjectEventStatus().getId())
        changeDetails.setStatusChanged(true);
    changeDetails.setRunningInTransaction(isTransaction);
    StudyEventBeanContainer container = new StudyEventBeanContainer(sb, changeDetails);
    notifyObservers(container);
    return sb;
}
Also used : HashMap(java.util.HashMap) StudyEventChangeDetails(org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) Timestamp(java.sql.Timestamp) StudyEventBeanContainer(org.akaza.openclinica.patterns.ocobserver.StudyEventBeanContainer)

Aggregations

StudyEventChangeDetails (org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails)7 StudyEventContainer (org.akaza.openclinica.patterns.ocobserver.StudyEventContainer)4 Date (java.util.Date)3 Timestamp (java.sql.Timestamp)2 HashMap (java.util.HashMap)2 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)2 StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)2 StudyEventBeanContainer (org.akaza.openclinica.patterns.ocobserver.StudyEventBeanContainer)2 DateFormat (java.text.DateFormat)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)1 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)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