Search in sources :

Example 31 with SubjectBean

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

the class ViewNoteServlet method processRequest.

@Override
protected void processRequest() throws Exception {
    FormProcessor fp = new FormProcessor(request);
    Locale locale = LocaleResolver.getLocale(request);
    DateFormat dateFormatter = DateFormat.getDateInstance(DateFormat.DEFAULT, locale);
    DiscrepancyNoteDAO dndao = new DiscrepancyNoteDAO(sm.getDataSource());
    dndao.setFetchMapping(true);
    int noteId = fp.getInt(NOTE_ID, true);
    DiscrepancyNoteBean note = (DiscrepancyNoteBean) dndao.findByPK(noteId);
    String entityType = note.getEntityType();
    if (note.getEntityId() > 0 && !entityType.equals("")) {
        if (!StringUtil.isBlank(entityType)) {
            if ("itemData".equalsIgnoreCase(entityType)) {
                ItemDataDAO iddao = new ItemDataDAO(sm.getDataSource());
                ItemDataBean itemData = (ItemDataBean) iddao.findByPK(note.getEntityId());
                ItemDAO idao = new ItemDAO(sm.getDataSource());
                ItemBean item = (ItemBean) idao.findByPK(itemData.getItemId());
                note.setEntityValue(itemData.getValue());
                note.setEntityName(item.getName());
                // Mantis Issue 5165. It should be itemData.getId() instead of item.getId()
                note.setEntityId(itemData.getId());
                EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
                EventCRFBean ec = (EventCRFBean) ecdao.findByPK(itemData.getEventCRFId());
                StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
                StudyEventBean se = (StudyEventBean) sed.findByPK(ec.getStudyEventId());
                StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
                StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
                note.setStudySub(ssub);
                StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
                StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
                se.setName(sedb.getName());
                note.setEvent(se);
                CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
                CRFVersionBean cv = (CRFVersionBean) cvdao.findByPK(ec.getCRFVersionId());
                CRFDAO cdao = new CRFDAO(sm.getDataSource());
                CRFBean crf = (CRFBean) cdao.findByPK(cv.getCrfId());
                note.setCrfName(crf.getName());
            } else if ("studySub".equalsIgnoreCase(entityType)) {
                StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
                StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(note.getEntityId());
                note.setStudySub(ssub);
                // System.out.println("column" + note.getColumn());
                SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
                SubjectBean sub = (SubjectBean) sdao.findByPK(ssub.getSubjectId());
                if (!StringUtil.isBlank(note.getColumn())) {
                    if ("enrollment_date".equalsIgnoreCase(note.getColumn())) {
                        if (ssub.getEnrollmentDate() != null) {
                            note.setEntityValue(dateFormatter.format(ssub.getEnrollmentDate()));
                        }
                        note.setEntityName(resword.getString("enrollment_date"));
                    } else if ("gender".equalsIgnoreCase(note.getColumn())) {
                        note.setEntityValue(sub.getGender() + "");
                        note.setEntityName(resword.getString("gender"));
                    } else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
                        if (sub.getDateOfBirth() != null) {
                            note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
                        }
                        note.setEntityName(resword.getString("date_of_birth"));
                    }
                }
            } else if ("subject".equalsIgnoreCase(entityType)) {
                SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
                SubjectBean sub = (SubjectBean) sdao.findByPK(note.getEntityId());
                StudySubjectBean ssub = new StudySubjectBean();
                ssub.setLabel(sub.getUniqueIdentifier());
                note.setStudySub(ssub);
                if (!StringUtil.isBlank(note.getColumn())) {
                    if ("gender".equalsIgnoreCase(note.getColumn())) {
                        note.setEntityValue(sub.getGender() + "");
                        note.setEntityName(resword.getString("gender"));
                    } else if ("date_of_birth".equalsIgnoreCase(note.getColumn())) {
                        if (sub.getDateOfBirth() != null) {
                            note.setEntityValue(dateFormatter.format(sub.getDateOfBirth()));
                        }
                        note.setEntityName(resword.getString("date_of_birth"));
                    } else if ("unique_identifier".equalsIgnoreCase(note.getColumn())) {
                        note.setEntityName(resword.getString("unique_identifier"));
                        note.setEntityValue(sub.getUniqueIdentifier());
                    }
                }
            } else if ("studyEvent".equalsIgnoreCase(entityType)) {
                StudyEventDAO sed = new StudyEventDAO(sm.getDataSource());
                StudyEventBean se = (StudyEventBean) sed.findByPK(note.getEntityId());
                StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
                StudySubjectBean ssub = (StudySubjectBean) ssdao.findByPK(se.getStudySubjectId());
                note.setStudySub(ssub);
                StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(sm.getDataSource());
                StudyEventDefinitionBean sedb = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
                se.setName(sedb.getName());
                note.setEvent(se);
                if (!StringUtil.isBlank(note.getColumn())) {
                    if ("location".equalsIgnoreCase(note.getColumn())) {
                        request.setAttribute("entityValue", se.getLocation());
                        request.setAttribute("entityName", resword.getString("location"));
                        note.setEntityName(resword.getString("location"));
                        note.setEntityValue(se.getLocation());
                    } else if ("date_start".equalsIgnoreCase(note.getColumn())) {
                        if (se.getDateStarted() != null) {
                            note.setEntityValue(dateFormatter.format(se.getDateStarted()));
                        }
                        note.setEntityName(resword.getString("start_date"));
                    } else if ("date_end".equalsIgnoreCase(note.getColumn())) {
                        if (se.getDateEnded() != null) {
                            note.setEntityValue(dateFormatter.format(se.getDateEnded()));
                        }
                        note.setEntityName(resword.getString("end_date"));
                    }
                }
            } else if ("eventCrf".equalsIgnoreCase(entityType)) {
                EventCRFDAO ecdao = new EventCRFDAO(sm.getDataSource());
                EventCRFBean ec = (EventCRFBean) ecdao.findByPK(note.getEntityId());
                StudySubjectBean ssub = (StudySubjectBean) new StudySubjectDAO(sm.getDataSource()).findByPK(ec.getStudySubjectId());
                note.setStudySub(ssub);
                StudyEventBean event = (StudyEventBean) new StudyEventDAO(sm.getDataSource()).findByPK(ec.getStudyEventId());
                note.setEvent(event);
                if (!StringUtil.isBlank(note.getColumn())) {
                    if ("date_interviewed".equals(note.getColumn())) {
                        if (ec.getDateInterviewed() != null) {
                            note.setEntityValue(dateFormatter.format(ec.getDateInterviewed()));
                        }
                        note.setEntityName(resword.getString("date_interviewed"));
                    } else if ("interviewer_name".equals(note.getColumn())) {
                        note.setEntityValue(ec.getInterviewerName());
                        note.setEntityName(resword.getString("interviewer_name"));
                    }
                }
            }
        }
    }
    // Mantis Issue 8495.
    if (note.getStudyId() != currentStudy.getId()) {
        if (currentStudy.getParentStudyId() > 0) {
            if (currentStudy.getId() != note.getStudySub().getStudyId()) {
                addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
                forwardPage(Page.MENU_SERVLET);
                return;
            }
        } else {
            // The SubjectStudy is not belong to currentstudy and current study is not a site.
            StudyDAO studydao = new StudyDAO(sm.getDataSource());
            Collection sites;
            sites = studydao.findOlnySiteIdsByStudy(currentStudy);
            if (!sites.contains(note.getStudySub().getStudyId())) {
                addPageMessage(respage.getString("no_have_correct_privilege_current_study") + " " + respage.getString("change_active_study_or_contact"));
                forwardPage(Page.MENU_SERVLET);
                return;
            }
        }
    }
    // Check end
    UserAccountDAO udao = new UserAccountDAO(sm.getDataSource());
    ArrayList<DiscrepancyNoteBean> notes = dndao.findAllEntityByPK(note.getEntityType(), noteId);
    Date lastUpdatedDate = note.getCreatedDate();
    UserAccountBean lastUpdator = (UserAccountBean) udao.findByPK(note.getOwnerId());
    /*
         * for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
         * (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
         * (pId == 0) { note = n; note.setLastUpdator((UserAccountBean)
         * udao.findByPK(n.getOwnerId()));
         * note.setLastDateUpdated(n.getCreatedDate()); lastUpdatedDate =
         * note.getLastDateUpdated(); lastUpdator = note.getLastUpdator(); } }
         */
    // BWP 3029 >> This algorithm needs to be changed to properly set
    // the parent note's status and updated date
    // First sort the notes on their ID; this will put the parent note
    // first; and
    // the note with the latest status and updated date last
    java.util.Collections.sort(notes);
    DiscrepancyNoteBean lastChild = notes.get(notes.size() - 1);
    lastUpdatedDate = lastChild.getCreatedDate();
    lastUpdator = (UserAccountBean) udao.findByPK(lastChild.getOwnerId());
    note.setLastUpdator(lastUpdator);
    note.setLastDateUpdated(lastUpdatedDate);
    note.setUpdatedDate(lastUpdatedDate);
    for (DiscrepancyNoteBean dnBean : notes) {
        if (dnBean.getParentDnId() > 0) {
            note.getChildren().add(dnBean);
        }
    }
    /*
         * for (int i = 0; i < notes.size(); i++) { DiscrepancyNoteBean n =
         * (DiscrepancyNoteBean) notes.get(i); int pId = n.getParentDnId(); if
         * (pId > 0) { note.getChildren().add(n);
         *
         * if (!n.getCreatedDate().before(lastUpdatedDate)) { lastUpdatedDate =
         * n.getCreatedDate(); lastUpdator = (UserAccountBean)
         * udao.findByPK(n.getOwnerId()); note.setLastUpdator(lastUpdator);
         * note.setLastDateUpdated(lastUpdatedDate);
         * note.setResolutionStatusId(n.getResolutionStatusId());
         * note.setResStatus(ResolutionStatus.get(n.getResolutionStatusId())); } } }
         */
    note.setNumChildren(note.getChildren().size());
    note.setDisType(DiscrepancyNoteType.get(note.getDiscrepancyNoteTypeId()));
    request.setAttribute(DIS_NOTE, note);
    forwardPage(Page.VIEW_SINGLE_NOTE);
}
Also used : Locale(java.util.Locale) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) DiscrepancyNoteDAO(org.akaza.openclinica.dao.managestudy.DiscrepancyNoteDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) UserAccountDAO(org.akaza.openclinica.dao.login.UserAccountDAO) Date(java.util.Date) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) DiscrepancyNoteBean(org.akaza.openclinica.bean.managestudy.DiscrepancyNoteBean) DateFormat(java.text.DateFormat) Collection(java.util.Collection) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Example 32 with SubjectBean

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

