Search in sources :

Example 26 with FormLayoutBean

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

the class FormLayoutDAO method create.

public EntityBean create(EntityBean eb) {
    // "INSERT INTO CRF_VERSION (NAME, DESCRIPTION, CRF_ID, STATUS_ID,DATE_CREATED," +
    // "OWNER_ID,REVISION_NOTES,OC_OID) "
    // + "VALUES ('" + stripQuotes(version) + "','" + stripQuotes(versionDesc) + "'," +
    // "(SELECT CRF_ID FROM CRF WHERE NAME='"
    // + crfName + "'),1,NOW()," + ub.getId() + ",'" + stripQuotes(revisionNotes) + "','" + oid + "')";
    // <sql>INSERT INTO CRF_VERSION (CRF_ID, STATUS_ID, NAME,
    // DESCRIPTION, OWNER_ID,
    // DATE_CREATED, REVISION_NOTES)
    // VALUES (?,?,?,?,?,NOW(),?)</sql>
    FormLayoutBean cvb = (FormLayoutBean) eb;
    HashMap variables = new HashMap();
    // variables.put(Integer.valueOf(2), cb.getLabel());
    variables.put(Integer.valueOf(1), Integer.valueOf(cvb.getCrfId()));
    variables.put(Integer.valueOf(2), Integer.valueOf(cvb.getStatus().getId()));
    variables.put(Integer.valueOf(3), cvb.getName());
    variables.put(Integer.valueOf(4), cvb.getDescription());
    variables.put(Integer.valueOf(5), Integer.valueOf(cvb.getOwner().getId()));
    variables.put(Integer.valueOf(6), cvb.getRevisionNotes());
    variables.put(Integer.valueOf(7), getValidOid(cvb, cvb.getName(), cvb.getOid()));
    variables.put(Integer.valueOf(8), cvb.getXform());
    variables.put(Integer.valueOf(9), cvb.getXformName());
    variables.put(Integer.valueOf(10), cvb.getUrl());
    // am i the only one who runs their daos' unit tests after I change
    // things, tbh?
    this.execute(digester.getQuery("create"), variables);
    if (isQuerySuccessful()) {
        cvb.setActive(true);
    }
    return cvb;
}
Also used : HashMap(java.util.HashMap) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean)

Example 27 with FormLayoutBean

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

the class StudySubjectServiceImpl method getDisplayStudyEventsForStudySubject.

