use of org.akaza.openclinica.patterns.ocobserver.StudyEventBeanContainer 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;
}
use of org.akaza.openclinica.patterns.ocobserver.StudyEventBeanContainer 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;
}
use of org.akaza.openclinica.patterns.ocobserver.StudyEventBeanContainer in project OpenClinica by OpenClinica.
the class StudyEventBeanListener method update.
@Override
public void update(Listener lstnr) {
// System.out.println("Triggering the rules based on event updates");
StudyEventBeanContainer studyEventBeanContainer = (StudyEventBeanContainer) lstnr;
// if (studyEventBeanContainer.getChangeDetails().getStartDateChanged() || studyEventBeanContainer.getChangeDetails().getStatusChanged()){
Integer studyEventDefId = studyEventBeanContainer.getEvent().getStudyEventDefinitionId();
// Integer studySubjectId = studyEventBeanContainer.getEvent().getStudySubjectId();
Integer userId = studyEventBeanContainer.getEvent().getUpdaterId();
Integer studyEventOrdinal = studyEventBeanContainer.getEvent().getSampleOrdinal();
if (userId == 0)
userId = studyEventBeanContainer.getEvent().getOwnerId();
StudyEventBean studyEvent = studyEventBeanContainer.getEvent();
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(), studyEvent));
ruleSetBeans.add(ruleSet);
// for (RuleSetBean ruleSet : ruleSetBeans){
String targetProperty = ruleSet.getTarget().getValue().substring(ruleSet.getTarget().getValue().indexOf("."));
if ((targetProperty.contains(ExpressionService.STARTDATE + ".A.B") && studyEventBeanContainer.getChangeDetails().getStartDateChanged()) || (targetProperty.contains(ExpressionService.STATUS + ".A.B") && studyEventBeanContainer.getChangeDetails().getStatusChanged())) {
getRuleSetService().runIndividualRulesInBeanProperty(ruleSetBeans, userId, studyEventBeanContainer.getChangeDetails(), studyEventOrdinal);
}
}
// }
}
Aggregations