use of org.akaza.openclinica.bean.submit.SubjectBean 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.SubjectBean in project OpenClinica by OpenClinica.
the class StudyAuditLogTableFactory method setDataAndLimitVariables.
@Override
public void setDataAndLimitVariables(TableFacade tableFacade) {
// initialize i18n
resword = ResourceBundleProvider.getWordsBundle(getLocale());
resformat = ResourceBundleProvider.getFormatBundle(getLocale());
Limit limit = tableFacade.getLimit();
StudyAuditLogFilter auditLogStudyFilter = getAuditLogStudyFilter(limit);
if (!limit.isComplete()) {
int totalRows = getStudySubjectDao().getCountWithFilter(auditLogStudyFilter, getCurrentStudy());
tableFacade.setTotalRows(totalRows);
}
StudyAuditLogSort auditLogStudySort = getAuditLogStudySort(limit);
/*
* if (auditLogStudySort.getSorts().size() == 0) {
* auditLogStudySort.addSort("loginAttemptDate", "desc"); }
*/
int rowStart = limit.getRowSelect().getRowStart();
int rowEnd = limit.getRowSelect().getRowEnd();
Collection<StudySubjectBean> items = getStudySubjectDao().getWithFilterAndSort(getCurrentStudy(), auditLogStudyFilter, auditLogStudySort, rowStart, rowEnd);
Collection<HashMap<Object, Object>> theItems = new ArrayList<HashMap<Object, Object>>();
for (StudySubjectBean studySubjectBean : items) {
SubjectBean subject = (SubjectBean) getSubjectDao().findByPK(studySubjectBean.getSubjectId());
UserAccountBean owner = (UserAccountBean) getUserAccountDao().findByPK(studySubjectBean.getOwnerId());
HashMap<Object, Object> h = new HashMap<Object, Object>();
h.put("studySubject", studySubjectBean);
h.put("studySubject.label", studySubjectBean.getLabel());
h.put("studySubject.secondaryLabel", studySubjectBean.getSecondaryLabel());
h.put("studySubject.oid", studySubjectBean.getOid());
h.put("studySubject.owner", owner);
h.put("studySubject.status", studySubjectBean.getStatus());
h.put("subject", subject);
h.put("subject.dateOfBirth", resolveBirthDay(subject.getDateOfBirth(), subject.isDobCollected(), getLocale()));
h.put("subject.uniqueIdentifier", subject.getUniqueIdentifier());
theItems.add(h);
}
tableFacade.setItems(theItems);
}
use of org.akaza.openclinica.bean.submit.SubjectBean 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.submit.SubjectBean 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.submit.SubjectBean in project OpenClinica by OpenClinica.
the class AuditEventDAO method setStudyAndSubjectInfo.
public AuditEventBean setStudyAndSubjectInfo(AuditEventBean aeb) {
if (aeb.getStudyId() > 0) {
StudyDAO sdao = new StudyDAO(this.ds);
StudyBean sbean = (StudyBean) sdao.findByPK(aeb.getStudyId());
aeb.setStudyName(sbean.getName());
}
if (aeb.getSubjectId() > 0) {
SubjectBean subbean = new SubjectBean();
SubjectDAO subdao = new SubjectDAO(this.ds);
subbean = (SubjectBean) subdao.findByPK(aeb.getSubjectId());
aeb.setSubjectName(subbean.getName());
}
if (aeb.getUserId() > 0) {
UserAccountBean updater = new UserAccountBean();
UserAccountDAO uadao = new UserAccountDAO(this.ds);
updater = (UserAccountBean) uadao.findByPK(aeb.getUserId());
aeb.setUpdater(updater);
}
return aeb;
}
Aggregations