Search in sources :

Example 1 with CRFDAO

use of org.akaza.openclinica.dao.admin.CRFDAO in project OpenClinica by OpenClinica.

the class ImportDataHelper method createEventCRF.

public EventCRFBean createEventCRF(HashMap<String, String> importedObject) {
    EventCRFBean eventCrfBean = null;
    int studyEventId = importedObject.get("study_event_id") == null ? -1 : Integer.parseInt(importedObject.get("study_event_id"));
    String crfVersionName = importedObject.get("crf_version_name") == null ? "" : importedObject.get("crf_version_name").toString();
    String crfName = importedObject.get("crf_name") == null ? "" : importedObject.get("crf_name").toString();
    String eventDefinitionCRFName = importedObject.get("event_definition_crf_name") == null ? "" : importedObject.get("event_definition_crf_name").toString();
    String subjectName = importedObject.get("subject_name") == null ? "" : importedObject.get("subject_name").toString();
    String studyName = importedObject.get("study_name") == null ? "" : importedObject.get("study_name").toString();
    logger.info("found the following: study event id " + studyEventId + ", crf version name " + crfVersionName + ", crf name " + crfName + ", event def crf name " + eventDefinitionCRFName + ", subject name " + subjectName + ", study name " + studyName);
    // << tbh
    int eventCRFId = 0;
    EventCRFDAO eventCrfDao = new EventCRFDAO(sm.getDataSource());
    StudyDAO studyDao = new StudyDAO(sm.getDataSource());
    StudySubjectDAO studySubjectDao = new StudySubjectDAO(sm.getDataSource());
    StudyEventDefinitionDAO studyEventDefinistionDao = new StudyEventDefinitionDAO(sm.getDataSource());
    CRFVersionDAO crfVersionDao = new CRFVersionDAO(sm.getDataSource());
    StudyEventDAO studyEventDao = new StudyEventDAO(sm.getDataSource());
    CRFDAO crfdao = new CRFDAO(sm.getDataSource());
    SubjectDAO subjectDao = new SubjectDAO(sm.getDataSource());
    StudyBean studyBean = (StudyBean) studyDao.findByName(studyName);
    // .findByPK(studyId);
    // generate the subject bean first, so that we can have the subject id
    // below...
    SubjectBean subjectBean = // .findByUniqueIdentifierAndStudy(subjectName,
    subjectDao.findByUniqueIdentifier(subjectName);
    StudySubjectBean studySubjectBean = studySubjectDao.findBySubjectIdAndStudy(subjectBean.getId(), studyBean);
    // .findByLabelAndStudy(subjectName, studyBean);
    logger.info("::: found study subject id here: " + studySubjectBean.getId() + " with the following: subject ID " + subjectBean.getId() + " study bean name " + studyBean.getName());
    StudyEventBean studyEventBean = (StudyEventBean) studyEventDao.findByPK(studyEventId);
    // TODO need to replace, can't really replace
    logger.info("found study event status: " + studyEventBean.getStatus().getName());
    // [study] event should be scheduled, event crf should be not started
    CRFVersionBean crfVersion = (CRFVersionBean) crfVersionDao.findByFullName(crfVersionName, crfName);
    // .findByPK(crfVersionId);
    // replaced by findByName(name, version)
    logger.info("found crf version name here: " + crfVersion.getName());
    EntityBean crf = crfdao.findByPK(crfVersion.getCrfId());
    logger.info("found crf name here: " + crf.getName());
    // trying it again up here since down there doesn't seem to work, tbh
    StudyEventDefinitionBean studyEventDefinitionBean = (StudyEventDefinitionBean) studyEventDefinistionDao.findByName(eventDefinitionCRFName);
    if (studySubjectBean.getId() <= 0 && studyEventBean.getId() <= 0 && crfVersion.getId() <= 0 && studyBean.getId() <= 0 && studyEventDefinitionBean.getId() <= 0) {
        logger.info("Throw an Exception, One of the provided ids is not valid");
    }
    // >> tbh repeating items:
    ArrayList eventCrfBeans = eventCrfDao.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersion);
    // TODO repeating items here? not yet
    if (eventCrfBeans.size() > 1) {
        logger.info("found more than one");
    }
    if (!eventCrfBeans.isEmpty() && eventCrfBeans.size() == 1) {
        eventCrfBean = (EventCRFBean) eventCrfBeans.get(0);
        logger.info("This EventCrfBean was found");
    }
    if (!eventCrfBeans.isEmpty() && eventCrfBeans.size() > 1) {
        logger.info("Throw a System exception , result should either be 0 or 1");
    }
    if (eventCrfBean == null) {
        StudyBean studyWithSED = studyBean;
        if (studyBean.getParentStudyId() > 0) {
            studyWithSED = new StudyBean();
            studyWithSED.setId(studyBean.getParentStudyId());
        }
        AuditableEntityBean studyEvent = studyEventDao.findByPKAndStudy(studyEventId, studyWithSED);
        if (studyEvent.getId() <= 0) {
            logger.info("Hello Exception");
        }
        eventCrfBean = new EventCRFBean();
        // eventCrfBean.setCrfVersion(crfVersion);
        if (eventCRFId == 0) {
            // ???
            if (studyBean.getStudyParameterConfig().getInterviewerNameDefault().equals("blank")) {
                eventCrfBean.setInterviewerName("");
            } else {
                // default will be event's owner name
                eventCrfBean.setInterviewerName(studyEventBean.getOwner().getName());
            }
            if (!studyBean.getStudyParameterConfig().getInterviewDateDefault().equals("blank")) {
                if (studyEventBean.getDateStarted() != null) {
                    // default
                    eventCrfBean.setDateInterviewed(studyEventBean.getDateStarted());
                // date
                } else {
                    // logger.info("evnet start date is null, so date
                    // interviewed is null");
                    eventCrfBean.setDateInterviewed(null);
                }
            } else {
                eventCrfBean.setDateInterviewed(null);
            }
            eventCrfBean.setAnnotations("");
            eventCrfBean.setCreatedDate(new Date());
            eventCrfBean.setCRFVersionId(crfVersion.getId());
            // eventCrfBean.setCrfVersion((CRFVersionBean)crfVersion);
            eventCrfBean.setOwner(ub);
            // eventCrfBean.setCrf((CRFBean)crf);
            eventCrfBean.setStatus(Status.AVAILABLE);
            eventCrfBean.setCompletionStatusId(1);
            // problem with the line below
            eventCrfBean.setStudySubjectId(studySubjectBean.getId());
            eventCrfBean.setStudyEventId(studyEventId);
            eventCrfBean.setValidateString("");
            eventCrfBean.setValidatorAnnotations("");
            try {
                eventCrfBean = (EventCRFBean) eventCrfDao.create(eventCrfBean);
            // TODO review
            // eventCrfBean.setCrfVersion((CRFVersionBean)crfVersion);
            // eventCrfBean.setCrf((CRFBean)crf);
            } catch (Exception ee) {
                logger.info(ee.getMessage());
                logger.info("throws with crf version id " + crfVersion.getId() + " and study event id " + studyEventId + " study subject id " + studySubjectBean.getId());
            }
        // note that you need to catch an exception if the numbers are
        // bogus, ie you can throw an error here
        // however, putting the try catch allows you to pass which is
        // also bad
        // logger.info("CREATED EVENT CRF");
        } else {
            // there is an event CRF already, only need to update
            // is the status not started???
            logger.info("*** already-started event CRF with msg: " + eventCrfBean.getStatus().getName());
            if (eventCrfBean.getStatus().equals(Status.PENDING)) {
                logger.info("Not Started???");
            }
            eventCrfBean = (EventCRFBean) eventCrfDao.findByPK(eventCRFId);
            eventCrfBean.setCRFVersionId(crfVersion.getId());
            eventCrfBean.setUpdatedDate(new Date());
            eventCrfBean.setUpdater(ub);
            eventCrfBean = (EventCRFBean) eventCrfDao.update(eventCrfBean);
        // eventCrfBean.setCrfVersion((CRFVersionBean)crfVersion);
        // eventCrfBean.setCrf((CRFBean)crf);
        }
        if (eventCrfBean.getId() <= 0) {
            logger.info("error");
        } else {
            // TODO change status here, tbh
            // 2/08 this part seems to work, tbh
            studyEventBean.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
            studyEventBean.setUpdater(ub);
            studyEventBean.setUpdatedDate(new Date());
            studyEventDao.update(studyEventBean);
        }
    }
    eventCrfBean.setCrfVersion(crfVersion);
    eventCrfBean.setCrf((CRFBean) crf);
    // repeating?
    return eventCrfBean;
}
Also used : EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EntityBean(org.akaza.openclinica.bean.core.EntityBean) AuditableEntityBean(org.akaza.openclinica.bean.core.AuditableEntityBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 2 with CRFDAO

use of org.akaza.openclinica.dao.admin.CRFDAO in project OpenClinica by OpenClinica.

the class BatchCRFMigrationServlet method processRequest.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    ArrayList<CRFVersionBean> crfVersionList = null;
    ArrayList<StudyEventDefinitionBean> eventList = null;
    ArrayList<StudyBean> siteList = null;
    // checks which module the requests are from, manage or admin
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);
    int crfId = fp.getInt(CRF_ID);
    if (crfId == 0) {
        addPageMessage(respage.getString("please_choose_a_CRF_to_view"));
        forwardPage(Page.CRF_LIST);
    } else {
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
        CRFBean crf = (CRFBean) cdao.findByPK(crfId);
        request.setAttribute("crfName", crf.getName());
        ArrayList<CRFVersionBean> versions = (ArrayList<CRFVersionBean>) vdao.findAllByCRF(crfId);
        crfVersionList = new ArrayList<CRFVersionBean>();
        for (CRFVersionBean version : versions) {
            if (version.getStatus().isAvailable())
                crfVersionList.add(version);
        }
        crf.setVersions(crfVersionList);
        ArrayList<StudyBean> listOfSites = (ArrayList<StudyBean>) sdao().findAllByParent(currentStudy.getId());
        siteList = new ArrayList<StudyBean>();
        StudyBean studyBean = new StudyBean();
        studyBean.setOid(currentStudy.getOid());
        studyBean.setName(resterm.getString("Study_Level_Subjects_Only"));
        siteList.add(studyBean);
        for (StudyBean s : listOfSites) {
            if (s.getStatus().isAvailable()) {
                siteList.add(s);
            }
        }
        ArrayList<StudyEventDefinitionBean> listOfDefn = seddao().findAllByStudy(currentStudy);
        eventList = new ArrayList<StudyEventDefinitionBean>();
        for (StudyEventDefinitionBean d : listOfDefn) {
            if (d.getStatus().isAvailable()) {
                eventList.add(d);
            }
        }
        // if coming from change crf version -> display message
        String crfVersionChangeMsg = fp.getString("isFromCRFVersionBatchChange");
        if (crfVersionChangeMsg != null && !crfVersionChangeMsg.equals("")) {
            addPageMessage(crfVersionChangeMsg);
        }
        request.setAttribute("study", currentStudy);
        request.setAttribute("siteList", siteList);
        request.setAttribute("eventList", eventList);
        request.setAttribute(CRF, crf);
        forwardPage(Page.BATCH_CRF_MIGRATION);
    }
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Example 3 with CRFDAO

