use of org.akaza.openclinica.dao.submit.SubjectDAO 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;
}
use of org.akaza.openclinica.dao.submit.SubjectDAO in project OpenClinica by OpenClinica.
the class RestoreSubjectServlet method processRequest.
@Override
public void processRequest() throws Exception {
SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
FormProcessor fp = new FormProcessor(request);
int subjectId = fp.getInt("id");
String action = fp.getString("action");
if (subjectId == 0 || StringUtil.isBlank(action)) {
addPageMessage(respage.getString("please_choose_a_subject_to_restore"));
forwardPage(Page.SUBJECT_LIST_SERVLET);
} else {
SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
// find all study subjects
StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
ArrayList studySubs = ssdao.findAllBySubjectId(subjectId);
// find study events
StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
ArrayList events = sedao.findAllBySubjectId(subjectId);
if ("confirm".equalsIgnoreCase(action)) {
request.setAttribute("subjectToRestore", subject);
request.setAttribute("studySubs", studySubs);
request.setAttribute("events", events);
forwardPage(Page.RESTORE_SUBJECT);
} else {
logger.info("submit to restore the subject");
// change all statuses to AVAILABLE
subject.setStatus(Status.AVAILABLE);
subject.setUpdater(ub);
subject.setUpdatedDate(new Date());
sdao.update(subject);
// remove subject references from study
for (int i = 0; i < studySubs.size(); i++) {
StudySubjectBean studySub = (StudySubjectBean) studySubs.get(i);
if (studySub.getStatus().equals(Status.AUTO_DELETED)) {
studySub.setStatus(Status.AVAILABLE);
studySub.setUpdater(ub);
studySub.setUpdatedDate(new Date());
ssdao.update(studySub);
}
}
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++) {
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);
// restore 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_succesfully");
addPageMessage(emailBody);
// sendEmail(emailBody);
forwardPage(Page.SUBJECT_LIST_SERVLET);
}
}
}
Aggregations