Search in sources :

Example 1 with StudyEventChangeDetails

use of org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails 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 2 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 {
        // Then i need to query the site for hidden crfs then subtract that from the count of study defined crfs to 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 3 with StudyEventChangeDetails

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

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

the class StudyEventDAO method create.

/**
 * Creates a new studysubject
 */
public EntityBean create(EntityBean eb, boolean isTransaction) {
    StudyEventBean sb = (StudyEventBean) eb;
    HashMap variables = new HashMap();
    HashMap nullVars = new HashMap();
    // INSERT INTO STUDY_EVENT
    // (STUDY_EVENT_DEFINITION_ID,SUBJECT_ID,LOCATION,SAMPLE_ORDINAL,
    // DATE_START,DATE_END,OWNER_ID,STATUS_ID,DATE_CREATED,subject_event_status_id
    // start_time_flag, end_time_flag)
    // VALUES (?,?,?,?,?,?,?,?,NOW())
    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()));
    nullVars.put(3, TypeNames.STRING);
    if (sb.getDateStarted() == null) {
        // YW 08-16-2007 << data type changed from DATE to TIMESTAMP
        nullVars.put(Integer.valueOf(5), Integer.valueOf(TypeNames.TIMESTAMP));
        variables.put(Integer.valueOf(5), null);
    } else {
        // YW 08-16-2007 << data type changed from DATE to TIMESTAMP
        variables.put(Integer.valueOf(5), new Timestamp(sb.getDateStarted().getTime()));
    }
    if (sb.getDateEnded() == null) {
        // YW 08-16-2007 << data type changed from DATE to TIMESTAMP
        nullVars.put(Integer.valueOf(6), Integer.valueOf(TypeNames.TIMESTAMP));
        variables.put(Integer.valueOf(6), null);
    } else {
        // YW 08-16-2007 << data type changed from DATE to TIMESTAMP
        variables.put(Integer.valueOf(6), new Timestamp(sb.getDateEnded().getTime()));
    }
    variables.put(Integer.valueOf(7), Integer.valueOf(sb.getOwner().getId()));
    variables.put(Integer.valueOf(8), Integer.valueOf(sb.getStatus().getId()));
    variables.put(Integer.valueOf(9), Integer.valueOf(sb.getSubjectEventStatus().getId()));
    variables.put(Integer.valueOf(10), sb.getStartTimeFlag());
    variables.put(Integer.valueOf(11), sb.getEndTimeFlag());
    this.executeWithPK(digester.getQuery("create"), variables, nullVars);
    if (isQuerySuccessful()) {
        sb.setId(getLatestPK());
    }
    StudyEventChangeDetails changeDetails = new StudyEventChangeDetails(true, 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)

Example 5 with StudyEventChangeDetails

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

the class JobTriggerService method triggerJob.

public void triggerJob() {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    ArrayList<RuleSetBean> ruleSets = ruleSetDao.findAllRunOnSchedules(true);
    for (RuleSetBean ruleSet : ruleSets) {
        if (ruleSet.getStatus().AVAILABLE != null && ruleSet.isRunSchedule()) {
            if (ruleSet.getItemId() != null) {
                // item Specific Rule
                ArrayList<RuleSetBean> ruleSetBeans = new ArrayList<>();
                StudyBean currentStudy = (StudyBean) getStudyDao().findByPK(ruleSet.getStudyId());
                ResourceBundleProvider.updateLocale(Locale.getDefault());
                UserAccountBean ub = (UserAccountBean) getUserAccountDao().findByPK(1);
                ruleSetBeans.add(ruleSet);
                ruleSetService.runRulesInBulk(ruleSetBeans, false, currentStudy, ub, true);
            } else {
                // Event Specific Rule
                StudyEventChangeDetails studyEventChangeDetails = new StudyEventChangeDetails(true, true);
                ArrayList<RuleSetBean> ruleSetBeans = new ArrayList<>();
                ExpressionBean eBean = new ExpressionBean();
                eBean.setValue(ruleSet.getTarget().getValue() + ".A.B");
                ruleSet.setTarget(eBean);
                ruleSetBeans.add(ruleSet);
                ruleSetService.runRulesInBeanProperty(ruleSetBeans, 1, studyEventChangeDetails);
            }
        }
    }
}
Also used : Locale(java.util.Locale) StudyEventChangeDetails(org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

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