use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class PrintAllEventCRFServlet method processRequest.
@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
FormProcessor fp = new FormProcessor(request);
SessionManager sm = (SessionManager) request.getSession().getAttribute("sm");
EventCRFBean ecb = (EventCRFBean) request.getAttribute(INPUT_EVENT_CRF);
SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
ArrayList<SectionBean> allSectionBeans;
// The PrintDataEntry servlet handles this parameter
boolean isSubmitted = false;
StudyEventDefinitionDAO sedao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyDAO studyDao = new StudyDAO(sm.getDataSource());
StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
seds = sedao.findAllByStudy(currentStudy);
// ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByStudy(site);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
ArrayList<EventDefinitionCRFBean> edcs = new ArrayList();
for (StudyEventDefinitionBean sed : seds) {
int defId = sed.getId();
edcs.addAll(edcdao.findAllByDefinition(currentStudy, defId));
}
Map eventDefinitionDefaultVersions = new LinkedHashMap();
for (int i = 0; i < edcs.size(); i++) {
EventDefinitionCRFBean edc = edcs.get(i);
ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
// edc.setCrfLabel(crf.getLabel());
edc.setCrfName(crf.getName());
// to show/hide edit action on jsp page
if (crf.getStatus().equals(Status.AVAILABLE)) {
edc.setOwner(crf.getOwner());
}
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) sedao.findByPK(edc.getStudyEventDefinitionId());
edc.setDefaultVersionName(defaultVersion.getName());
if (defaultVersion.getStatus().isAvailable()) {
List list = (ArrayList) eventDefinitionDefaultVersions.get(studyEventDefinitionBean);
if (list == null)
list = new ArrayList();
list.add(defaultVersion);
eventDefinitionDefaultVersions.put(studyEventDefinitionBean, list);
}
}
// Whether IE6 or IE7 is involved
String isIE = fp.getString("ie");
if ("y".equalsIgnoreCase(isIE)) {
request.setAttribute("isInternetExplorer", "true");
}
SectionDAO sdao = new SectionDAO(sm.getDataSource());
CRFVersionDAO crfVersionDAO = new CRFVersionDAO(sm.getDataSource());
CRFDAO crfDao = new CRFDAO(sm.getDataSource());
Map sedCrfBeans = null;
for (Iterator it = eventDefinitionDefaultVersions.keySet().iterator(); it.hasNext(); ) {
if (sedCrfBeans == null)
sedCrfBeans = new LinkedHashMap();
StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) it.next();
List crfVersions = (ArrayList) eventDefinitionDefaultVersions.get(sedBean);
for (Iterator crfIt = crfVersions.iterator(); crfIt.hasNext(); ) {
CRFVersionBean crfVersionBean = (CRFVersionBean) crfIt.next();
allSectionBeans = new ArrayList<SectionBean>();
ArrayList sectionBeans = new ArrayList();
ItemGroupDAO itemGroupDao = new ItemGroupDAO(sm.getDataSource());
// Find truely grouped tables, not groups with a name of 'Ungrouped'
List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionBean.getId());
CRFBean crfBean = crfDao.findByVersionId(crfVersionBean.getId());
if (itemGroupBeans.size() > 0) {
// get a DisplaySectionBean for each section of the CRF, sort
// them, then
// dispatch the request to a print JSP. The constructor for this
// handler takes
// a boolean value depending on whether data is involved or not
// ('false' in terms of this
// servlet; see PrintDataEntryServlet).
DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(false, getDataSource(), getServletContext());
handler.setCrfVersionId(crfVersionBean.getId());
//handler.setEventCRFId(eventCRFId);
List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
// Make available the CRF names and versions for
// the web page's header
CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
request.setAttribute("crfVersionBean", crfverBean);
request.setAttribute("crfBean", crfBean);
// Set an attribute signaling that data is not involved
request.setAttribute("dataInvolved", "false");
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setDisplaySectionBeans(displaySectionBeans);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setGrouped(true);
List list = (ArrayList) sedCrfBeans.get(sedBean);
if (list == null)
list = new ArrayList();
list.add(printCrfBean);
sedCrfBeans.put(sedBean, list);
continue;
}
ecb = new EventCRFBean();
ecb.setCRFVersionId(crfVersionBean.getId());
CRFVersionBean version = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionBean.getId());
ArrayList sects = (ArrayList) sdao.findByVersionId(version.getId());
for (int i = 0; i < sects.size(); i++) {
sb = (SectionBean) sects.get(i);
// super.sb = sb;
int sectId = sb.getId();
if (sectId > 0) {
allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
}
}
request.setAttribute(INPUT_EVENT_CRF, ecb);
request.setAttribute(SECTION_BEAN, sb);
request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
sectionBeans = super.getAllDisplayBeans(request);
DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
PrintCRFBean printCrfBean = new PrintCRFBean();
printCrfBean.setAllSections(sectionBeans);
printCrfBean.setDisplaySectionBean(dsb);
printCrfBean.setEventCrfBean(ecb);
printCrfBean.setCrfVersionBean(crfVersionBean);
printCrfBean.setCrfBean(crfBean);
printCrfBean.setGrouped(false);
List list = (ArrayList) sedCrfBeans.get(sedBean);
if (list == null)
list = new ArrayList();
list.add(printCrfBean);
sedCrfBeans.put(sedBean, list);
}
}
request.setAttribute("sedCrfBeans", sedCrfBeans);
request.setAttribute("studyName", currentStudy.getName());
forwardPage(Page.VIEW_ALL_DEFAULT_CRF_VERSIONS_PRINT, request, response);
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class RemoveEventCRFServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// eventCRFId
int eventCRFId = fp.getInt("id");
// studySubjectId
int studySubId = fp.getInt("studySubId");
checkStudyLocked("ViewStudySubject?id" + studySubId, respage.getString("current_study_locked"));
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
StudyDAO sdao = new StudyDAO(sm.getDataSource());
if (eventCRFId == 0) {
addPageMessage(respage.getString("please_choose_an_event_CRF_to_remove"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
EventCRFBean eventCRF = (EventCRFBean) ecdao.findByPK(eventCRFId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
// construct info needed on view event crf page
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
int crfVersionId = eventCRF.getCRFVersionId();
CRFBean cb = cdao.findByVersionId(crfVersionId);
eventCRF.setCrf(cb);
CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
eventCRF.setCrfVersion(cvb);
// then get the definition so we can call
// DisplayEventCRFBean.setFlags
int studyEventId = eventCRF.getStudyEventId();
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(studyEventDefinitionId);
event.setStudyEventDefinition(sed);
request.setAttribute("event", event);
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
DisplayEventCRFBean dec = new DisplayEventCRFBean();
dec.setEventCRF(eventCRF);
dec.setFlags(eventCRF, ub, currentRole, edc.isDoubleEntry());
// find all item data
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ArrayList itemData = iddao.findAllByEventCRFId(eventCRF.getId());
request.setAttribute("items", itemData);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (eventCRF.getStatus().equals(Status.DELETED) || eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
addPageMessage(respage.getString("this_event_CRF_is_removed_for_this_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
return;
}
request.setAttribute("displayEventCRF", dec);
forwardPage(Page.REMOVE_EVENT_CRF);
} else {
logger.info("submit to remove the event CRF from study");
eventCRF.setStatus(Status.DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
for (int a = 0; a < itemData.size(); a++) {
ItemDataBean item = (ItemDataBean) itemData.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
DiscrepancyNoteDAO dnDao = new DiscrepancyNoteDAO(sm.getDataSource());
List dnNotesOfRemovedItem = dnDao.findExistingNotesForItemData(item.getId());
if (!dnNotesOfRemovedItem.isEmpty()) {
DiscrepancyNoteBean itemParentNote = null;
for (Object obj : dnNotesOfRemovedItem) {
if (((DiscrepancyNoteBean) obj).getParentDnId() == 0) {
itemParentNote = (DiscrepancyNoteBean) obj;
}
}
DiscrepancyNoteBean dnb = new DiscrepancyNoteBean();
if (itemParentNote != null) {
dnb.setParentDnId(itemParentNote.getId());
dnb.setDiscrepancyNoteTypeId(itemParentNote.getDiscrepancyNoteTypeId());
}
dnb.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
dnb.setStudyId(currentStudy.getId());
dnb.setAssignedUserId(ub.getId());
dnb.setOwner(ub);
dnb.setEntityType(DiscrepancyNoteBean.ITEM_DATA);
dnb.setEntityId(item.getId());
dnb.setColumn("value");
dnb.setCreatedDate(new Date());
dnb.setDescription("The item has been removed, this Discrepancy Note has been Closed.");
dnDao.create(dnb);
dnDao.createMapping(dnb);
itemParentNote.setResolutionStatusId(ResolutionStatus.CLOSED.getId());
dnDao.update(itemParentNote);
}
}
}
String emailBody = respage.getString("the_event_CRF") + " " + cb.getName() + " " + respage.getString("has_been_removed_from_the_event") + event.getStudyEventDefinition().getName() + ". " + respage.getString("has_been_removed_from_the_event_cont");
addPageMessage(emailBody);
sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class ListSubjectGroupClassServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
// YW <<
StudyDAO stdao = new StudyDAO(sm.getDataSource());
int parentStudyId = currentStudy.getParentStudyId();
ArrayList groups = new ArrayList();
if (parentStudyId > 0) {
StudyBean parentStudy = (StudyBean) stdao.findByPK(parentStudyId);
groups = sgcdao.findAllByStudy(parentStudy);
} else {
groups = sgcdao.findAllByStudy(currentStudy);
}
// YW >>
String isReadOnly = request.getParameter("read");
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
for (int i = 0; i < groups.size(); i++) {
StudyGroupClassBean group = (StudyGroupClassBean) groups.get(i);
ArrayList studyGroups = sgdao.findAllByGroupClass(group);
group.setStudyGroups(studyGroups);
}
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allGroupRows = StudyGroupClassRow.generateRowsFromBeans(groups);
boolean isParentStudy = currentStudy.getParentStudyId() > 0 ? false : true;
request.setAttribute("isParentStudy", isParentStudy);
String[] columns = { resword.getString("subject_group_class"), resword.getString("type"), resword.getString("subject_assignment"), resword.getString("study_name"), resword.getString("subject_groups"), resword.getString("status"), resword.getString("actions") };
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.hideColumnLink(4);
table.hideColumnLink(6);
table.setQuery("ListSubjectGroupClass", new HashMap());
// if (isParentStudy && (!currentStudy.getStatus().isLocked())) {
// table.addLink(resword.getString("create_a_subject_group_class"),
// "CreateSubjectGroupClass");
// }
table.setRows(allGroupRows);
table.computeDisplay();
request.setAttribute("table", table);
if (request.getParameter("read") != null && request.getParameter("read").equals("true")) {
request.setAttribute("readOnly", true);
}
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST);
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class LockCRFVersionServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
int crfVersionId = fp.getInt("id", true);
String action = fp.getString("action");
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
if (crfVersionId == 0) {
addPageMessage(respage.getString("choose_valid_crf_version"));
forwardPage(Page.CRF_LIST_SERVLET);
return;
}
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(crfVersionId);
//System.out.println("crf version found:" + version.getName());
CRFBean crf = (CRFBean) cdao.findByPK(version.getCrfId());
if (!ub.isSysAdmin() && (version.getOwnerId() != ub.getId())) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = ecdao.findAllStudySubjectByCRFVersion(crfVersionId);
if (StringUtil.isBlank(action)) {
request.setAttribute("crfVersionToLock", version);
request.setAttribute("crf", crf);
request.setAttribute("eventSubjectsUsingVersion", eventCRFs);
forwardPage(Page.CONFIRM_LOCKING_CRF_VERSION);
} else if ("confirm".equalsIgnoreCase(action)) {
version.setStatus(Status.LOCKED);
version.setUpdater(ub);
cvdao.update(version);
ArrayList versionList = (ArrayList) cvdao.findAllByCRF(version.getCrfId());
if (versionList.size() > 0) {
EventDefinitionCRFDAO edCRFDao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList edcList = (ArrayList) edCRFDao.findAllByCRF(version.getCrfId());
for (int i = 0; i < edcList.size(); i++) {
EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) edcList.get(i);
// @pgawade 18-May-2011 #5414 - Changes for setting the correct
// default crf version Id to event
// when existing default version is locked
// RemoveCRFVersionServlet.updateEventDef(edcBean, edCRFDao,
// versionList);
RemoveCRFVersionServlet.updateEventDef(edcBean, edCRFDao, versionList, crfVersionId);
}
}
addPageMessage(respage.getString("crf_version_archived_successfully"));
forwardPage(Page.CRF_LIST_SERVLET);
}
}
use of org.akaza.openclinica.control.form.FormProcessor in project OpenClinica by OpenClinica.
the class RestoreStudyUserRoleServlet method processRequest.
@Override
public void processRequest() throws Exception {
UserAccountDAO udao = new UserAccountDAO(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_restore_his_role"));
forwardPage(Page.LIST_USER_IN_STUDY_SERVLET);
} else {
String action = request.getParameter("action");
UserAccountBean user = (UserAccountBean) udao.findByUserName(name);
if ("confirm".equalsIgnoreCase(action)) {
int studyId = Integer.valueOf(studyIdString.trim()).intValue();
request.setAttribute("user", user);
StudyUserRoleBean uRole = udao.findRoleByUserNameAndStudyId(name, studyId);
request.setAttribute("uRole", uRole);
StudyDAO sdao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) sdao.findByPK(studyId);
request.setAttribute("uStudy", study);
forwardPage(Page.RESTORE_USER_ROLE_IN_STUDY);
} else {
// restore role
FormProcessor fp = new FormProcessor(request);
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.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);
}
}
}
Aggregations