Search in sources :

Example 31 with EventDefinitionCRFDAO

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

the class MarkEventCRFCompleteServlet method processRequest.

/*
     * (non-Javadoc)
     *
     * @see org.akaza.openclinica.control.core.SecureController#processRequest()
     */
@Override
protected void processRequest() throws Exception {
    // FormDiscrepancyNotes discNotes =
    // (FormDiscrepancyNotes)session.getAttribute(AddNewSubjectServlet.
    // FORM_DISCREPANCY_NOTES_NAME);
    getEventCRFBean();
    getEventDefinitionCRFBean();
    DataEntryStage stage = ecb.getStage();
    request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN, ecb);
    // Page errorPage = Page.TABLE_OF_CONTENTS_SERVLET;
    Page errorPage = Page.LIST_STUDY_SUBJECTS_SERVLET;
    if (stage.equals(DataEntryStage.UNCOMPLETED) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.LOCKED)) {
        throw new InconsistentStateException(errorPage, respage.getString("not_mark_CRF_complete1"));
    }
    if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
        if (!edcb.isDoubleEntry()) {
            throw new InconsistentStateException(errorPage, respage.getString("not_mark_CRF_complete2"));
        }
    }
    if (!isEachRequiredFieldFillout()) {
        throw new InconsistentStateException(errorPage, respage.getString("not_mark_CRF_complete4"));
    }
    if (ecb.getInterviewerName().trim().equals("")) {
        throw new InconsistentStateException(errorPage, respage.getString("not_mark_CRF_complete5"));
    }
    if (!fp.isSubmitted()) {
        DisplayTableOfContentsBean toc = TableOfContentsServlet.getDisplayBean(ecb, sm.getDataSource(), currentStudy);
        toc = TableOfContentsServlet.getDisplayBeanWithShownSections(sm.getDataSource(), toc, (DynamicsMetadataService) SpringServletAccess.getApplicationContext(getServletContext()).getBean("dynamicsMetadataService"));
        request.setAttribute(BEAN_DISPLAY, toc);
        resetPanel();
        panel.setStudyInfoShown(false);
        panel.setOrderedData(true);
        setToPanel(resword.getString("subject"), toc.getStudySubject().getLabel());
        setToPanel(resword.getString("study_event_definition"), toc.getStudyEventDefinition().getName());
        StudyEventBean seb = toc.getStudyEvent();
        setToPanel(resword.getString("location"), seb.getLocation());
        setToPanel(resword.getString("start_date"), seb.getDateStarted().toString());
        setToPanel(resword.getString("end_date"), seb.getDateEnded().toString());
        setToPanel(resword.getString("CRF"), toc.getCrf().getName());
        setToPanel(resword.getString("CRF_version"), toc.getCrfVersion().getName());
        forwardPage(Page.MARK_EVENT_CRF_COMPLETE);
    } else {
        boolean markComplete = fp.getString(INPUT_MARK_COMPLETE).equals(VALUE_YES);
        if (markComplete) {
            Status newStatus = ecb.getStatus();
            boolean ide = true;
            if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && edcb.isDoubleEntry()) {
                newStatus = Status.PENDING;
                ecb.setUpdaterId(ub.getId());
                ecb.setUpdatedDate(new Date());
                ecb.setDateCompleted(new Date());
            } else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) && !edcb.isDoubleEntry()) {
                newStatus = Status.UNAVAILABLE;
                ecb.setUpdaterId(ub.getId());
                ecb.setUpdatedDate(new Date());
                ecb.setDateCompleted(new Date());
                ecb.setDateValidateCompleted(new Date());
            } else if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
                newStatus = Status.UNAVAILABLE;
                ecb.setDateValidateCompleted(new Date());
                ide = false;
            }
            ecb.setStatus(newStatus);
            ecb = (EventCRFBean) ecdao.update(ecb);
            ecdao.markComplete(ecb, ide);
            ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
            iddao.updateStatusByEventCRF(ecb, newStatus);
            // change status for event
            StudyEventDAO sedao = new StudyEventDAO(sm.getDataSource());
            StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
            seb.setUpdatedDate(new Date());
            seb.setUpdater(ub);
            EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
            ArrayList allCRFs = ecdao.findAllByStudyEvent(seb);
            ArrayList allEDCs = edcdao.findAllActiveByEventDefinitionId(seb.getStudyEventDefinitionId());
            boolean eventCompleted = true;
            for (int i = 0; i < allCRFs.size(); i++) {
                EventCRFBean ec = (EventCRFBean) allCRFs.get(i);
                if (!ec.getStatus().equals(Status.UNAVAILABLE)) {
                    eventCompleted = false;
                    break;
                }
            }
            if (eventCompleted && allCRFs.size() >= allEDCs.size()) {
                seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
            }
            seb = (StudyEventBean) sedao.update(seb);
            addPageMessage(respage.getString("event_CRF_marked_complete"));
            request.setAttribute(EnterDataForStudyEventServlet.INPUT_EVENT_ID, String.valueOf(ecb.getStudyEventId()));
            forwardPage(Page.ENTER_DATA_FOR_STUDY_EVENT_SERVLET);
        } else {
            request.setAttribute(DataEntryServlet.INPUT_IGNORE_PARAMETERS, Boolean.TRUE);
            addPageMessage(respage.getString("event_CRF_not_marked_complete"));
            forwardPage(errorPage);
        }
    }
}
Also used : Status(org.akaza.openclinica.bean.core.Status) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) ArrayList(java.util.ArrayList) Page(org.akaza.openclinica.view.Page) DisplayTableOfContentsBean(org.akaza.openclinica.bean.submit.DisplayTableOfContentsBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) InconsistentStateException(org.akaza.openclinica.web.InconsistentStateException) Date(java.util.Date) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) DataEntryStage(org.akaza.openclinica.bean.core.DataEntryStage) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) DynamicsMetadataService(org.akaza.openclinica.service.crfdata.DynamicsMetadataService)