@Override
@SuppressWarnings({ "unchecked", "rawtypes" })
public List<DisplayStudyEventBean> getDisplayStudyEventsForStudySubject(StudySubjectBean studySubject, UserAccountBean userAccount, StudyUserRoleBean currentRole) {
    StudyEventDAO studyEventDao = new StudyEventDAO(dataSource);
    StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(dataSource);
    StudyDAO studyDao = new StudyDAO(dataSource);
    EventDefinitionCRFDAO eventDefinitionCrfDao = new EventDefinitionCRFDAO(dataSource);
    EventCRFDAO eventCrfDao = new EventCRFDAO(dataSource);
    CRFDAO crfDao = new CRFDAO(dataSource);
    FormLayoutDAO formLayoutDAO = new FormLayoutDAO(dataSource);
    ArrayList events = studyEventDao.findAllByStudySubject(studySubject);
    Map<Integer, StudyEventDefinitionBean> eventDefinitionByEvent = studyEventDefinitionDao.findByStudySubject(studySubject.getId());
    StudyBean study = (StudyBean) studyDao.findByPK(studySubject.getStudyId());
    Map<Integer, SortedSet<EventDefinitionCRFBean>> eventDefinitionCrfByStudyEventDefinition;
    if (study.getParentStudyId() < 1) {
        // Is a study
        eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinitionForStudy(studySubject.getId());
    } else {
        // Is a site
        eventDefinitionCrfByStudyEventDefinition = eventDefinitionCrfDao.buildEventDefinitionCRFListByStudyEventDefinition(studySubject.getId(), study.getId(), study.getParentStudyId());
    }
    Map<Integer, SortedSet<EventCRFBean>> eventCrfListByStudyEvent = eventCrfDao.buildEventCrfListByStudyEvent(studySubject.getId());
    Map<Integer, Integer> maxOrdinalByStudyEvent = studyEventDefinitionDao.buildMaxOrdinalByStudyEvent(studySubject.getId());
    Set<Integer> nonEmptyEventCrf = eventCrfDao.buildNonEmptyEventCrfIds(studySubject.getId());
    Map<Integer, FormLayoutBean> formLayoutById = formLayoutDAO.buildFormLayoutById(studySubject.getId());
    Map<Integer, CRFBean> crfById = crfDao.buildCrfById(studySubject.getId());
    ArrayList<DisplayStudyEventBean> displayEvents = new ArrayList<DisplayStudyEventBean>();
    for (int i = 0; i < events.size(); i++) {
        StudyEventBean event = (StudyEventBean) events.get(i);
        StudyEventDefinitionBean sed = eventDefinitionByEvent.get(event.getStudyEventDefinitionId());
        event.setStudyEventDefinition(sed);
        List eventDefinitionCRFs = new ArrayList((eventDefinitionCrfByStudyEventDefinition.containsKey(sed.getId()) ? eventDefinitionCrfByStudyEventDefinition.get(sed.getId()) : Collections.EMPTY_LIST));
        List eventCRFs = new ArrayList((eventCrfListByStudyEvent.containsKey(event.getId())) ? eventCrfListByStudyEvent.get(event.getId()) : Collections.EMPTY_LIST);
        // construct info needed on view study event page
        DisplayStudyEventBean de = new DisplayStudyEventBean();
        de.setStudyEvent(event);
        de.setDisplayEventCRFs((ArrayList<DisplayEventCRFBean>) getDisplayEventCRFs(eventCRFs, userAccount, currentRole, event.getSubjectEventStatus(), study, nonEmptyEventCrf, formLayoutById, crfById, event.getStudyEventDefinitionId(), eventDefinitionCRFs));
        ArrayList<DisplayEventDefinitionCRFBean> al = getUncompletedCRFs(eventDefinitionCRFs, eventCRFs, event.getSubjectEventStatus(), nonEmptyEventCrf, formLayoutById, crfById);
        populateUncompletedCRFsWithCRFAndVersions(al, formLayoutById, crfById);
        de.setUncompletedCRFs(al);
        // de.setMaximumSampleOrdinal(studyEventDao.getMaxSampleOrdinal(sed,
        // studySubject));
        de.setMaximumSampleOrdinal(maxOrdinalByStudyEvent.get(event.getStudyEventDefinitionId()));
        displayEvents.add(de);
    // event.setEventCRFs(createAllEventCRFs(eventCRFs,
    // eventDefinitionCRFs));
    }
    return displayEvents;
}
Also used : ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) SortedSet(java.util.SortedSet) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) List(java.util.List) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) DisplayStudyEventBean(org.akaza.openclinica.bean.managestudy.DisplayStudyEventBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean)

Example 28 with FormLayoutBean

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

the class StudySubjectServiceImpl method getDisplayEventCRFs.

