Search in sources :

Example 41 with StudySubjectDAO

use of org.akaza.openclinica.dao.managestudy.StudySubjectDAO 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 42 with StudySubjectDAO

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

the class SubjectIdSDVFactory method getFilteredItems.

@SuppressWarnings("unchecked")
private Collection<SubjectAggregateContainer> getFilteredItems(StudySubjectSDVFilter filterSet, StudySubjectSDVSort sortSet, int rowStart, int rowEnd) {
    List<SubjectAggregateContainer> rows = new ArrayList<SubjectAggregateContainer>();
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
    List<StudySubjectBean> studySubjectBeans = studySubjectDAO.findAllByStudySDV(studyId, studyId, filterSet, sortSet, rowStart, rowEnd);
    SubjectAggregateContainer containerTmp = null;
    for (StudySubjectBean studSubjBean : studySubjectBeans) {
        containerTmp = getRow(studSubjBean);
        rows.add(containerTmp);
    }
    return rows;
}
Also used : SubjectAggregateContainer(org.akaza.openclinica.controller.helper.table.SubjectAggregateContainer) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) ArrayList(java.util.ArrayList) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Example 43 with StudySubjectDAO

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

the class SubjectIdSDVFactory method getRow.

private SubjectAggregateContainer getRow(StudySubjectBean studySubjectBean) {
    SubjectAggregateContainer row = new SubjectAggregateContainer();
    EventCRFDAO eventCRFDAO = new EventCRFDAO(dataSource);
    StudyDAO studyDAO = new StudyDAO(dataSource);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
    StudyGroupDAO studyGroupDAO = new StudyGroupDAO(dataSource);
    row.setStudySubjectId(studySubjectBean.getLabel());
    row.setPersonId(studySubjectBean.getUniqueIdentifier());
    row.setStudySubjectStatus(studySubjectBean.getStatus().getName());
    int numberEventCRFs = eventCRFDAO.countEventCRFsByStudySubject(studySubjectBean.getId(), studySubjectBean.getStudyId(), studySubjectBean.getStudyId());
    row.setTotalEventCRF(numberEventCRFs + "");
    StudyBean studyBean = (StudyBean) studyDAO.findByPK(studySubjectBean.getStudyId());
    row.setSiteId(studyBean.getIdentifier());
    List<EventCRFBean> eventCRFBeans = eventCRFDAO.getEventCRFsByStudySubject(studySubjectBean.getId(), studySubjectBean.getStudyId(), studySubjectBean.getStudyId());
    HashMap<String, Integer> stats = getEventCRFStats(eventCRFBeans, studySubjectBean);
    //int numberCRFComplete = getNumberCompletedEventCRFs(eventCRFBeans);
    //row.setNumberCRFComplete(numberCRFComplete + "");
    row.setNumberCRFComplete(stats.get("numberOfCompletedEventCRFs") + "");
    row.setNumberOfCRFsSDV(stats.get("numberOfSDVdEventCRFs") + "");
    //row.setNumberOfCRFsSDV(getNumberSDVdEventCRFs(eventCRFBeans) + "");
    //boolean studySubjectSDVd = eventCRFDAO.countEventCRFsByByStudySubjectCompleteOrLockedAndNotSDVd(studySubjectBean.getId()) == 0 && numberCRFComplete > 0;
    boolean studySubjectSDVd = stats.get("areEventCRFsSDVd") == -1 || stats.get("areEventCRFsSDVd") == 1 ? false : true;
    StringBuilder sdvStatus = new StringBuilder("");
    if (stats.get("shouldDisplaySDVButton") == 0) {
        sdvStatus.append("");
    } else if (studySubjectSDVd) {
        sdvStatus.append("<center><a href='javascript:void(0)' onclick='prompt(document.sdvForm,");
        sdvStatus.append(studySubjectBean.getId());
        sdvStatus.append(")'>");
        sdvStatus.append(getIconForCrfStatusPrefix()).append("DoubleCheck").append(ICON_FORCRFSTATUS_SUFFIX).append("</a></center>");
    } else {
        sdvStatus.append("<center><input style='margin-right: 5px' type='checkbox' ").append("class='sdvCheck'").append(" name='").append("sdvCheck_").append(studySubjectBean.getId()).append("' /></center>");
    }
    row.setSdvStatus(sdvStatus.toString());
    List<StudyGroupBean> studyGroupBeans = studyGroupDAO.getGroupByStudySubject(studySubjectBean.getId(), studySubjectBean.getStudyId(), studySubjectBean.getStudyId());
    if (studyGroupBeans != null && !studyGroupBeans.isEmpty()) {
        row.setGroup(studyGroupBeans.get(0).getName());
    }
    StringBuilder actions = new StringBuilder("<table><tr><td>");
    StringBuilder urlPrefix = new StringBuilder("<a href=\"");
    StringBuilder path = new StringBuilder(contextPath).append("/pages/viewAllSubjectSDVtmp?studyId=").append(studyId).append("&sdv_f_studySubjectId=");
    path.append(studySubjectBean.getLabel());
    urlPrefix.append(path).append("\">");
    actions.append(urlPrefix).append(SDVUtil.VIEW_ICON_HTML).append("</a></td>");
    if (!studySubjectSDVd && stats.get("shouldDisplaySDVButton") == 1) {
        StringBuilder jsCodeString = new StringBuilder("this.form.method='GET'; this.form.action='").append(contextPath).append("/pages/sdvStudySubject").append("';").append("this.form.theStudySubjectId.value='").append(studySubjectBean.getId()).append("';").append("this.form.submit();");
        actions.append("<td><input type=\"submit\" class=\"button\" value=\"SDV\" name=\"sdvSubmit\" ").append("onclick=\"").append(jsCodeString.toString()).append("\" /></td>");
    } else if (!studySubjectSDVd) {
        actions.append("<td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SDV N/A</td>");
    }
    actions.append("</tr></table>");
    row.setActions(actions.toString());
    return row;
}
Also used : StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyGroupBean(org.akaza.openclinica.bean.managestudy.StudyGroupBean) SubjectAggregateContainer(org.akaza.openclinica.controller.helper.table.SubjectAggregateContainer) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 44 with StudySubjectDAO

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

