Search in sources :

Example 76 with CRFVersionBean

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

the class ViewStudySubjectServlet method getDisplayEventCRFs.

/**
     * Each of the event CRFs with its corresponding CRFBean. Then generates a
     * list of DisplayEventCRFBeans, one for each event CRF.
     *
     * @param eventCRFs
     *            The list of event CRFs for this study event.
     * @param eventDefinitionCRFs
     *            The list of event definition CRFs for this study event.
     * @return The list of DisplayEventCRFBeans for this study event.
     */
public static ArrayList getDisplayEventCRFs(DataSource ds, ArrayList eventCRFs, ArrayList eventDefinitionCRFs, UserAccountBean ub, StudyUserRoleBean currentRole, SubjectEventStatus status, StudyBean study) {
    ArrayList answer = new ArrayList();
    // HashMap definitionsById = new HashMap();
    int i;
    /*
         * for (i = 0; i < eventDefinitionCRFs.size(); i++) {
         * EventDefinitionCRFBean edc = (EventDefinitionCRFBean)
         * eventDefinitionCRFs.get(i); definitionsById.put(new
         * Integer(edc.getStudyEventDefinitionId()), edc); }
         */
    StudyEventDAO sedao = new StudyEventDAO(ds);
    CRFDAO cdao = new CRFDAO(ds);
    CRFVersionDAO cvdao = new CRFVersionDAO(ds);
    FormLayoutDAO fldao = new FormLayoutDAO(ds);
    ItemDataDAO iddao = new ItemDataDAO(ds);
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(ds);
    for (i = 0; i < eventCRFs.size(); i++) {
        EventCRFBean ecb = (EventCRFBean) eventCRFs.get(i);
        // populate the event CRF with its crf bean
        int crfVersionId = ecb.getCRFVersionId();
        int formLayoutId = ecb.getFormLayoutId();
        CRFBean cb = cdao.findByLayoutId(formLayoutId);
        ecb.setCrf(cb);
        CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(crfVersionId);
        ecb.setCrfVersion(cvb);
        FormLayoutBean flb = (FormLayoutBean) fldao.findByPK(formLayoutId);
        ecb.setFormLayout(flb);
        // then get the definition so we can call
        // DisplayEventCRFBean.setFlags
        int studyEventId = ecb.getStudyEventId();
        int studyEventDefinitionId = sedao.getDefinitionIdFromStudyEventId(studyEventId);
        // EventDefinitionCRFBean edc = (EventDefinitionCRFBean)
        // definitionsById.get(new Integer(
        // studyEventDefinitionId));
        // fix problem of the above code(commented out), find the correct
        // edc, note that on definitionId can be related to multiple
        // eventdefinitioncrfBeans
        EventDefinitionCRFBean edc = edcdao.findByStudyEventDefinitionIdAndCRFId(study, studyEventDefinitionId, cb.getId());
        // rules updated 112007 tbh
        if (status.equals(SubjectEventStatus.LOCKED) || status.equals(SubjectEventStatus.SKIPPED) || status.equals(SubjectEventStatus.STOPPED)) {
            ecb.setStage(DataEntryStage.LOCKED);
        // we need to set a SED-wide flag here, because other edcs
        // in this event can be filled in and change the status, tbh
        } else if (status.equals(SubjectEventStatus.INVALID)) {
            ecb.setStage(DataEntryStage.LOCKED);
        } else if (!cb.getStatus().equals(Status.AVAILABLE)) {
            ecb.setStage(DataEntryStage.LOCKED);
        } else if (!cvb.getStatus().equals(Status.AVAILABLE)) {
            ecb.setStage(DataEntryStage.LOCKED);
        }
        // TODO need to refactor since this is similar to other code, tbh
        if (edc != null) {
            // System.out.println("edc is not null, need to set flags");
            DisplayEventCRFBean dec = new DisplayEventCRFBean();
            dec.setEventDefinitionCRF(edc);
            // System.out.println("edc.isDoubleEntry()" +
            // edc.isDoubleEntry() + ecb.getId());
            dec.setFlags(ecb, ub, currentRole, edc.isDoubleEntry());
            if (dec.isLocked()) {
            // System.out.println("*** found a locked DEC:
            // "+edc.getCrfName());
            }
            ArrayList idata = iddao.findAllByEventCRFId(ecb.getId());
            if (!idata.isEmpty()) {
                // consider an event crf started only if item data get
                // created
                answer.add(dec);
            }
        }
    }
    return answer;
}
Also used : EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ArrayList(java.util.ArrayList) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) ItemDataDAO(org.akaza.openclinica.dao.submit.ItemDataDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) DisplayEventCRFBean(org.akaza.openclinica.bean.submit.DisplayEventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) DisplayEventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.DisplayEventDefinitionCRFBean)

