use of org.akaza.openclinica.dao.submit.ItemDataDAO 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);
}
}
use of org.akaza.openclinica.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.
the class ViewNoteServlet method processRequest.
@Override
protected void processRequest() throws Exception {
FormProcessor fp = new FormProcessor(request);
Locale locale = LocaleResolver.getLocale(request);
DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
dndao.setFetchMapping(true);
int noteId = fp.getInt(NOTE_ID, true);
DiscrepancyNoteBean note = (DiscrepancyNoteBean) dndao.findByPK(noteId);
String entityType = note.getEntityType();
if (note.getEntityId() > 0 && !entityType.equals("")) {
if (!StringUtil.isBlank(entityType)) {
if ("itemData".equalsIgnoreCase(entityType)) {
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
ItemDataBean itemData = (ItemDataBean) iddao.findByPK(note.getEntityId());
ItemDAO idao = new ItemDAO(sm.getDataSource());
ItemBean item = (ItemBean) idao.findByPK(itemData.getItemId());
note.setEntityValue(itemData.getValue());
note.setEntityName(item.getName());
// Mantis Issue 5165. It should be itemData.getId() instead of item.getId()
note.setEntityId(itemData.getId());
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean se = (StudyEventBean) sed.findByPK(ec.getStudyEventId());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
note.setStudySub(ssub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
note.setEvent(se);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFVersionBean cv = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
CRFBean crf = (CRFBean) cdao.findByPK(cv.getCrfId());
note.setCrfName(crf.getName());
} else if ("studySub".equalsIgnoreCase(entityType)) {
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(note.getEntityId());
note.setStudySub(ssub);
// System.out.println("column" + note.getColumn());
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
SubjectBean sub = (SubjectBean) sdao.findByPK(ssub.getSubjectId());
if (!StringUtil.isBlank(note.getColumn())) {
if ("enrollment_date".equalsIgnoreCase(note.getColumn())) {
if (ssub.getEnrollmentDate() != null) {
note.setEntityValue(dateFormatter.format(ssub.getEnrollmentDate()));
}
note.setEntityName(resword.getString("enrollment_date"));
} else if ("gender".equalsIgnoreCase(note.getColumn())) {
note.setEntityValue(sub.getGender() + "");
note.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
if (sub.getDateOfBirth() != null) {
note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
}
note.setEntityName(resword.getString("date_of_birth"));
}
}
} else if ("subject".equalsIgnoreCase(entityType)) {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
SubjectBean sub = (SubjectBean) sdao.findByPK(note.getEntityId());
StudySubjectBean ssub = new StudySubjectBean();
ssub.setLabel(sub.getUniqueIdentifier());
note.setStudySub(ssub);
if (!StringUtil.isBlank(note.getColumn())) {
if ("gender".equalsIgnoreCase(note.getColumn())) {
note.setEntityValue(sub.getGender() + "");
note.setEntityName(resword.getString("gender"));
} else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
if (sub.getDateOfBirth() != null) {
note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
}
note.setEntityName(resword.getString("date_of_birth"));
} else if ("unique_identifier".equalsIgnoreCase(note.getColumn())) {
note.setEntityName(resword.getString("unique_identifier"));
note.setEntityValue(sub.getUniqueIdentifier());
}
}
} else if ("studyEvent".equalsIgnoreCase(entityType)) {
StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
StudyEventBean se = (StudyEventBean) sed.findByPK(note.getEntityId());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
note.setStudySub(ssub);
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
se.setName(sedb.getName());
note.setEvent(se);
if (!StringUtil.isBlank(note.getColumn())) {
if ("location".equalsIgnoreCase(note.getColumn())) {
request.setAttribute("entityValue", se.getLocation());
request.setAttribute("entityName", resword.getString("location"));
note.setEntityName(resword.getString("location"));
note.setEntityValue(se.getLocation());
} else if ("date_start".equalsIgnoreCase(note.getColumn())) {
if (se.getDateStarted() != null) {
note.setEntityValue(dateFormatter.format(se.getDateStarted()));
}
note.setEntityName(resword.getString("start_date"));
} else if ("date_end".equalsIgnoreCase(note.getColumn())) {
if (se.getDateEnded() != null) {
note.setEntityValue(dateFormatter.format(se.getDateEnded()));
}
note.setEntityName(resword.getString("end_date"));
}
}
} else if ("eventCrf".equalsIgnoreCase(entityType)) {
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
EventCRFBean ec = (EventCRFBean) ecdao.findByPK(note.getEntityId());
StudySubjectBean ssub = (StudySubjectBean) new StudySubjectDAO(sm.getDataSource()).findByPK(ec.getStudySubjectId());
note.setStudySub(ssub);
StudyEventBean event = (StudyEventBean) new StudyEventDAO(sm.getDataSource()).findByPK(ec.getStudyEventId());
note.setEvent(event);
if (!StringUtil.isBlank(note.getColumn())) {
if ("date_interviewed".equals(note.getColumn())) {
if (ec.getDateInterviewed() != null) {
note.setEntityValue(dateFormatter.format(ec.getDateInterviewed()));
}
note.setEntityName(resword.getString("date_interviewed"));
} else if ("interviewer_name".equals(note.getColumn())) {
note.setEntityValue(ec.getInterviewerName());
note.setEntityName(resword.getString("interviewer_name"));
}
}
}
}
}
// Mantis Issue 8495.
if (note.getStudyId() != currentStudy.getId()) {
if (currentStudy.getParentStudyId() > 0) {
if (currentStudy.getId() != note.getStudySub().getStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
} else {
// The SubjectStudy is not belong to currentstudy and current study is not a site.
StudyDAO studydao = new StudyDAO(sm.getDataSource());
Collection sites;
sites = studydao.findOlnySiteIdsByStudy(currentStudy);
if (!sites.contains(note.getStudySub().getStudyId())) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
}
}
// Check end
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList<DiscrepancyNoteBean> notes = dndao.findAllEntityByPK(note.getEntityType(), noteId);
Date lastUpdatedDate = note.getCreatedDate();
UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
/*
* for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
* (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
* (pId == 0) { note = n; note.setLastUpdator((UserAccountBean)
* udao.findByPK(n.getOwnerId()));
* note.setLastDateUpdated(n.getCreatedDate()); lastUpdatedDate =
* note.getLastDateUpdated(); lastUpdator = note.getLastUpdator(); } }
*/
// BWP 3029 >> This algorithm needs to be changed to properly set
// the parent note's status and updated date
// First sort the notes on their ID; this will put the parent note
// first; and
// the note with the latest status and updated date last
java.util.Collections.sort(notes);
DiscrepancyNoteBean lastChild = notes.get(notes.size() - 1);
lastUpdatedDate = lastChild.getCreatedDate();
lastUpdator = (UserAccountBean) udao.findByPK(lastChild.getOwnerId());
note.setLastUpdator(lastUpdator);
note.setLastDateUpdated(lastUpdatedDate);
note.setUpdatedDate(lastUpdatedDate);
for (DiscrepancyNoteBean dnBean : notes) {
if (dnBean.getParentDnId() > 0) {
note.getChildren().add(dnBean);
}
}
/*
* for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
* (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
* (pId > 0) { note.getChildren().add(n);
*
* if (!n.getCreatedDate().before(lastUpdatedDate)) { lastUpdatedDate =
* n.getCreatedDate(); lastUpdator = (UserAccountBean)
* udao.findByPK(n.getOwnerId()); note.setLastUpdator(lastUpdator);
* note.setLastDateUpdated(lastUpdatedDate);
* note.setResolutionStatusId(n.getResolutionStatusId());
* note.setResStatus(ResolutionStatus.get(n.getResolutionStatusId())); } } }
*/
note.setNumChildren(note.getChildren().size());
note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
request.setAttribute(DIS_NOTE, note);
forwardPage(Page.VIEW_SINGLE_NOTE);
}
use of org.akaza.openclinica.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.
the class RestoreEventDefinitionServlet method processRequest.
@Override
public void processRequest() throws Exception {
String idString = request.getParameter("id");
int defId = Integer.valueOf(idString.trim()).intValue();
StudyEventDefinitionDAO sdao = new StudyEventDefinitionDAO(sm.getDataSource());
StudyEventDefinitionBean sed = (StudyEventDefinitionBean) sdao.findByPK(defId);
// find all CRFs
EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
ArrayList eventDefinitionCRFs = (ArrayList) edao.findAllByDefinition(defId);
CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
CRFDAO cdao = new CRFDAO(sm.getDataSource());
for (int i = 0; i < eventDefinitionCRFs.size(); i++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(i);
ArrayList versions = (ArrayList) cvdao.findAllByCRF(edc.getCrfId());
edc.setVersions(versions);
CRFBean crf = (CRFBean) cdao.findByPK(edc.getCrfId());
edc.setCrfName(crf.getName());
CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(edc.getDefaultVersionId());
edc.setDefaultVersionName(defaultVersion.getName());
CRFBean cBean = (CRFBean) cdao.findByPK(edc.getCrfId());
String crfPath = sed.getOid() + "." + cBean.getOid();
edc.setOffline(getEventDefinitionCrfTagService().getEventDefnCrfOfflineStatus(2, crfPath, true));
}
// finds all events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
ArrayList events = (ArrayList) sedao.findAllByDefinition(sed.getId());
String action = request.getParameter("action");
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_SED_to_restore"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
if (!sed.getStatus().equals(Status.DELETED)) {
addPageMessage(respage.getString("this_SED_cannot_be_restored") + " " + respage.getString("please_contact_sysadmin_for_more_information"));
forwardPage(Page.LIST_DEFINITION_SERVLET);
return;
}
String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
request.setAttribute("participateFormStatus", participateFormStatus);
if (participateFormStatus.equals("enabled"))
baseUrl();
request.setAttribute("definitionToRestore", sed);
request.setAttribute("eventDefinitionCRFs", eventDefinitionCRFs);
request.setAttribute("events", events);
forwardPage(Page.RESTORE_DEFINITION);
} else {
logger.info("submit to restore the definition");
// restore definition
sed.setStatus(Status.AVAILABLE);
sed.setUpdater(ub);
sed.setUpdatedDate(new Date());
sdao.update(sed);
// restore all crfs
for (int j = 0; j < eventDefinitionCRFs.size(); j++) {
EventDefinitionCRFBean edc = (EventDefinitionCRFBean) eventDefinitionCRFs.get(j);
if (edc.getStatus().equals(Status.AUTO_DELETED)) {
edc.setStatus(Status.AVAILABLE);
edc.setUpdater(ub);
edc.setUpdatedDate(new Date());
edao.update(edc);
}
}
// restore all events
EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
for (int j = 0; j < events.size(); j++) {
StudyEventBean event = (StudyEventBean) events.get(j);
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);
// remove all the item data
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);
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_SED") + " " + sed.getName() + "(" + respage.getString("and_all_associated_event_data_restored_to_study") + currentStudy.getName() + ".";
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.LIST_DEFINITION_SERVLET);
}
}
}
use of org.akaza.openclinica.dao.submit.ItemDataDAO 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("subStudy", 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.dao.submit.ItemDataDAO in project OpenClinica by OpenClinica.
the class ViewPersistanceHandler method fetchPersistedData.
public List<ItemDataBean> fetchPersistedData(int sectionId, int eventcrfId) {
// SessionManager sessionManager = new SessionManager();
ItemDataDAO itemDataDAO = new ItemDataDAO(SessionManager.getStaticDataSource());
List<ItemDataBean> itemDataBeans = itemDataDAO.findAllActiveBySectionIdAndEventCRFId(sectionId, eventcrfId);
return itemDataBeans == null ? new ArrayList<ItemDataBean>() : itemDataBeans;
}
Aggregations