Search in sources :

Example 86 with StudyDAO

use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.

the class DownloadAttachedFileServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    String filePathName = "";
    String fileName = fp.getString("fileName");
    File f = new File(fileName);
    if (fileName != null && fileName.length() > 0) {
        int parentStudyId = currentStudy.getParentStudyId();
        String testPath = Utils.getAttachedFileRootPath();
        String tail = File.separator + f.getName();
        String testName = testPath + currentStudy.getOid() + tail;
        File temp = new File(testName);
        if (temp.exists()) {
            filePathName = testName;
            logger.info(currentStudy.getName() + " existing filePathName=" + filePathName);
        } else {
            if (currentStudy.isSite(parentStudyId)) {
                testName = testPath + ((StudyBean) new StudyDAO(sm.getDataSource()).findByPK(parentStudyId)).getOid() + tail;
                temp = new File(testName);
                if (temp.exists()) {
                    filePathName = testName;
                    logger.info("parent existing filePathName=" + filePathName);
                }
            } else {
                ArrayList<StudyBean> sites = (ArrayList<StudyBean>) new StudyDAO(sm.getDataSource()).findAllByParent(currentStudy.getId());
                for (StudyBean s : sites) {
                    testPath = Utils.getAttachedFilePath(s);
                    // + s.getIdentifier() + tail;
                    testName = testPath + tail;
                    File test = new File(testName);
                    if (test.exists()) {
                        filePathName = testName;
                        logger.info("site of currentStudy existing filePathName=" + filePathName);
                        break;
                    }
                }
            }
        }
    }
    logger.info("filePathName=" + filePathName + " fileName=" + fileName);
    File file = new File(filePathName);
    if (!file.exists() || file.length() <= 0) {
        addPageMessage("File " + filePathName + " " + respage.getString("not_exist"));
        // try to use the passed in the existing file
        file = new File(fileName);
    }
    if (!file.exists() || file.length() <= 0) {
        addPageMessage("File " + filePathName + " " + respage.getString("not_exist"));
    } else {
        // response.setContentType("application/octet-stream");
        response.setHeader("Content-disposition", "attachment; filename=\"" + fileName + "\";");
        response.setHeader("Pragma", "public");
        ServletOutputStream outStream = response.getOutputStream();
        DataInputStream inStream = null;
        try {
            response.setContentType("application/download");
            response.setHeader("Cache-Control", "max-age=0");
            response.setContentLength((int) file.length());
            byte[] bbuf = new byte[(int) file.length()];
            inStream = new DataInputStream(new FileInputStream(file));
            int length;
            while (inStream != null && (length = inStream.read(bbuf)) != -1) {
                outStream.write(bbuf, 0, length);
            }
            inStream.close();
            outStream.flush();
            outStream.close();
        } catch (Exception ee) {
            ee.printStackTrace();
        } finally {
            if (inStream != null) {
                inStream.close();
            }
            if (outStream != null) {
                outStream.close();
            }
        }
    }
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) DataInputStream(java.io.DataInputStream) FileInputStream(java.io.FileInputStream) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) File(java.io.File) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 87 with StudyDAO

use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.

the class EnterDataForStudyEventServlet method processRequest.