Example 77 with CRFVersionBean

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

the class RemoveCRFVersionServlet method updateEventDef.

// @pgawade 18-May-2011 #5414 - Ovrloaded the method updateEventDef for an
// additional parameter of crf version being locked.
// These are changes for setting the correct default crf version Id to event
// when existing default version is locked
public static void updateEventDef(EventDefinitionCRFBean edcBean, EventDefinitionCRFDAO edcDao, ArrayList versionList, int crfVIdToLock) {
    ArrayList<Integer> idList = new ArrayList<Integer>();
    CRFVersionBean temp = null;
    if ((null != versionList) && (versionList.size() > 0)) {
        temp = (CRFVersionBean) versionList.get(0);
    }
    if (StringUtil.isBlank(edcBean.getSelectedVersionIds())) {
        if ((null != temp) && (temp.getId() == crfVIdToLock) && (null != versionList) && (versionList.size() > 1)) {
            CRFVersionBean temp2 = (CRFVersionBean) versionList.get(1);
            edcBean.setDefaultVersionId(temp2.getId());
        } else {
            edcBean.setDefaultVersionId(temp.getId());
        }
        edcDao.update(edcBean);
    } else {
        String sversionIds = edcBean.getSelectedVersionIds();
        String[] ids = sversionIds.split("\\,");
        for (String id : ids) {
            idList.add(Integer.valueOf(id));
        }
        for (int i = 0; i < versionList.size(); i++) {
            CRFVersionBean versionBean = (CRFVersionBean) versionList.get(i);
            if (idList.contains(versionBean.getId())) {
                edcBean.setDefaultVersionId(versionBean.getId());
                edcDao.update(edcBean);
                break;
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Example 78 with CRFVersionBean

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

the class RemoveCRFVersionServlet method updateEventDef.

public static void updateEventDef(EventDefinitionCRFBean edcBean, EventDefinitionCRFDAO edcDao, ArrayList versionList) {
    ArrayList<Integer> idList = new ArrayList<Integer>();
    CRFVersionBean temp = (CRFVersionBean) versionList.get(0);
    if (StringUtil.isBlank(edcBean.getSelectedVersionIds())) {
        edcBean.setDefaultVersionId(temp.getId());
        edcDao.update(edcBean);
    } else {
        String sversionIds = edcBean.getSelectedVersionIds();
        String[] ids = sversionIds.split("\\,");
        for (String id : ids) {
            idList.add(Integer.valueOf(id));
        }
        for (int i = 0; i < versionList.size(); i++) {
            CRFVersionBean versionBean = (CRFVersionBean) versionList.get(i);
            if (idList.contains(versionBean.getId())) {
                edcBean.setDefaultVersionId(versionBean.getId());
                edcDao.update(edcBean);
                break;
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Example 79 with CRFVersionBean

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

the class CreateSubStudyServlet method createSiteEventDefinitions.

private ArrayList<StudyEventDefinitionBean> createSiteEventDefinitions(StudyBean site, Validator v) throws MalformedURLException {
    FormProcessor fp = new FormProcessor(request);
    StudyParameterValueDAO spvdao = new StudyParameterValueDAO(sm.getDataSource());
    ArrayList<EventDefinitionCRFBean> edcsInSession = new ArrayList<EventDefinitionCRFBean>();
    StudyBean parentStudyBean;
    if (site.getParentStudyId() == 0) {
        parentStudyBean = site;
    } else {
        StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
        parentStudyBean = (StudyBean) studyDAO.findByPK(site.getParentStudyId());
    }
    EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
    ArrayList<EventDefinitionCRFBean> eventDefCrfList = (ArrayList<EventDefinitionCRFBean>) edcdao.findAllActiveSitesAndStudiesPerParentStudy(parentStudyBean.getId());
    ArrayList<StudyEventDefinitionBean> seds = new ArrayList<StudyEventDefinitionBean>();
    StudyBean parentStudy = (StudyBean) new StudyDAO(sm.getDataSource()).findByPK(site.getParentStudyId());
    seds = (ArrayList<StudyEventDefinitionBean>) session.getAttribute("definitions");
    if (seds == null || seds.size() <= 0) {
        StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(sm.getDataSource());
        seds = sedDao.findAllByStudy(parentStudy);
    }
    CRFVersionDAO cvdao = new CRFVersionDAO(sm.getDataSource());
    HashMap<String, Boolean> changes = new HashMap<String, Boolean>();
    for (StudyEventDefinitionBean sed : seds) {
        String participateFormStatus = spvdao.findByHandleAndStudy(sed.getStudyId(), "participantPortal").getValue();
        if (participateFormStatus.equals("enabled"))
            baseUrl();
        request.setAttribute("participateFormStatus", participateFormStatus);
        // EventDefinitionCRFDAO edcdao = new EventDefinitionCRFDAO(sm.getDataSource());
        ArrayList<EventDefinitionCRFBean> edcs = sed.getCrfs();
        int start = 0;
        for (EventDefinitionCRFBean edcBean : edcs) {
            EventDefinitionCRFBean persistEventDefBean = (EventDefinitionCRFBean) edcdao.findByPK(edcBean.getId());
            int edcStatusId = edcBean.getStatus().getId();
            if (edcStatusId == 5 || edcStatusId == 7) {
            } else {
                String order = start + "-" + edcBean.getId();
                int defaultVersionId = fp.getInt("defaultVersionId" + order);
                String requiredCRF = fp.getString("requiredCRF" + order);
                String doubleEntry = fp.getString("doubleEntry" + order);
                String electronicSignature = fp.getString("electronicSignature" + order);
                String hideCRF = fp.getString("hideCRF" + order);
                int sdvId = fp.getInt("sdvOption" + order);
                String participantForm = fp.getString("participantForm" + order);
                String allowAnonymousSubmission = fp.getString("allowAnonymousSubmission" + order);
                String submissionUrl = fp.getString("submissionUrl" + order);
                String offline = fp.getString("offline" + order);
                ArrayList<String> selectedVersionIdList = fp.getStringArray("versionSelection" + order);
                int selectedVersionIdListSize = selectedVersionIdList.size();
                String selectedVersionIds = "";
                if (selectedVersionIdListSize > 0) {
                    for (String id : selectedVersionIdList) {
                        selectedVersionIds += id + ",";
                    }
                    selectedVersionIds = selectedVersionIds.substring(0, selectedVersionIds.length() - 1);
                }
                boolean changed = false;
                boolean isRequired = !StringUtil.isBlank(requiredCRF) && "yes".equalsIgnoreCase(requiredCRF.trim()) ? true : false;
                boolean isDouble = !StringUtil.isBlank(doubleEntry) && "yes".equalsIgnoreCase(doubleEntry.trim()) ? true : false;
                boolean hasPassword = !StringUtil.isBlank(electronicSignature) && "yes".equalsIgnoreCase(electronicSignature.trim()) ? true : false;
                boolean isHide = !StringUtil.isBlank(hideCRF) && "yes".equalsIgnoreCase(hideCRF.trim()) ? true : false;
                if (edcBean.getParentId() > 0) {
                    int dbDefaultVersionId = edcBean.getDefaultVersionId();
                    if (defaultVersionId != dbDefaultVersionId) {
                        changed = true;
                        CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(defaultVersionId);
                        edcBean.setDefaultVersionId(defaultVersionId);
                        edcBean.setDefaultVersionName(defaultVersion.getName());
                    }
                    if (isRequired != edcBean.isRequiredCRF()) {
                        changed = true;
                        edcBean.setRequiredCRF(isRequired);
                    }
                    if (isDouble != edcBean.isDoubleEntry()) {
                        changed = true;
                        edcBean.setDoubleEntry(isDouble);
                    }
                    if (hasPassword != edcBean.isElectronicSignature()) {
                        changed = true;
                        edcBean.setElectronicSignature(hasPassword);
                    }
                    if (isHide != edcBean.isHideCrf()) {
                        changed = true;
                        edcBean.setHideCrf(isHide);
                    }
                    if (!submissionUrl.equals(edcBean.getSubmissionUrl()) || !submissionUrl.equals(persistEventDefBean.getSubmissionUrl())) {
                        changed = true;
                        edcBean.setSubmissionUrl(submissionUrl);
                    }
                    if (!StringUtil.isBlank(selectedVersionIds) && !selectedVersionIds.equals(edcBean.getSelectedVersionIds())) {
                        changed = true;
                        String[] ids = selectedVersionIds.split(",");
                        ArrayList<Integer> idList = new ArrayList<Integer>();
                        for (String id : ids) {
                            idList.add(Integer.valueOf(id));
                        }
                        edcBean.setSelectedVersionIdList(idList);
                        edcBean.setSelectedVersionIds(selectedVersionIds);
                    }
                    if (sdvId > 0 && sdvId != edcBean.getSourceDataVerification().getCode()) {
                        changed = true;
                        edcBean.setSourceDataVerification(SourceDataVerification.getByCode(sdvId));
                    }
                } else {
                    // only if definition-crf has been modified, will it be
                    // saved for the site
                    int defaultId = defaultVersionId > 0 ? defaultVersionId : edcBean.getDefaultVersionId();
                    if (defaultId == defaultVersionId) {
                        if (isRequired == edcBean.isRequiredCRF()) {
                            if (isDouble == edcBean.isDoubleEntry()) {
                                if (hasPassword == edcBean.isElectronicSignature()) {
                                    if (isHide == edcBean.isHideCrf()) {
                                        if (submissionUrl.equals("")) {
                                            if (selectedVersionIdListSize > 0) {
                                                if (selectedVersionIdListSize == edcBean.getVersions().size()) {
                                                    if (sdvId > 0) {
                                                        if (sdvId != edcBean.getSourceDataVerification().getCode()) {
                                                            changed = true;
                                                            edcBean.setSourceDataVerification(SourceDataVerification.getByCode(sdvId));
                                                            edcBean.setSubmissionUrl(submissionUrl);
                                                        }
                                                    }
                                                } else {
                                                    changed = true;
                                                    String[] ids = selectedVersionIds.split(",");
                                                    ArrayList<Integer> idList = new ArrayList<Integer>();
                                                    for (String id : ids) {
                                                        idList.add(Integer.valueOf(id));
                                                    }
                                                    edcBean.setSelectedVersionIdList(idList);
                                                    edcBean.setSelectedVersionIds(selectedVersionIds);
                                                    edcBean.setSubmissionUrl(submissionUrl);
                                                }
                                            }
                                        } else {
                                            changed = true;
                                            edcBean.setSubmissionUrl(submissionUrl);
                                        }
                                    } else {
                                        changed = true;
                                        edcBean.setHideCrf(isHide);
                                        edcBean.setSubmissionUrl(submissionUrl);
                                    }
                                } else {
                                    changed = true;
                                    edcBean.setElectronicSignature(hasPassword);
                                    edcBean.setSubmissionUrl(submissionUrl);
                                }
                            } else {
                                changed = true;
                                edcBean.setDoubleEntry(isDouble);
                                edcBean.setSubmissionUrl(submissionUrl);
                            }
                        } else {
                            changed = true;
                            edcBean.setRequiredCRF(isRequired);
                            edcBean.setSubmissionUrl(submissionUrl);
                        }
                    } else {
                        changed = true;
                        CRFVersionBean defaultVersion = (CRFVersionBean) cvdao.findByPK(defaultVersionId);
                        edcBean.setDefaultVersionId(defaultVersionId);
                        edcBean.setDefaultVersionName(defaultVersion.getName());
                    }
                }
                changes.put(sed.getId() + "-" + edcBean.getId(), changed);
                ++start;
            }
            edcsInSession.add(edcBean);
        }
        sed.setPopulated(false);
        eventDefCrfList = validateSubmissionUrl(edcsInSession, eventDefCrfList, v, sed);
        edcsInSession.clear();
    }
    errors = v.validate();
    StudyDAO studyDAO = new StudyDAO(sm.getDataSource());
    ArrayList<StudyBean> allStudies = (ArrayList<StudyBean>) studyDAO.findAll();
    for (StudyBean thisBean : allStudies) {
        if (fp.getString("uniqueProId").trim().equals(thisBean.getIdentifier())) {
            v.addError(errors, "uniqueProId", resexception.getString("unique_protocol_id_existed"));
        }
    }
    // << tbh #3999 08/2009
    if (fp.getString("name").trim().length() > 100) {
    // Validator.addError(errors, "name", resexception.getString("maximum_lenght_name_100"));
    }
    if (fp.getString("uniqueProId").trim().length() > 30) {
        Validator.addError(errors, "uniqueProId", resexception.getString("maximum_lenght_unique_protocol_30"));
    }
    if (fp.getString("description").trim().length() > 255) {
        Validator.addError(errors, "description", resexception.getString("maximum_lenght_brief_summary_255"));
    }
    if (fp.getString("prinInvestigator").trim().length() > 255) {
        Validator.addError(errors, "prinInvestigator", resexception.getString("maximum_lenght_principal_investigator_255"));
    }
    if (fp.getInt("expectedTotalEnrollment") <= 0) {
        Validator.addError(errors, "expectedTotalEnrollment", respage.getString("expected_total_enrollment_must_be_a_positive_number"));
    }
    if (!errors.isEmpty()) {
        // logger.info("has errors");
        StudyBean study = createStudyBean();
        session.setAttribute("newStudy", study);
        session.setAttribute("definitions", seds);
        request.setAttribute("formMessages", errors);
        /*
             * try {
             * local_df.parse(fp.getString(INPUT_START_DATE));
             * fp.addPresetValue(INPUT_START_DATE, local_df.format(fp.getDate(INPUT_START_DATE)));
             * } catch (ParseException pe) {
             * fp.addPresetValue(INPUT_START_DATE, fp.getString(INPUT_START_DATE));
             * }
             * try {
             * local_df.parse(fp.getString(INPUT_END_DATE));
             * fp.addPresetValue(INPUT_END_DATE, local_df.format(fp.getDate(INPUT_END_DATE)));
             * } catch (ParseException pe) {
             * fp.addPresetValue(INPUT_END_DATE, fp.getString(INPUT_END_DATE));
             * }
             * try {
             * local_df.parse(fp.getString(INPUT_VER_DATE));
             * fp.addPresetValue(INPUT_VER_DATE, local_df.format(fp.getDate(INPUT_VER_DATE)));
             * } catch (ParseException pe) {
             * fp.addPresetValue(INPUT_VER_DATE, fp.getString(INPUT_VER_DATE));
             * }
             */
        // setPresetValues(fp.getPresetValues());
        logger.info("has validation errors");
        // request.setAttribute("formMessages", errors);
        // request.setAttribute("facRecruitStatusMap",
        // CreateStudyServlet.facRecruitStatusMap);
        // request.setAttribute("statuses", Status.toActiveArrayList());
        // forwardPage(Page.CREATE_SUB_STUDY);
        forwardPage(Page.CREATE_SUB_STUDY);
    }
    session.setAttribute("changed", changes);
    return seds;
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) FormProcessor(org.akaza.openclinica.control.form.FormProcessor) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyParameterValueDAO(org.akaza.openclinica.dao.service.StudyParameterValueDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO)

Example 80 with CRFVersionBean

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

the class ImportCRFDataService method lookupValidationErrors.

public List<DisplayItemBeanWrapper> lookupValidationErrors(HttpServletRequest request, ODMContainer odmContainer, UserAccountBean ub, HashMap<String, String> totalValidationErrors, HashMap<String, String> hardValidationErrors, ArrayList<Integer> permittedEventCRFIds) throws OpenClinicaException {
    DisplayItemBeanWrapper displayItemBeanWrapper = null;
    HashMap validationErrors = new HashMap();
    List<DisplayItemBeanWrapper> wrappers = new ArrayList<DisplayItemBeanWrapper>();
    ImportHelper importHelper = new ImportHelper();
    FormDiscrepancyNotes discNotes = new FormDiscrepancyNotes();
    DiscrepancyValidator discValidator = new DiscrepancyValidator(request, discNotes);
    // create a second Validator, this one for hard edit checks
    HashMap<String, String> hardValidator = new HashMap<String, String>();
    StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
    StudyDAO studyDAO = new StudyDAO(ds);
    StudyBean studyBean = studyDAO.findByOid(odmContainer.getCrfDataPostImportContainer().getStudyOID());
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
    StudyEventDefinitionDAO sedDao = new StudyEventDefinitionDAO(ds);
    HashMap<String, ItemDataBean> blankCheck = new HashMap<String, ItemDataBean>();
    String hardValidatorErrorMsgs = "";
    ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
    int totalEventCRFCount = 0;
    int totalItemDataBeanCount = 0;
    for (SubjectDataBean subjectDataBean : subjectDataBeans) {
        ArrayList<DisplayItemBean> displayItemBeans = new ArrayList<DisplayItemBean>();
        logger.debug("iterating through subject data beans: found " + subjectDataBean.getSubjectOID());
        ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
        totalEventCRFCount += studyEventDataBeans.size();
        StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
        for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
            int parentStudyId = studyBean.getParentStudyId();
            StudyEventDefinitionBean sedBean = sedDao.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), parentStudyId);
            ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
            logger.debug("iterating through study event data beans: found " + studyEventDataBean.getStudyEventOID());
            int ordinal = 1;
            try {
                ordinal = new Integer(studyEventDataBean.getStudyEventRepeatKey()).intValue();
            } catch (Exception e) {
            // trying to catch NPEs, because tags can be without the
            // repeat key
            }
            StudyEventBean studyEvent = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), sedBean.getId(), ordinal);
            displayItemBeans = new ArrayList<DisplayItemBean>();
            for (FormDataBean formDataBean : formDataBeans) {
                Map<String, Integer> groupMaxOrdinals = new HashMap<String, Integer>();
                displayItemBeanWrapper = null;
                CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
                EventCRFDAO eventCRFDAO = new EventCRFDAO(ds);
                ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
                ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
                if ((crfVersionBeans == null) || (crfVersionBeans.size() == 0)) {
                    MessageFormat mf = new MessageFormat("");
                    mf.applyPattern(respage.getString("your_crf_version_oid_did_not_generate"));
                    Object[] arguments = { formDataBean.getFormOID() };
                    throw new OpenClinicaException(mf.format(arguments), "");
                }
                CRFVersionBean crfVersion = crfVersionBeans.get(0);
                // if you have a mispelled form oid you get an error here
                // need to error out gracefully and post an error
                logger.debug("iterating through form beans: found " + crfVersion.getOid());
                // may be the point where we cut off item groups etc and
                // instead work on sections
                EventCRFBean eventCRFBean = eventCRFDAO.findByEventCrfVersion(studyEvent, crfVersion);
                EventDefinitionCRFDAO eventDefinitionCRFDAO = new EventDefinitionCRFDAO(ds);
                EventDefinitionCRFBean eventDefinitionCRF = eventDefinitionCRFDAO.findByStudyEventIdAndCRFVersionId(studyBean, studyEvent.getId(), crfVersion.getId());
                if (eventCRFBean != null) {
                    if (permittedEventCRFIds.contains(new Integer(eventCRFBean.getId()))) {
                        for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
                            groupMaxOrdinals.put(itemGroupDataBean.getItemGroupOID(), 1);
                        }
                        // correctness, tbh
                        for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
                            ArrayList<ItemBean> blankCheckItems = new ArrayList<ItemBean>();
                            ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
                            logger.debug("iterating through group beans: " + itemGroupDataBean.getItemGroupOID());
                            // put a checker in here
                            ItemGroupDAO itemGroupDAO = new ItemGroupDAO(ds);
                            ItemGroupBean testBean = itemGroupDAO.findByOid(itemGroupDataBean.getItemGroupOID());
                            if (testBean == null) {
                                // TODO i18n of message
                                MessageFormat mf = new MessageFormat("");
                                mf.applyPattern(respage.getString("your_item_group_oid_for_form_oid"));
                                Object[] arguments = { itemGroupDataBean.getItemGroupOID(), formDataBean.getFormOID() };
                                throw new OpenClinicaException(mf.format(arguments), "");
                            }
                            totalItemDataBeanCount += itemDataBeans.size();
                            for (ImportItemDataBean importItemDataBean : itemDataBeans) {
                                logger.debug("   iterating through item data beans: " + importItemDataBean.getItemOID());
                                ItemDAO itemDAO = new ItemDAO(ds);
                                ItemFormMetadataDAO itemFormMetadataDAO = new ItemFormMetadataDAO(ds);
                                List<ItemBean> itemBeans = itemDAO.findByOid(importItemDataBean.getItemOID());
                                if (!itemBeans.isEmpty()) {
                                    ItemBean itemBean = itemBeans.get(0);
                                    logger.debug("   found " + itemBean.getName());
                                    // throw a null pointer? hopefully not if its been checked...
                                    DisplayItemBean displayItemBean = new DisplayItemBean();
                                    displayItemBean.setItem(itemBean);
                                    ArrayList<ItemFormMetadataBean> metadataBeans = itemFormMetadataDAO.findAllByItemId(itemBean.getId());
                                    logger.debug("      found metadata item beans: " + metadataBeans.size());
                                    int groupOrdinal = 1;
                                    if (itemGroupDataBean.getItemGroupRepeatKey() != null) {
                                        try {
                                            groupOrdinal = new Integer(itemGroupDataBean.getItemGroupRepeatKey()).intValue();
                                            if (groupOrdinal > groupMaxOrdinals.get(itemGroupDataBean.getItemGroupOID())) {
                                                groupMaxOrdinals.put(itemGroupDataBean.getItemGroupOID(), groupOrdinal);
                                            }
                                        } catch (Exception e) {
                                            // do nothing here currently, we are
                                            // looking for a number format
                                            // exception
                                            // from the above.
                                            logger.debug("found npe for group ordinals, line 344!");
                                        }
                                    }
                                    ItemDataBean itemDataBean = createItemDataBean(itemBean, eventCRFBean, importItemDataBean.getValue(), ub, groupOrdinal);
                                    blankCheckItems.add(itemBean);
                                    String newKey = groupOrdinal + "_" + itemGroupDataBean.getItemGroupOID() + "_" + itemBean.getOid() + "_" + subjectDataBean.getSubjectOID();
                                    blankCheck.put(newKey, itemDataBean);
                                    logger.info("adding " + newKey + " to blank checks");
                                    if (!metadataBeans.isEmpty()) {
                                        ItemFormMetadataBean metadataBean = metadataBeans.get(0);
                                        // also possible nullpointer
                                        displayItemBean.setData(itemDataBean);
                                        displayItemBean.setMetadata(metadataBean);
                                        displayItemBean.setEventDefinitionCRF(eventDefinitionCRF);
                                        String eventCRFRepeatKey = studyEventDataBean.getStudyEventRepeatKey();
                                        // if you do indeed leave off this in the XML it will pass but return 'null'
                                        // tbh
                                        attachValidator(displayItemBean, importHelper, discValidator, hardValidator, request, eventCRFRepeatKey, studySubjectBean.getOid());
                                        displayItemBeans.add(displayItemBean);
                                    } else {
                                        MessageFormat mf = new MessageFormat("");
                                        mf.applyPattern(respage.getString("no_metadata_could_be_found"));
                                        Object[] arguments = { importItemDataBean.getItemOID() };
                                        throw new OpenClinicaException(mf.format(arguments), "");
                                    }
                                } else {
                                    // report the error there
                                    MessageFormat mf = new MessageFormat("");
                                    mf.applyPattern(respage.getString("no_item_could_be_found"));
                                    Object[] arguments = { importItemDataBean.getItemOID() };
                                    throw new OpenClinicaException(mf.format(arguments), "");
                                }
                            }
                            // end item data beans
                            logger.debug(".. found blank check: " + blankCheck.toString());
                            for (int i = 1; i <= groupMaxOrdinals.get(itemGroupDataBean.getItemGroupOID()); i++) {
                                for (ItemBean itemBean : blankCheckItems) {
                                    String newKey = i + "_" + itemGroupDataBean.getItemGroupOID() + "_" + itemBean.getOid() + "_" + subjectDataBean.getSubjectOID();
                                    if (blankCheck.get(newKey) == null) {
                                        // if it already exists, Do Not Add It.
                                        ItemDataBean itemDataCheck = getItemDataDao().findByItemIdAndEventCRFIdAndOrdinal(itemBean.getId(), eventCRFBean.getId(), i);
                                        logger.debug("found item data bean id: " + itemDataCheck.getId() + " for ordinal " + i);
                                        if (itemDataCheck.getId() == 0) {
                                            ItemDataBean blank = createItemDataBean(itemBean, eventCRFBean, "", ub, i);
                                            DisplayItemBean displayItemBean = new DisplayItemBean();
                                            displayItemBean.setItem(itemBean);
                                            displayItemBean.setData(blank);
                                            // displayItemBean.setMetadata(metadataBean);
                                            // set event def crf?
                                            displayItemBean.setEventDefinitionCRF(eventDefinitionCRF);
                                            String eventCRFRepeatKey = studyEventDataBean.getStudyEventRepeatKey();
                                            // if you do indeed leave off this in the XML it will pass but return
                                            // 'null'
                                            // tbh
                                            displayItemBeans.add(displayItemBean);
                                            logger.debug("... adding display item bean");
                                        }
                                    }
                                    logger.debug("found a blank at " + i + ", adding " + blankCheckItems.size() + " blank items");
                                }
                            }
                            // << tbh #5548
                            blankCheckItems = new ArrayList<ItemBean>();
                        }
                    // end item group data beans
                    }
                    // matches if on permittedCRFIDs
                    CRFDAO crfDAO = new CRFDAO(ds);
                    CRFBean crfBean = crfDAO.findByVersionId(crfVersion.getCrfId());
                    // seems like an extravagance, but is not contained in crf
                    // version or event crf bean
                    validationErrors = discValidator.validate();
                    // totalValidationErrors.addAll(validationErrors);
                    for (Object errorKey : validationErrors.keySet()) {
                        // JN: to avoid duplicate errors
                        if (!totalValidationErrors.containsKey(errorKey.toString()))
                            totalValidationErrors.put(errorKey.toString(), validationErrors.get(errorKey).toString());
                        // assuming that this will be put back in to the core
                        // method's hashmap, updating statically, tbh 06/2008
                        logger.debug("+++ adding " + errorKey.toString());
                    }
                    logger.debug("-- hard validation checks: --");
                    for (Object errorKey : hardValidator.keySet()) {
                        logger.debug(errorKey.toString() + " -- " + hardValidator.get(errorKey));
                        hardValidationErrors.put(errorKey.toString(), hardValidator.get(errorKey));
                        // updating here 'statically' tbh 06/2008
                        hardValidatorErrorMsgs += hardValidator.get(errorKey) + "<br/><br/>";
                    }
                    String studyEventId = studyEvent.getId() + "";
                    String crfVersionId = crfVersion.getId() + "";
                    logger.debug("creation of wrapper: original count of display item beans " + displayItemBeans.size() + ", count of item data beans " + totalItemDataBeanCount + " count of validation errors " + validationErrors.size() + " count of study subjects " + subjectDataBeans.size() + " count of event crfs " + totalEventCRFCount + " count of hard error checks " + hardValidator.size());
                    // check if we need to overwrite
                    DataEntryStage dataEntryStage = eventCRFBean.getStage();
                    Status eventCRFStatus = eventCRFBean.getStatus();
                    boolean overwrite = false;
                    // //JN: Commenting out the following 2 lines, coz the prompt should come in the cases on
                    if (// eventCRFStatus.equals(Status.UNAVAILABLE) ||
                    dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY) || dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
                        overwrite = true;
                    }
                    // << tbh, adding extra statuses to prevent appending, 06/2009
                    // SummaryStatsBean ssBean = new SummaryStatsBean();
                    // ssBean.setDiscNoteCount(totalValidationErrors);
                    // ssBean.setEventCrfCount(totalEventCRFCount);
                    // ssBean.setStudySubjectCount(subjectDataBeans.size());
                    // // add other stats here, tbh
                    // not working here, need to do it in a different method,
                    // tbh
                    // summary stats added tbh 05/2008
                    // JN: Changed from validationErrors to totalValidationErrors to create discrepancy notes for
                    // all
                    // the
                    displayItemBeanWrapper = new DisplayItemBeanWrapper(displayItemBeans, true, overwrite, validationErrors, studyEventId, crfVersionId, studyEventDataBean.getStudyEventOID(), studySubjectBean.getLabel(), eventCRFBean.getCreatedDate(), crfBean.getName(), crfVersion.getName(), studySubjectBean.getOid(), studyEventDataBean.getStudyEventRepeatKey());
                    // JN: Commenting out the following code, since we shouldn't re-initialize at this point, as
                    // validationErrors would get overwritten and the
                    // older errors will be overriden. Moving it after the form.
                    // Removing the comments for now, since it seems to be creating duplicate Discrepancy Notes.
                    validationErrors = new HashMap();
                    discValidator = new DiscrepancyValidator(request, discNotes);
                // reset to allow for new errors...
                }
            }
            // discValidator = new DiscrepancyValidator(request, discNotes);
            if (displayItemBeanWrapper != null && displayItemBeans.size() > 0)
                wrappers.add(displayItemBeanWrapper);
        }
    // after study events
    // remove repeats here? remove them below by only forwarding the
    // first
    // each wrapper represents an Event CRF and a Form, but we don't
    // have all events for all forms
    // need to not add a wrapper for every event + form combination,
    // but instead for every event + form combination which is present
    // look at the hack below and see what happens
    }
    // thrown, tbh 06/2008
    if (!hardValidator.isEmpty()) {
    // throw new OpenClinicaException(hardValidatorErrorMsgs, "");
    }
    return wrappers;
}
Also used : ItemBean(org.akaza.openclinica.bean.submit.ItemBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) HashMap(java.util.HashMap) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) 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) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) ItemDataBean(org.akaza.openclinica.bean.submit.ItemDataBean) ImportItemDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) DisplayItemBeanWrapper(org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper) 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) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) FormDiscrepancyNotes(org.akaza.openclinica.control.form.FormDiscrepancyNotes) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) EventDefinitionCRFDAO(org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) DataEntryStage(org.akaza.openclinica.bean.core.DataEntryStage) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean) ImportItemGroupDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemGroupDataBean) ImportItemDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) MessageFormat(java.text.MessageFormat) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) ParseException(java.text.ParseException) DiscrepancyValidator(org.akaza.openclinica.control.form.DiscrepancyValidator) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Aggregations

CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)100 ArrayList (java.util.ArrayList)70 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)61 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)54 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)53 CRFDAO (org.akaza.openclinica.dao.admin.CRFDAO)46 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)44 HashMap (java.util.HashMap)38 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)37 FormProcessor (org.akaza.openclinica.control.form.FormProcessor)36 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)36 EventDefinitionCRFDAO (org.akaza.openclinica.dao.managestudy.EventDefinitionCRFDAO)33 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)32 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)30 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)30 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)29 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)25 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)22 Iterator (java.util.Iterator)20 SectionBean (org.akaza.openclinica.bean.submit.SectionBean)20