Example 32 with EventDefinitionCRFDAO

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

the class AnonymousFormControllerV2 method getEnketoForm.

/**
     * @api {post} /pages/api/v2/anonymousform/form Retrieve anonymous form URL
     * @apiName getEnketoForm
     * @apiPermission Module participate - enabled
     * @apiVersion 3.8.0
     * @apiParam {String} studyOid Study Oid
     * @apiParam {String} submissionUri Submission Url
     * @apiGroup Form
     * @apiDescription Retrieve anonymous form url.
     * @apiParamExample {json} Request-Example:
     *                  {
     *                  "studyOid": "S_BL101",
     *                  "submissionUri": "abcde"
     *                  }
     * @apiSuccessExample {json} Success-Response:
     *                    HTTP/1.1 200 OK
     *                    {
     *                    "url":
     *                    "http://localhost:8006/::YYYi?iframe=true&ecid=abb764d026830e98b895ece6d9dcaf3c5e817983cc00a4ebfaabcb6c3700b4d5",
     *                    "offline": "false"
     *                    }
     */
@RequestMapping(value = "/form", method = RequestMethod.POST)
public ResponseEntity<AnonymousUrlResponse> getEnketoForm(@RequestBody HashMap<String, String> map) throws Exception {
    ResourceBundleProvider.updateLocale(new Locale("en_US"));
    EventDefinitionCrfTagService tagService = (EventDefinitionCrfTagService) SpringServletAccess.getApplicationContext(context).getBean("eventDefinitionCrfTagService");
    String formUrl = null;
    String studyOid = map.get("studyOid");
    if (!mayProceed(studyOid))
        return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    String submissionUri = map.get("submissionUri");
    if (submissionUri != "" && submissionUri != null) {
        StudyBean study = getStudy(studyOid);
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(dataSource);
        ArrayList<EventDefinitionCRFBean> edcBeans = edcdao.findAllSubmissionUriAndStudyId(submissionUri, study.getId());
        if (edcBeans.size() != 0) {
            EventDefinitionCRFBean edcBean = edcBeans.get(0);
            CRFDAO crfdao = new CRFDAO(dataSource);
            FormLayoutDAO fldao = new FormLayoutDAO(dataSource);
            StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(dataSource);
            FormLayoutBean formLayout = (FormLayoutBean) fldao.findByPK(edcBean.getDefaultVersionId());
            CRFBean crf = (CRFBean) crfdao.findByPK(formLayout.getCrfId());
            StudyBean sBean = (StudyBean) sdao.findByPK(edcBean.getStudyId());
            StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) seddao.findByPK(edcBean.getStudyEventDefinitionId());
            String tagPath = sedBean.getOid() + "." + crf.getOid();
            boolean isOffline = tagService.getEventDefnCrfOfflineStatus(2, tagPath, true);
            String offline = null;
            if (isOffline)
                offline = "true";
            else
                offline = "false";
            formUrl = createAnonymousEnketoUrl(sBean.getOid(), formLayout, edcBean, isOffline);
            AnonymousUrlResponse anonResponse = new AnonymousUrlResponse(formUrl, offline, crf.getName(), formLayout.getDescription());
            return new ResponseEntity<AnonymousUrlResponse>(anonResponse, org.springframework.http.HttpStatus.OK);
        } else {
            return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
        }
    } else {
        return new ResponseEntity<AnonymousUrlResponse>(org.springframework.http.HttpStatus.NOT_ACCEPTABLE);
    }
}
Also used : Locale(java.util.Locale) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventDefinitionCrfTagService(org.akaza.openclinica.service.managestudy.EventDefinitionCrfTagService) ResponseEntity(org.springframework.http.ResponseEntity) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 33 with EventDefinitionCRFDAO

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

