Search in sources :

Example 61 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.

the class CRFVersionDAO method buildCrfVersionById.

/**
     * 
     * @param studySubjectId
     * @return
     */
public Map<Integer, CRFVersionBean> buildCrfVersionById(Integer studySubjectId) {
    // <== Must be called first
    this.setTypesExpected();
    Map<Integer, CRFVersionBean> result = new HashMap<Integer, CRFVersionBean>();
    HashMap<Integer, Object> param = new HashMap<Integer, Object>();
    int i = 1;
    param.put(i++, studySubjectId);
    List selectResult = select(digester.getQuery("buildCrfVersionById"), param);
    Iterator it = selectResult.iterator();
    while (it.hasNext()) {
        CRFVersionBean bean = (CRFVersionBean) this.getEntityFromHashMap((HashMap) it.next());
        result.put(bean.getId(), bean);
    }
    return result;
}
Also used : HashMap(java.util.HashMap) Iterator(java.util.Iterator) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ArrayList(java.util.ArrayList) List(java.util.List)

Example 62 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.

the class CRFVersionDAO method findDefCRFVersionsByStudyEvent.

public ArrayList findDefCRFVersionsByStudyEvent(int studyEventDefinitionId) {
    this.setTypesExpected();
    HashMap variables = new HashMap();
    variables.put(new Integer(1), new Integer(studyEventDefinitionId));
    String sql = digester.getQuery("findDefCRFVersionsByStudyEvent");
    ArrayList alist = this.select(sql, variables);
    ArrayList al = new ArrayList();
    Iterator it = alist.iterator();
    while (it.hasNext()) {
        CRFVersionBean eb = (CRFVersionBean) this.getEntityFromHashMap((HashMap) it.next());
        al.add(eb);
    }
    return al;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Example 63 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.

the class CRFVersionDAO method findByOid.

public CRFVersionBean findByOid(String oid) {
    CRFVersionBean crfVersionBean = new CRFVersionBean();
    this.unsetTypeExpected();
    setTypesExpected();
    HashMap variables = new HashMap();
    variables.put(new Integer(1), oid);
    String sql = digester.getQuery("findByOID");
    ArrayList rows = this.select(sql, variables);
    Iterator it = rows.iterator();
    if (it.hasNext()) {
        crfVersionBean = (CRFVersionBean) this.getEntityFromHashMap((HashMap) it.next());
        return crfVersionBean;
    } else {
        return null;
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Example 64 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.

the class DeleteCRFVersionServlet method processRequest.

@Override
public void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    int versionId = fp.getInt(VERSION_ID, true);
    String action = request.getParameter("action");
    if (versionId == 0) {
        addPageMessage(respage.getString("please_choose_a_CRF_version_to_delete"));
        forwardPage(Page.CRF_LIST_SERVLET);
    } else {
        CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
        CRFDAO cdao = new CRFDAO(sm.getDataSource());
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
        StudyEventDAO seDao = new StudyEventDAO(sm.getDataSource());
        ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
        EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        CRFVersionBean version = (CRFVersionBean) cvdao.findByPK(versionId);
        // find definitions using this version
        ArrayList definitions = edcdao.findByDefaultVersion(version.getId());
        for (Object edcBean : definitions) {
            StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(((EventDefinitionCRFBean) edcBean).getStudyEventDefinitionId());
            ((EventDefinitionCRFBean) edcBean).setEventName(sedBean.getName());
        }
        // find event crfs using this version
        ArrayList<ItemDataBean> idBeans = iddao.findByCRFVersion(version);
        ArrayList<EventCRFBean> eCRFs = ecdao.findAllByCRF(version.getCrfId());
        for (EventCRFBean eCRF : eCRFs) {
            StudySubjectBean ssBean = (StudySubjectBean) ssdao.findByPK(eCRF.getStudySubjectId());
            eCRF.setStudySubject(ssBean);
            StudyEventBean seBean = (StudyEventBean) seDao.findByPK(eCRF.getStudyEventId());
            StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) sedDao.findByPK(seBean.getStudyEventDefinitionId());
            seBean.setStudyEventDefinition(sedBean);
            eCRF.setStudyEvent(seBean);
        }
        ArrayList eventCRFs = ecdao.findAllByCRFVersion(versionId);
        boolean canDelete = true;
        if (!definitions.isEmpty()) {
            // used in definition
            canDelete = false;
            request.setAttribute("definitions", definitions);
            addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_study_events_definitions_cannot_delete"));
        } else if (!idBeans.isEmpty()) {
            canDelete = false;
            request.setAttribute("eventCRFs", eCRFs);
            request.setAttribute("itemDataForVersion", idBeans);
            addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_item_data_cannot_delete"));
        } else if (!eventCRFs.isEmpty()) {
            canDelete = false;
            request.setAttribute("eventsForVersion", eventCRFs);
            addPageMessage(respage.getString("this_CRF_version") + " " + version.getName() + respage.getString("has_associated_study_events_cannot_delete"));
        }
        if ("confirm".equalsIgnoreCase(action)) {
            request.setAttribute(VERSION_TO_DELETE, version);
            forwardPage(Page.DELETE_CRF_VERSION);
        } else {
            // submit
            if (canDelete) {
                ArrayList items = cvdao.findNotSharedItemsByVersion(versionId);
                NewCRFBean nib = new NewCRFBean(sm.getDataSource(), version.getCrfId());
                nib.setDeleteQueries(cvdao.generateDeleteQueries(versionId, items));
                nib.deleteFromDB();
                addPageMessage(respage.getString("the_CRF_version_has_been_deleted_succesfully"));
            } else {
                addPageMessage(respage.getString("the_CRF_version_cannot_be_deleted"));
            }
            forwardPage(Page.CRF_LIST_SERVLET);
        }
    }
}
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) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) NewCRFBean(org.akaza.openclinica.bean.admin.NewCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 65 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean in project OpenClinica by OpenClinica.

the class CreateCRFServlet method processRequest.

@Override
public void processRequest() throws Exception {
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    String action = request.getParameter("action");
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    request.setAttribute(MODULE, module);
    request.setAttribute("xformEnabled", CoreResources.getField("xform.enabled"));
    // add the list here so that users can tell about crf creation
    // process together with workflow, tbh
    resetPanel();
    panel.setStudyInfoShown(false);
    panel.setOrderedData(true);
    setToPanel(resword.getString("create_CRF"), respage.getString("br_create_new_CRF_entering"));
    setToPanel(resword.getString("create_CRF_version"), respage.getString("br_create_new_CRF_uploading"));
    setToPanel(resword.getString("revise_CRF_version"), respage.getString("br_if_you_owner_CRF_version"));
    setToPanel(resword.getString("CRF_spreadsheet_template"), respage.getString("br_download_blank_CRF_spreadsheet_from"));
    setToPanel(resword.getString("example_CRF_br_spreadsheets"), respage.getString("br_download_example_CRF_instructions_from"));
    if (StringUtil.isBlank(action)) {
        session.setAttribute("crf", new CRFBean());
        forwardPage(Page.CREATE_CRF);
    } else {
        if ("confirm".equalsIgnoreCase(action)) {
            Validator v = new Validator(request);
            v.addValidation("name", Validator.NO_BLANKS);
            String name = fp.getString("name");
            String description = fp.getString("description");
            CRFBean crf = new CRFBean();
            crf.setName(name.trim());
            crf.setDescription(description.trim());
            session.setAttribute("crf", crf);
            errors = v.validate();
            if (fp.getString("name").trim().length() > 255) {
                Validator.addError(errors, "name", resexception.getString("maximum_length_name_255"));
            }
            if (fp.getString("description").trim().length() > 2048) {
                Validator.addError(errors, "description", resexception.getString("maximum_length_description_255"));
            }
            if (!errors.isEmpty()) {
                logger.info("has validation errors in the first section");
                request.setAttribute("formMessages", errors);
                forwardPage(Page.CREATE_CRF);
            } else {
                CRFBean crf1 = (CRFBean) cdao.findByName(name.trim());
                if (crf1.getId() > 0) {
                    Validator.addError(errors, "name", resexception.getString("CRF_name_used_choose_unique_name"));
                    request.setAttribute("formMessages", errors);
                    forwardPage(Page.CREATE_CRF);
                } else {
                    crf = (CRFBean) session.getAttribute("crf");
                    logger.info("The crf to be saved:" + crf.getName());
                    crf.setOwner(ub);
                    crf.setCreatedDate(new Date());
                    crf.setStatus(Status.AVAILABLE);
                    crf.setStudyId(currentStudy.getId());
                    cdao.create(crf);
                    crf = (CRFBean) cdao.findByName(crf.getName());
                    CRFVersionBean version = new CRFVersionBean();
                    version.setCrfId(crf.getId());
                    session.setAttribute("version", version);
                    session.setAttribute("crfName", crf.getName());
                    session.removeAttribute("crf");
                    forwardPage(Page.CREATE_CRF_VERSION);
                }
            }
        }
    }
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) Validator(org.akaza.openclinica.control.form.Validator) Date(java.util.Date) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Aggregations

CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)100 ArrayList (java.util.ArrayList)70 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)61 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)54 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)53 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)46 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)44 HashMap (java.util.HashMap)38 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)37 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)36 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)36 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)33 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)32 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)30 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)30 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)29 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)25 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)22 Iterator (java.util.Iterator)20 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)20