use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class ViewStudyEventsServlet method genTables.
/**
* @param fp
* @param definitions
* @param startDate
* @param endDate
* @param sedId
* @param definitionId
* @param statusId
* @return
*/
private ArrayList genTables(FormProcessor fp, ArrayList definitions, Date startDate, Date endDate, int sedId, int definitionId, int statusId) {
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList allEvents = new ArrayList();
definitions = findDefinitionById(definitions, definitionId);
// YW <<
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList studySubjects = ssdao.findAllByStudyId(currentStudy.getId());
// YW >>
for (int i = 0; i < definitions.size(); i++) {
ViewEventDefinitionBean ved = new ViewEventDefinitionBean();
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) definitions.get(i);
ved.setDefinition(sed);
// YW <<
ArrayList events = new ArrayList();
for (int s = 0; s < studySubjects.size(); ++s) {
StudySubjectBean ssb = (StudySubjectBean) studySubjects.get(s);
ArrayList evts = sedao.findAllWithSubjectLabelByStudySubjectAndDefinition(ssb, sed.getId());
for (int v = 0; v < evts.size(); ++v) {
StudyEventBean seb = (StudyEventBean) evts.get(v);
if (!(currentRole.isDirector() || currentRole.isCoordinator()) && seb.getSubjectEventStatus().isLocked()) {
seb.setEditable(false);
}
events.add(seb);
}
}
int subjectScheduled = 0;
int subjectCompleted = 0;
int subjectDiscontinued = 0;
events = findEventByStatusAndDate(events, statusId, startDate, endDate);
Date firstStartDateForScheduled = null;
Date lastCompletionDate = null;
// find the first firstStartDateForScheduled
for (int k = 0; k < events.size(); k++) {
StudyEventBean se = (StudyEventBean) events.get(k);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
firstStartDateForScheduled = se.getDateStarted();
break;
}
}
// find the first lastCompletionDate
for (int k = 0; k < events.size(); k++) {
StudyEventBean se = (StudyEventBean) events.get(k);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED) && se.getDateEnded() != null) {
lastCompletionDate = se.getDateEnded();
break;
}
}
for (int j = 0; j < events.size(); j++) {
StudyEventBean se = (StudyEventBean) events.get(j);
if (se.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED)) {
subjectScheduled++;
if (se.getDateStarted().before(new Date())) {
ArrayList eventCRFs = ecdao.findAllByStudyEvent(se);
if (eventCRFs.isEmpty()) {
se.setScheduledDatePast(true);
}
}
if (firstStartDateForScheduled == null) {
firstStartDateForScheduled = se.getDateStarted();
} else if (se.getDateStarted().before(firstStartDateForScheduled)) {
firstStartDateForScheduled = se.getDateStarted();
}
} else if (se.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) {
subjectCompleted++;
if (lastCompletionDate == null) {
lastCompletionDate = se.getDateEnded();
} else if (se.getDateEnded() != null && se.getDateEnded().after(lastCompletionDate)) {
lastCompletionDate = se.getDateEnded();
}
} else if (se.getSubjectEventStatus().getId() > 4) {
// dropped out/stopped/skipped/relapse
subjectDiscontinued++;
}
}
ved.setSubjectCompleted(subjectCompleted);
ved.setSubjectScheduled(subjectScheduled);
ved.setSubjectDiscontinued(subjectDiscontinued);
ved.setFirstScheduledStartDate(firstStartDateForScheduled);
ved.setLastCompletionDate(lastCompletionDate);
EntityBeanTable table;
if (sedId == sed.getId()) {
// apply finding function or ordering
// function
// to a specific table
table = fp.getEntityBeanTable();
} else {
table = new EntityBeanTable();
}
// sort by event
table.setSortingIfNotExplicitlySet(1, false);
// start date,
// desc
ArrayList allEventRows = StudyEventRow.generateRowsFromBeans(events);
String[] columns = { resword.getString("study_subject_ID"), resword.getString("event_date_started"), resword.getString("subject_event_status"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(3);
HashMap args = new HashMap();
args.put("sedId", new Integer(sed.getId()).toString());
args.put("definitionId", new Integer(definitionId).toString());
args.put("statusId", new Integer(statusId).toString());
args.put("startDate", local_df.format(startDate));
args.put("endDate", local_df.format(endDate));
table.setQuery("ViewStudyEvents", args);
table.setRows(allEventRows);
table.computeDisplay();
ved.setStudyEventTable(table);
if (!events.isEmpty()) {
allEvents.add(ved);
}
}
// A. Hamid.
return allEvents;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class ViewStudySubjectServlet method getDisplayStudyEventsForStudySubject.
public static ArrayList<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(StudySubjectBean studySub, DataSource ds, UserAccountBean ub, StudyUserRoleBean currentRole) {
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
StudyEventDAO sedao = new StudyEventDAO(ds);
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
StudySubjectDAO ssdao = new StudySubjectDAO(ds);
StudyDAO sdao = new StudyDAO(ds);
ArrayList events = sedao.findAllByStudySubject(studySub);
ArrayList displayEvents = new ArrayList();
for (int i = 0; i < events.size(); i++) {
StudyEventBean event = (StudyEventBean) events.get(i);
StudySubjectBean studySubject = (StudySubjectBean) ssdao.findByPK(event.getStudySubjectId());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
// find all active crfs in the definition
StudyBean study = (StudyBean) sdao.findByPK(studySubject.getStudyId());
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, sed.getId());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs(getDisplayEventCRFs(ds, eventCRFs, eventDefinitionCRFs, ub, currentRole, event.getSubjectEventStatus(), study));
ArrayList al = getUncompletedCRFs(ds, eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus());
populateUncompletedCRFsWithCRFAndVersions(ds, al);
de.setUncompletedCRFs(al);
de.setMaximumSampleOrdinal(sedao.getMaxSampleOrdinal(sed, studySubject));
displayEvents.add(de);
// event.setEventCRFs(createAllEventCRFs(eventCRFs,
// eventDefinitionCRFs));
}
return displayEvents;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class EnterDataForStudyEventServlet method processRequest.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
@Override
protected void processRequest() throws Exception {
// removeLockedCRF(ub.getId());
getCrfLocker().unlockAllForUser(ub.getId());
FormProcessor fp = new FormProcessor(request);
int eventId = fp.getInt(INPUT_EVENT_ID, true);
request.setAttribute("eventId", eventId + "");
// so we can display the event for which we're entering data
StudyEventBean seb = getStudyEvent(eventId);
// so we can display the subject's label
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean studySubjectBean = (StudySubjectBean) ssdao.findByPK(seb.getStudySubjectId());
int studyId = studySubjectBean.getStudyId();
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
// If the study subject derives from a site, and is being viewed from a
// parent study,
// then the study IDs will be different. However, since each note is
// saved with the specific
// study ID, then its study ID may be different than the study subject's
// ID.
boolean subjectStudyIsCurrentStudy = studyId == currentStudy.getId();
boolean isParentStudy = study.getParentStudyId() < 1;
// Get any disc notes for this study event
DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(sm.getDataSource());
ArrayList<DiscrepancyNoteBean> allNotesforSubjectAndEvent = new ArrayList<DiscrepancyNoteBean>();
// These methods return only parent disc notes
if (subjectStudyIsCurrentStudy && isParentStudy) {
allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudyAndId(currentStudy, studySubjectBean.getId());
} else {
// findAllStudyEventByStudiesAndSubjectId
if (!isParentStudy) {
StudyBean stParent = (StudyBean) studydao.findByPK(study.getParentStudyId());
allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(stParent, study, studySubjectBean.getId());
} else {
allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(currentStudy, study, studySubjectBean.getId());
}
}
if (!allNotesforSubjectAndEvent.isEmpty()) {
setRequestAttributesForNotes(allNotesforSubjectAndEvent);
}
// prepare to figure out what the display should look like
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList<EventCRFBean> eventCRFs = ecdao.findAllByStudyEvent(seb);
ArrayList<Boolean> doRuleSetsExist = new ArrayList<Boolean>();
RuleSetDAO ruleSetDao = new RuleSetDAO(sm.getDataSource());
for (EventCRFBean eventCrfBean : eventCRFs) {
// Boolean result = ruleSetDao.findByEventCrf(eventCrfBean) != null
// ? Boolean.TRUE : Boolean.FALSE;
// doRuleSetsExist.add(result);
}
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, seb.getStudyEventDefinitionId());
// get the event definition CRFs for which no event CRF exists
// the event definition CRFs must be populated with versions so we can
// let the user choose which version he will enter data for
// However, this method seems to be returning DisplayEventDefinitionCRFs
// that contain valid eventCRFs??
ArrayList uncompletedEventDefinitionCRFs = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs);
populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
// BWP 2816 << Attempt to provide the DisplayEventDefinitionCRF with a
// valid owner
// only if its container eventCRf has a valid id
populateUncompletedCRFsWithAnOwner(uncompletedEventDefinitionCRFs);
// >>BWP
// for the event definition CRFs for which event CRFs exist, get
// DisplayEventCRFBeans, which the JSP will use to determine what
// the user will see for each event CRF
// removing the below row in exchange for the ViewStudySubjectServlet
// version, for two
// reasons:
// 1. concentrate all business logic in one place
// 2. VSSS seems to handle the javascript creation correctly
// ArrayList displayEventCRFs = getDisplayEventCRFs(eventCRFs,
// eventDefinitionCRFs, seb.getSubjectEventStatus());
ArrayList displayEventCRFs = ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(), eventCRFs, eventDefinitionCRFs, ub, currentRole, seb.getSubjectEventStatus(), study);
// Issue 3212 BWP << hide certain CRFs at the site level
if (currentStudy.getParentStudyId() > 0) {
HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
uncompletedEventDefinitionCRFs = hideCRFManager.removeHiddenEventDefinitionCRFBeans(uncompletedEventDefinitionCRFs);
displayEventCRFs = hideCRFManager.removeHiddenEventCRFBeans(displayEventCRFs);
}
// >>
request.setAttribute(BEAN_STUDY_EVENT, seb);
request.setAttribute("doRuleSetsExist", doRuleSetsExist);
request.setAttribute(BEAN_STUDY_SUBJECT, studySubjectBean);
request.setAttribute(BEAN_UNCOMPLETED_EVENTDEFINITIONCRFS, uncompletedEventDefinitionCRFs);
request.setAttribute(BEAN_DISPLAY_EVENT_CRFS, displayEventCRFs);
// @pgawade 31-Aug-2012 fix for issue #15315: Reverting to set the request variable "beans" back
// this is for generating side info panel
ArrayList beans = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySubjectBean, sm.getDataSource(), ub, currentRole);
request.setAttribute("beans", beans);
EventCRFBean ecb = new EventCRFBean();
ecb.setStudyEventId(eventId);
request.setAttribute("eventCRF", ecb);
// Make available the study
request.setAttribute("study", currentStudy);
forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT);
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class CreateDiscrepancyNoteServlet method getStudyEvent.
private StudyEventBean getStudyEvent(int eventCRFId) {
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventBean event = (StudyEventBean) sedao.findByPK(getEventCrf(eventCRFId).getStudyEventId());
return event;
}
use of org.akaza.openclinica.bean.managestudy.StudyEventBean in project OpenClinica by OpenClinica.
the class CreateDiscrepancyNoteServlet method updateStudySubjectStatus.
/**
* Pulls the note related information from database according to note type
*
* @param note
*/
private void updateStudySubjectStatus(String entityType, int entityId) {
if ("itemData".equalsIgnoreCase(entityType)) {
int itemDataId = entityId;
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDataBean itemData = (ItemDataBean) iddao.findByPK(itemDataId);
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyEventDAO svdao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO studySubjectDAO = new StudySubjectDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
StudyEventBean event = (StudyEventBean) svdao.findByPK(ec.getStudyEventId());
StudySubjectBean studySubject = (StudySubjectBean) studySubjectDAO.findByPK(event.getStudySubjectId());
if (studySubject.getStatus() != null && studySubject.getStatus().equals(Status.SIGNED)) {
studySubject.setStatus(Status.AVAILABLE);
studySubject.setUpdater(ub);
studySubject.setUpdatedDate(new Date());
studySubjectDAO.update(studySubject);
}
if (ec.isSdvStatus()) {
studySubject.setStatus(Status.AVAILABLE);
studySubject.setUpdater(ub);
studySubject.setUpdatedDate(new Date());
studySubjectDAO.update(studySubject);
ec.setSdvStatus(false);
ec.setSdvUpdateId(ub.getId());
ecdao.update(ec);
}
}
}
Aggregations