the class FormBeanUtil method getNullValuesByEventCRFDefId.

public List<String> getNullValuesByEventCRFDefId(int eventDefinitionCRFId, DataSource dataSource) {
    if (eventDefinitionCRFId < 1 || dataSource == null) {
        return new ArrayList<String>();
    }
    List<String> nullValuesList = new ArrayList<String>();
    // hold the bean's return value
    List<NullValue> nullObjectList = new ArrayList<NullValue>();
    EventDefinitionCRFBean eventCRFDefBean;
    EventDefinitionCRFDAO eventDefinitionCRFDAO = new EventDefinitionCRFDAO(dataSource);
    eventCRFDefBean = (EventDefinitionCRFBean) eventDefinitionCRFDAO.findByPK(eventDefinitionCRFId);
    nullObjectList = eventCRFDefBean.getNullValuesList();
    if (nullObjectList == null) {
        return new ArrayList<String>();
    }
    for (NullValue nullVal : nullObjectList) {
        nullValuesList.add(nullVal.getName());
    }
    return nullValuesList;
}
Also used : NullValue(org.akaza.openclinica.bean.core.NullValue) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Example 34 with EventDefinitionCRFDAO

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

the class FormBeanUtil method createDisplaySectionWithItemGroups.

/**
     * Create a DisplaySectionBean with a list of ItemGroupBeans. NOTE:
     * unGrouped Items are not included
     * 
     * @param study
     *            The StudyBean
     * @param sectionId
     *            The Section ID associated with the Items, which end up
     *            providing the content of the tables.
     * @param crfVersionId
     *            The CRF version ID associated with the Items.
     * @param studyEventId
     *            The Study Event ID associated with the CRF Version ID.
     * @param sm
     *            A SessionManager, from which DataSources are acquired for the
     *            DAO objects.
     * @return A DisplaySectionBean.
     */
