Search in sources :

Example 36 with StudyEventDAO

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

the class UrlRewriteServlet method getOpenClinicaResourceFromURL.

/**
     * Method to parse the request URL parameters and get the respective
     * database identifiers
     *
     * @param URLPath
     *            - example "S_CPCS/320999/SE_CPCS%5B1%5D/F_CPCS_1"
     * @param queryString
     *            - example
     *            "format=html&mode=view&tabId=1&exitTo=ViewStudySubject"
     * @return
     */
public OpenClinicaResource getOpenClinicaResourceFromURL(String URLPath) /*
                                                                            * ,
                                                                            * String
                                                                            * queryString
                                                                            */
{
    OpenClinicaResource openClinicaResource = new OpenClinicaResource();
    if ((null != URLPath) && (!URLPath.equals(""))) {
        if (URLPath.contains("/")) {
            String[] tokens = URLPath.split("/");
            if (tokens.length != 0) {
                String URLParamValue = "";
                StudyDAO stdao = new StudyDAO(getDataSource());
                StudySubjectDAO ssubdao = new StudySubjectDAO(getDataSource());
                StudyEventDefinitionDAO sedefdao = new StudyEventDefinitionDAO(getDataSource());
                CRFDAO crfdao = new CRFDAO(getDataSource());
                CRFVersionDAO crfvdao = new CRFVersionDAO(getDataSource());
                ItemDAO idao = new ItemDAO(getDataSource());
                ItemGroupDAO igdao = new ItemGroupDAO(getDataSource());
                StudyEventDAO sedao = new StudyEventDAO(getDataSource());
                StudyBean study = null;
                StudySubjectBean subject = null;
                StudyEventDefinitionBean sed = null;
                CRFBean c = null;
                CRFVersionBean cv = null;
                ItemBean item = null;
                ItemGroupBean ig = null;
                StudyEventBean studyEvent = null;
                Integer studySubjectId = 0;
                Integer eventDefId = 0;
                Integer eventRepeatKey = 0;
                for (int i = 0; i < tokens.length; i++) {
                    // when interpreting these request URL parameters, the
                    // assumption is that the position of
                    // each type of parameters will be fixed. Meaning, study
                    // OID is always going to be at the start
                    // followed by StudySubjectKey followed by study event
                    // definition OID followed by
                    // study event repeat key followed by form OID followed
                    // by item group OID followed by
                    // item group repeat key followed by item OID
                    // It can also be done based on the start of OID value
                    // (example study OID presently
                    // starts with 'S_' but we will have to change it if we
                    // change the method of generating
                    // oID values in future.
                    URLParamValue = tokens[i].trim();
                    //System.out.println("URLParamValue::"+URLParamValue);
                    logger.info("URLPAramValue::" + URLParamValue);
                    if ((null != URLParamValue) && (!URLParamValue.equals(""))) {
                        switch(i) {
                            case 0:
                                {
                                    // study OID
                                    study = stdao.findByOid(URLParamValue);
                                    //validate study OID
                                    if (study == null) {
                                        openClinicaResource.setInValid(true);
                                        openClinicaResource.getMessages().add(resexception.getString("invalid_study_oid"));
                                        return openClinicaResource;
                                    } else {
                                        openClinicaResource.setStudyOID(URLParamValue);
                                        if (null != study) {
                                            openClinicaResource.setStudyID(study.getId());
                                        }
                                    }
                                    break;
                                }
                            case 1:
                                {
                                    // StudySubjectKey
                                    subject = ssubdao.findByOidAndStudy(URLParamValue, study.getId());
                                    //validate subject OID
                                    if (subject == null) {
                                        openClinicaResource.setInValid(true);
                                        openClinicaResource.getMessages().add(resexception.getString("invalid_subject_oid"));
                                        return openClinicaResource;
                                    } else {
                                        openClinicaResource.setStudySubjectOID(URLParamValue);
                                        if (null != subject) {
                                            studySubjectId = subject.getId();
                                            openClinicaResource.setStudySubjectID(studySubjectId);
                                        }
                                    }
                                    break;
                                }
                            case 2:
                                {
                                    // study event definition OID
                                    // separate study event OID and study event
                                    // repeat key
                                    String seoid = "";
                                    String eventOrdinal = "";
                                    if (URLParamValue.contains("%5B") && URLParamValue.contains("%5D")) {
                                        seoid = URLParamValue.substring(0, URLParamValue.indexOf("%5B"));
                                        openClinicaResource.setStudyEventDefOID(seoid);
                                        eventOrdinal = URLParamValue.substring(URLParamValue.indexOf("%5B") + 3, URLParamValue.indexOf("%5D"));
                                    } else if (URLParamValue.contains("[") && URLParamValue.contains("]")) {
                                        seoid = URLParamValue.substring(0, URLParamValue.indexOf("["));
                                        logger.info("seoid" + seoid);
                                        openClinicaResource.setStudyEventDefOID(seoid);
                                        eventOrdinal = URLParamValue.substring(URLParamValue.indexOf("[") + 1, URLParamValue.indexOf("]"));
                                        logger.info("eventOrdinal::" + eventOrdinal);
                                    } else {
                                        //event ordinal not specified
                                        openClinicaResource.setInValid(true);
                                        openClinicaResource.getMessages().add(resexception.getString("event_ordinal_not_specified"));
                                        return openClinicaResource;
                                    }
                                    if ((null != seoid) && (null != study)) {
                                        sed = sedefdao.findByOidAndStudy(seoid, study.getId(), study.getParentStudyId());
                                        //validate study event oid
                                        if (null == sed) {
                                            openClinicaResource.setInValid(true);
                                            openClinicaResource.getMessages().add(resexception.getString("invalid_event_oid"));
                                            return openClinicaResource;
                                        } else {
                                            eventDefId = sed.getId();
                                            openClinicaResource.setStudyEventDefID(eventDefId);
                                        }
                                    }
                                    if (null != eventRepeatKey) {
                                        eventRepeatKey = Integer.parseInt(eventOrdinal.trim());
                                        //validate the event ordinal specified exists in database
                                        studyEvent = (StudyEventBean) sedao.findByStudySubjectIdAndDefinitionIdAndOrdinal(subject.getId(), sed.getId(), eventRepeatKey);
                                        //this method return new StudyEvent (not null) even if no studyEvent can be found
                                        if (null == studyEvent || studyEvent.getId() == 0) {
                                            openClinicaResource.setInValid(true);
                                            openClinicaResource.getMessages().add(resexception.getString("invalid_event_ordinal"));
                                            return openClinicaResource;
                                        } else {
                                            openClinicaResource.setStudyEventRepeatKey(eventRepeatKey);
                                        }
                                    }
                                    break;
                                }
                            case 3:
                                {
                                    // form OID
                                    openClinicaResource.setFormVersionOID(URLParamValue);
                                    //validate the crf version oid
                                    cv = crfvdao.findByOid(URLParamValue);
                                    if (cv == null) {
                                        openClinicaResource.setInValid(true);
                                        openClinicaResource.getMessages().add(resexception.getString("invalid_crf_oid"));
                                        return openClinicaResource;
                                    } else {
                                        openClinicaResource.setFormVersionID(cv.getId());
                                        //validate if crf is removed
                                        if (cv.getStatus().equals(Status.DELETED)) {
                                            openClinicaResource.setInValid(true);
                                            openClinicaResource.getMessages().add(resexception.getString("removed_crf"));
                                            return openClinicaResource;
                                        } else {
                                            if (null != study) {
                                                // cv =
                                                // crfvdao.findByCrfVersionOidAndStudy(URLParamValue,
                                                // study.getId());
                                                // if (null != cv) {
                                                // openClinicaResource.setFormVersionID(cv.getId());
                                                // openClinicaResource.setFormID(cv.getCrfId());
                                                // }
                                                HashMap studySubjectCRFDataDetails = sedao.getStudySubjectCRFData(study, studySubjectId, eventDefId, URLParamValue, eventRepeatKey);
                                                if ((null != studySubjectCRFDataDetails) && (studySubjectCRFDataDetails.size() != 0)) {
                                                    if (studySubjectCRFDataDetails.containsKey("event_crf_id")) {
                                                        openClinicaResource.setEventCrfId((Integer) studySubjectCRFDataDetails.get("event_crf_id"));
                                                    }
                                                    if (studySubjectCRFDataDetails.containsKey("event_definition_crf_id")) {
                                                        openClinicaResource.setEventDefinitionCrfId((Integer) studySubjectCRFDataDetails.get("event_definition_crf_id"));
                                                    }
                                                    if (studySubjectCRFDataDetails.containsKey("study_event_id")) {
                                                        openClinicaResource.setStudyEventId((Integer) studySubjectCRFDataDetails.get("study_event_id"));
                                                    }
                                                } else {
                                                    //no data was found in the database for the combination of parameters in the RESTful URL. There are 2 possible reasons:
                                                    //a. The data entry is not started yet for this event CRF. As of OpenClinica 3.1.3 we have not implemented the 
                                                    // RESTful URL functionality in this case.
                                                    //b. The form version OID entered in the URL could be different than the one used in the data entry
                                                    openClinicaResource.setInValid(true);
                                                    openClinicaResource.getMessages().add(resexception.getString("either_no_data_for_crf_or_data_entry_not_started"));
                                                    return openClinicaResource;
                                                }
                                            }
                                        }
                                    }
                                    break;
                                }
                            case 4:
                                {
                                    // item group OID
                                    // separate item group OID and item group
                                    // repeat key
                                    String igoid = "";
                                    String igRepeatKey = "";
                                    if (URLParamValue.contains("[")) {
                                        igoid = URLParamValue.substring(1, URLParamValue.indexOf("["));
                                        igRepeatKey = URLParamValue.substring(URLParamValue.indexOf("["), URLParamValue.indexOf("}]"));
                                    }
                                    if ((null != igoid) && (null != cv)) {
                                        ig = igdao.findByOidAndCrf(URLParamValue, cv.getCrfId());
                                        if (null != ig) {
                                            openClinicaResource.setItemGroupID(ig.getId());
                                        }
                                    }
                                    if (null != igRepeatKey) {
                                        openClinicaResource.setItemGroupRepeatKey(Integer.parseInt(igRepeatKey));
                                    }
                                    break;
                                }
                            case 5:
                                {
                                    // item = idao.find
                                    break;
                                }
                        }
                    // switch end
                    }
                }
            }
        }
    }
    return openClinicaResource;
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 37 with StudyEventDAO

use of org.akaza.openclinica.dao.managestudy.StudyEventDAO 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)

