Search in sources :

Example 36 with StudySubjectDAO

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

the class OdmController method getODM.

private ODM getODM(String studyOID, String subjectKey) {
    ODM odm = new ODM();
    String ssoid = subjectKey;
    if (ssoid == null) {
        return null;
    }
    FormLayoutDAO formLayoutDAO = new FormLayoutDAO(dataSource);
    StudyDAO studyDAO = new StudyDAO(dataSource);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
    EventCRFDAO eventCRFDAO = new EventCRFDAO(dataSource);
    ItemDataDAO itemDataDAO = new ItemDataDAO(dataSource);
    CRFDAO crfDAO = new CRFDAO(dataSource);
    List<ODMcomplexTypeDefinitionFormData> formDatas = new ArrayList<>();
    try {
        // Retrieve crfs for next event
        StudySubjectBean studySubjectBean = studySubjectDAO.findByOid(ssoid);
        ParticipantEventService participantEventService = new ParticipantEventService(dataSource);
        StudyEventBean nextEvent = participantEventService.getNextParticipantEvent(studySubjectBean);
        if (nextEvent != null) {
            logger.debug("Found event: " + nextEvent.getName() + " - ID: " + nextEvent.getId());
            List<EventCRFBean> eventCrfs = eventCRFDAO.findAllByStudyEvent(nextEvent);
            StudyBean study = studyDAO.findByOid(studyOID);
            if (!mayProceed(studyOID, studySubjectBean))
                return odm;
            List<EventDefinitionCRFBean> eventDefCrfs = participantEventService.getEventDefCrfsForStudyEvent(studySubjectBean, nextEvent);
            for (EventDefinitionCRFBean eventDefCrf : eventDefCrfs) {
                if (eventDefCrf.isParticipantForm()) {
                    EventCRFBean eventCRF = participantEventService.getExistingEventCRF(studySubjectBean, nextEvent, eventDefCrf);
                    boolean itemDataExists = false;
                    boolean validStatus = true;
                    FormLayoutBean formLayout = null;
                    if (eventCRF != null) {
                        if (eventCRF.getStatus().getId() != 1 && eventCRF.getStatus().getId() != 2)
                            validStatus = false;
                        if (itemDataDAO.findAllByEventCRFId(eventCRF.getId()).size() > 0)
                            itemDataExists = true;
                        formLayout = (FormLayoutBean) formLayoutDAO.findByPK(eventCRF.getFormLayoutId());
                    } else
                        formLayout = (FormLayoutBean) formLayoutDAO.findByPK(eventDefCrf.getDefaultVersionId());
                    if (validStatus) {
                        String formUrl = null;
                        if (!itemDataExists)
                            formUrl = createEnketoUrl(studyOID, formLayout, nextEvent, ssoid);
                        else
                            formUrl = createEditUrl(studyOID, formLayout, nextEvent, ssoid);
                        formDatas.add(getFormDataPerCrf(formLayout, nextEvent, eventCrfs, crfDAO, formUrl, itemDataExists));
                    }
                }
            }
            return createOdm(study, studySubjectBean, nextEvent, formDatas);
        } else {
            logger.debug("Unable to find next event for subject.");
        }
    } catch (Exception e) {
        logger.error(e.getMessage());
        logger.error(ExceptionUtils.getStackTrace(e));
    }
    return odm;
}
Also used : EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) ParticipantEventService(org.akaza.openclinica.service.ParticipantEventService) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) ODMcomplexTypeDefinitionFormData(org.cdisc.ns.odm.v130.ODMcomplexTypeDefinitionFormData) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) ODM(org.cdisc.ns.odm.v130.ODM) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 37 with StudySubjectDAO

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

the class AccountController method getStudySubjectByOidAndStudy.

private StudySubjectBean getStudySubjectByOidAndStudy(String oid, int studyId) {
    ssdao = new StudySubjectDAO(dataSource);
    StudySubjectBean studySubjectBean = (StudySubjectBean) ssdao.findByOidAndStudy(oid, studyId);
    return studySubjectBean;
}
Also used : StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Example 38 with StudySubjectDAO

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

the class AccountController method getStudySubject.

private StudySubjectBean getStudySubject(String oid) {
    ssdao = new StudySubjectDAO(dataSource);
    StudySubjectBean studySubjectBean = (StudySubjectBean) ssdao.findByOid(oid);
    return studySubjectBean;
}
Also used : StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Example 39 with StudySubjectDAO

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

the class OdmStudySubjectController method getODM.

