Search in sources :

Example 1 with StudyEvent

use of org.akaza.openclinica.domain.datamap.StudyEvent 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 StudyEvent

use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.

the class BeanPropertyService method runAction.

/**
     * Complete adding to this Service to evaluate Event action
     * @param ruleActionBean
     * @param eow
     * @param isTransaction 
     */
public void runAction(RuleActionBean ruleActionBean, ExpressionBeanObjectWrapper eow, Integer userId, Boolean isTransaction) {
    boolean statusMatch = false;
    OpenClinicaExpressionParser oep = new OpenClinicaExpressionParser(eow);
    ExpressionBeanService ebs = new ExpressionBeanService(eow);
    StudyEvent studyEvent = ebs.getStudyEventFromOID(((EventActionBean) ruleActionBean).getOc_oid_reference());
    RuleActionRunBean runOnStatuses = ruleActionBean.getRuleActionRun();
    if (studyEvent != null) {
        switch(SubjectEventStatus.getByCode(studyEvent.getSubjectEventStatusId())) {
            case NOT_SCHEDULED:
                if (runOnStatuses.getNot_started())
                    statusMatch = true;
                break;
            case SCHEDULED:
                if (runOnStatuses.getScheduled())
                    statusMatch = true;
                break;
            case DATA_ENTRY_STARTED:
                if (runOnStatuses.getData_entry_started())
                    statusMatch = true;
                break;
            case COMPLETED:
                if (runOnStatuses.getComplete())
                    statusMatch = true;
                break;
            case SKIPPED:
                if (runOnStatuses.getSkipped())
                    statusMatch = true;
                break;
            case STOPPED:
                if (runOnStatuses.getStopped())
                    statusMatch = true;
                break;
            case SIGNED:
            case LOCKED:
            default:
                statusMatch = false;
                break;
        }
    } else //Special case if destination study event doesn't exist yet, ie not scheduled.
    {
        if (runOnStatuses.getNot_started())
            statusMatch = true;
    }
    if (statusMatch) {
        for (PropertyBean propertyBean : ((EventActionBean) ruleActionBean).getProperties()) {
            // This will execute the contents of <ValueExpression>SS.ENROLLMENT_DATE + 2</ValueExpression>
            LOGGER.debug("Values:expression??::" + propertyBean.getValueExpression().getValue());
            Object result = oep.parseAndEvaluateExpression(propertyBean.getValueExpression().getValue());
            executeAction(result, propertyBean, eow, (EventActionBean) ruleActionBean, userId, isTransaction);
        }
    }
}
Also used : OpenClinicaExpressionParser(org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser) ExpressionBeanService(org.akaza.openclinica.service.rule.expression.ExpressionBeanService) EventActionBean(org.akaza.openclinica.domain.rule.action.EventActionBean) RuleActionRunBean(org.akaza.openclinica.domain.rule.action.RuleActionRunBean) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) PropertyBean(org.akaza.openclinica.domain.rule.action.PropertyBean)

Example 3 with StudyEvent

use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.

the class RuleSetListenerService method onApplicationEvent.

@Override
public void onApplicationEvent(final OnStudyEventUpdated event) {
    LOGGER.debug("listening");
    if (event.getContainer().getChangeDetails().getStartDateChanged() || event.getContainer().getChangeDetails().getStatusChanged()) {
        StudyEvent studyEvent = event.getContainer().getEvent();
        Integer studyEventDefId = studyEvent.getStudyEventDefinition().getStudyEventDefinitionId();
        Integer studyEventOrdinal = studyEvent.getSampleOrdinal();
        Integer userId = studyEvent.getUpdateId();
        if (userId == null && studyEvent.getUserAccount() != null)
            userId = studyEvent.getUserAccount().getUserId();
        StudyEventBean studyEventBean = new StudyEventBean();
        studyEventBean.setId(studyEvent.getStudyEventId());
        ArrayList<RuleSetBean> ruleSets = (ArrayList<RuleSetBean>) createRuleSet(studyEventDefId);
        for (RuleSetBean ruleSet : ruleSets) {
            ArrayList<RuleSetBean> ruleSetBeans = new ArrayList();
            ExpressionBean eBean = new ExpressionBean();
            eBean.setValue(ruleSet.getTarget().getValue() + ".A.B");
            ruleSet.setTarget(eBean);
            ruleSet.addExpression(getRuleSetService().replaceSEDOrdinal(ruleSet.getTarget(), studyEventBean));
            ruleSetBeans.add(ruleSet);
            getRuleSetService().runIndividualRulesInBeanProperty(ruleSetBeans, userId, event.getContainer().getChangeDetails(), studyEventOrdinal);
        }
    }
}
Also used : ArrayList(java.util.ArrayList) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) ExpressionBean(org.akaza.openclinica.domain.rule.expression.ExpressionBean)

Example 4 with StudyEvent

use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.

the class GenerateClinicalDataServiceImpl method constructClinicalDataStudy.