Example 38 with StudyEventDAO

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

the class OpenRosaServices method getSchedule.

@GET
@Path("/{studyOID}/getSchedule")
@Produces(MediaType.APPLICATION_XML)
public String getSchedule(@Context HttpServletRequest request, @Context HttpServletResponse response, @Context ServletContext context, @PathParam("studyOID") String studyOID, @RequestHeader("Authorization") String authorization) throws Exception {
    String ssoid = request.getParameter("studySubjectOID");
    StudySubjectDAO ssdao = new StudySubjectDAO<String, ArrayList>(dataSource);
    StudySubjectBean ssBean = ssdao.findByOid(ssoid);
    if (!mayProceedSubmission(studyOID, ssBean))
        return null;
    HashMap<String, String> urlCache = (HashMap<String, String>) context.getAttribute("pformURLCache");
    context.getAttribute("subjectContextCache");
    if (ssoid == null) {
        return "<error>studySubjectOID is null :(</error>";
    }
    try {
        // Need to retrieve crf's for next event
        StudyEventDAO eventDAO = new StudyEventDAO(getDataSource());
        StudyEventBean nextEvent = (StudyEventBean) eventDAO.getNextScheduledEvent(ssoid);
        CRFVersionDAO versionDAO = new CRFVersionDAO(getDataSource());
        ArrayList<CRFVersionBean> crfs = versionDAO.findDefCRFVersionsByStudyEvent(nextEvent.getStudyEventDefinitionId());
        PFormCache cache = PFormCache.getInstance(context);
        for (CRFVersionBean crfVersion : crfs) {
            String enketoURL = cache.getPFormURL(studyOID, crfVersion.getOid());
            String contextHash = cache.putSubjectContext(ssoid, String.valueOf(nextEvent.getStudyEventDefinitionId()), String.valueOf(nextEvent.getSampleOrdinal()), crfVersion.getOid(), studyOID);
        }
    } catch (Exception e) {
        LOGGER.debug(e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return "<error>" + e.getMessage() + "</error>";
    }
    response.setHeader("Content-Type", "text/xml; charset=UTF-8");
    response.setHeader("Content-Disposition", "attachment; filename=\"schedule.xml\";");
    response.setContentType("text/xml; charset=utf-8");
    return "<result>success</result>";
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) WebApplicationException(javax.ws.rs.WebApplicationException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 39 with StudyEventDAO

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

the class SDVUtil method prepareSDVSelectElements.

public void prepareSDVSelectElements(HttpServletRequest request, StudyBean studyBean) {
    //Study event statuses
    List<String> studyEventStatuses = new ArrayList<String>();
    for (org.akaza.openclinica.domain.Status stat : org.akaza.openclinica.domain.Status.values()) {
        studyEventStatuses.add(stat.getDescription());
    }
    request.setAttribute("studyEventStatuses", studyEventStatuses);
    //SDV requirements
    List<String> sdvRequirements = new ArrayList<String>();
    for (SourceDataVerification sdvRequire : SourceDataVerification.values()) {
        sdvRequirements.add(sdvRequire.getDescription());
    }
    request.setAttribute("sdvRequirements", SourceDataVerification.values());
    //study event definitions
    StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(dataSource);
    List<StudyEventDefinitionBean> studyEventDefinitionBeans = new ArrayList<StudyEventDefinitionBean>();
    studyEventDefinitionBeans = studyEventDefinitionDAO.findAllByStudy(studyBean);
    request.setAttribute("studyEventDefinitions", studyEventDefinitionBeans);
    //study event status
    request.setAttribute("studyEventStatuses", Status.toArrayList());
    //event CRF status
    request.setAttribute("eventCRFDStatuses", SubjectEventStatus.toArrayList());
    StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
    List<StudyEventBean> studyEventBeans = studyEventDAO.findAllByStudy(studyBean);
    List<EventCRFBean> eventCRFBeans = getAllEventCRFs(studyEventBeans);
    SortedSet<String> eventCRFNames = new TreeSet<String>();
    for (EventCRFBean bean : eventCRFBeans) {
        eventCRFNames.add(getCRFName(bean.getCRFVersionId()));
    }
    request.setAttribute("eventCRFNames", eventCRFNames);
}
Also used : ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) SourceDataVerification(org.akaza.openclinica.domain.SourceDataVerification) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) TreeSet(java.util.TreeSet) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO)

