Search in sources :

Example 31 with SubjectDAO

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;
}
Also used : SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 32 with SubjectDAO

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);
        }
    }
}
Also used : StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Aggregations

SubjectDAO (org.akaza.openclinica.dao.submit.SubjectDAO)32 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)27 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)27 SubjectBean (org.akaza.openclinica.bean.submit.SubjectBean)25 ArrayList (java.util.ArrayList)23 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)22 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)21 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)21 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)20 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)18 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)18 Date (java.util.Date)16 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)15 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)15 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)12 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)11 DiscrepancyNoteDAO (org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO)11 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)11 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)11 HashMap (java.util.HashMap)10