use of org.akaza.openclinica.dao.admin.CRFDAO in project OpenClinica by OpenClinica.

the class CreateCRFVersionServlet method processRequest.

@SuppressWarnings("unchecked")
@Override
public void processRequest() throws Exception {
    resetPanel();
    panel.setStudyInfoShown(true);
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO vdao = new CRFVersionDAO(sm.getDataSource());
    EventDefinitionCRFDAO edao = new EventDefinitionCRFDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    // keep the module in the session
    session.setAttribute(MODULE, module);
    request.setAttribute("xformEnabled", CoreResources.getField("xform.enabled"));
    String action = request.getParameter("action");
    CRFVersionBean version = (CRFVersionBean) session.getAttribute("version");
    if (StringUtil.isBlank(action)) {
        logger.debug("action is blank");
        request.setAttribute("version", version);
        forwardPage(Page.CREATE_CRF_VERSION);
    } else if ("confirm".equalsIgnoreCase(action)) {
        String dir = SQLInitServlet.getField("filePath");
        if (!new File(dir).exists()) {
            logger.debug("The filePath in datainfo.properties is invalid " + dir);
            addPageMessage(resword.getString("the_filepath_you_defined"));
            forwardPage(Page.CREATE_CRF_VERSION);
            // BWP 01/13/2009 >>
            return;
        // >>
        }
        // All the uploaded files will be saved in filePath/crf/original/
        String theDir = dir + "crf" + File.separator + "original" + File.separator;
        if (!new File(theDir).isDirectory()) {
            new File(theDir).mkdirs();
            logger.debug("Made the directory " + theDir);
        }
        // MultipartRequest multi = new MultipartRequest(request, theDir, 50 * 1024 * 1024);
        String tempFile = "";
        try {
            tempFile = uploadFile(theDir, version);
        } catch (CRFReadingException crfException) {
            Validator.addError(errors, "excel_file", crfException.getMessage());
            String msg = crfException.getMessage();
            request.setAttribute("formMessages", errors);
            forwardPage(Page.CREATE_CRF_VERSION);
            return;
        } catch (Exception e) {
            // 
            logger.warn("*** Found exception during file upload***");
            e.printStackTrace();
        }
        session.setAttribute("tempFileName", tempFile);
        // provided and/or not xls format
        if (errors.isEmpty()) {
            String s = ((NewCRFBean) session.getAttribute("nib")).getVersionName();
            if (s.length() > 255) {
                Validator.addError(errors, "excel_file", resword.getString("the_version_CRF_version_more_than_255"));
            } else if (s.length() <= 0) {
                Validator.addError(errors, "excel_file", resword.getString("the_VERSION_column_was_blank"));
            }
            version.setName(s);
            if (version.getCrfId() == 0) {
                version.setCrfId(fp.getInt("crfId"));
            }
            session.setAttribute("version", version);
        }
        if (!errors.isEmpty()) {
            logger.debug("has validation errors ");
            request.setAttribute("formMessages", errors);
            forwardPage(Page.CREATE_CRF_VERSION);
        } else {
            CRFBean crf = (CRFBean) cdao.findByPK(version.getCrfId());
            ArrayList versions = (ArrayList) vdao.findAllByCRF(crf.getId());
            for (int i = 0; i < versions.size(); i++) {
                CRFVersionBean version1 = (CRFVersionBean) versions.get(i);
                if (version.getName().equals(version1.getName())) {
                    // version already exists
                    logger.debug("Version already exists; owner or not:" + ub.getId() + "," + version1.getOwnerId());
                    if (ub.getId() != version1.getOwnerId()) {
                        // not owner
                        addPageMessage(respage.getString("CRF_version_try_upload_exists_database") + version1.getOwner().getName() + respage.getString("please_contact_owner_to_delete"));
                        forwardPage(Page.CREATE_CRF_VERSION);
                        return;
                    } else {
                        // owner,
                        ArrayList definitions = edao.findByDefaultVersion(version1.getId());
                        if (!definitions.isEmpty()) {
                            // used in
                            // definition
                            request.setAttribute("definitions", definitions);
                            forwardPage(Page.REMOVE_CRF_VERSION_DEF);
                            return;
                        } else {
                            // not used in definition
                            int previousVersionId = version1.getId();
                            version.setId(previousVersionId);
                            session.setAttribute("version", version);
                            session.setAttribute("previousVersionId", new Integer(previousVersionId));
                            forwardPage(Page.REMOVE_CRF_VERSION_CONFIRM);
                            return;
                        }
                    }
                }
            }
            // didn't find same version in the DB,let user upload the excel
            // file
            logger.debug("didn't find same version in the DB,let user upload the excel file.");
            // List excelErr =
            // ((ArrayList)request.getAttribute("excelErrors"));
            List excelErr = (ArrayList) session.getAttribute("excelErrors");
            logger.debug("excelErr.isEmpty()=" + excelErr.isEmpty());
            if (excelErr != null && excelErr.isEmpty()) {
                addPageMessage(resword.getString("congratulations_your_spreadsheet_no_errors"));
                forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PREVIEW);
            } else {
                logger.debug("OpenClinicaException thrown, forwarding to CREATE_CRF_VERSION_CONFIRM.");
                forwardPage(Page.CREATE_CRF_VERSION_CONFIRM);
            }
            return;
        }
    } else if ("confirmsql".equalsIgnoreCase(action)) {
        NewCRFBean nib = (NewCRFBean) session.getAttribute("nib");
        if (nib != null && nib.getItemQueries() != null) {
            request.setAttribute("openQueries", nib.getItemQueries());
        } else {
            request.setAttribute("openQueries", new HashMap());
        }
        boolean canDelete = false;
        // check whether need to delete previous version
        Boolean deletePreviousVersion = (Boolean) session.getAttribute("deletePreviousVersion");
        Integer previousVersionId = (Integer) session.getAttribute("previousVersionId");
        if (deletePreviousVersion != null && deletePreviousVersion.equals(Boolean.TRUE) && previousVersionId != null && previousVersionId.intValue() > 0) {
            logger.debug("Need to delete previous version");
            // whether we can delete
            canDelete = canDeleteVersion(previousVersionId.intValue());
            if (!canDelete) {
                logger.debug("but cannot delete previous version");
                if (session.getAttribute("itemsHaveData") == null && session.getAttribute("eventsForVersion") == null) {
                    addPageMessage(respage.getString("you_are_not_owner_some_items_cannot_delete"));
                }
                if (session.getAttribute("itemsHaveData") == null) {
                    session.setAttribute("itemsHaveData", new ArrayList());
                }
                if (session.getAttribute("eventsForVersion") == null) {
                    session.setAttribute("eventsForVersion", new ArrayList());
                }
                forwardPage(Page.CREATE_CRF_VERSION_NODELETE);
                return;
            }
            ArrayList<ItemBean> nonSharedItems = (ArrayList<ItemBean>) vdao.findNotSharedItemsByVersion(previousVersionId.intValue());
            // htaycher: here is the trick we need to put in nib1.setItemQueries()
            // update statements for shared items and insert for nonShared that were just deleted 5927
            HashMap item_table_statements = new HashMap();
            ArrayList<String> temp = new ArrayList<String>(nonSharedItems.size());
            for (ItemBean item : nonSharedItems) {
                temp.add(item.getName());
                item_table_statements.put(item.getName(), nib.getBackupItemQueries().get(item.getName()));
            }
            for (String item_name : (Set<String>) nib.getItemQueries().keySet()) {
                // check if item shared
                if (!temp.contains(item_name)) {
                    item_table_statements.put(item_name, nib.getItemQueries().get(item_name));
                }
            }
            // statements to run
            if (!nonSharedItems.isEmpty()) {
                request.setAttribute("openQueries", item_table_statements);
            }
            // htaycher: put all statements in
            nib.setItemQueries(item_table_statements);
            session.setAttribute("nib", nib);
        }
        // submit
        logger.debug("commit sql");
        NewCRFBean nib1 = (NewCRFBean) session.getAttribute("nib");
        if (nib1 != null) {
            try {
                if (canDelete) {
                    nib1.deleteInsertToDB();
                } else {
                    nib1.insertToDB();
                }
                request.setAttribute("queries", nib1.getQueries());
                // YW << for add a link to "View CRF Version Data Entry".
                // For this purpose, CRFVersion id is needed.
                // So the latest CRFVersion Id of A CRF Id is it.
                CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
                ArrayList crfvbeans = new ArrayList();
                logger.debug("CRF-ID [" + version.getCrfId() + "]");
                int crfVersionId = 0;
                String versionOID = null;
                if (version.getCrfId() != 0) {
                    crfvbeans = cvdao.findAllByCRFId(version.getCrfId());
                    CRFVersionBean cvbean = (CRFVersionBean) crfvbeans.get(crfvbeans.size() - 1);
                    crfVersionId = cvbean.getId();
                    versionOID = cvbean.getOid();
                    for (Iterator iter = crfvbeans.iterator(); iter.hasNext(); ) {
                        cvbean = (CRFVersionBean) iter.next();
                        if (crfVersionId < cvbean.getId()) {
                            crfVersionId = cvbean.getId();
                        }
                    }
                }
                // Not needed; crfVersionId will be autoboxed in Java 5
                // this was added for the old CVS java compiler
                Integer cfvID = new Integer(crfVersionId);
                if (cfvID == 0) {
                    cfvID = cvdao.findCRFVersionId(nib1.getCrfId(), nib1.getVersionName());
                }
                CRFVersionBean finalVersion = (CRFVersionBean) cvdao.findByPK(cfvID);
                version.setCrfId(nib1.getCrfId());
                version.setOid(finalVersion.getOid());
                CRFBean crfBean = (CRFBean) cdao.findByPK(version.getCrfId());
                crfBean.setUpdatedDate(version.getCreatedDate());
                crfBean.setUpdater(ub);
                cdao.update(crfBean);
                // workaround to get a correct file name below, tbh 06/2008
                request.setAttribute("crfVersionId", cfvID);
                // YW >>
                // return those properties to initial values
                session.removeAttribute("version");
                session.removeAttribute("eventsForVersion");
                session.removeAttribute("itemsHaveData");
                session.removeAttribute("nib");
                session.removeAttribute("deletePreviousVersion");
                session.removeAttribute("previousVersionId");
                // save new version spreadsheet
                String tempFile = (String) session.getAttribute("tempFileName");
                if (tempFile != null) {
                    logger.debug("*** ^^^ *** saving new version spreadsheet" + tempFile);
                    try {
                        String dir = SQLInitServlet.getField("filePath");
                        File f = new File(dir + "crf" + File.separator + "original" + File.separator + tempFile);
                        // check to see whether crf/new/ folder exists
                        // inside, if not,
                        // creates
                        // the crf/new/ folder
                        String finalDir = dir + "crf" + File.separator + "new" + File.separator;
                        if (!new File(finalDir).isDirectory()) {
                            logger.debug("need to create folder for excel files" + finalDir);
                            new File(finalDir).mkdirs();
                        }
                        // String newFile = version.getCrfId() +
                        // version.getName() + ".xls";
                        String newFile = version.getCrfId() + version.getOid() + ".xls";
                        logger.debug("*** ^^^ *** new file: " + newFile);
                        File nf = new File(finalDir + newFile);
                        logger.debug("copying old file " + f.getName() + " to new file " + nf.getName());
                        copy(f, nf);
                    // ?
                    } catch (IOException ie) {
                        logger.debug("==============");
                        addPageMessage(respage.getString("CRF_version_spreadsheet_could_not_saved_contact"));
                    }
                }
                session.removeAttribute("tempFileName");
                session.removeAttribute(MODULE);
                session.removeAttribute("excelErrors");
                session.removeAttribute("htmlTab");
                forwardPage(Page.CREATE_CRF_VERSION_DONE);
            } catch (OpenClinicaException pe) {
                logger.debug("--------------");
                session.setAttribute("excelErrors", nib1.getErrors());
                // request.setAttribute("excelErrors", nib1.getErrors());
                forwardPage(Page.CREATE_CRF_VERSION_ERROR);
            }
        } else {
            forwardPage(Page.CREATE_CRF_VERSION);
        }
    } else if ("delete".equalsIgnoreCase(action)) {
        logger.debug("user wants to delete previous version");
        List excelErr = (ArrayList) session.getAttribute("excelErrors");
        logger.debug("for overwrite CRF version, excelErr.isEmpty()=" + excelErr.isEmpty());
        if (excelErr != null && excelErr.isEmpty()) {
            addPageMessage(resword.getString("congratulations_your_spreadsheet_no_errors"));
            // should be moved to excelErr != null block
            session.setAttribute("deletePreviousVersion", Boolean.TRUE);
            forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PREVIEW);
        } else {
            // should be moved to excelErr != null
            session.setAttribute("deletePreviousVersion", Boolean.FALSE);
            // block
            logger.debug("OpenClinicaException thrown, forwarding to CREATE_CRF_VERSION_CONFIRM.");
            forwardPage(Page.CREATE_CRF_VERSION_CONFIRM);
        }
    }
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) Set(java.util.Set) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CRFReadingException(org.akaza.openclinica.exception.CRFReadingException) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) IOException(java.io.IOException) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) InsufficientPermissionException(org.akaza.openclinica.web.InsufficientPermissionException) CRFReadingException(org.akaza.openclinica.exception.CRFReadingException) IOException(java.io.IOException) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) File(java.io.File)