/*
     * (non-Javadoc)
     *
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
@Override
protected void processRequest() throws Exception {
    // removeLockedCRF(ub.getId());
    getCrfLocker().unlockAllForUser(ub.getId());
    FormProcessor fp = new FormProcessor(request);
    int eventId = fp.getInt(INPUT_EVENT_ID, true);
    request.setAttribute("eventId", eventId + "");
    // so we can display the event for which we're entering data
    StudyEventBean seb = getStudyEvent(eventId);
    // so we can display the subject's label
    StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
    StudySubjectBean studySubjectBean = (StudySubjectBean) ssdao.findByPK(seb.getStudySubjectId());
    int studyId = studySubjectBean.getStudyId();
    StudyDAO studydao = new StudyDAO(sm.getDataSource());
    StudyBean study = (StudyBean) studydao.findByPK(studyId);
    // If the study subject derives from a site, and is being viewed from a
    // parent study,
    // then the study IDs will be different. However, since each note is
    // saved with the specific
    // study ID, then its study ID may be different than the study subject's
    // ID.
    boolean subjectStudyIsCurrentStudy = studyId == currentStudy.getId();
    boolean isParentStudy = study.getParentStudyId() < 1;
    // Get any disc notes for this study event
    DiscrepancyNoteDAO discrepancyNoteDAO = new DiscrepancyNoteDAO(sm.getDataSource());
    ArrayList<DiscrepancyNoteBean> allNotesforSubjectAndEvent = new ArrayList<DiscrepancyNoteBean>();
    // These methods return only parent disc notes
    if (subjectStudyIsCurrentStudy && isParentStudy) {
        allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudyAndId(currentStudy, studySubjectBean.getId());
    } else {
        // findAllStudyEventByStudiesAndSubjectId
        if (!isParentStudy) {
            StudyBean stParent = (StudyBean) studydao.findByPK(study.getParentStudyId());
            allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(stParent, study, studySubjectBean.getId());
        } else {
            allNotesforSubjectAndEvent = discrepancyNoteDAO.findAllStudyEventByStudiesAndSubjectId(currentStudy, study, studySubjectBean.getId());
        }
    }
    if (!allNotesforSubjectAndEvent.isEmpty()) {
        setRequestAttributesForNotes(allNotesforSubjectAndEvent);
    }
    // prepare to figure out what the display should look like
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    ArrayList<EventCRFBean> eventCRFs = ecdao.findAllByStudyEvent(seb);
    ArrayList<Boolean> doRuleSetsExist = new ArrayList<Boolean>();
    RuleSetDAO ruleSetDao = new RuleSetDAO(sm.getDataSource());
    for (EventCRFBean eventCrfBean : eventCRFs) {
    // Boolean result = ruleSetDao.findByEventCrf(eventCrfBean) != null
    // ? Boolean.TRUE : Boolean.FALSE;
    // doRuleSetsExist.add(result);
    }
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    ArrayList eventDefinitionCRFs = (ArrayList) edcdao.findAllActiveByEventDefinitionId(study, seb.getStudyEventDefinitionId());
    // get the event definition CRFs for which no event CRF exists
    // the event definition CRFs must be populated with versions so we can
    // let the user choose which version he will enter data for
    // However, this method seems to be returning DisplayEventDefinitionCRFs
    // that contain valid eventCRFs??
    ArrayList uncompletedEventDefinitionCRFs = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs);
    populateUncompletedCRFsWithCRFAndVersions(uncompletedEventDefinitionCRFs);
    // BWP 2816 << Attempt to provide the DisplayEventDefinitionCRF with a
    // valid owner
    // only if its container eventCRf has a valid id
    populateUncompletedCRFsWithAnOwner(uncompletedEventDefinitionCRFs);
    // >>BWP
    // for the event definition CRFs for which event CRFs exist, get
    // DisplayEventCRFBeans, which the JSP will use to determine what
    // the user will see for each event CRF
    // removing the below row in exchange for the ViewStudySubjectServlet
    // version, for two
    // reasons:
    // 1. concentrate all business logic in one place
    // 2. VSSS seems to handle the javascript creation correctly
    // ArrayList displayEventCRFs = getDisplayEventCRFs(eventCRFs,
    // eventDefinitionCRFs, seb.getSubjectEventStatus());
    ArrayList displayEventCRFs = ViewStudySubjectServlet.getDisplayEventCRFs(sm.getDataSource(), eventCRFs, eventDefinitionCRFs, ub, currentRole, seb.getSubjectEventStatus(), study);
    // Issue 3212 BWP << hide certain CRFs at the site level
    if (currentStudy.getParentStudyId() > 0) {
        HideCRFManager hideCRFManager = HideCRFManager.createHideCRFManager();
        uncompletedEventDefinitionCRFs = hideCRFManager.removeHiddenEventDefinitionCRFBeans(uncompletedEventDefinitionCRFs);
        displayEventCRFs = hideCRFManager.removeHiddenEventCRFBeans(displayEventCRFs);
    }
    // >>
    request.setAttribute(BEAN_STUDY_EVENT, seb);
    request.setAttribute("doRuleSetsExist", doRuleSetsExist);
    request.setAttribute(BEAN_STUDY_SUBJECT, studySubjectBean);
    request.setAttribute(BEAN_UNCOMPLETED_EVENTDEFINITIONCRFS, uncompletedEventDefinitionCRFs);
    request.setAttribute(BEAN_DISPLAY_EVENT_CRFS, displayEventCRFs);
    // @pgawade 31-Aug-2012 fix for issue #15315: Reverting to set the request variable "beans" back
    // this is for generating side info panel
    ArrayList beans = ViewStudySubjectServlet.getDisplayStudyEventsForStudySubject(studySubjectBean, sm.getDataSource(), ub, currentRole);
    request.setAttribute("beans", beans);
    EventCRFBean ecb = new EventCRFBean();
    ecb.setStudyEventId(eventId);
    request.setAttribute("eventCRF", ecb);
    // Make available the study
    request.setAttribute("study", currentStudy);
    forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT);
}
Also used : DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) RuleSetDAO(org.akaza.openclinica.dao.rule.RuleSetDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) HideCRFManager(org.akaza.openclinica.service.crfdata.HideCRFManager) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 88 with StudyDAO

use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.

the class EditFormController method getStudy.

private StudyBean getStudy(Integer id) {
    sdao = new StudyDAO(dataSource);
    StudyBean studyBean = (StudyBean) sdao.findByPK(id);
    return studyBean;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 89 with StudyDAO

use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.

the class IdtViewController method getStudy.

private StudyBean getStudy(Integer id) {
    sdao = new StudyDAO(dataSource);
    StudyBean studyBean = (StudyBean) sdao.findByPK(id);
    return studyBean;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 90 with StudyDAO

use of org.akaza.openclinica.dao.managestudy.StudyDAO in project OpenClinica by OpenClinica.

the class IdtViewController method getStudy.

private StudyBean getStudy(String oid) {
    sdao = new StudyDAO(dataSource);
    StudyBean studyBean = (StudyBean) sdao.findByOid(oid);
    return studyBean;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Aggregations

StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)205 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)184 ArrayList (java.util.ArrayList)116 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)73 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)59 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)57 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)50 Date (java.util.Date)49 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)49 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)47 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)46 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 UserAccountDAO (org.akaza.openclinica.dao.login.UserAccountDAO)43 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)43 HashMap (java.util.HashMap)42 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)39 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)37 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)35 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)34 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)30