private OdmClinicalDataBean constructClinicalDataStudy(List<StudySubject> studySubjs, Study study, List<StudyEvent> studyEvents, String formVersionOID) {
    OdmClinicalDataBean odmClinicalDataBean = new OdmClinicalDataBean();
    ExportSubjectDataBean expSubjectBean;
    List<ExportSubjectDataBean> exportSubjDataBeanList = new ArrayList<ExportSubjectDataBean>();
    for (StudySubject studySubj : studySubjs) {
        studyEvents = (ArrayList<StudyEvent>) getStudySubjectDao().fetchListSEs(studySubj.getOcOid());
        if (studyEvents != null) {
            expSubjectBean = setExportSubjectDataBean(studySubj, study, studyEvents, formVersionOID);
            exportSubjDataBeanList.add(expSubjectBean);
            odmClinicalDataBean.setExportSubjectData(exportSubjDataBeanList);
            odmClinicalDataBean.setStudyOID(study.getOc_oid());
        }
    }
    return odmClinicalDataBean;
// return null;
}
Also used : StudySubject(org.akaza.openclinica.domain.datamap.StudySubject) ArrayList(java.util.ArrayList) OdmClinicalDataBean(org.akaza.openclinica.bean.odmbeans.OdmClinicalDataBean) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) ExportSubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.ExportSubjectDataBean)

Example 5 with StudyEvent

use of org.akaza.openclinica.domain.datamap.StudyEvent in project OpenClinica by OpenClinica.

the class GenerateClinicalDataServiceImpl method setExportStudyEventDataBean.

private ArrayList<ExportStudyEventDataBean> setExportStudyEventDataBean(StudySubject ss, List<StudyEvent> sEvents, String formVersionOID) {
    ArrayList<ExportStudyEventDataBean> al = new ArrayList<ExportStudyEventDataBean>();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    for (StudyEvent se : sEvents) {
        if (se != null) {
            ExportStudyEventDataBean expSEBean = new ExportStudyEventDataBean();
            expSEBean.setLocation(se.getLocation());
            if (se.getDateEnd() != null)
                if (se.getEndTimeFlag())
                    expSEBean.setEndDate(se.getDateEnd() + "");
                else {
                    String temp = sdf.format(se.getDateEnd());
                    expSEBean.setEndDate(temp);
                }
            if (se.getStartTimeFlag())
                expSEBean.setStartDate(se.getDateStart() + "");
            else {
                String temp = sdf.format(se.getDateStart());
                expSEBean.setStartDate(temp);
            }
            expSEBean.setStudyEventOID(se.getStudyEventDefinition().getOc_oid());
            expSEBean.setStudyEventRepeatKey(se.getSampleOrdinal().toString());
            if (se.getStudySubject().getSubject().getDateOfBirth() != null && se.getDateStart() != null)
                expSEBean.setAgeAtEvent(Utils.getAge(se.getStudySubject().getSubject().getDateOfBirth(), se.getDateStart()));
            expSEBean.setStatus(fetchStudyEventStatus(se.getSubjectEventStatusId()));
            if (collectAudits)
                expSEBean.setAuditLogs(fetchAuditLogs(se.getStudyEventId(), "study_event", se.getStudyEventDefinition().getOc_oid(), null));
            if (collectDns)
                expSEBean.setDiscrepancyNotes(fetchDiscrepancyNotes(se));
            expSEBean.setExportFormData(getFormDataForClinicalStudy(ss, se, formVersionOID));
            expSEBean.setStudyEventDefinition(se.getStudyEventDefinition());
            al.add(expSEBean);
        }
    }
    return al;
}
Also used : ArrayList(java.util.ArrayList) StudyEvent(org.akaza.openclinica.domain.datamap.StudyEvent) SimpleDateFormat(java.text.SimpleDateFormat) ExportStudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.ExportStudyEventDataBean)

Aggregations

StudyEvent (org.akaza.openclinica.domain.datamap.StudyEvent)25 StudySubject (org.akaza.openclinica.domain.datamap.StudySubject)6 ArrayList (java.util.ArrayList)5 EventCrf (org.akaza.openclinica.domain.datamap.EventCrf)5 Date (java.util.Date)4 FormLayout (org.akaza.openclinica.domain.datamap.FormLayout)4 Study (org.akaza.openclinica.domain.datamap.Study)4 StudyEventDefinition (org.akaza.openclinica.domain.datamap.StudyEventDefinition)4 Transactional (org.springframework.transaction.annotation.Transactional)4 SimpleDateFormat (java.text.SimpleDateFormat)3 HashMap (java.util.HashMap)2 EventDefinitionCrf (org.akaza.openclinica.domain.datamap.EventDefinitionCrf)2 RuleSetBean (org.akaza.openclinica.domain.rule.RuleSetBean)2 EventActionBean (org.akaza.openclinica.domain.rule.action.EventActionBean)2 ExpressionBean (org.akaza.openclinica.domain.rule.expression.ExpressionBean)2 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)2 OpenClinicaExpressionParser (org.akaza.openclinica.logic.expressionTree.OpenClinicaExpressionParser)2 OnStudyEventUpdated (org.akaza.openclinica.patterns.ocobserver.OnStudyEventUpdated)2 StudyEventChangeDetails (org.akaza.openclinica.patterns.ocobserver.StudyEventChangeDetails)2 StudyEventContainer (org.akaza.openclinica.patterns.ocobserver.StudyEventContainer)2