use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class SignStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
String action = fp.getString("action");
// studySubjectId
int studySubId = fp.getInt("id", true);
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
if (studySubId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_to_view"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
if (!permitSign(studySub, sm.getDataSource())) {
addPageMessage(respage.getString("subject_event_cannot_signed"));
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
// >> changed tbh, 06/2009
return;
}
if (action.equalsIgnoreCase("confirm")) {
String username = request.getParameter("j_user");
String password = request.getParameter("j_pass");
SecurityManager securityManager = ((SecurityManager) SpringServletAccess.getApplicationContext(context).getBean("securityManager"));
// String encodedUserPass =
// org.akaza.openclinica.core.SecurityManager
// .getInstance().encrytPassword(password);
UserAccountBean ub = (UserAccountBean) session.getAttribute("userBean");
if (securityManager.verifyPassword(password, getUserDetails()) && ub.getName().equals(username)) {
if (signSubjectEvents(studySub, sm.getDataSource(), ub)) {
// Making the StudySubject signed as all the events have
// become signed.
studySub.setStatus(Status.SIGNED);
studySub.setUpdater(ub);
subdao.update(studySub);
addPageMessage(respage.getString("subject_event_signed"));
// forwardPage(Page.SUBMIT_DATA_SERVLET);
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
// >> changed tbh, 06/2009
return;
} else {
addPageMessage(respage.getString("errors_in_submission_see_below"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
} else {
request.setAttribute("id", new Integer(studySubId).toString());
addPageMessage(restext.getString("password_match"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
}
request.setAttribute("studySub", studySub);
int studyId = studySub.getStudyId();
int subjectId = studySub.getSubjectId();
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
Date dob = subject.getDateOfBirth();
if (dob != null) {
Calendar cal = Calendar.getInstance();
cal.setTime(dob);
int year = cal.get(Calendar.YEAR);
request.setAttribute("yearOfBirth", new Integer(year));
} else {
request.setAttribute("yearOfBirth", "");
}
}
request.setAttribute("subject", subject);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
study.getStudyParameterConfig().setCollectDob(spvdao.findByHandleAndStudy(studyId, "collectDob").getValue());
if (study.getParentStudyId() > 0) {
// this is a site,find parent
StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
request.setAttribute("parentStudy", parentStudy);
} else {
request.setAttribute("parentStudy", new StudyBean());
}
ArrayList children = (ArrayList) sdao.findAllChildrenByPK(subjectId);
request.setAttribute("children", children);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
// find all eventcrfs for each event
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList<DisplayStudyEventBean> displayEvents = getDisplayStudyEventsForStudySubject(study, studySub, sm.getDataSource(), ub, currentRole);
DiscrepancyNoteUtil discNoteUtil = new DiscrepancyNoteUtil();
// Don't filter for now; disc note beans are returned with eventCRFId
// set
discNoteUtil.injectParentDiscNotesIntoDisplayStudyEvents(displayEvents, new HashSet(), sm.getDataSource(), 0);
// All the displaystudyevents for one subject
request.setAttribute("displayStudyEvents", displayEvents);
// Set up a Map for the JSP view, mapping the eventCRFId to another Map:
// the
// inner Map maps the resolution status name to the number of notes for
// that
// eventCRF id, as in New --> 2
Map discNoteByEventCRFid = discNoteUtil.createDiscNoteMapByEventCRF(displayEvents);
request.setAttribute("discNoteByEventCRFid", discNoteByEventCRFid);
EntityBeanTable table = fp.getEntityBeanTable();
// sort by start date,
table.setSortingIfNotExplicitlySet(1, false);
// desc
ArrayList allEventRows = DisplayStudyEventRow.generateRowsFromBeans(displayEvents);
String[] columns = { resword.getString("event") + " (" + resword.getString("occurrence_number") + ")", resword.getString("start_date1"), resword.getString("location"), resword.getString("status"), resword.getString("actions"), resword.getString("CRFs_atrib") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(4);
table.hideColumnLink(5);
if (!"removed".equalsIgnoreCase(studySub.getStatus().getName()) && !"auto-removed".equalsIgnoreCase(studySub.getStatus().getName())) {
table.addLink(resword.getString("add_new_event"), "CreateNewStudyEvent?" + CreateNewStudyEventServlet.INPUT_STUDY_SUBJECT_ID_FROM_VIEWSUBJECT + "=" + studySub.getId());
}
HashMap args = new HashMap();
args.put("id", new Integer(studySubId).toString());
table.setQuery("ViewStudySubject", args);
table.setRows(allEventRows);
table.computeDisplay();
request.setAttribute("table", table);
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groupMaps = (ArrayList) sgmdao.findAllByStudySubject(studySubId);
request.setAttribute("groups", groupMaps);
AuditEventDAO aedao = new AuditEventDAO(sm.getDataSource());
ArrayList logs = aedao.findEventStatusLogByStudySubject(studySubId);
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList eventLogs = new ArrayList();
for (int i = 0; i < logs.size(); i++) {
AuditEventBean avb = (AuditEventBean) logs.get(i);
StudyEventAuditBean sea = new StudyEventAuditBean();
sea.setAuditEvent(avb);
StudyEventBean se = (StudyEventBean) sedao.findByPK(avb.getEntityId());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
sea.setDefinition(sed);
String old = avb.getOldValue().trim();
try {
if (!StringUtil.isBlank(old)) {
SubjectEventStatus oldStatus = SubjectEventStatus.get(new Integer(old).intValue());
sea.setOldSubjectEventStatus(oldStatus);
}
String newValue = avb.getNewValue().trim();
if (!StringUtil.isBlank(newValue)) {
SubjectEventStatus newStatus = SubjectEventStatus.get(new Integer(newValue).intValue());
sea.setNewSubjectEventStatus(newStatus);
}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
// logger.warning("^^^ caught NFE");
}
UserAccountBean updater = (UserAccountBean) udao.findByPK(avb.getUserId());
sea.setUpdater(updater);
eventLogs.add(sea);
}
// logger.warning("^^^ finished iteration");
request.setAttribute("eventLogs", eventLogs);
forwardPage(Page.SIGN_STUDY_SUBJECT);
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class DisplayStudySubjectEventsRow method compareColumn.
@Override
protected int compareColumn(Object row, int sortingColumn) {
if (!row.getClass().equals(DisplayStudySubjectEventsRow.class)) {
return 0;
}
DisplayStudySubjectBean thisStudy = (DisplayStudySubjectBean) bean;
DisplayStudySubjectBean argStudy = (DisplayStudySubjectBean) ((DisplayStudySubjectEventsRow) row).bean;
int answer = 0;
// YW <<
int groupSize = thisStudy.getStudyGroups().size();
int code;
if (sortingColumn > 4 + groupSize) {
code = COL_STUDYCRF;
} else if (sortingColumn > 4 && sortingColumn <= 4 + groupSize) {
code = COL_STUDYGROUP;
} else {
code = sortingColumn;
}
switch(code) {
case COL_SUBJECT_LABEL:
answer = thisStudy.getStudySubject().getLabel().toLowerCase().compareTo(argStudy.getStudySubject().getLabel().toLowerCase());
break;
case COL_GENDER:
answer = (thisStudy.getStudySubject().getGender() + "").compareTo(argStudy.getStudySubject().getGender() + "");
break;
case COL_STATUS:
answer = thisStudy.getStudySubject().getStatus().compareTo(argStudy.getStudySubject().getStatus());
break;
case COL_EVENT_STATUS:
if (thisStudy.getStudyEvents() == null || thisStudy.getStudyEvents().isEmpty()) {
answer = -1;
break;
}
if (argStudy.getStudyEvents() == null || argStudy.getStudyEvents().isEmpty()) {
answer = 1;
break;
}
answer = ((DisplayStudyEventBean) thisStudy.getStudyEvents().get(0)).getStudyEvent().getSubjectEventStatus().compareTo(((DisplayStudyEventBean) argStudy.getStudyEvents().get(0)).getStudyEvent().getSubjectEventStatus());
break;
case COL_EVENT_DATE:
if (thisStudy.getStudyEvents() == null || thisStudy.getStudyEvents().isEmpty()) {
answer = -1;
break;
}
if (argStudy.getStudyEvents() == null || argStudy.getStudyEvents().isEmpty()) {
answer = 1;
break;
}
answer = ((DisplayStudyEventBean) thisStudy.getStudyEvents().get(0)).getStudyEvent().getDateStarted().compareTo(((DisplayStudyEventBean) argStudy.getStudyEvents().get(0)).getStudyEvent().getDateStarted());
break;
case COL_STUDYGROUP:
answer = ((SubjectGroupMapBean) thisStudy.getStudyGroups().get(sortingColumn - 5)).getStudyGroupName().toLowerCase().compareTo(((SubjectGroupMapBean) argStudy.getStudyGroups().get(sortingColumn - 5)).getStudyGroupName().toLowerCase());
break;
case COL_STUDYCRF:
if (thisStudy.getStudyEvents() == null || thisStudy.getStudyEvents().isEmpty()) {
answer = -1;
break;
}
if (argStudy.getStudyEvents() == null || argStudy.getStudyEvents().isEmpty()) {
answer = 1;
break;
}
ArrayList thisAllEventCRFs = ((DisplayStudyEventBean) thisStudy.getStudyEvents().get(0)).getAllEventCRFs();
ArrayList argAllEventCRFs = ((DisplayStudyEventBean) argStudy.getStudyEvents().get(0)).getAllEventCRFs();
if (thisAllEventCRFs == null || thisAllEventCRFs.isEmpty()) {
answer = -1;
break;
}
if (argAllEventCRFs == null || argAllEventCRFs.isEmpty()) {
answer = 1;
break;
}
// Event crf status comparision
DataEntryStage thisDes = ((DisplayEventCRFBean) thisAllEventCRFs.get(sortingColumn - 5)).getEventCRF().getStage();
DataEntryStage argDes = ((DisplayEventCRFBean) argAllEventCRFs.get(sortingColumn - 5)).getEventCRF().getStage();
/*Event crf status is ordered in this sequence, Not Started=1,Data Entry Started=2,Initial Data Entry Completed=3,
Double Data Entry Started=4,Double Data Entry Complete=5,Complete=6,Locked=7,Invalid/Removed=0*/
switch(thisDes.getId()) {
//DataEntryStage.INVALID
case 0:
if (thisDes.getId() == argDes.getId()) {
answer = 0;
} else {
answer = 1;
}
break;
//DataEntryStage.UNCOMPLETED
case 1:
if (thisDes.getId() == argDes.getId()) {
answer = 0;
} else {
answer = -1;
}
break;
//DataEntryStage.INITIAL_DATA_ENTRY
case 2:
if (thisDes.getId() == argDes.getId()) {
answer = 0;
} else if (argDes.getId() == 1) {
answer = 1;
} else {
answer = -1;
}
break;
//DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE
case 3:
if (thisDes.getId() == argDes.getId()) {
answer = 0;
} else if (argDes.getId() == 1 || argDes.getId() == 2) {
answer = 1;
} else {
answer = -1;
}
break;
//DataEntryStage.DOUBLE_DATA_ENTRY
case 4:
if (thisDes.getId() == argDes.getId()) {
answer = 0;
} else if (argDes.getId() == 1 || argDes.getId() == 2 || argDes.getId() == 3) {
answer = 1;
} else {
answer = -1;
}
break;
//DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE
case 5:
if (thisDes.getId() == argDes.getId()) {
answer = 0;
} else if (argDes.getId() == 0 || argDes.getId() == 7) {
answer = -1;
} else {
answer = 1;
}
break;
//DataEntryStage.ADMINISTRATIVE_EDITING
case 6:
if (thisDes.getId() == argDes.getId()) {
answer = 0;
} else if (argDes.getId() == 7 || argDes.getId() == 0) {
answer = -1;
} else {
answer = 1;
}
break;
//DataEntryStage.LOCKED
case 7:
if (thisDes.getId() == argDes.getId()) {
answer = 0;
} else if (argDes.getId() == 0) {
answer = -1;
} else {
answer = 1;
}
break;
default:
answer = 1;
}
}
return answer;
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class StudyInfoPanel method generateTreeFromBeansWithoutLink.
/**
* Generates a tree view in sdie info panel for submitting data page
*
* @param rows
* @param displayData
* @param studySubject
* @param ecb
* @return
*/
public ArrayList generateTreeFromBeansWithoutLink(ArrayList rows, ArrayList displayData, StudySubjectBean studySubject, EventCRFBean ecb) {
Iterator itRows = rows.iterator();
displayData.add(new StudyInfoPanelLine("Study Events", "(" + rows.size() + ")", true, false, false));
while (itRows.hasNext()) {
DisplayStudyEventBean dseBean = (DisplayStudyEventBean) itRows.next();
StudyEventBean seBean = dseBean.getStudyEvent();
// checks whether the event is the current one
if (ecb != null && ecb.getStudyEventId() == seBean.getId()) {
displayData.add(new StudyInfoPanelLine("Study Event", seBean.getStudyEventDefinition().getName(), true, false, true));
} else {
displayData.add(new StudyInfoPanelLine("Study Event", seBean.getStudyEventDefinition().getName(), true, false, false));
}
displayData.add(new StudyInfoPanelLine("<b>Status: </b>", seBean.getSubjectEventStatus().getName(), false, false, false));
ArrayList displayCRFs = dseBean.getDisplayEventCRFs();
int count = 0;
Iterator displayIt = displayCRFs.iterator();
while (displayIt.hasNext()) {
DisplayEventCRFBean dec = (DisplayEventCRFBean) displayIt.next();
if (count == displayCRFs.size() - 1 && dseBean.getUncompletedCRFs().size() == 0) {
// it's the current crf
if (ecb != null && ecb.getId() == dec.getEventCRF().getId()) {
displayData.add(new StudyInfoPanelLine("" + getStageImageText(dec.getStage()), "<span class='alert'>" + dec.getEventCRF().getCrf().getName() + " " + dec.getEventCRF().getCrfVersion().getName() + "</span>", false, true, true));
} else {
displayData.add(new StudyInfoPanelLine("" + getStageImageText(dec.getStage()), dec.getEventCRF().getCrf().getName() + " " + dec.getEventCRF().getCrfVersion().getName(), false, true, false));
}
} else {
if (ecb != null && ecb.getId() == dec.getEventCRF().getId()) {
displayData.add(new StudyInfoPanelLine("" + getStageImageText(dec.getStage()), "<span class='alert'>" + dec.getEventCRF().getCrf().getName() + " " + dec.getEventCRF().getCrfVersion().getName() + "</span>", false, false, true));
} else {
displayData.add(new StudyInfoPanelLine("" + getStageImageText(dec.getStage()), dec.getEventCRF().getCrf().getName() + " " + dec.getEventCRF().getCrfVersion().getName(), false, false, false));
}
}
count++;
}
count = 0;
ArrayList uncompleted = dseBean.getUncompletedCRFs();
Iterator uncompIt = uncompleted.iterator();
while (uncompIt.hasNext()) {
DisplayEventDefinitionCRFBean dedc = (DisplayEventDefinitionCRFBean) uncompIt.next();
if (count == uncompleted.size() - 1) {
if (ecb != null && ecb.getId() == dedc.getEventCRF().getId() && ecb.getCrf().getId() == dedc.getEventCRF().getCrf().getId()) {
// logger.info("ecb id*******" + ecb.getId() +
// dedc.getEventCRF().getId());
displayData.add(new StudyInfoPanelLine("<img src='images/icon_NotStarted.gif' alt='Not Started'/>", "<span class='alert'>" + dedc.getEdc().getCrf().getName() + "</span>", false, true, true));
} else {
displayData.add(new StudyInfoPanelLine("<img src='images/icon_NotStarted.gif' alt='Not Started'/>", dedc.getEdc().getCrf().getName(), false, true, false));
}
} else {
if (ecb != null && ecb.getId() == dedc.getEventCRF().getId()) {
// logger.info("ecb id*******" + ecb.getId() +
// dedc.getEventCRF().getId());
displayData.add(new StudyInfoPanelLine("<img src='images/icon_NotStarted.gif' alt='Not Started'/>", "<span class='alert'>" + dedc.getEdc().getCrf().getName() + "</span>", false, false, true));
} else {
displayData.add(new StudyInfoPanelLine("<img src='images/icon_NotStarted.gif' alt='Not Started'/>", dedc.getEdc().getCrf().getName(), false, false, false));
}
}
count++;
}
}
return displayData;
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class ListStudySubjectServlet method getDisplayStudyEventsForStudySubject.
public static DisplayStudyEventBean getDisplayStudyEventsForStudySubject(StudySubjectBean studySub, StudyEventBean event, DataSource ds, UserAccountBean ub, StudyUserRoleBean currentRole, StudyBean study) {
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
StudyEventDAO sedao = new StudyEventDAO(ds);
EventCRFDAO ecdao = new EventCRFDAO(ds);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
// find all active crfs in the definition
ArrayList eventDefinitionCRFs = edcdao.findAllActiveByEventDefinitionId(sed.getId());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs(ViewStudySubjectServlet.getDisplayEventCRFs(ds, eventCRFs, eventDefinitionCRFs, ub, currentRole, event.getSubjectEventStatus(), study));
ArrayList al = ViewStudySubjectServlet.getUncompletedCRFs(ds, eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus());
// ViewStudySubjectServlet.populateUncompletedCRFsWithCRFAndVersions(ds,
// al);
de.setUncompletedCRFs(al);
return de;
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean 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;
}
Aggregations