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