the class SDVUtil method getSubjectRows.

/*
     * Generate the rows for the study table. Each row represents an Event CRF.
     */
public Collection<SubjectSDVContainer> getSubjectRows(List<EventCRFBean> eventCRFBeans, HttpServletRequest request) {
    if (eventCRFBeans == null || eventCRFBeans.isEmpty()) {
        return new ArrayList<SubjectSDVContainer>();
    }
    getEventNamesForEventCRFs(eventCRFBeans);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(dataSource);
    SubjectDAO subjectDAO = new SubjectDAO(dataSource);
    StudyDAO studyDAO = new StudyDAO(dataSource);
    StudyEventDAO studyEventDAO = new StudyEventDAO(dataSource);
    EventDefinitionCRFDAO eventDefinitionCRFDAO = new EventDefinitionCRFDAO(dataSource);
    StudySubjectBean studySubjectBean = null;
    SubjectBean subjectBean = null;
    StudyEventBean studyEventBean = null;
    StudyBean studyBean = null;
    EventDefinitionCRFBean eventDefinitionCRFBean = null;
    Collection<SubjectSDVContainer> allRows = new ArrayList<SubjectSDVContainer>();
    SubjectSDVContainer tempSDVBean = null;
    StringBuilder actions = new StringBuilder("");
    for (EventCRFBean crfBean : eventCRFBeans) {
        tempSDVBean = new SubjectSDVContainer();
        studySubjectBean = (StudySubjectBean) studySubjectDAO.findByPK(crfBean.getStudySubjectId());
        studyEventBean = (StudyEventBean) studyEventDAO.findByPK(crfBean.getStudyEventId());
        subjectBean = (SubjectBean) subjectDAO.findByPK(studySubjectBean.getSubjectId());
        // find out the study's identifier
        studyBean = (StudyBean) studyDAO.findByPK(studySubjectBean.getStudyId());
        tempSDVBean.setStudyIdentifier(studyBean.getIdentifier());
        eventDefinitionCRFBean = eventDefinitionCRFDAO.findByStudyEventIdAndCRFVersionId(studyBean, studyEventBean.getId(), crfBean.getCRFVersionId());
        SourceDataVerification sourceData = eventDefinitionCRFBean.getSourceDataVerification();
        if (sourceData != null) {
            tempSDVBean.setSdvRequirementDefinition(sourceData.toString());
        } else {
            tempSDVBean.setSdvRequirementDefinition("");
        }
        tempSDVBean.setCrfNameVersion(getCRFName(crfBean.getCRFVersionId()) + "/ " + getCRFVersionName(crfBean.getCRFVersionId()));
        if (crfBean.getStatus() != null) {
            Integer status = crfBean.getStage().getId();
            if (studyEventBean.getSubjectEventStatus() == SubjectEventStatus.LOCKED || studyEventBean.getSubjectEventStatus() == SubjectEventStatus.STOPPED || studyEventBean.getSubjectEventStatus() == SubjectEventStatus.SKIPPED) {
                status = DataEntryStage.LOCKED.getId();
            }
            tempSDVBean.setCrfStatus(getCRFStatusIconPath(status, request, studySubjectBean.getId(), crfBean.getId(), crfBean.getCRFVersionId()));
        }
        tempSDVBean.setStudyEventStatus(studyEventBean.getStatus().getName());
        // TODO: I18N Date must be formatted properly
        Locale locale = LocaleResolver.getLocale(request);
        SimpleDateFormat sdformat = I18nFormatUtil.getDateFormat(locale);
        if (studySubjectBean.getEnrollmentDate() != null) {
            tempSDVBean.setEnrollmentDate(sdformat.format(studySubjectBean.getEnrollmentDate()));
        } else {
        // tempSDVBean.setEnrollmentDate("unknown");
        }
        // TODO: I18N Date must be formatted properly
        // Fix OC 1888
        StudyEventDAO sedao = new StudyEventDAO(dataSource);
        StudyEventBean seBean = (StudyEventBean) sedao.findByPK(crfBean.getStudyEventId());
        tempSDVBean.setEventDate(sdformat.format(seBean.getDateStarted()));
        // if (crfBean.getCreatedDate() != null) {
        // tempSDVBean.setEventDate(sdformat.format(crfBean.getCreatedDate()));
        // } else {
        // //tempSDVBean.setEventDate("unknown");
        // 
        // }
        // crfBean.getEventName()
        tempSDVBean.setEventName(crfBean.getEventName());
        // The checkbox is next to the study subject id
        StringBuilder sdvStatus = new StringBuilder("");
        // to cancel this transaction."
        if (crfBean.isSdvStatus() && studyBean.getStatus().isLocked()) {
            sdvStatus.append(getIconForSdvStatusPrefix()).append("DoubleCheck").append(ICON_FORCRFSTATUS_SUFFIX).append("</a></center>");
        } else if (crfBean.isSdvStatus() && !studyBean.getStatus().isLocked()) {
            sdvStatus.append("<center><a href='javascript:void(0)' onclick='prompt(document.sdvForm,");
            sdvStatus.append(crfBean.getId());
            sdvStatus.append(")'>");
            sdvStatus.append(getIconForSdvStatusPrefix()).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(CHECKBOX_NAME).append(crfBean.getId()).append("' /></center>");
        }
        // sdvStatus.append(studySubjectBean.getLabel());
        tempSDVBean.setSdvStatus(sdvStatus.toString());
        tempSDVBean.setStudySubjectId(studySubjectBean.getLabel());
        if (subjectBean != null) {
            tempSDVBean.setPersonId(subjectBean.getUniqueIdentifier());
        } else {
            tempSDVBean.setPersonId("");
        }
        // studySubjectBean.getSecondaryLabel()
        tempSDVBean.setSecondaryId(studySubjectBean.getSecondaryLabel());
        String statusName = studySubjectBean.getStatus().getName();
        int statusId = studySubjectBean.getStatus().getId();
        if (statusName != null) {
            tempSDVBean.setStudySubjectStatus(statusName);
        }
        // TODO: I18N Date must be formatted properly
        if (crfBean.getUpdatedDate() != null) {
            tempSDVBean.setLastUpdatedDate(sdformat.format(crfBean.getUpdatedDate()));
        } else {
            tempSDVBean.setLastUpdatedDate("unknown");
        }
        if (crfBean.getUpdater() != null) {
            tempSDVBean.setLastUpdatedBy(crfBean.getUpdater().getFirstName() + " " + crfBean.getUpdater().getLastName());
        }
        actions = new StringBuilder("");
        // append("<input type='hidden' name='crfId' value='").append(crfBean.getId()).append("'").append("/> ")
        if (!crfBean.isSdvStatus()) {
            StringBuilder jsCodeString = new StringBuilder("this.form.method='GET'; this.form.action='").append(request.getContextPath()).append("/pages/handleSDVGet").append("';").append("this.form.crfId.value='").append(crfBean.getId()).append("';").append("this.form.submit();");
            if (!studyBean.getStatus().isLocked()) {
                actions.append("<input type=\"submit\" class=\"button_medium\" value=\"SDV\" name=\"sdvSubmit\" ").append("onclick=\"").append(jsCodeString.toString()).append("\" />");
            }
        }
        // Only implement the view icon if it is a event crf request
        /*
             * String bool = (String) request.getAttribute("isViewSubjectRequest");
             * if(! "y".equalsIgnoreCase(bool)){
             * StringBuilder urlPrefix = new
             * StringBuilder("<a href='javascript:void(0)' onclick=\"document.location.href='");
             * StringBuilder path = new
             * StringBuilder(request.getContextPath()).append("/pages/viewAllSubjectSDV?studyId=").append(
             * studySubjectBean.getStudyId()).append("&studySubjectId=");
             * path.append(studySubjectBean.getId());
             * 
             * urlPrefix.append(path).append("'\">");
             * actions.append("&nbsp;").append(urlPrefix).append(VIEW_ICON_HTML).append("</a>");
             * }
             */
        tempSDVBean.setSdvStatusActions(actions.toString());
        allRows.add(tempSDVBean);
    }
    return allRows;
}
Also used : Locale(java.util.Locale) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) SubjectSDVContainer(org.akaza.openclinica.controller.helper.table.SubjectSDVContainer) SourceDataVerification(org.akaza.openclinica.domain.SourceDataVerification) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) SimpleDateFormat(java.text.SimpleDateFormat)

