use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class ViewStudyServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int studyId = fp.getInt("id");
if (studyId == 0) {
addPageMessage(respage.getString("please_choose_a_study_to_view"));
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
if (currentStudy.getId() != studyId && currentStudy.getParentStudyId() != studyId) {
checkRoleByUserAndStudy(ub, studyId, 0);
}
String viewFullRecords = fp.getString("viewFull");
StudyBean study = (StudyBean) sdao.findByPK(studyId);
StudyConfigService scs = new StudyConfigService(sm.getDataSource());
study = scs.setParametersForStudy(study);
StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
String randomizationStatusInOC = spvdao.findByHandleAndStudy(study.getId(), "randomization").getValue();
String participantStatusInOC = spvdao.findByHandleAndStudy(study.getId(), "participantPortal").getValue();
if (participantStatusInOC == "")
participantStatusInOC = "disabled";
if (randomizationStatusInOC == "")
randomizationStatusInOC = "disabled";
RandomizationRegistrar randomizationRegistrar = new RandomizationRegistrar();
SeRandomizationDTO seRandomizationDTO = randomizationRegistrar.getCachedRandomizationDTOObject(study.getOid(), false);
if (seRandomizationDTO != null && seRandomizationDTO.getStatus().equalsIgnoreCase("ACTIVE") && randomizationStatusInOC.equalsIgnoreCase("enabled")) {
study.getStudyParameterConfig().setRandomization("enabled");
} else {
study.getStudyParameterConfig().setRandomization("disabled");
}
;
ParticipantPortalRegistrar participantPortalRegistrar = new ParticipantPortalRegistrar();
String pStatus = participantPortalRegistrar.getCachedRegistrationStatus(study.getOid(), session);
if (participantPortalRegistrar != null && pStatus.equalsIgnoreCase("ACTIVE") && participantStatusInOC.equalsIgnoreCase("enabled")) {
study.getStudyParameterConfig().setParticipantPortal("enabled");
} else {
study.getStudyParameterConfig().setParticipantPortal("disabled");
}
;
request.setAttribute("studyToView", study);
if ("yes".equalsIgnoreCase(viewFullRecords)) {
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList sites = new ArrayList();
ArrayList userRoles = new ArrayList();
ArrayList subjects = new ArrayList();
if (this.currentStudy.getParentStudyId() > 0 && this.currentRole.getRole().getId() > 3) {
sites.add(this.currentStudy);
userRoles = udao.findAllUsersByStudy(currentStudy.getId());
subjects = ssdao.findAllByStudy(currentStudy);
} else {
sites = (ArrayList) sdao.findAllByParent(studyId);
userRoles = udao.findAllUsersByStudy(studyId);
subjects = ssdao.findAllByStudy(study);
}
// find all subjects in the study, include ones in sites
StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
// StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
// ArrayList displayStudySubs = new ArrayList();
// for (int i = 0; i < subjects.size(); i++) {
// StudySubjectBean studySub = (StudySubjectBean) subjects.get(i);
// // find all events
// ArrayList events = sedao.findAllByStudySubject(studySub);
//
// // find all eventcrfs for each event
// EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
//
// DisplayStudySubjectBean dssb = new DisplayStudySubjectBean();
// dssb.setStudyEvents(events);
// dssb.setStudySubject(studySub);
// displayStudySubs.add(dssb);
// }
// find all events in the study, include ones in sites
ArrayList definitions = seddao.findAllByStudy(study);
for (int i = 0; i < definitions.size(); i++) {
StudyEventDefinitionBean def = (StudyEventDefinitionBean) definitions.get(i);
ArrayList crfs = (ArrayList) edcdao.findAllActiveParentsByEventDefinitionId(def.getId());
def.setCrfNum(crfs.size());
}
String moduleManager = CoreResources.getField("moduleManager");
request.setAttribute("moduleManager", moduleManager);
String portalURL = CoreResources.getField("portalURL");
request.setAttribute("portalURL", portalURL);
request.setAttribute("config", study);
request.setAttribute("sitesToView", sites);
request.setAttribute("siteNum", sites.size() + "");
request.setAttribute("userRolesToView", userRoles);
request.setAttribute("userNum", userRoles.size() + "");
// request.setAttribute("subjectsToView", displayStudySubs);
// request.setAttribute("subjectNum", subjects.size() + "");
request.setAttribute("definitionsToView", definitions);
request.setAttribute("defNum", definitions.size() + "");
forwardPage(Page.VIEW_FULL_STUDY);
} else {
forwardPage(Page.VIEW_STUDY);
}
}
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class RestoreSiteServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
String idString = request.getParameter("id");
logger.info("site id:" + idString);
int siteId = Integer.valueOf(idString.trim()).intValue();
StudyBean study = (StudyBean) sdao.findByPK(siteId);
// find all user and roles
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList userRoles = udao.findAllByStudyId(siteId);
// find all subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList subjects = ssdao.findAllByStudy(study);
// find all events
StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = sefdao.findAllByStudy(study);
String action = request.getParameter("action");
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_site_to_restore"));
forwardPage(Page.SITE_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
// site can be restored when its parent study is not "removed"
// -- YW -6-21-2007
StudyBean parentstudy = (StudyBean) sdao.findByPK(study.getParentStudyId());
if (!"removed".equals(parentstudy.getStatus().getName())) {
request.setAttribute("siteToRestore", study);
request.setAttribute("userRolesToRestore", userRoles);
request.setAttribute("subjectsToRestore", subjects);
// request.setAttribute("definitionsToRestore",
// definitions);
} else {
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("choosen_site_cannot_restored"));
Object[] arguments = { study.getName(), parentstudy.getName() };
addPageMessage(mf.format(arguments));
forwardPage(Page.STUDY_LIST_SERVLET);
}
forwardPage(Page.RESTORE_SITE);
} else {
logger.info("submit to restore the site");
// change all statuses to unavailable
StudyDAO studao = new StudyDAO(sm.getDataSource());
study.setStatus(study.getOldStatus());
study.setUpdater(ub);
study.setUpdatedDate(new Date());
studao.update(study);
// restore all users and roles
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
if (role.getStatus().equals(Status.AUTO_DELETED)) {
role.setStatus(Status.AVAILABLE);
role.setUpdater(ub);
role.setUpdatedDate(new Date());
// YW << So study_user_role table status_id field can be
// updated
udao.updateStudyUserRole(role, role.getUserName());
}
// YW 06-18-2007 >>
}
// study
if (study.getId() == currentStudy.getId()) {
currentStudy.setStatus(Status.AVAILABLE);
StudyUserRoleBean r = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getId());
StudyUserRoleBean rInParent = (new UserAccountDAO(sm.getDataSource())).findRoleByUserNameAndStudyId(ub.getName(), currentStudy.getParentStudyId());
// according to logic in SecureController.java: inherited
// role from parent study, pick the higher role
currentRole.setRole(Role.max(r.getRole(), rInParent.getRole()));
}
// YW >>
// restore all study_group
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groups = sgdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupBean group = (StudyGroupBean) groups.get(i);
if (group.getStatus().equals(Status.AUTO_DELETED)) {
group.setStatus(Status.AVAILABLE);
group.setUpdater(ub);
group.setUpdatedDate(new Date());
sgdao.update(group);
// all subject_group_map
ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupId(group.getId());
for (int j = 0; j < subjectGroupMaps.size(); j++) {
SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
if (sgMap.getStatus().equals(Status.AUTO_DELETED)) {
sgMap.setStatus(Status.AVAILABLE);
sgMap.setUpdater(ub);
sgMap.setUpdatedDate(new Date());
sgmdao.update(sgMap);
}
}
}
}
// restore all events with subjects
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
if (subject.getStatus().equals(Status.AUTO_DELETED)) {
subject.setStatus(Status.AVAILABLE);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
ssdao.update(subject);
ArrayList events = sedao.findAllByStudySubject(subject);
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);
ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
for (int k = 0; k < eventCRFs.size(); k++) {
// YW << fix broken page for storing site
EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(k);
// >> YW
if (eventCRF.getStatus().equals(Status.AUTO_DELETED)) {
eventCRF.setStatus(eventCRF.getOldStatus());
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(item.getOldStatus());
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
}
}
// for subjects
DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
ArrayList dataset = datadao.findAllByStudyId(study.getId());
for (int i = 0; i < dataset.size(); i++) {
DatasetBean data = (DatasetBean) dataset.get(i);
data.setStatus(Status.AVAILABLE);
data.setUpdater(ub);
data.setUpdatedDate(new Date());
datadao.update(data);
}
addPageMessage(respage.getString("this_site_has_been_restored_succesfully"));
String fromListSite = (String) session.getAttribute("fromListSite");
if (fromListSite != null && fromListSite.equals("yes") && currentRole.getRole().equals(Role.STUDYDIRECTOR)) {
session.removeAttribute("fromListSite");
forwardPage(Page.SITE_LIST_SERVLET);
} else {
session.removeAttribute("fromListSite");
if (currentRole.getRole().equals(Role.ADMIN)) {
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
forwardPage(Page.SITE_LIST_SERVLET);
}
}
}
}
}
use of org.akaza.openclinica.dao.login.UserAccountDAO 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.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class RemoveSiteServlet method processRequest.
@Override
public void processRequest() throws Exception {
StudyDAO sdao = new StudyDAO(sm.getDataSource());
String idString = request.getParameter("id");
logger.info("site id:" + idString);
int siteId = Integer.valueOf(idString.trim()).intValue();
StudyBean study = (StudyBean) sdao.findByPK(siteId);
if (currentStudy.getId() != study.getParentStudyId()) {
addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
forwardPage(Page.MENU_SERVLET);
return;
}
// find all user and roles
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList userRoles = udao.findAllByStudyId(siteId);
// find all subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList subjects = ssdao.findAllByStudy(study);
// find all events
StudyEventDefinitionDAO sefdao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList definitions = sefdao.findAllByStudy(study);
String action = request.getParameter("action");
if (StringUtil.isBlank(idString)) {
addPageMessage(respage.getString("please_choose_a_site_to_remove"));
forwardPage(Page.SITE_LIST_SERVLET);
} else {
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("siteToRemove", study);
request.setAttribute("userRolesToRemove", userRoles);
request.setAttribute("subjectsToRemove", subjects);
forwardPage(Page.REMOVE_SITE);
} else {
logger.info("submit to remove the site");
// change all statuses to unavailable
StudyDAO studao = new StudyDAO(sm.getDataSource());
study.setOldStatus(study.getStatus());
study.setStatus(Status.DELETED);
study.setUpdater(ub);
study.setUpdatedDate(new Date());
studao.update(study);
// remove all users and roles
for (int i = 0; i < userRoles.size(); i++) {
StudyUserRoleBean role = (StudyUserRoleBean) userRoles.get(i);
if (!role.getStatus().equals(Status.DELETED)) {
role.setStatus(Status.AUTO_DELETED);
role.setUpdater(ub);
role.setUpdatedDate(new Date());
// YW << So study_user_role table status_id field can be
// updated
udao.updateStudyUserRole(role, role.getUserName());
}
// YW 06-18-2007 >>
}
// YW << bug fix that current active study has been deleted
if (study.getId() == currentStudy.getId()) {
currentStudy.setStatus(Status.DELETED);
// currentRole.setRole(Role.INVALID);
currentRole.setStatus(Status.DELETED);
}
// remove all subjects
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
}
// remove all study_group
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groups = sgdao.findAllByStudy(study);
for (int i = 0; i < groups.size(); i++) {
StudyGroupBean group = (StudyGroupBean) groups.get(i);
if (!group.getStatus().equals(Status.DELETED)) {
group.setStatus(Status.AUTO_DELETED);
group.setUpdater(ub);
group.setUpdatedDate(new Date());
sgdao.update(group);
// all subject_group_map
ArrayList subjectGroupMaps = sgmdao.findAllByStudyGroupId(group.getId());
for (int j = 0; j < subjectGroupMaps.size(); j++) {
SubjectGroupMapBean sgMap = (SubjectGroupMapBean) subjectGroupMaps.get(j);
if (!sgMap.getStatus().equals(Status.DELETED)) {
sgMap.setStatus(Status.AUTO_DELETED);
sgMap.setUpdater(ub);
sgMap.setUpdatedDate(new Date());
sgmdao.update(sgMap);
}
}
}
}
// remove all events
EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
for (int i = 0; i < subjects.size(); i++) {
StudySubjectBean subject = (StudySubjectBean) subjects.get(i);
if (!subject.getStatus().equals(Status.DELETED)) {
subject.setStatus(Status.AUTO_DELETED);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
ssdao.update(subject);
ArrayList events = sedao.findAllByStudySubject(subject);
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.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.setOldStatus(eventCRF.getStatus());
eventCRF.setStatus(Status.AUTO_DELETED);
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.DELETED)) {
item.setOldStatus(item.getStatus());
item.setStatus(Status.AUTO_DELETED);
item.setUpdater(ub);
item.setUpdatedDate(new Date());
iddao.update(item);
}
}
}
}
}
}
}
}
// for subjects
DatasetDAO datadao = new DatasetDAO(sm.getDataSource());
ArrayList dataset = datadao.findAllByStudyId(study.getId());
for (int i = 0; i < dataset.size(); i++) {
DatasetBean data = (DatasetBean) dataset.get(i);
if (!data.getStatus().equals(Status.DELETED)) {
data.setStatus(Status.AUTO_DELETED);
data.setUpdater(ub);
data.setUpdatedDate(new Date());
datadao.update(data);
}
}
addPageMessage(respage.getString("this_site_has_been_removed_succesfully"));
String fromListSite = (String) session.getAttribute("fromListSite");
if (fromListSite != null && fromListSite.equals("yes") && currentRole.getRole().equals(Role.STUDYDIRECTOR)) {
session.removeAttribute("fromListSite");
forwardPage(Page.SITE_LIST_SERVLET);
} else {
session.removeAttribute("fromListSite");
if (currentRole.getRole().equals(Role.ADMIN)) {
forwardPage(Page.STUDY_LIST_SERVLET);
} else {
forwardPage(Page.SITE_LIST_SERVLET);
}
}
}
}
}
use of org.akaza.openclinica.dao.login.UserAccountDAO in project OpenClinica by OpenClinica.
the class ManageStudyServlet method processRequest.
/*
* (non-Javadoc)
*
* @see org.akaza.openclinica.control.core.SecureController#processRequest()
*/
@Override
protected void processRequest() throws Exception {
// for the sake of testing a prototype; 2560
if (!INSTRUCTIONS.isEmpty()) {
INSTRUCTIONS.clear();
}
INSTRUCTIONS.add(restext.getString("director_coordinator_privileges_manage"));
INSTRUCTIONS.add(restext.getString("side_tables_shows_last_modified"));
request.setAttribute("instructions", INSTRUCTIONS);
// show icon keys on the sidebar, and display the instructions and
// alert messages fields
request.setAttribute("showIcons", true);
request.setAttribute("openIcons", true);
request.setAttribute("openAlerts", true);
request.setAttribute("openInstructions", true);
// find last 5 modifed sites
StudyDAO sdao = new StudyDAO(sm.getDataSource());
// ArrayList sites = (ArrayList)
// sdao.findAllByParentAndLimit(currentStudy.getId(),true);
ArrayList allSites = (ArrayList) sdao.findAllByParent(currentStudy.getId());
ArrayList sites = new ArrayList();
for (int i = 0; i < allSites.size(); i++) {
sites.add(allSites.get(i));
if (i == 5) {
break;
}
}
request.setAttribute("sites", sites);
request.setAttribute("sitesCount", new Integer(sites.size()));
request.setAttribute("allSitesCount", new Integer(allSites.size()));
// BWP 3057: add study name to JSP
if (currentStudy != null) {
request.setAttribute("studyIdentifier", currentStudy.getIdentifier());
}
StudyEventDefinitionDAO edao = new StudyEventDefinitionDAO(sm.getDataSource());
ArrayList seds = (ArrayList) edao.findAllByStudyAndLimit(currentStudy.getId());
ArrayList allSeds = edao.findAllByStudy(currentStudy);
request.setAttribute("seds", seds);
request.setAttribute("sedsCount", new Integer(seds.size()));
request.setAttribute("allSedsCount", new Integer(allSeds.size()));
UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
ArrayList users = udao.findAllUsersByStudyIdAndLimit(currentStudy.getId(), true);
ArrayList allUsers = udao.findAllUsersByStudy(currentStudy.getId());
request.setAttribute("users", users);
request.setAttribute("usersCount", new Integer(users.size()));
request.setAttribute("allUsersCount", new Integer(allUsers.size()));
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
// ArrayList subjects = (ArrayList)
// ssdao.findAllByStudyIdAndLimit(currentStudy.getId(),true);
ArrayList allSubjects = ssdao.findAllByStudyId(currentStudy.getId());
ArrayList subjects = new ArrayList();
for (int i = 0; i < allSubjects.size(); i++) {
subjects.add(allSubjects.get(i));
if (i == 5) {
break;
}
}
request.setAttribute("subs", subjects);
request.setAttribute("subsCount", new Integer(subjects.size()));
request.setAttribute("allSubsCount", new Integer(allSubjects.size()));
// added tbh, 9-21-2005
// AuditEventDAO aedao = new AuditEventDAO(sm.getDataSource());
// ArrayList audits = (ArrayList)
// aedao.findAllByStudyIdAndLimit(currentStudy.getId());
// request.setAttribute("audits", audits);
resetPanel();
if (allSubjects.size() > 0) {
setToPanel("Subjects", new Integer(allSubjects.size()).toString());
}
if (allUsers.size() > 0) {
setToPanel("Users", new Integer(allUsers.size()).toString());
}
if (allSites.size() > 0) {
setToPanel("Sites", new Integer(allSites.size()).toString());
}
if (allSeds.size() > 0) {
setToPanel("Event Definitions", new Integer(allSeds.size()).toString());
}
String proto = request.getParameter("proto");
if (proto == null || "".equalsIgnoreCase(proto)) {
forwardPage(Page.MANAGE_STUDY);
} else {
forwardPage(Page.MANAGE_STUDY_BODY);
}
}
Aggregations