public DisplaySectionBean createDisplaySectionWithItemGroups(StudyBean study, int sectionId, EventCRFBean eventCrfBean, int studyEventId, SessionManager sm, int eventDefinitionCRFId, ServletContext context) {
    DisplaySectionBean dBean = new DisplaySectionBean();
    ItemGroupDAO formGroupDAO = new ItemGroupDAO(sm.getDataSource());
    ItemGroupMetadataDAO igMetaDAO = new ItemGroupMetadataDAO(sm.getDataSource());
    ItemDAO itemDao = new ItemDAO(sm.getDataSource());
    ItemFormMetadataDAO metaDao = new ItemFormMetadataDAO(sm.getDataSource());
    List<ItemGroupBean> arrList = formGroupDAO.findLegitGroupBySectionId(sectionId);
    // all items associated with the section, including those not in a group
    List<ItemFormMetadataBean> allMetas = new ArrayList<ItemFormMetadataBean>();
    try {
        allMetas = metaDao.findAllBySectionId(sectionId);
    } catch (OpenClinicaException oce) {
        logger.info("oce.getOpenClinicaMessage() = " + oce.getOpenClinicaMessage());
    }
    // Collections.sort(allMetas);
    if (arrList.isEmpty())
        return dBean;
    // Find out whether there are any checkboxes/radios/select elements
    // and if so, get any null values
    // associated with them
    List<String> nullValuesList = new ArrayList<String>();
    boolean itemsHaveChecksRadios = itemsIncludeChecksRadiosSelects(allMetas);
    // "+eventDefinitionCRFId);
    if (eventDefinitionCRFId <= 0) {
        EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        EventDefinitionCRFBean edcBean = edcdao.findByStudyEventIdAndCRFVersionId(study, studyEventId, eventCrfBean.getCRFVersionId());
        eventDefinitionCRFId = edcBean.getId();
    }
    // "+eventDefinitionCRFId);
    if (itemsHaveChecksRadios && eventDefinitionCRFId > 0) {
        // method returns null values as a List<String>
        nullValuesList = this.getNullValuesByEventCRFDefId(eventDefinitionCRFId, sm.getDataSource());
    }
    // Get the items associated with each group
    List<ItemBean> itBeans;
    List<DisplayItemBean> displayItems;
    List<DisplayItemGroupBean> displayFormBeans = new ArrayList<DisplayItemGroupBean>();
    DisplayItemGroupBean displayItemGBean;
    for (ItemGroupBean itemGroup : arrList) {
        itBeans = itemDao.findAllItemsByGroupId(itemGroup.getId(), eventCrfBean.getCRFVersionId());
        List<ItemGroupMetadataBean> metadata = igMetaDAO.findMetaByGroupAndSection(itemGroup.getId(), eventCrfBean.getCRFVersionId(), sectionId);
        if (!metadata.isEmpty()) {
            // for a given crf version, all the items in the same group
            // have the same group metadata
            // so we can get one of them and set metadata for the group
            ItemGroupMetadataBean meta = metadata.get(0);
            itemGroup.setMeta(meta);
        }
        // include arrayList parameter until I determine difference in
        // classes
        displayItems = getDisplayBeansFromItems(itBeans, sm.getDataSource(), eventCrfBean, sectionId, nullValuesList, context);
        displayItemGBean = this.createDisplayFormGroup(displayItems, itemGroup);
        displayFormBeans.add(displayItemGBean);
    }
    // We still have to sort these display item group beans on their
    // ItemGroupMetadataBean?
    // then number their ordinals accordingly
    Collections.sort(displayFormBeans, new Comparator<DisplayItemGroupBean>() {

        public int compare(DisplayItemGroupBean displayItemGroupBean, DisplayItemGroupBean displayItemGroupBean1) {
            return displayItemGroupBean.getGroupMetaBean().compareTo(displayItemGroupBean1.getGroupMetaBean());
        }
    });
    // Now provide the display item group beans with an ordinal
    int digOrdinal = 0;
    for (DisplayItemGroupBean digBean : displayFormBeans) {
        digBean.setOrdinal(++digOrdinal);
    }
    dBean.setDisplayFormGroups(displayFormBeans);
    return dBean;
}
Also used : DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) ArrayList(java.util.ArrayList) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) ItemGroupMetadataBean(org.akaza.openclinica.bean.submit.ItemGroupMetadataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) ItemGroupMetadataDAO(org.akaza.openclinica.dao.submit.ItemGroupMetadataDAO) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 35 with EventDefinitionCRFDAO

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

the class CrfBusinessLogicHelper method areAllRequired.

protected boolean areAllRequired(StudyEventBean seBean, StudyBean study) {
    EventDefinitionCRFDAO edcDao = new EventDefinitionCRFDAO(ds);
    // EventCRFDAO eventCrfDao = new EventCRFDAO(ds);
    // ArrayList allCRFs = eventCrfDao.findAllByStudyEvent(seBean);
    ArrayList allEDCs = (ArrayList) edcDao.findAllActiveByEventDefinitionId(study, seBean.getStudyEventDefinitionId());
    boolean areAllRequired = true;
    for (int i = 0; i < allEDCs.size(); i++) {
        EventDefinitionCRFBean ec = (EventDefinitionCRFBean) allEDCs.get(i);
        if (!ec.isRequiredCRF()) {
            areAllRequired = false;
            break;
        }
    }
    logger.info("returning for are all required: " + areAllRequired);
    return areAllRequired;
}
Also used : ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)

Aggregations

EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)84 ArrayList (java.util.ArrayList)72 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)58 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)53 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)51 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)47 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)45 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)45 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)41 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)41 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)40 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)39 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)39 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)36 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)35 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)30 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)28 Date (java.util.Date)27 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)27 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)26