use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class RemoveStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
// studySubjectId
String studySubIdString = request.getParameter("id");
String subIdString = request.getParameter("subjectId");
String studyIdString = request.getParameter("studyId");
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (StringUtil.isBlank(studySubIdString) || StringUtil.isBlank(subIdString) || StringUtil.isBlank(studyIdString)) {
addPageMessage(respage.getString("please_choose_a_study_subject_to_remove"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
} else {
int studyId = Integer.valueOf(studyIdString.trim()).intValue();
int studySubId = Integer.valueOf(studySubIdString.trim()).intValue();
int subjectId = Integer.valueOf(subIdString.trim()).intValue();
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
checkRoleByUserAndStudy(ub, study.getParentStudyId(), study.getId());
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
// ArrayList events = sedao.findAllByStudyAndStudySubjectId(study, studySubId);
ArrayList<DisplayStudyEventBean> displayEvents = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, sm.getDataSource(), ub, currentRole);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (!studySub.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_subject_is_not_available_for_this_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
return;
}
request.setAttribute("subject", subject);
request.setAttribute("study", study);
request.setAttribute("studySub", studySub);
request.setAttribute("events", displayEvents);
forwardPage(Page.REMOVE_STUDY_SUBJECT);
} else {
logger.info("submit to remove the subject from study");
// remove subject from study
studySub.setStatus(Status.DELETED);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
subdao.update(studySub);
// remove all study events
// remove all event crfs
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < displayEvents.size(); j++) {
DisplayStudyEventBean dispEvent = displayEvents.get(j);
StudyEventBean event = dispEvent.getStudyEvent();
if (!event.getStatus().equals(Status.DELETED)) {
event.setStatus(Status.AUTO_DELETED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (!eventCRF.getStatus().equals(Status.DELETED)) {
eventCRF.setStatus(Status.AUTO_DELETED);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (!item.getStatus().equals(Status.DELETED)) {
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
String emailBody = respage.getString("the_subject") + " " + subject.getName() + " " + respage.getString("has_been_removed_from_the_study") + study.getName() + ".";
addPageMessage(emailBody);
// try{
// sendEmail(emailBody);
// }catch(Exception ex){
// addPageMessage(respage.getString("mail_cannot_be_sent_to_admin"));
// }
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class RestoreStudyEventServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// studyEventId
int studyEventId = fp.getInt("id");
// studySubjectId
int studySubId = fp.getInt("studySubId");
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (studyEventId == 0) {
addPageMessage(respage.getString("please_choose_a_SE_to_restore"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
// YW 11-07-2007, a study event could not be restored if its study
// subject has been removed
Status s = studySub.getStatus();
if ("removed".equalsIgnoreCase(s.getName()) || "auto-removed".equalsIgnoreCase(s.getName())) {
addPageMessage(resword.getString("study_event") + resterm.getString("could_not_be") + resterm.getString("restored") + "." + respage.getString("study_subject_has_been_deleted"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
// YW
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
request.setAttribute("studySub", studySub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studySub.getStudyId());
request.setAttribute("study", study);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (event.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_event_is_already_available_for_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
return;
}
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
// find all crfs in the definition
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllByEventDefinitionId(study, sed.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
de.setDisplayEventCRFs(getDisplayEventCRFs(eventCRFs, eventDefinitionCRFs));
request.setAttribute("displayEvent", de);
forwardPage(Page.RESTORE_STUDY_EVENT);
} else {
logger.info("submit to restore the event to study");
// restore event to study
event.setStatus(Status.AVAILABLE);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
// restore event crfs
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (item.getStatus().equals(Status.AUTO_DELETED)) {
item.setStatus(Status.AVAILABLE);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
String emailBody = respage.getString("the_event") + event.getStudyEventDefinition().getName() + " " + respage.getString("has_been_restored_to_the_study") + " " + study.getName() + ".";
addPageMessage(emailBody);
// sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class RestoreStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
// studySubjectId
String studySubIdString = request.getParameter("id");
String subIdString = request.getParameter("subjectId");
String studyIdString = request.getParameter("studyId");
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (StringUtil.isBlank(studySubIdString) || StringUtil.isBlank(subIdString) || StringUtil.isBlank(studyIdString)) {
addPageMessage(respage.getString("please_choose_study_subject_to_restore"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
} else {
int studyId = Integer.valueOf(studyIdString.trim()).intValue();
int studySubId = Integer.valueOf(studySubIdString.trim()).intValue();
int subjectId = Integer.valueOf(subIdString.trim()).intValue();
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studyId);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
// ArrayList events = sedao.findAllByStudyAndStudySubjectId(study, studySubId);
ArrayList<DisplayStudyEventBean> displayEvents = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, sm.getDataSource(), ub, currentRole);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
if (studySub.getStatus().equals(Status.AVAILABLE)) {
addPageMessage(respage.getString("this_subject_is_already_available_for_study") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
return;
}
request.setAttribute("subject", subject);
request.setAttribute("study", study);
request.setAttribute("studySub", studySub);
request.setAttribute("events", displayEvents);
forwardPage(Page.RESTORE_STUDY_SUBJECT);
} else {
logger.info("submit to restore the subject from study");
// restore subject from study
studySub.setStatus(Status.AVAILABLE);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
subdao.update(studySub);
// restore all study events
// restore all event crfs
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < displayEvents.size(); j++) {
DisplayStudyEventBean dispEvent = displayEvents.get(j);
StudyEventBean event = dispEvent.getStudyEvent();
if (event.getStatus().equals(Status.AUTO_DELETED)) {
event.setStatus(Status.AVAILABLE);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
}
ArrayList eventCRFs = ecdao.findAllByStudyEvent(event);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
eventCRF.setStatus(Status.AVAILABLE);
eventCRF.setUpdater(ub);
eventCRF.setUpdatedDate(new Date());
ecdao.update(eventCRF);
// remove all the item data
ArrayList itemDatas = iddao.findAllByEventCRFId(eventCRF.getId());
for (int a = 0; a < itemDatas.size(); a++) {
ItemDataBean item = (ItemDataBean) itemDatas.get(a);
if (item.getStatus().equals(Status.AUTO_DELETED)) {
item.setStatus(Status.AVAILABLE);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
String emailBody = respage.getString("the_subject") + " " + subject.getName() + " " + respage.getString("has_been_restored_to_the_study") + " " + study.getName() + ".";
addPageMessage(emailBody);
// try{
// sendEmail(emailBody);
// }catch (Exception ex){
// addPageMessage(respage.getString("mail_cannot_be_sent_to_admin"));
// }
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
}
}
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class ListEventsForSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// checks which module the requests are from
String module = fp.getString(MODULE);
request.setAttribute(MODULE, module);
String pageNumber = fp.getString(ListStudySubjectServlet.SUBJECT_PAGE_NUMBER);
String filterKeyword = fp.getString(ListStudySubjectServlet.FILTER_KEYWORD);
String tmpSearch = fp.getString(ListStudySubjectServlet.SEARCH_SUBMITTED);
boolean searchSubmitted = !(tmpSearch == null || "".equalsIgnoreCase(tmpSearch)) && !"".equalsIgnoreCase(filterKeyword);
SubjectMatrixUtil matrixUtil = new SubjectMatrixUtil();
String query = matrixUtil.createPaginatingQuery(pageNumber);
StringBuilder extendedQuery = new StringBuilder(query);
// URL encode the search keyword, since it will be a parameter in the
// URL
String filterKeywordURLEncode = java.net.URLEncoder.encode(filterKeyword, "UTF-8");
if (searchSubmitted) {
extendedQuery.append("&ebl_sortColumnInd=0&submitted=1&ebl_sortAscending=1&ebl_filtered=1");
extendedQuery.append("&").append(ListStudySubjectServlet.FILTER_KEYWORD).append("=").append(filterKeywordURLEncode);
}
request.setAttribute(ListStudySubjectServlet.PAGINATING_QUERY, extendedQuery.toString());
int definitionId = fp.getInt("defId");
int tabId = fp.getInt("tab");
if (definitionId <= 0) {
addPageMessage(respage.getString("please_choose_an_ED_ta_to_vies_details"));
forwardPage(Page.LIST_STUDY_SUBJECTS);
return;
}
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(definitionId);
StudySubjectDAO sdao = new StudySubjectDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
CRFDAO crfdao = new CRFDAO(sm.getDataSource());
// find all the groups in the current study
ArrayList studyGroupClasses = sgcdao.findAllActiveByStudy(currentStudy);
// information for the event tabs
ArrayList allDefs = seddao.findAllActiveByStudy(currentStudy);
boolean isASite = false;
if (currentStudy.getParentStudyId() > 0) {
StudyDAO stdao = new StudyDAO(sm.getDataSource());
StudyBean parent = (StudyBean) stdao.findByPK(currentStudy.getParentStudyId());
allDefs = seddao.findAllActiveByStudy(parent);
}
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(this.currentStudy, definitionId);
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
CRFBean crf = (CRFBean) crfdao.findByPK(edc.getCrfId());
edc.setCrf(crf);
}
request.setAttribute("studyGroupClasses", studyGroupClasses);
request.setAttribute("allDefsArray", allDefs);
request.setAttribute("allDefsNumber", new Integer(allDefs.size()));
request.setAttribute("groupSize", new Integer(studyGroupClasses.size()));
request.setAttribute("eventDefCRFSize", new Integer(eventDefinitionCRFs.size()));
request.setAttribute("tabId", new Integer(tabId));
request.setAttribute("studyEventDef", sed);
request.setAttribute("eventDefCRFs", eventDefinitionCRFs);
// find all the subjects in current study
ArrayList subjects = sdao.findAllByStudyId(currentStudy.getId());
ArrayList displayStudySubs = new ArrayList();
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
ArrayList groups = (ArrayList) sgmdao.findAllByStudySubject(studySub.getId());
ArrayList subGClasses = new ArrayList();
for (int j = 0; j < studyGroupClasses.size(); j++) {
StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(j);
boolean hasClass = false;
for (int k = 0; k < groups.size(); k++) {
SubjectGroupMapBean sgmb = (SubjectGroupMapBean) groups.get(k);
if (sgmb.getGroupClassName().equalsIgnoreCase(sgc.getName())) {
subGClasses.add(sgmb);
hasClass = true;
break;
}
}
if (!hasClass) {
subGClasses.add(new SubjectGroupMapBean());
}
}
// find all eventcrfs for each event, for each event tab
ArrayList displaySubjectEvents = new ArrayList();
ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
ArrayList events = sedao.findAllByStudySubjectAndDefinition(studySub, sed);
for (int k = 0; k < events.size(); k++) {
StudyEventBean seb = (StudyEventBean) events.get(k);
DisplayStudyEventBean dseb = ListStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySub, seb, sm.getDataSource(), ub, currentRole, this.currentStudy);
// ArrayList eventCRFs = ecdao.findAllByStudyEvent(seb);
// ArrayList al =
// ViewStudySubjectServlet.getUncompletedCRFs(sm.getDataSource(),
// eventDefinitionCRFs, eventCRFs);
// dseb.getUncompletedCRFs().add(al);
displayEvents.add(dseb);
}
ArrayList al = new ArrayList();
for (int k = 0; k < displayEvents.size(); k++) {
DisplayStudyEventBean dseb = displayEvents.get(k);
ArrayList eventCRFs = dseb.getDisplayEventCRFs();
for (int a = 0; a < eventDefinitionCRFs.size(); a++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(a);
int crfId = edc.getCrfId();
boolean hasCRF = false;
for (int b = 0; b < eventCRFs.size(); b++) {
DisplayEventCRFBean decb = (DisplayEventCRFBean) eventCRFs.get(b);
// decb.getStage().getName() );
if (decb.getEventCRF().getCrf().getId() == crfId) {
dseb.getAllEventCRFs().add(decb);
// logger.info("hasCRf" + crfId +
// decb.getEventCRF().getCrf().getName());
hasCRF = true;
break;
}
}
if (hasCRF == false) {
DisplayEventCRFBean db = new DisplayEventCRFBean();
db.setEventDefinitionCRF(edc);
db.getEventDefinitionCRF().setCrf(edc.getCrf());
dseb.getAllEventCRFs().add(db);
// logger.info("noCRf" + crfId);
}
}
// Issue 3212 BWP <<
if (currentStudy.getParentStudyId() > 0) {
// check each eventDefCRFBean and set its isHidden property
// to true, if its
// persistent/database-derived hideCrf is true (domain rule:
// hide the CRF from users logged into a site)
HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
hideCRFManager.optionallyCheckHideCRFProperty(dseb);
// remove a DisplayEventCRFBean from a DisplayStudyEventBean
// in the list
// if it contains a hidden CRF in its event definition
hideCRFManager.removeHiddenEventCRF(dseb);
// generate a boolean request attribute indicating whether
// any of the CRFs
// should be hidden
boolean hideCRFs = hideCRFManager.studyEventHasAHideCRFProperty(dseb);
request.setAttribute("hideCRFs", hideCRFs);
}
// >>
}
DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
dssb.setStudySubject(studySub);
dssb.setStudyGroups(subGClasses);
dssb.setStudyEvents(displayEvents);
if (definitionId > 0) {
dssb.setSedId(definitionId);
} else {
dssb.setSedId(-1);
}
displayStudySubs.add(dssb);
}
EntityBeanTable table = fp.getEntityBeanTable();
ArrayList allStudyRows = DisplayStudySubjectEventsRow.generateRowsFromBeans(displayStudySubs);
ArrayList columnArray = new ArrayList();
columnArray.add(resword.getString("ID"));
columnArray.add(resword.getString("subject_status"));
columnArray.add(resword.getString("gender"));
for (int i = 0; i < studyGroupClasses.size(); i++) {
StudyGroupClassBean sgc = (StudyGroupClassBean) studyGroupClasses.get(i);
columnArray.add(sgc.getName());
}
// columnArray.add("Event Sequence");
columnArray.add(resword.getString("event_status"));
columnArray.add(resword.getString("event_date"));
// Issue 3212 BWP <<
HideCRFManager hideCRFMgr = HideCRFManager.createHideCRFManager();
hideCRFMgr.hideSpecifiedEventCRFDefBeans(eventDefinitionCRFs);
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
// Issue 3212 BWP <<
if (!(currentStudy.getParentStudyId() > 0)) {
columnArray.add(edc.getCrf().getName());
} else {
if (!edc.isHideCrf()) {
columnArray.add(edc.getCrf().getName());
}
}
// >>
}
columnArray.add(resword.getString("actions"));
String[] columns = new String[columnArray.size()];
columnArray.toArray(columns);
table.setColumns(new ArrayList(Arrays.asList(columns)));
table.setQuery("ListEventsForSubject?module=" + module + "&defId=" + definitionId + "&tab=" + tabId, new HashMap());
table.hideColumnLink(columnArray.size() - 1);
// if(currentStudy.getStatus().isAvailable()){
// table.addLink(resword.getString("add_new_subject"), "AddNewSubject");
// }
table.setRows(allStudyRows);
if (filterKeyword != null && !"".equalsIgnoreCase(filterKeyword)) {
table.setKeywordFilter(filterKeyword);
}
table.computeDisplay();
request.setAttribute("table", table);
forwardPage(Page.LIST_EVENTS_FOR_SUBJECT);
}
use of org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean in project OpenClinica by OpenClinica.
the class DeleteStudyEventServlet method processRequest.
@Override
public void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
// studyEventId
int studyEventId = fp.getInt("id");
// studySubjectId
int studySubId = fp.getInt("studySubId");
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
if (studyEventId == 0) {
addPageMessage(respage.getString("please_choose_a_SE_to_remove"));
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
} else {
StudyEventBean event = (StudyEventBean) sedao.findByPK(studyEventId);
StudySubjectBean studySub = (StudySubjectBean) subdao.findByPK(studySubId);
request.setAttribute("studySub", studySub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(event.getStudyEventDefinitionId());
event.setStudyEventDefinition(sed);
StudyDAO studydao = new StudyDAO(sm.getDataSource());
StudyBean study = (StudyBean) studydao.findByPK(studySub.getStudyId());
request.setAttribute("study", study);
String action = request.getParameter("action");
if ("confirm".equalsIgnoreCase(action)) {
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
// find all crfs in the definition
ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllByEventDefinitionId(study, sed.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
// construct info needed on view study event page
DisplayStudyEventBean de = new DisplayStudyEventBean();
de.setStudyEvent(event);
request.setAttribute("displayEvent", de);
// request.setAttribute("crfs", eventDefinitionCRFs);
forwardPage(Page.DELETE_STUDY_EVENT);
} else {
logger.info("submit to delete the event from study");
// delete event from study
event.setSubjectEventStatus(SubjectEventStatus.NOT_SCHEDULED);
event.setUpdater(ub);
event.setUpdatedDate(new Date());
sedao.update(event);
String emailBody = respage.getString("the_event") + " " + event.getStudyEventDefinition().getName() + " " + respage.getString("has_been_removed_from_the_subject_record_for") + " " + studySub.getLabel() + " " + respage.getString("in_the_study") + " " + study.getName() + ".";
addPageMessage(emailBody);
// sendEmail(emailBody);
request.setAttribute("id", new Integer(studySubId).toString());
forwardPage(Page.VIEW_STUDY_SUBJECT_SERVLET);
}
}
}
Aggregations