use of org.akaza.openclinica.control.submit.ListNotesTableFactory in project OpenClinica by OpenClinica.
the class ViewNotesServlet method processRequest.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
@Override
protected void processRequest() throws Exception {
String module = request.getParameter("module");
String moduleStr = "manage";
if (module != null && module.trim().length() > 0) {
if ("submit".equals(module)) {
request.setAttribute("module", "submit");
moduleStr = "submit";
} else if ("admin".equals(module)) {
request.setAttribute("module", "admin");
moduleStr = "admin";
} else {
request.setAttribute("module", "manage");
}
}
FormProcessor fp = new FormProcessor(request);
if (fp.getString("showMoreLink").equals("")) {
showMoreLink = true;
} else {
showMoreLink = Boolean.parseBoolean(fp.getString("showMoreLink"));
}
int oneSubjectId = fp.getInt("id");
// BWP 11/03/2008 3029: This session attribute in removed in
// ResolveDiscrepancyServlet.mayProceed() >>
session.setAttribute("subjectId", oneSubjectId);
// >>
int resolutionStatusSubj = fp.getInt(RESOLUTION_STATUS);
int discNoteType = 0;
try {
discNoteType = Integer.parseInt(request.getParameter("type"));
} catch (NumberFormatException nfe) {
// Show all DN's
discNoteType = -1;
}
request.setAttribute(DISCREPANCY_NOTE_TYPE, discNoteType);
boolean removeSession = fp.getBoolean("removeSession");
// BWP 11/03/2008 3029: This session attribute in removed in
// ResolveDiscrepancyServlet.mayProceed() >>
session.setAttribute("module", module);
// >>
// Do we only want to view the notes for 1 subject?
String viewForOne = fp.getString("viewForOne");
boolean isForOneSubjectsNotes = "y".equalsIgnoreCase(viewForOne);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
dndao.setFetchMapping(true);
int resolutionStatus = 0;
try {
resolutionStatus = Integer.parseInt(request.getParameter("resolutionStatus"));
} catch (NumberFormatException nfe) {
// Show all DN's
resolutionStatus = -1;
}
if (removeSession) {
session.removeAttribute(WIN_LOCATION);
session.removeAttribute(NOTES_TABLE);
}
// after resolving a note, user wants to go back to view notes page, we
// save the current URL
// so we can go back later
session.setAttribute(WIN_LOCATION, "ViewNotes?viewForOne=" + viewForOne + "&id=" + oneSubjectId + "&module=" + module + " &removeSession=1");
boolean hasAResolutionStatus = resolutionStatus >= 1 && resolutionStatus <= 5;
Set<Integer> resolutionStatusIds = (HashSet) session.getAttribute(RESOLUTION_STATUS);
// remove the session if there is no resolution status
if (!hasAResolutionStatus && resolutionStatusIds != null) {
session.removeAttribute(RESOLUTION_STATUS);
resolutionStatusIds = null;
}
if (hasAResolutionStatus) {
if (resolutionStatusIds == null) {
resolutionStatusIds = new HashSet<Integer>();
}
resolutionStatusIds.add(resolutionStatus);
session.setAttribute(RESOLUTION_STATUS, resolutionStatusIds);
}
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
UserAccountDAO uadao = new UserAccountDAO(sm.getDataSource());
CRFVersionDAO crfVersionDao = new CRFVersionDAO(sm.getDataSource());
CRFDAO crfDao = new CRFDAO(sm.getDataSource());
StudyEventDAO studyEventDao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO eventDefinitionCRFDao = new EventDefinitionCRFDAO(sm.getDataSource());
ItemDataDAO itemDataDao = new ItemDataDAO(sm.getDataSource());
ItemDAO itemDao = new ItemDAO(sm.getDataSource());
EventCRFDAO eventCRFDao = new EventCRFDAO(sm.getDataSource());
ListNotesTableFactory factory = new ListNotesTableFactory(showMoreLink);
factory.setSubjectDao(sdao);
factory.setStudySubjectDao(subdao);
factory.setUserAccountDao(uadao);
factory.setStudyDao(studyDao);
factory.setCurrentStudy(currentStudy);
factory.setDiscrepancyNoteDao(dndao);
factory.setCrfDao(crfDao);
factory.setCrfVersionDao(crfVersionDao);
factory.setStudyEventDao(studyEventDao);
factory.setStudyEventDefinitionDao(studyEventDefinitionDao);
factory.setEventDefinitionCRFDao(eventDefinitionCRFDao);
factory.setItemDao(itemDao);
factory.setItemDataDao(itemDataDao);
factory.setEventCRFDao(eventCRFDao);
factory.setModule(moduleStr);
factory.setDiscNoteType(discNoteType);
factory.setResolutionStatus(resolutionStatus);
factory.setViewNotesService(resolveViewNotesService());
// factory.setResolutionStatusIds(resolutionStatusIds);
TableFacade tf = factory.createTable(request, response);
Map<String, Map<String, String>> stats = generateDiscrepancyNotesSummary(factory.getNotesSummary());
Map<String, String> totalMap = generateDiscrepancyNotesTotal(stats);
int grandTotal = 0;
for (String typeName : totalMap.keySet()) {
String total = totalMap.get(typeName);
grandTotal = total.equals("--") ? grandTotal + 0 : grandTotal + Integer.parseInt(total);
}
request.setAttribute("summaryMap", stats);
tf.setTotalRows(grandTotal);
String viewNotesHtml = tf.render();
request.setAttribute("viewNotesHtml", viewNotesHtml);
String viewNotesURL = this.getPageURL();
session.setAttribute("viewNotesURL", viewNotesURL);
String viewNotesPageFileName = this.getPageServletFileName();
session.setAttribute("viewNotesPageFileName", viewNotesPageFileName);
request.setAttribute("mapKeys", ResolutionStatus.getMembers());
request.setAttribute("typeNames", DiscrepancyNoteUtil.getTypeNames());
request.setAttribute("typeKeys", totalMap);
request.setAttribute("grandTotal", grandTotal);
if ("yes".equalsIgnoreCase(fp.getString(PRINT))) {
List<DiscrepancyNoteBean> allNotes = factory.findAllNotes(tf);
request.setAttribute("allNotes", allNotes);
forwardPage(Page.VIEW_DISCREPANCY_NOTES_IN_STUDY_PRINT);
} else {
forwardPage(Page.VIEW_DISCREPANCY_NOTES_IN_STUDY);
}
}
Aggregations