private ODM getODM(String studyOID, String studySubjectLabel, String crcUserName) {
    StudyDAO studyDAO = new StudyDAO(dataSource);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
    StudyBean studyBean = null;
    StudySubjectBean studySubjectBean = null;
    try {
        // Retrieve crfs for next event
        studyBean = studyDAO.findByOid(studyOID);
        if (studyBean != null) {
            studySubjectBean = (StudySubjectBean) studySubjectDAO.findByLabelAndStudy(studySubjectLabel, studyBean);
            if (!mayProceed(studyOID, studySubjectBean))
                return null;
            if (studySubjectBean.getId() != 0 && !accountController.isCRCHasAccessToStudySubject(studyOID, crcUserName, studySubjectLabel)) {
                return createOdm(studyBean, studySubjectBean);
            } else if (studySubjectBean.getId() != 0 && accountController.isCRCHasAccessToStudySubject(studyOID, crcUserName, studySubjectLabel)) {
                return null;
            } else {
                return createOdm(studyBean, null);
            }
        } else {
            return createOdm(null, null);
        }
    } catch (Exception e) {
        logger.debug(e.getMessage());
        logger.debug(ExceptionUtils.getStackTrace(e));
    }
    return null;
}
Also used : StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Example 40 with StudySubjectDAO

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

the class CrfBusinessLogicHelper method markCRFComplete.

/**
     * The following methods are for 'mark CRF complete' Note that we will also wrap Study Event status changes in this
     * code, possibly split out in a later release, tbh 06/2008
     * 
     * @return
     */