Example 33 with SubjectBean

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

the class UpdateSubjectServlet method confirm.

/**
 * Processes 'confirm' request, validate the subject object
 *
 * @throws Exception
 */
private void confirm(SubjectBean subject, int subjectId) throws Exception {
    FormDiscrepancyNotes discNotes = (FormDiscrepancyNotes) session.getAttribute(AddNewSubjectServlet.FORM_DISCREPANCY_NOTES_NAME);
    if (discNotes == null) {
        discNotes = new FormDiscrepancyNotes();
    }
    DiscrepancyValidator v = new DiscrepancyValidator(request, discNotes);
    FormProcessor fp = new FormProcessor(request);
    if (currentStudy.getStudyParameterConfig().getPersonIdShownOnCRF().equals("true")) {
        v.addValidation("uniqueIdentifier", Validator.LENGTH_NUMERIC_COMPARISON, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, 255);
        v.alwaysExecuteLastValidation("uniqueIdentifier");
    }
    String personId = fp.getString(INPUT_UNIQUE_IDENTIFIER);
    if (personId.contains("<") || personId.contains(">")) {
        v.addValidation("uniqueIdentifier", Validator.DOES_NOT_CONTAIN_HTML_LESSTHAN_GREATERTHAN_ELEMENTS);
    }
    if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
        if (!StringUtil.isBlank(fp.getString(DATE_DOB))) {
            v.addValidation(DATE_DOB, Validator.IS_A_DATE);
            v.alwaysExecuteLastValidation(DATE_DOB);
        } else if (StringUtil.isBlank(fp.getString(DATE_DOB)) && subject.getDateOfBirth() != null) {
            Validator.addError(errors, DATE_DOB, resexception.getString("field_not_blank"));
        }
        if (fp.getDate(DATE_DOB) != null) {
            subject.setDateOfBirth(fp.getDate(DATE_DOB));
            String converted_date = local_df.format(subject.getDateOfBirth());
            request.setAttribute(DATE_DOB_TO_SAVE, converted_date);
        }
    } else if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2")) {
        if (!StringUtils.isBlank(fp.getString(DATE_DOB))) {
            // if DOB was not updated (and originally entered as a full day, post it as is
            String submitted_date = fp.getString(DATE_DOB);
            boolean isTheSameDate = false;
            try {
                Date fakeDOB = yformat.parse(submitted_date);
                if (subject.getDateOfBirth() != null) {
                    if (subject.getDateOfBirth().getYear() == (fakeDOB.getYear())) {
                        isTheSameDate = true;
                        String converted_date = yformat.format(subject.getDateOfBirth());
                        request.setAttribute(DATE_DOB_TO_SAVE, converted_date);
                    }
                }
            } catch (ParseException pe) {
                logger.debug("update subject: cannot convert date " + submitted_date);
            // I am putting on Pradnya's request the link to code review with a long discussion
            // about what type of logging should be here: enjoy
            // https://dev.openclinica.com/crucible/cru/OC-117
            }
            if (!isTheSameDate) {
                v.addValidation(DATE_DOB, Validator.IS_AN_INTEGER);
                v.alwaysExecuteLastValidation(DATE_DOB);
                v.addValidation(DATE_DOB, Validator.COMPARES_TO_STATIC_VALUE, NumericComparisonOperator.GREATER_THAN_OR_EQUAL_TO, 1000);
                // get today's year
                Date today = new Date();
                Calendar c = Calendar.getInstance();
                c.setTime(today);
                int currentYear = c.get(Calendar.YEAR);
                v.addValidation(DATE_DOB, Validator.COMPARES_TO_STATIC_VALUE, NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO, currentYear);
                int yob = fp.getInt(DATE_DOB);
                Date fakeDate = new Date(yob);
                String dobString = yformat.format(fakeDate);
                try {
                    Date fakeDOB = yformat.parse(dobString);
                    if (yob != 0) {
                        subject.setDateOfBirth(fakeDOB);
                    }
                    request.setAttribute(DATE_DOB_TO_SAVE, yob);
                } catch (ParseException pe) {
                    logger.debug("Parse exception happened.");
                    // I am putting on Pradnya's request the link to code review with a long discussion
                    // about what type of logging should be here: enjoy
                    // https://dev.openclinica.com/crucible/cru/OC-117
                    Validator.addError(errors, DATE_DOB, resexception.getString("please_enter_a_valid_year_birth"));
                }
            }
            request.setAttribute(DATE_DOB, fp.getString(DATE_DOB));
        } else {
            Validator.addError(errors, DATE_DOB, resexception.getString("field_not_blank"));
        }
    }
    errors = v.validate();
    // uniqueIdentifier must be unique in the system
    if (currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("required") || currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("optional")) {
        String uniqueIdentifier = fp.getString("uniqueIdentifier");
        if (currentStudy.getStudyParameterConfig().getSubjectPersonIdRequired().equals("required") && !(subject.getUniqueIdentifier() == null || subject.getUniqueIdentifier().isEmpty()) && (uniqueIdentifier == null || uniqueIdentifier.isEmpty())) {
            Validator.addError(errors, "uniqueIdentifier", resexception.getString("field_not_blank"));
        }
        if (uniqueIdentifier != null && !uniqueIdentifier.isEmpty()) {
            if (uniqueIdentifier.length() > 255) {
                String descr = resexception.getString("input_provided_is_not") + NumericComparisonOperator.LESS_THAN_OR_EQUAL_TO.getDescription() + " 255 " + resword.getString("characters_long") + ".";
                Validator.addError(errors, "uniqueIdentifier", descr);
            }
            SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
            SubjectBean sub1 = (SubjectBean) sdao.findAnotherByIdentifier(uniqueIdentifier, subject.getId());
            if (sub1.getId() > 0) {
                Validator.addError(errors, "uniqueIdentifier", resexception.getString("person_ID_used_by_another_choose_unique"));
            }
            SubjectBean subjectWithSameId = sdao.findByUniqueIdentifier(uniqueIdentifier);
            if (subjectWithSameId.isActive() && subjectWithSameId.getId() != subject.getId()) {
                Validator.addError(errors, "uniqueIdentifier", resexception.getString("another_assigned_this_ID_choose_unique"));
            }
        }
        subject.setUniqueIdentifier(uniqueIdentifier);
    }
    if (!StringUtil.isBlank(fp.getString("gender"))) {
        subject.setGender(fp.getString("gender").charAt(0));
    } else {
        if (currentStudy.getStudyParameterConfig().getGenderRequired().equals("true") && subject.getGender() != ' ') {
            Validator.addError(errors, "gender", resexception.getString("field_not_blank"));
        }
        subject.setGender(' ');
    }
    request.setAttribute("subjectToUpdate", subject);
    if (errors.isEmpty()) {
        forwardPage(Page.UPDATE_SUBJECT_CONFIRM);
    } else {
        // I am putting on Pradnya's request the link to code review with a long discussion
        // about what type of logging should be here: enjoy
        // https://dev.openclinica.com/crucible/cru/OC-117
        logger.error("update subject validation errors");
        setInputMessages(errors);
        setDNFlag(subjectId);
        setLocalDOB(subject);
        if (currentStudy.getStudyParameterConfig().getCollectDob().equals("2"))
            request.setAttribute("localBirthDate", "");
        forwardPage(Page.UPDATE_SUBJECT);
    }
}
Also used : SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) DiscrepancyValidator(org.akaza.openclinica.control.form.DiscrepancyValidator) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) Calendar(java.util.Calendar) ParseException(java.text.ParseException) Date(java.util.Date)

