use of org.akaza.openclinica.control.form.FormProcessor 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.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class StudyAuditLogServlet method processRequest.
/*
* (non-Javadoc) Assume that we get the user id automatically. We will jump
* from the edit user page if the user is an admin, they can get to see the
* users' log
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
/*
* (non-Javadoc) redo this servlet to run the audits per study subject for
* the study; need to add a studyId param and then use the
* StudySubjectDAO.findAllByStudyOrderByLabel() method to grab a lot of
* study subject beans and then return them much like in
* ViewStudySubjectAuditLogServet.process() currentStudy instead of studyId?
*/
@Override
protected void processRequest() throws Exception {
int studyId = currentStudy.getId();
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
AuditDAO adao = new AuditDAO(sm.getDataSource());
UserAccountDAO uadao = new UserAccountDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyDAO studydao = new StudyDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
StudyAuditLogTableFactory factory = new StudyAuditLogTableFactory();
factory.setSubjectDao(sdao);
factory.setStudySubjectDao(subdao);
factory.setUserAccountDao(uadao);
factory.setCurrentStudy(currentStudy);
String auditLogsHtml = factory.createTable(request, response).render();
request.setAttribute("auditLogsHtml", auditLogsHtml);
forwardPage(Page.AUDIT_LOGS_STUDY);
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class RestoreSubjectGroupClassServlet method processRequest.
@Override
public void processRequest() throws Exception {
String action = request.getParameter("action");
FormProcessor fp = new FormProcessor(request);
int classId = fp.getInt("id");
if (classId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_group_class_to_restore"));
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
} else {
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
if (action.equalsIgnoreCase("confirm")) {
StudyGroupClassBean sgcb = (StudyGroupClassBean) sgcdao.findByPK(classId);
if (sgcb.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_subject_group_class_is_available_cannot_restore"));
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
return;
}
ArrayList groups = sgdao.findAllByGroupClass(sgcb);
for (int i = 0; i < groups.size(); i++) {
StudyGroupBean sg = (StudyGroupBean) groups.get(i);
ArrayList subjectMaps = sgmdao.findAllByStudyGroupClassAndGroup(sgcb.getId(), sg.getId());
sg.setSubjectMaps(subjectMaps);
}
session.setAttribute("group", sgcb);
session.setAttribute("studyGroups", groups);
forwardPage(Page.RESTORE_SUBJECT_GROUP_CLASS);
} else if (action.equalsIgnoreCase("submit")) {
StudyGroupClassBean group = (StudyGroupClassBean) session.getAttribute("group");
group.setStatus(Status.AVAILABLE);
group.setUpdater(ub);
sgcdao.update(group);
ArrayList subjectMaps = sgmdao.findAllByStudyGroupClassId(group.getId());
for (int i = 0; i < subjectMaps.size(); i++) {
SubjectGroupMapBean sgmb = (SubjectGroupMapBean) subjectMaps.get(i);
if (sgmb.getStatus().equals(Status.AUTO_DELETED)) {
sgmb.setStatus(Status.AVAILABLE);
sgmb.setUpdater(ub);
sgmdao.update(sgmb);
}
}
addPageMessage(respage.getString("this_subject_group_class_was_restored_succesfully"));
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
} else {
addPageMessage(respage.getString("no_action_specified"));
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class SetStudyUserRoleServlet method processRequest.
@Override
public void processRequest() throws Exception {
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
String name = request.getParameter("name");
String studyIdString = request.getParameter("studyId");
if (StringUtil.isBlank(name) || StringUtil.isBlank(studyIdString)) {
addPageMessage(respage.getString("please_choose_a_user_to_set_role_for"));
forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
} else {
String action = request.getParameter("action");
FormProcessor fp = new FormProcessor(request);
UserAccountBean user = (UserAccountBean) udao.findByUserName(name);
StudyBean userStudy = (StudyBean) sdao.findByPK(fp.getInt("studyId"));
if ("confirm".equalsIgnoreCase(action)) {
int studyId = Integer.valueOf(studyIdString.trim()).intValue();
request.setAttribute("user", user);
StudyUserRoleBean uRole = udao.findRoleByUserNameAndStudyId(name, studyId);
uRole.setStudyName(userStudy.getName());
request.setAttribute("uRole", uRole);
ArrayList roles = Role.toArrayList();
// admin is not a user role, only used for tomcat
roles.remove(Role.ADMIN);
roles.remove(Role.RESEARCHASSISTANT2);
StudyBean studyBean = (StudyBean) sdao.findByPK(uRole.getStudyId());
if (currentStudy.getParentStudyId() > 0) {
roles.remove(Role.COORDINATOR);
roles.remove(Role.STUDYDIRECTOR);
} else if (studyBean.getParentStudyId() > 0) {
roles.remove(Role.COORDINATOR);
roles.remove(Role.STUDYDIRECTOR);
// TODO: redo this fix
Role r = Role.RESEARCHASSISTANT;
r.setDescription("site_Data_Entry_Person");
roles.remove(Role.RESEARCHASSISTANT);
roles.add(r);
Role ri = Role.INVESTIGATOR;
ri.setDescription("site_investigator");
roles.remove(Role.INVESTIGATOR);
roles.add(ri);
Role r2 = Role.RESEARCHASSISTANT2;
r2.setDescription("site_Data_Entry_Person2");
roles.remove(Role.RESEARCHASSISTANT2);
roles.add(r2);
}
request.setAttribute("roles", roles);
forwardPage(Page.SET_USER_ROLE_IN_STUDY);
} else {
// set role
String userName = fp.getString("name");
int studyId = fp.getInt("studyId");
int roleId = fp.getInt("roleId");
StudyUserRoleBean sur = new StudyUserRoleBean();
sur.setName(userName);
sur.setRole(Role.get(roleId));
sur.setStudyId(studyId);
sur.setStudyName(userStudy.getName());
sur.setStatus(Status.AVAILABLE);
sur.setUpdater(ub);
sur.setUpdatedDate(new Date());
udao.updateStudyUserRole(sur, userName);
addPageMessage(sendEmail(user, sur));
forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class UpdateSubjectGroupClassServlet method confirmGroup.
/**
* Validates the first section of study and save it into study bean
*
* @param request
* @param response
* @throws Exception
*/
private void confirmGroup() throws Exception {
Validator v = new Validator(request);
FormProcessor fp = new FormProcessor(request);
v.addValidation("name", Validator.NO_BLANKS);
// v.addValidation("groupClassTypeId", Validator.IS_AN_INTEGER);
v.addValidation("subjectAssignment", Validator.NO_BLANKS);
v.addValidation("name", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 30);
v.addValidation("subjectAssignment", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 30);
ArrayList studyGroups = new ArrayList();
for (int i = 0; i < 10; i++) {
String name = fp.getString("studyGroup" + i);
int studyGroupId = fp.getInt("studyGroupId" + i);
String description = fp.getString("studyGroupDescription" + i);
if (!StringUtil.isBlank(name)) {
StudyGroupBean g = new StudyGroupBean();
g.setName(name);
g.setDescription(description);
g.setId(studyGroupId);
studyGroups.add(g);
if (name.length() > 255) {
request.setAttribute("studyGroupError", resexception.getString("group_name_cannot_be_more_255"));
break;
}
if (description.length() > 1000) {
request.setAttribute("studyGroupError", resexception.getString("group_description_cannot_be_more_100"));
break;
}
}
}
errors = v.validate();
if (fp.getInt("groupClassTypeId") == 0) {
Validator.addError(errors, "groupClassTypeId", "Group Class Type is required.");
}
StudyGroupClassBean group = (StudyGroupClassBean) session.getAttribute("group");
group.setName(fp.getString("name"));
group.setGroupClassTypeId(fp.getInt("groupClassTypeId"));
group.setSubjectAssignment(fp.getString("subjectAssignment"));
session.setAttribute("group", group);
session.setAttribute("studyGroups", studyGroups);
if (errors.isEmpty()) {
logger.info("no errors in the first section");
group.setGroupClassTypeName(GroupClassType.get(group.getGroupClassTypeId()).getName());
forwardPage(Page.UPDATE_SUBJECT_GROUP_CLASS_CONFIRM);
} else {
logger.info("has validation errors in the first section");
request.setAttribute("formMessages", errors);
request.setAttribute("groupTypes", GroupClassType.toArrayList());
forwardPage(Page.UPDATE_SUBJECT_GROUP_CLASS);
}
}
Aggregations