Example 45 with StudySubjectDAO

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

the class ImportCRFDataService method eventCRFStatusesValid.

/*
     * purpose: returns false if any of the forms/EventCRFs fail the UpsertOnBean rules.
     */
public boolean eventCRFStatusesValid(ODMContainer odmContainer, UserAccountBean ub) {
    ArrayList<EventCRFBean> eventCRFBeans = new ArrayList<EventCRFBean>();
    ArrayList<Integer> eventCRFBeanIds = new ArrayList<Integer>();
    EventCRFDAO eventCrfDAO = new EventCRFDAO(ds);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
    StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
    StudyDAO studyDAO = new StudyDAO(ds);
    StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
    UpsertOnBean upsert = odmContainer.getCrfDataPostImportContainer().getUpsertOn();
    // If Upsert bean is not present, create one with default settings
    if (upsert == null)
        upsert = new UpsertOnBean();
    String studyOID = odmContainer.getCrfDataPostImportContainer().getStudyOID();
    StudyBean studyBean = studyDAO.findByOid(studyOID);
    ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
    for (SubjectDataBean subjectDataBean : subjectDataBeans) {
        ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
        StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
        for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
            ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
            String sampleOrdinal = studyEventDataBean.getStudyEventRepeatKey() == null ? "1" : studyEventDataBean.getStudyEventRepeatKey();
            StudyEventDefinitionBean studyEventDefinitionBean = studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), studyBean.getParentStudyId());
            logger.info("find all by def and subject " + studyEventDefinitionBean.getName() + " study subject " + studySubjectBean.getName());
            StudyEventBean studyEventBean = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), studyEventDefinitionBean.getId(), Integer.parseInt(sampleOrdinal));
            // locked
            if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.STOPPED)) {
                return true;
            }
            for (FormDataBean formDataBean : formDataBeans) {
                CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
                ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
                for (CRFVersionBean crfVersionBean : crfVersionBeans) {
                    ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersionBean);
                    // event crf, yet.
                    if (eventCrfBeans.isEmpty()) {
                        logger.debug("   found no event crfs from Study Event id " + studyEventBean.getId() + ", location " + studyEventBean.getLocation());
                        if ((studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED))) {
                            if (!upsert.isNotStarted())
                                return false;
                        }
                    }
                    for (EventCRFBean ecb : eventCrfBeans) {
                        Integer ecbId = new Integer(ecb.getId());
                        if (!(ecb.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY) && upsert.isDataEntryStarted()) && !(ecb.getStage().equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) && upsert.isDataEntryComplete()))
                            return false;
                    }
                }
            }
        }
    }
    return true;
}
Also used : UpsertOnBean(org.akaza.openclinica.bean.submit.crfdata.UpsertOnBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

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