private List<DisplayEventCRFBean> getDisplayEventCRFs(List eventCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status, StudyBean study, Set<Integer> nonEmptyEventCrf, Map<Integer, FormLayoutBean> formLayoutById, Map<Integer, CRFBean> crfById, Integer studyEventDefinitionId, List eventDefinitionCRFs) {
    ArrayList<DisplayEventCRFBean> answer = new ArrayList<DisplayEventCRFBean>();
    for (int i = 0; i < eventCRFs.size(); i++) {
        EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
        // populate the event CRF with its crf bean
        int formLayoutId = ecb.getFormLayoutId();
        FormLayoutBean flb = formLayoutById.get(formLayoutId);
        ecb.setFormLayout(flb);
        CRFBean cb = crfById.get(flb.getCrfId());
        ecb.setCrf(cb);
        EventDefinitionCRFBean edc = null;
        Iterator it = eventDefinitionCRFs.iterator();
        while (it.hasNext()) {
            EventDefinitionCRFBean edcBean = (EventDefinitionCRFBean) it.next();
            if (edcBean.getCrfId() == cb.getId()) {
                edc = edcBean;
                break;
            }
        }
        // rules updated 112007 tbh
        if (status.equals(SubjectEventStatus.LOCKED) || status.equals(SubjectEventStatus.SKIPPED) || status.equals(SubjectEventStatus.STOPPED)) {
            ecb.setStage(DataEntryStage.LOCKED);
        // we need to set a SED-wide flag here, because other edcs
        // in this event can be filled in and change the status, tbh
        } else if (status.equals(SubjectEventStatus.INVALID)) {
            ecb.setStage(DataEntryStage.LOCKED);
        } else if (!cb.getStatus().equals(Status.AVAILABLE)) {
            ecb.setStage(DataEntryStage.LOCKED);
        } else if (!flb.getStatus().equals(Status.AVAILABLE)) {
            ecb.setStage(DataEntryStage.LOCKED);
        }
        // TODO need to refactor since this is similar to other code, tbh
        if (edc != null) {
            // System.out.println("edc is not null, need to set flags");
            DisplayEventCRFBean dec = new DisplayEventCRFBean();
            dec.setEventDefinitionCRF(edc);
            // System.out.println("edc.isDoubleEntry()" +
            // edc.isDoubleEntry() + ecb.getId());
            dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
            if (dec.isLocked()) {
            // System.out.println("*** found a locked DEC:
            // "+edc.getCrfName());
            }
            if (nonEmptyEventCrf.contains(ecb.getId())) {
                // consider an event crf started only if item data get
                // created
                answer.add(dec);
            }
        }
    }
    return answer;
}
Also used : DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 29 with FormLayoutBean

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

the class OdmExtractDAO method getFormLayoutRefs.

List<ElementRefBean> getFormLayoutRefs(FormDefBean formDef) {
    CRFBean crfBean = crfdao.findByOid(formDef.getOid());
    List<FormLayoutBean> formLayouts = fldao.findAllByCRFId(crfBean.getId());
    List<ElementRefBean> elementRefs = new ArrayList<>();
    ElementRefBean element;
    for (FormLayoutBean formLayout : formLayouts) {
        element = new ElementRefBean();
        element.setName(formLayout.getName());
        element.setUrl(formLayout.getUrl());
        elementRefs.add(element);
    }
    return elementRefs;
}
Also used : ElementRefBean(org.akaza.openclinica.bean.odmbeans.ElementRefBean) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean)

Example 30 with FormLayoutBean

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

the class ListCRFServlet method processRequest.

/**
     * Finds all the crfs
     *
     */
