use of org.akaza.openclinica.bean.submit.SubjectGroupMapBean in project OpenClinica by OpenClinica.
the class ReassignStudySubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
String action = request.getParameter("action");
StudyDAO sdao = new StudyDAO(sm.getDataSource());
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
SubjectDAO subdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int studySubId = fp.getInt("id");
if (studySubId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_to_reassign"));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
return;
} else {
StudySubjectBean studySub = (StudySubjectBean) ssdao.findByPK(studySubId);
int subjectId = studySub.getSubjectId();
request.setAttribute("studySub", studySub);
SubjectBean subject = (SubjectBean) subdao.findByPK(subjectId);
request.setAttribute("subject", subject);
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
ArrayList groupMaps = (ArrayList) sgmdao.findAllByStudySubject(studySubId);
if (StringUtil.isBlank(action)) {
ArrayList studies = null;
DisplayStudyBean displayStudy = new DisplayStudyBean();
StudyBean study = (StudyBean) sdao.findByPK(studySub.getStudyId());
if (study.getParentStudyId() > 0) {
// current in site
studies = (ArrayList) sdao.findAllByParent(study.getParentStudyId());
StudyBean parent = (StudyBean) sdao.findByPK(study.getParentStudyId());
displayStudy.setParent(parent);
// studies.add(parent);
displayStudy.setChildren(studies);
} else {
studies = (ArrayList) sdao.findAllByParent(study.getId());
displayStudy.setParent(study);
displayStudy.setChildren(studies);
// studies.add(study);
}
// request.setAttribute("studies", studies);
request.setAttribute("displayStudy", displayStudy);
forwardPage(Page.REASSIGN_STUDY_SUBJECT);
} else {
int studyId = fp.getInt("studyId");
if (studyId == 0) {
addPageMessage(respage.getString("please_choose_a_study_site_to_reassign_the_subject"));
forwardPage(Page.REASSIGN_STUDY_SUBJECT);
return;
}
StudyBean st = (StudyBean) sdao.findByPK(studyId);
if ("confirm".equalsIgnoreCase(action)) {
StudySubjectBean sub1 = (StudySubjectBean) ssdao.findAnotherBySameLabel(studySub.getLabel(), studyId, studySub.getId());
if (sub1.getId() > 0) {
addPageMessage(respage.getString("the_study_subject_ID_used_by_another_in_study_site"));
forwardPage(Page.REASSIGN_STUDY_SUBJECT);
return;
}
// YW << comment out this message
// if (groupMaps.size() > 0) {
// addPageMessage("Warning: This subject has Group data
// assoicated with current study,"
// + "the group data will be lost if it is reassigned to
// another study.");
// }
// YW >>
request.setAttribute("newStudy", st);
forwardPage(Page.REASSIGN_STUDY_SUBJECT_CONFIRM);
} else {
logger.info("submit to reassign the subject");
studySub.setUpdatedDate(new Date());
studySub.setUpdater(ub);
studySub.setStudyId(studyId);
ssdao.update(studySub);
for (int i = 0; i < groupMaps.size(); i++) {
SubjectGroupMapBean sgm = (SubjectGroupMapBean) groupMaps.get(i);
sgm.setUpdatedDate(new Date());
sgm.setUpdater(ub);
sgm.setStatus(Status.DELETED);
sgmdao.update(sgm);
}
MessageFormat mf = new MessageFormat("");
mf.applyPattern(respage.getString("subject_reassigned"));
Object[] arguments = { studySub.getLabel(), st.getName() };
addPageMessage(mf.format(arguments));
forwardPage(Page.LIST_STUDY_SUBJECTS_SERVLET);
}
}
}
}
use of org.akaza.openclinica.bean.submit.SubjectGroupMapBean in project OpenClinica by OpenClinica.
the class RemoveSubjectGroupClassServlet method processRequest.
@Override
public void processRequest() throws Exception {
String action = request.getParameter("action");
FormProcessor fp = new FormProcessor(request);
int classId = fp.getInt("id");
if (classId == 0) {
addPageMessage(respage.getString("please_choose_a_subject_group_class_to_remove"));
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
} else {
StudyGroupClassDAO sgcdao = new StudyGroupClassDAO(sm.getDataSource());
StudyGroupDAO sgdao = new StudyGroupDAO(sm.getDataSource());
SubjectGroupMapDAO sgmdao = new SubjectGroupMapDAO(sm.getDataSource());
if (action.equalsIgnoreCase("confirm")) {
StudyGroupClassBean sgcb = (StudyGroupClassBean) sgcdao.findByPK(classId);
if (sgcb.getStatus().equals(Status.DELETED)) {
addPageMessage(respage.getString("this_subject_group_class_has_been_deleted_already"));
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
return;
}
ArrayList groups = sgdao.findAllByGroupClass(sgcb);
for (int i = 0; i < groups.size(); i++) {
StudyGroupBean sg = (StudyGroupBean) groups.get(i);
ArrayList subjectMaps = sgmdao.findAllByStudyGroupClassAndGroup(sgcb.getId(), sg.getId());
sg.setSubjectMaps(subjectMaps);
}
session.setAttribute("group", sgcb);
session.setAttribute("studyGroups", groups);
forwardPage(Page.REMOVE_SUBJECT_GROUP_CLASS);
} else if (action.equalsIgnoreCase("submit")) {
StudyGroupClassBean group = (StudyGroupClassBean) session.getAttribute("group");
group.setStatus(Status.DELETED);
group.setUpdater(ub);
sgcdao.update(group);
ArrayList subjectMaps = sgmdao.findAllByStudyGroupClassId(group.getId());
for (int i = 0; i < subjectMaps.size(); i++) {
SubjectGroupMapBean sgmb = (SubjectGroupMapBean) subjectMaps.get(i);
if (!sgmb.getStatus().equals(Status.DELETED)) {
sgmb.setStatus(Status.AUTO_DELETED);
sgmb.setUpdater(ub);
sgmdao.update(sgmb);
}
}
addPageMessage(respage.getString("this_subject_group_class_was_removed_succesfully"));
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
} else {
addPageMessage(respage.getString("no_action_specified"));
forwardPage(Page.SUBJECT_GROUP_CLASS_LIST_SERVLET);
}
}
}
Aggregations