public boolean markCRFComplete(EventCRFBean ecb, UserAccountBean ub) throws Exception {
    // locale = LocaleResolver.getLocale(request);
    // < respage =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.page_messages",
    // locale);
    // < restext =
    // ResourceBundle.getBundle("org.akaza.openclinica.i18n.notes",locale);
    // <
    // resexception=ResourceBundle.getBundle(
    // "org.akaza.openclinica.i18n.exceptions",locale);
    // getEventCRFBean();
    // getEventDefinitionCRFBean();
    DataEntryStage stage = ecb.getStage();
    EventCRFDAO eventCrfDao = new EventCRFDAO(ds);
    ItemDataDAO itemDataDao = new ItemDataDAO(ds);
    StudyDAO sdao = new StudyDAO(ds);
    StudySubjectDAO ssdao = new StudySubjectDAO(ds);
    StudyBean study = sdao.findByStudySubjectId(ecb.getStudySubjectId());
    EventDefinitionCRFBean edcb = getEventDefinitionCrfByStudyEventAndCrfVersion(ecb, study);
    // StudyEventDAO studyEventDao = new StudyEventDAO(ds);
    // StudyEventBean studyEventBean = (StudyEventBean)
    // studyEventDao.findByPK(ecb.getStudyEventId());
    // Status studyEventStatus = studyEventBean.getStatus();
    StudyEventDefinitionDAO studyEventDefinitionDao = new StudyEventDefinitionDAO(ds);
    StudyEventDefinitionBean sedBean = (StudyEventDefinitionBean) studyEventDefinitionDao.findByPK(edcb.getStudyEventDefinitionId());
    CRFDAO crfDao = new CRFDAO(ds);
    ArrayList crfs = (ArrayList) crfDao.findAllActiveByDefinition(sedBean);
    sedBean.setCrfs(crfs);
    // request.setAttribute(TableOfContentsServlet.INPUT_EVENT_CRF_BEAN,
    // ecb);
    // request.setAttribute(INPUT_EVENT_CRF_ID, new
    // Integer(ecb.getId()));
    logger.debug("inout_event_crf_id:" + ecb.getId());
    logger.debug("inout_study_event_def_id:" + sedBean.getId());
    // below bit is from DataEntryServlet, is more appropriate for filling
    // in by hand than by automatic
    // removing this in favor of the more streamlined effect below, tbh
    // 06/2008
    // Page errorPage = getJSPPage();
    // if (stage.equals(DataEntryStage.UNCOMPLETED) ||
    // stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) ||
    // stage.equals(DataEntryStage.LOCKED)) {
    // logger.info(
    // "addPageMessage(respage.getString(\"not_mark_CRF_complete1\"))");
    // return false;
    // }
    //
    // if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) ||
    // stage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
    //
    // /*
    // * if (!edcb.isDoubleEntry()) {
    // *
    // logger.info(
    // "addPageMessage(respage.getString(\"not_mark_CRF_complete2\"))");
    // * return false; }
    // *
    // */
    // }
    //
    // /*
    // * if (!isEachSectionReviewedOnce()) { addPageMessage("You may not
    // mark
    // * this Event CRF complete, because there are some sections which have
    // * not been reviewed once."); return false; }
    // */
    //
    // if (!isEachRequiredFieldFillout(ecb)) {
    // logger.info(
    // "addPageMessage(respage.getString(\"not_mark_CRF_complete4\"))");
    // return false;
    // }
    //
    // /*
    // * if (ecb.getInterviewerName().trim().equals("")) { throw new
    // * InconsistentStateException(errorPage, "You may not mark this Event
    // * CRF complete, because the interviewer name is blank."); }
    // */
    Status newStatus = ecb.getStatus();
    DataEntryStage newStage = ecb.getStage();
    boolean ide = true;
    // currently we are setting the event crf status to complete, so this
    // block is all to
    // complete, tbh
    // if (stage.equals(DataEntryStage.INITIAL_DATA_ENTRY) &&
    // edcb.isDoubleEntry()) {
    // newStatus = Status.PENDING;
    // ecb.setUpdaterId(ub.getId());
    // ecb.setUpdater(ub);
    // 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.setUpdater(ub);
    // 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;
    // }
    newStatus = Status.UNAVAILABLE;
    // ecb.setUpdaterId(ub.getId());
    ecb.setUpdater(ub);
    ecb.setUpdatedDate(new Date());
    ecb.setDateCompleted(new Date());
    ecb.setDateValidateCompleted(new Date());
    /*
         * //for the non-reviewed sections, no item data in DB yet, need to //create them if
         * (!isEachSectionReviewedOnce()) { boolean canSave = saveItemsToMarkComplete(newStatus); if (canSave == false){
         * addPageMessage("You may not mark this Event CRF complete, because there are some required entries which have
         * not been filled out."); return false; } }
         */
    ecb.setStatus(newStatus);
    ecb.setStage(newStage);
    ecb = (EventCRFBean) eventCrfDao.update(ecb);
    logger.debug("just updated event crf id: " + ecb.getId());
    // note the below statement only updates the DATES, not the STATUS
    eventCrfDao.markComplete(ecb, ide);
    // update all the items' status to complete
    itemDataDao.updateStatusByEventCRF(ecb, newStatus);
    // change status for study event
    StudyEventDAO sedao = new StudyEventDAO(ds);
    StudyEventBean seb = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
    seb.setUpdatedDate(new Date());
    seb.setUpdater(ub);
    // updates with Pauls observation from bug:2488:
    // 1. If there is only one CRF in the event (whether the CRF was
    // required or not), and data was imported for it, the status of the
    // event should be Completed.
    //
    logger.debug("sed bean get crfs get size: " + sedBean.getCrfs().size());
    logger.debug("edcb get crf id: " + edcb.getCrfId() + " version size? " + edcb.getVersions().size());
    logger.debug("ecb get crf id: " + ecb.getCrf().getId());
    logger.debug("ecb get crf version id: " + ecb.getCRFVersionId());
    if (sedBean.getCrfs().size() == 1) {
        seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
        logger.info("just set subj event status to -- COMPLETED --");
    } else // removing sedBean.getCrfs().size() > 1 &&
    if (areAllRequired(seb, study) && !areAllCompleted(seb, study)) {
        seb.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
        logger.info("just set subj event status to -- DATAENTRYSTARTED --");
    } else // removing sedBean.getCrfs().size() > 1 &&
    if (!areAllRequired(seb, study)) {
        if (areAllRequiredCompleted(seb, study)) {
            seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
            logger.info("just set subj event status to -- 3completed3 --");
        } else {
            seb.setSubjectEventStatus(SubjectEventStatus.DATA_ENTRY_STARTED);
            logger.info("just set subj event status to -- DATAENTRYSTARTED --");
        }
    } else if (noneAreRequired(seb, study)) {
        seb.setSubjectEventStatus(SubjectEventStatus.COMPLETED);
        logger.info("just set subj event status to -- 5completed5 --");
    }
    logger.debug("just set subj event status, final status is " + seb.getSubjectEventStatus().getName());
    logger.debug("final overall status is " + seb.getStatus().getName());
    seb = (StudyEventBean) sedao.update(seb);
    return true;
}
Also used : Status(org.akaza.openclinica.bean.core.Status) SubjectEventStatus(org.akaza.openclinica.bean.core.SubjectEventStatus) 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) 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) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) Date(java.util.Date) DataEntryStage(org.akaza.openclinica.bean.core.DataEntryStage) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Aggregations

StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)102 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)86 ArrayList (java.util.ArrayList)63 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)62 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)62 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)59 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)58 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)54 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)50 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)47 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)42 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)41 Date (java.util.Date)38 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)32 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)29 SubjectDAO (org.akaza.openclinica.dao.submit.SubjectDAO)27 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)26 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)24 SubjectBean (org.akaza.openclinica.bean.submit.SubjectBean)23 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)23