Example 4 with CRFDAO

use of org.akaza.openclinica.dao.admin.CRFDAO in project OpenClinica by OpenClinica.

the class AdminSystemServlet method processRequest.

// < ResourceBundleresword,resexception;
/*
     * (non-Javadoc)
     *
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
@Override
protected void processRequest() throws Exception {
    // find last 5 modifed studies
    StudyDAO sdao = new StudyDAO(sm.getDataSource());
    ArrayList studies = (ArrayList) sdao.findAllByLimit(true);
    request.setAttribute("studies", studies);
    ArrayList allStudies = (ArrayList) sdao.findAll();
    request.setAttribute("allStudyNumber", new Integer(allStudies.size()));
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList users = (ArrayList) udao.findAllByLimit(true);
    request.setAttribute("users", users);
    ArrayList allUsers = (ArrayList) udao.findAll();
    request.setAttribute("allUserNumber", new Integer(allUsers.size()));
    SubjectDAO subdao = new SubjectDAO(sm.getDataSource());
    ArrayList subjects = (ArrayList) subdao.findAllByLimit(true);
    request.setAttribute("subjects", subjects);
    ArrayList allSubjects = (ArrayList) subdao.findAll();
    request.setAttribute("allSubjectNumber", new Integer(allSubjects.size()));
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    ArrayList crfs = (ArrayList) cdao.findAllByLimit(true);
    request.setAttribute("crfs", crfs);
    ArrayList allCrfs = (ArrayList) cdao.findAll();
    request.setAttribute("allCrfNumber", new Integer(allCrfs.size()));
    resetPanel();
    panel.setOrderedData(true);
    setToPanel(resword.getString("in_the_application"), "");
    if (allSubjects.size() > 0) {
        setToPanel(resword.getString("subjects"), new Integer(allSubjects.size()).toString());
    }
    if (allUsers.size() > 0) {
        setToPanel(resword.getString("users"), new Integer(allUsers.size()).toString());
    }
    if (allStudies.size() > 0) {
        setToPanel(resword.getString("studies"), new Integer(allStudies.size()).toString());
    }
    if (allCrfs.size() > 0) {
        setToPanel(resword.getString("CRFs"), new Integer(allCrfs.size()).toString());
    }
    panel.setStudyInfoShown(false);
    forwardPage(Page.ADMIN_SYSTEM);
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) ArrayList(java.util.ArrayList) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO)

Example 5 with CRFDAO

use of org.akaza.openclinica.dao.admin.CRFDAO in project OpenClinica by OpenClinica.

the class AuditLogStudyServlet method processRequest.

/*
     * (non-Javadoc) Assume that we get the user id automatically. We will jump
     * from the edit user page if the user is an admin, they can get to see the
     * users' log
     * 
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
/*
     * (non-Javadoc) redo this servlet to run the audits per study subject for
     * the study; need to add a studyId param and then use the
     * StudySubjectDAO.findAllByStudyOrderByLabel() method to grab a lot of
     * study subject beans and then return them much like in
     * ViewStudySubjectAuditLogServet.process()
     * 
     * currentStudy instead of studyId?
     */