Example 34 with SubjectBean

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

the class ViewSubjectServlet method processRequest.

@Override
public void processRequest() throws Exception {
    SubjectDAO sdao = new SubjectDAO(sm.getDataSource());
    FormProcessor fp = new FormProcessor(request);
    int subjectId = fp.getInt("id");
    if (subjectId == 0) {
        addPageMessage(respage.getString("please_choose_a_subject_to_view"));
        forwardPage(Page.SUBJECT_LIST_SERVLET);
    } else {
        SubjectBean subject = (SubjectBean) sdao.findByPK(subjectId);
        // find all study subjects
        StudySubjectDAO ssdao = new StudySubjectDAO(sm.getDataSource());
        ArrayList studySubs = ssdao.findAllBySubjectId(subjectId);
        request.setAttribute("subject", subject);
        request.setAttribute("studySubs", studySubs);
        forwardPage(Page.VIEW_SUBJECT);
    }
}
Also used : SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) ArrayList(java.util.ArrayList) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO)

Example 35 with SubjectBean

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

the class PrintDataEntryServlet method processRequest.

@Override
public void processRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
    FormProcessor fp = new FormProcessor(request);
    boolean isSubmitted = false;
    int eventCRFId = fp.getInt("ecId");
    // JN:The following were the the global variables, moved as local.
    EventCRFBean ecb;
    SectionDAO sdao = new SectionDAO(getDataSource());
    ArrayList<SectionBean> allSectionBeans = new ArrayList<SectionBean>();
    ArrayList sectionBeans = new ArrayList();
    String age = "";
    StudyBean currentStudy = (StudyBean) request.getSession().getAttribute("study");
    SectionBean sb = (SectionBean) request.getAttribute(SECTION_BEAN);
    // Whether IE6 or IE7 is involved
    String isIE = fp.getString("ie");
    if ("y".equalsIgnoreCase(isIE)) {
        request.setAttribute("isInternetExplorer", "true");
    }
    if (eventCRFId == 0) {
        ecb = new EventCRFBean();
    // super.ecb.setCRFVersionId(sb.getCRFVersionId());
    } else {
        EventCRFDAO ecdao = new EventCRFDAO(getDataSource());
        ecb = (EventCRFBean) ecdao.findByPK(eventCRFId);
        // Get all the SectionBeans attached to this ECB
        ArrayList sects = sdao.findAllByCRFVersionId(ecb.getCRFVersionId());
        for (int i = 0; i < sects.size(); i++) {
            sb = (SectionBean) sects.get(i);
            // super.sb = sb;
            int sectId = sb.getId();
            if (sectId > 0) {
                allSectionBeans.add((SectionBean) sdao.findByPK(sectId));
            }
        }
        // This is the StudySubjectBean
        StudySubjectDAO ssdao = new StudySubjectDAO(getDataSource());
        StudySubjectBean sub = (StudySubjectBean) ssdao.findByPK(ecb.getStudySubjectId());
        // This is the SubjectBean
        SubjectDAO subjectDao = new SubjectDAO(getDataSource());
        int subjectId = sub.getSubjectId();
        int studyId = sub.getStudyId();
        SubjectBean subject = (SubjectBean) subjectDao.findByPK(subjectId);
        StudyEventDAO sedao = new StudyEventDAO(getDataSource());
        StudyEventBean se = (StudyEventBean) sedao.findByPK(ecb.getStudyEventId());
        StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(getDataSource());
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) seddao.findByPK(se.getStudyEventDefinitionId());
        se.setStudyEventDefinition(sed);
        // Let us process the age
        if (currentStudy.getStudyParameterConfig().getCollectDob().equals("1")) {
            // YW 11-16-2007 enrollment-date is used for computing age
            age = Utils.getInstacne().processAge(sub.getEnrollmentDate(), subject.getDateOfBirth());
        }
        // Get the study then the parent study
        StudyDAO studydao = new StudyDAO(getDataSource());
        StudyBean study = (StudyBean) studydao.findByPK(studyId);
        if (study.getParentStudyId() > 0) {
            // this is a site,find parent
            StudyBean parentStudy = (StudyBean) studydao.findByPK(study.getParentStudyId());
            request.setAttribute("studyTitle", parentStudy.getName() + " - " + study.getName());
        } else {
            request.setAttribute("studyTitle", study.getName());
        }
        request.setAttribute("studySubject", sub);
        request.setAttribute("subject", subject);
        request.setAttribute("studyEvent", se);
        request.setAttribute("age", age);
        request.setAttribute(INPUT_EVENT_CRF, ecb);
        request.setAttribute(SECTION_BEAN, sb);
        request.setAttribute(ALL_SECTION_BEANS, allSectionBeans);
        // Get the section beans from super
        sectionBeans = super.getAllDisplayBeans(request);
    }
    // Find out whether the sections involve groups
    ItemGroupDAO itemGroupDao = new ItemGroupDAO(getDataSource());
    // Find truely grouped tables, not groups with a name of 'Ungrouped'
    // CRF VERSION ID WILL BE 0 IF "ecId" IS NOT IN THE QUERYSTRING
    int crfVersionId = ecb.getCRFVersionId();
    List<ItemGroupBean> itemGroupBeans = itemGroupDao.findOnlyGroupsByCRFVersionID(crfVersionId);
    boolean sectionsHaveGroups = false;
    if (itemGroupBeans.size() > 0) {
        sectionsHaveGroups = true;
        // get a DisplaySectionBean for each section of the CRF, sort them,
        // then
        // dispatch the request to a print JSP. the constructor for this
        // handler takes
        // a boolean value depending on whether an event or data is involved
        // or not
        DisplaySectionBeanHandler handler = new DisplaySectionBeanHandler(true, getDataSource(), getServletContext());
        handler.setCrfVersionId(crfVersionId);
        handler.setEventCRFId(eventCRFId);
        List<DisplaySectionBean> displaySectionBeans = handler.getDisplaySectionBeans();
        CRFVersionDAO crfVersionDAO = new CRFVersionDAO(getDataSource());
        CRFDAO crfDao = new CRFDAO(getDataSource());
        request.setAttribute("listOfDisplaySectionBeans", displaySectionBeans);
        // Make available the CRF names and versions for
        // the web page's header
        CRFVersionBean crfverBean = (CRFVersionBean) crfVersionDAO.findByPK(crfVersionId);
        request.setAttribute("crfVersionBean", crfverBean);
        CRFBean crfBean = crfDao.findByVersionId(crfVersionId);
        request.setAttribute("crfBean", crfBean);
        // Set an attribute signaling that an event and/or data is involved
        request.setAttribute("dataInvolved", "true");
    }
    request.setAttribute(BEAN_ANNOTATIONS, ecb.getAnnotations());
    request.setAttribute("EventCRFBean", ecb);
    // We do not need most of these attributes if groups are involved
    if (!sectionsHaveGroups) {
        request.setAttribute(INPUT_EVENT_CRF, ecb);
        request.setAttribute(SECTION_BEAN, sb);
        DisplaySectionBean dsb = super.getDisplayBean(false, false, request, isSubmitted);
        request.setAttribute("allSections", sectionBeans);
        request.setAttribute("displayAll", "1");
        request.setAttribute(BEAN_DISPLAY, dsb);
        request.setAttribute("sec", sb);
        forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT, request, response);
    } else {
        // end if(! sectionsHaveGroups)
        forwardPage(Page.VIEW_SECTION_DATA_ENTRY_PRINT_GROUPS, request, response);
    }
}
Also used : StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) SubjectDAO(org.akaza.openclinica.dao.submit.SubjectDAO) ArrayList(java.util.ArrayList) ItemGroupDAO(org.akaza.openclinica.dao.submit.ItemGroupDAO) 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) DisplaySectionBeanHandler(org.akaza.openclinica.view.display.DisplaySectionBeanHandler) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SectionBean(org.akaza.openclinica.bean.submit.SectionBean) DisplaySectionBean(org.akaza.openclinica.bean.submit.DisplaySectionBean) SubjectBean(org.akaza.openclinica.bean.submit.SubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) DisplayItemGroupBean(org.akaza.openclinica.bean.submit.DisplayItemGroupBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) SectionDAO(org.akaza.openclinica.dao.submit.SectionDAO)

Aggregations

SubjectBean (org.akaza.openclinica.bean.submit.SubjectBean)50 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)44 ArrayList (java.util.ArrayList)37 HashMap (java.util.HashMap)26 SubjectDAO (org.akaza.openclinica.dao.submit.SubjectDAO)25 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)23 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)22 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)22 Date (java.util.Date)21 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)21 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)19 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)19 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)18 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)15 Iterator (java.util.Iterator)14 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)13 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)11 ItemDataBean (org.akaza.openclinica.bean.submit.ItemDataBean)10 ItemDataDAO (org.akaza.openclinica.dao.submit.ItemDataDAO)10 UserAccountBean (org.akaza.openclinica.bean.login.UserAccountBean)9