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