@Override
protected void processRequest() throws Exception {
    int studyId = currentStudy.getId();
    StudySubjectDAO subdao = new StudySubjectDAO(sm.getDataSource());
    SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
    AuditDAO adao = new AuditDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
    StudyDAO studydao = new StudyDAO(sm.getDataSource());
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    HashMap eventCRFAuditsHashMap = new HashMap();
    HashMap eventsHashMap = new HashMap();
    HashMap studySubjectAuditsHashMap = new HashMap();
    HashMap subjectHashMap = new HashMap();
    ArrayList studySubjects = subdao.findAllByStudyOrderByLabel(currentStudy);
    logger.info("found " + studySubjects.size() + " study subjects");
    request.setAttribute("studySubjects", studySubjects);
    for (int ss = 0; ss < studySubjects.size(); ss++) {
        ArrayList studySubjectAudits = new ArrayList();
        ArrayList eventCRFAudits = new ArrayList();
        StudySubjectBean studySubject = (StudySubjectBean) studySubjects.get(ss);
        // request.setAttribute("studySub"+ss, studySubject);
        SubjectBean subject = (SubjectBean) sdao.findByPK(studySubject.getSubjectId());
        subjectHashMap.put(new Integer(studySubject.getId()), subject);
        // logger.info("just set a subject with a status of
        // "+subject.getStatus().getName());
        // request.setAttribute("subject"+ss, subject);
        StudyBean study = (StudyBean) studydao.findByPK(studySubject.getStudyId());
        request.setAttribute("study", study);
        // hmm, repetitive work?
        // Show both study subject and subject audit events together
        // Study
        studySubjectAudits.addAll(adao.findStudySubjectAuditEvents(studySubject.getId()));
        // subject
        // value
        // changed
        // Global
        studySubjectAudits.addAll(adao.findSubjectAuditEvents(subject.getId()));
        // subject
        // value
        // changed
        studySubjectAuditsHashMap.put(new Integer(studySubject.getId()), studySubjectAudits);
        // request.setAttribute("studySubjectAudits"+ss,
        // studySubjectAudits);
        // Get the list of events
        ArrayList events = sedao.findAllByStudySubject(studySubject);
        for (int i = 0; i < events.size(); i++) {
            // Link study event definitions
            StudyEventBean studyEvent = (StudyEventBean) events.get(i);
            studyEvent.setStudyEventDefinition((StudyEventDefinitionBean) seddao.findByPK(studyEvent.getStudyEventDefinitionId()));
            // Link event CRFs
            studyEvent.setEventCRFs(ecdao.findAllByStudyEvent(studyEvent));
        }
        // for (int i = 0; i < events.size(); i++) {
        // StudyEventBean studyEvent = (StudyEventBean) events.get(i);
        // ArrayList eventCRFs = studyEvent.getEventCRFs();
        // for (int j = 0; j < eventCRFs.size(); j++) {
        // //Link CRF and CRF Versions
        // EventCRFBean eventCRF = (EventCRFBean) eventCRFs.get(j);
        // eventCRF.setCrfVersion((CRFVersionBean)
        // cvdao.findByPK(eventCRF.getCRFVersionId()));
        // eventCRF.setCrf((CRFBean)
        // cdao.findByVersionId(eventCRF.getCRFVersionId()));
        // //Get the event crf audits
        // eventCRFAudits.addAll(adao.findEventCRFAuditEvents(eventCRF.getId()));
        // }
        // }
        eventsHashMap.put(new Integer(studySubject.getId()), events);
    // request.setAttribute("events"+ss, events);
    // eventCRFAuditsHashMap.put(new Integer(studySubject.getId()),
    // eventCRFAudits);
    // request.setAttribute("eventCRFAudits"+ss, eventCRFAudits);
    }
    // request.setAttribute("eventCRFAudits", eventCRFAuditsHashMap);
    request.setAttribute("events", eventsHashMap);
    request.setAttribute("studySubjectAudits", studySubjectAuditsHashMap);
    request.setAttribute("study", currentStudy);
    request.setAttribute("subjects", subjectHashMap);
    // FormProcessor fp = new FormProcessor(request);
    // 
    // AuditEventDAO aeDAO = new AuditEventDAO(sm.getDataSource());
    // ArrayList al = aeDAO.findAllByStudyId(currentStudy.getId());
    // 
    // EntityBeanTable table = fp.getEntityBeanTable();
    // ArrayList allRows = AuditEventStudyRow.generateRowsFromBeans(al);
    // String[] columns = { "Date and Time", "Action", "Entity/Operation",
    // "Record ID", "Changes and Additions","Other Info" };
    // table.setColumns(new ArrayList(Arrays.asList(columns)));
    // table.hideColumnLink(4);
    // table.hideColumnLink(1);
    // table.hideColumnLink(5);
    // table.setQuery("AuditLogUser?userLogId="+userId, new HashMap());
    // String[] columns =
    // {resword.getString("date_and_time"),resword.getString("action_message"),
    // resword.getString("entity_operation"),
    // resword.getString("updated_by"),resword.getString("subject_unique_ID"),resword.getString("changes_and_additions"),
    // //"Other Info",
    // resword.getString("actions")};
    // table.setColumns(new ArrayList(Arrays.asList(columns)));
    // table.setAscendingSort(false);
    // table.hideColumnLink(1);
    // table.hideColumnLink(5);
    // table.hideColumnLink(6);
    // //table.hideColumnLink(7);
    // table.setQuery("AuditLogStudy", new HashMap());
    // table.setRows(allRows);
    // table.computeDisplay();
    // 
    // 
    // request.setAttribute("table", table);
    logger.warn("*** found servlet, sending to page ***");
    String pattn = "";
    String pattern2 = "";
    pattn = ResourceBundleProvider.getFormatBundle().getString("date_format_string");
    pattern2 = ResourceBundleProvider.getFormatBundle().getString("date_time_format_string");
    request.setAttribute("dateFormatPattern", pattn);
    request.setAttribute("dateTimeFormatPattern", pattern2);
    forwardPage(Page.AUDIT_LOG_STUDY);
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) 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) AuditDAO(org.akaza.openclinica.dao.admin.AuditDAO) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Aggregations

CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)98 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)78 ArrayList (java.util.ArrayList)77 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)68 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)59 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)56 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)54 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)52 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)51 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)49 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)47 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)46 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)41 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)36 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)34 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)31 HashMap (java.util.HashMap)29 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)27 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)23 Date (java.util.Date)21