Example 40 with StudyEventDAO

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

the class SDVUtil method filterEventCRFs.

public List<EventCRFBean> filterEventCRFs(List<EventCRFBean> eventCRFBeans, BindingResult bindingResult) {
    /* study_subject_id=Subject+D&eventCRF=0&studyEventDefinition=0&
        studyEventStatus=-1&eventCRFStatus=-1&eventcrfSDVStatus=None&
        sdvRequirement=0&startUpdatedDate=&endDate=&submit=Apply+Filter*/
    List<EventCRFBean> newList = new ArrayList<EventCRFBean>();
    if (eventCRFBeans == null || eventCRFBeans.isEmpty() || bindingResult == null) {
        return eventCRFBeans;
    }
    SdvFilterDataBean filterBean = (SdvFilterDataBean) bindingResult.getTarget();
    StudySubjectBean studySubjectBean = null;
    StudyEventBean studyEventBean = null;
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
    StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
    boolean studySub = true, studyEventDef = true, studyEventStatus = true, eventCRFStatusBool = true, eventcrfSDVStatus = true, eventCRFNameBool = true, upDatedDateBool = true, sdvRequirementBool = true;
    for (EventCRFBean eventCBean : eventCRFBeans) {
        //filter study subject
        if (filterBean.getStudy_subject_id().length() > 0) {
            studySubjectBean = (StudySubjectBean) studySubjectDAO.findByPK(eventCBean.getStudySubjectId());
            studySub = filterBean.getStudy_subject_id().equalsIgnoreCase(studySubjectBean.getLabel());
        }
        if (filterBean.getStudyEventDefinition() > 0) {
            studyEventBean = (StudyEventBean) studyEventDAO.findByPK(eventCBean.getStudyEventId());
            studyEventDef = filterBean.getStudyEventDefinition() == studyEventBean.getStudyEventDefinitionId();
        }
        //Event CRF status
        if (filterBean.getStudyEventStatus() > 0) {
            studyEventStatus = filterBean.getStudyEventStatus() == eventCBean.getStatus().getId();
        }
        //Event CRF subject event status
        if (filterBean.getEventCRFStatus() > 0) {
            studyEventBean = (StudyEventBean) studyEventDAO.findByPK(eventCBean.getStudyEventId());
            eventCRFStatusBool = filterBean.getEventCRFStatus() == studyEventBean.getSubjectEventStatus().getId();
        }
        //Event CRF SDV status; true or false
        if (!filterBean.getEventcrfSDVStatus().equalsIgnoreCase("N/A")) {
            boolean sdvBool = filterBean.getEventcrfSDVStatus().equalsIgnoreCase("complete");
            eventcrfSDVStatus = eventCBean.isSdvStatus() == sdvBool;
        }
        //Event CRF name match
        if (filterBean.getEventCRFName().length() > 0) {
            String tmpName = getCRFName(eventCBean.getCRFVersionId());
            eventCRFNameBool = tmpName.equalsIgnoreCase(filterBean.getEventCRFName());
        }
        //event CRF updated date
        if (eventCBean.getUpdatedDate() != null && filterBean.getStartUpdatedDate() != null && filterBean.getEndDate() != null) {
            GregorianCalendar calStart = new GregorianCalendar();
            calStart.setTime(filterBean.getStartUpdatedDate());
            GregorianCalendar calendarEnd = new GregorianCalendar();
            calendarEnd.setTime(filterBean.getEndDate());
            GregorianCalendar calendarNow = new GregorianCalendar();
            calendarNow.setTime(eventCBean.getUpdatedDate());
            upDatedDateBool = calendarNow.after(calStart) && calendarNow.before(calendarEnd) || calendarNow.equals(calStart) || calendarNow.equals(calendarEnd);
        }
        if (upDatedDateBool && eventCRFNameBool && eventcrfSDVStatus && eventCRFStatusBool && studyEventStatus && studyEventDef && studySub) {
            newList.add(eventCBean);
        }
    }
    return newList;
}
Also used : EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) GregorianCalendar(java.util.GregorianCalendar) SdvFilterDataBean(org.akaza.openclinica.controller.helper.SdvFilterDataBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Aggregations

StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)107 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)90 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)80 ArrayList (java.util.ArrayList)76 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)69 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)69 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)62 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)61 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)57 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)57 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)51 Date (java.util.Date)49 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)49 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)41 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)40 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)38 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)35 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)35 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)33 HashMap (java.util.HashMap)29