@Override
public void processRequest() throws Exception {
    if (currentStudy.getParentStudyId() > 0) {
        addPageMessage(respage.getString("no_crf_available_study_is_a_site"));
        forwardPage(Page.MENU_SERVLET);
        return;
    }
    session.removeAttribute("version");
    FormProcessor fp = new FormProcessor(request);
    // checks which module the requests are from
    String module = fp.getString(MODULE);
    if (module.equalsIgnoreCase("admin") && !(ub.isSysAdmin() || ub.isTechAdmin())) {
        addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
        forwardPage(Page.MENU_SERVLET);
        return;
    }
    request.setAttribute(MODULE, module);
    // if coming from change crf version -> display message
    String crfVersionChangeMsg = fp.getString("isFromCRFVersionBatchChange");
    if (crfVersionChangeMsg != null && !crfVersionChangeMsg.equals("")) {
        addPageMessage(crfVersionChangeMsg);
    }
    // for
    String dir = SQLInitServlet.getField("filePath") + "crf" + File.separator + "new" + File.separator;
    // crf
    // version
    // spreadsheet
    logger.debug("found directory: " + dir);
    CRFDAO cdao = new CRFDAO(sm.getDataSource());
    FormLayoutDAO fldao = new FormLayoutDAO(sm.getDataSource());
    ArrayList crfs = (ArrayList) cdao.findAll();
    for (int i = 0; i < crfs.size(); i++) {
        CRFBean eb = (CRFBean) crfs.get(i);
        logger.debug("crf id:" + eb.getId());
        ArrayList versions = (ArrayList) fldao.findAllByCRF(eb.getId());
        // check whether the speadsheet is available on the server
        for (int j = 0; j < versions.size(); j++) {
            FormLayoutBean cv = (FormLayoutBean) versions.get(j);
            File file = new File(dir + eb.getId() + cv.getOid() + ".xls");
            logger.debug("looking in " + dir + eb.getId() + cv.getOid() + ".xls");
            if (file.exists()) {
                cv.setDownloadable(true);
            } else {
                File file2 = new File(dir + eb.getId() + cv.getName() + ".xls");
                logger.debug("initial failed, looking in " + dir + eb.getId() + cv.getName() + ".xls");
                if (file2.exists()) {
                    cv.setDownloadable(true);
                }
            }
        }
        eb.setVersions(versions);
    }
    EntityBeanTable table = fp.getEntityBeanTable();
    ArrayList allRows = ListCRFRow.generateRowsFromBeans(crfs);
    String[] columns = { resword.getString("CRF_name"), resword.getString("date_updated"), resword.getString("last_updated_by"), resword.getString("crf_oid"), resword.getString("versions"), resword.getString("date_created"), resword.getString("owner"), resword.getString("status"), resword.getString("download"), resword.getString("actions") };
    table.setColumns(new ArrayList(Arrays.asList(columns)));
    table.hideColumnLink(3);
    // oid column
    table.hideColumnLink(4);
    // BWP 3281: make the "owner" column sortable; table.hideColumnLink(7);
    table.hideColumnLink(8);
    table.setQuery("ListCRF", new HashMap());
    table.addLink(resword.getString("blank_CRF_template"), "DownloadVersionSpreadSheet?template=1");
    // YW << add "Enterprise CRF Catalog" link
    String crfCatalogField = "crfCatalog";
    // table.addLink(resword.getString("openclinica_CRF_catalog"),
    // SQLInitServlet.getEnterpriseField(crfCatalogField));
    // YW >>
    // TODO add i18n links to the above, tbh
    table.addLink(resword.getString("create_a_new_CRF"), "CreateCRFVersion?module=" + module);
    table.setRows(allRows);
    table.computeDisplay();
    request.setAttribute("table", table);
    request.setAttribute("study", currentStudy);
    resetPanel();
    panel.setStudyInfoShown(false);
    panel.setOrderedData(true);
    panel.setSubmitDataModule(false);
    panel.setExtractData(false);
    panel.setCreateDataset(false);
    if (crfs.size() > 0) {
        setToPanel("CRFs", new Integer(crfs.size()).toString());
    }
    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"));
    forwardPage(Page.CRF_LIST);
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) EntityBeanTable(org.akaza.openclinica.web.bean.EntityBeanTable) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) File(java.io.File)

Aggregations

FormLayoutBean (org.akaza.openclinica.bean.submit.FormLayoutBean)41 ArrayList (java.util.ArrayList)32 FormLayoutDAO (org.akaza.openclinica.dao.submit.FormLayoutDAO)23 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)22 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)21 HashMap (java.util.HashMap)20 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)16 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)14 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)13 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)12 Iterator (java.util.Iterator)10 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)10 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)9 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)9 StudyParameterValueDAO (org.akaza.openclinica.dao.service.StudyParameterValueDAO)8 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)8 DisplayEventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean)7 DisplayEventCRFBean (org.akaza.openclinica.bean.submit.DisplayEventCRFBean)7 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)5