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);
}
}
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);
}
}
}
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);
}
}
}
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;
}
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;
}
Aggregations