Search in sources :

Example 6 with SubjectDataBean

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

the class ImportCRFDataService method fetchEventCRFStatuses.

/*
     * purpose: Build a map of EventCRFs and the statuses they should have postimport. Assumes EventCRFs have been
     * created for "Not Started" forms.
     */
public void fetchEventCRFStatuses(ODMContainer odmContainer, HashMap<Integer, String> importedCRFStatuses) {
    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);
    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));
            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);
                    for (EventCRFBean ecb : eventCrfBeans) {
                        Integer ecbId = new Integer(ecb.getId());
                        if (!importedCRFStatuses.keySet().contains(ecbId) && formDataBean.getEventCRFStatus() != null) {
                            importedCRFStatuses.put(ecb.getId(), formDataBean.getEventCRFStatus());
                        }
                    }
                }
            }
        }
    }
}
Also used : CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 7 with SubjectDataBean

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

the class ImportCRFDataService method fetchEventCRFStatuses.

/*
     * purpose: Build a map of EventCRFs and the statuses they should have post-import. Assumes EventCRFs have been
     * created for "Not Started" forms.
     */
public HashMap<Integer, String> fetchEventCRFStatuses(ODMContainer odmContainer) {
    HashMap<Integer, String> eventCRFStatuses = new HashMap<Integer, String>();
    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);
    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));
            for (FormDataBean formDataBean : formDataBeans) {
                FormLayoutDAO formLayoutDAO = new FormLayoutDAO(ds);
                ArrayList<FormLayoutBean> formLayoutBeans = formLayoutDAO.findAllByOid(formDataBean.getFormOID());
                for (FormLayoutBean formLayoutBean : formLayoutBeans) {
                    ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectFormLayout(studyEventBean, studySubjectBean, formLayoutBean);
                    for (EventCRFBean ecb : eventCrfBeans) {
                        Integer ecbId = new Integer(ecb.getId());
                        if (!eventCRFStatuses.keySet().contains(ecbId) && formDataBean.getEventCRFStatus() != null) {
                            eventCRFStatuses.put(ecb.getId(), formDataBean.getEventCRFStatus());
                        }
                    }
                }
            }
        }
    }
    return eventCRFStatuses;
}
Also used : HashMap(java.util.HashMap) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) FormLayoutBean(org.akaza.openclinica.bean.submit.FormLayoutBean) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) FormLayoutDAO(org.akaza.openclinica.dao.submit.FormLayoutDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO)

Example 8 with SubjectDataBean

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

the class DataImportService method validateData.

/**
     * Import Data, the logic which imports the data for our data service. Note that we will return three strings string
     * 0: status, either 'success', 'fail', or 'warn'. string 1: the message string which will be returned in our soap
     * response string 2: the audit message, currently not used but will be saved in the event of a success.
     * 
     * import consist from 3 steps 1) parse xml and extract data 2) validation 3) data submission
     * 
     * @author thickerson
     * @param dataSource
     * @param resources
     * @param studyBean
     * @param userBean
     * @param xml
     * @return
     * @throws Exception
     * 
     *             /* VALIDATE data on all levels
     * 
     *             msg - contains status messages
     * @return list of errors
     */
public List<String> validateData(ODMContainer odmContainer, DataSource dataSource, CoreResources resources, StudyBean studyBean, UserAccountBean userBean, List<DisplayItemBeanWrapper> displayItemBeanWrappers, HashMap<Integer, String> importedCRFStatuses) {
    ResourceBundle respage = ResourceBundleProvider.getPageMessagesBundle();
    setRespage(respage);
    TriggerService triggerService = new TriggerService();
    StringBuffer auditMsg = new StringBuffer();
    List<String> errors = new ArrayList<String>();
    // htaycher: return back later?
    auditMsg.append(respage.getString("passed_study_check") + " ");
    auditMsg.append(respage.getString("passed_oid_metadata_check") + " ");
    // validation errors, the same as in the ImportCRFDataServlet. DRY?
    Boolean eventCRFStatusesValid = getImportCRFDataService(dataSource).eventCRFStatusesValid(odmContainer, userBean);
    List<EventCRFBean> eventCRFBeans = getImportCRFDataService(dataSource).fetchEventCRFBeans(odmContainer, userBean);
    // The following line updates a map that is used for setting the EventCRF status post import
    getImportCRFDataService(dataSource).fetchEventCRFStatuses(odmContainer, importedCRFStatuses);
    ArrayList<Integer> permittedEventCRFIds = new ArrayList<Integer>();
    // -- does the event already exist? if not, fail
    if (eventCRFBeans == null) {
        errors.add(respage.getString("the_event_crf_not_correct_status"));
        return errors;
    } else if (eventCRFBeans.isEmpty() && !eventCRFStatusesValid) {
        errors.add(respage.getString("the_event_crf_not_correct_status"));
        return errors;
    } else if (eventCRFBeans.isEmpty()) {
        errors.add(respage.getString("no_event_crfs_matching_the_xml_metadata"));
        return errors;
    }
    logger.debug("found a list of eventCRFBeans: " + eventCRFBeans.toString());
    for (EventCRFBean eventCRFBean : eventCRFBeans) {
        DataEntryStage dataEntryStage = eventCRFBean.getStage();
        Status eventCRFStatus = eventCRFBean.getStatus();
        logger.debug("Event CRF Bean: id " + eventCRFBean.getId() + ", data entry stage " + dataEntryStage.getName() + ", status " + eventCRFStatus.getName());
        if (eventCRFStatus.equals(Status.AVAILABLE) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY) || dataEntryStage.equals(DataEntryStage.INITIAL_DATA_ENTRY_COMPLETE) || dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE) || dataEntryStage.equals(DataEntryStage.DOUBLE_DATA_ENTRY)) {
            permittedEventCRFIds.add(new Integer(eventCRFBean.getId()));
        } else {
            errors.add(respage.getString("your_listed_crf_in_the_file") + " " + eventCRFBean.getEventName());
            continue;
        }
    }
    if (eventCRFBeans.size() >= permittedEventCRFIds.size()) {
        auditMsg.append(respage.getString("passed_event_crf_status_check") + " ");
    } else {
        auditMsg.append(respage.getString("the_event_crf_not_correct_status") + " ");
    }
    // List<DisplayItemBeanWrapper> displayItemBeanWrappers = new ArrayList<DisplayItemBeanWrapper>();
    HashMap<String, String> totalValidationErrors = new HashMap<String, String>();
    HashMap<String, String> hardValidationErrors = new HashMap<String, String>();
    try {
        List<DisplayItemBeanWrapper> tempDisplayItemBeanWrappers = new ArrayList<DisplayItemBeanWrapper>();
        // htaycher: this should be rewritten with validator not to use request to store data
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.addPreferredLocale(getLocale());
        tempDisplayItemBeanWrappers = getImportCRFDataService(dataSource).lookupValidationErrors(request, odmContainer, userBean, totalValidationErrors, hardValidationErrors, permittedEventCRFIds);
        displayItemBeanWrappers.addAll(tempDisplayItemBeanWrappers);
        logger.debug("size of total validation errors: " + (totalValidationErrors.size() + hardValidationErrors.size()));
        ArrayList<SubjectDataBean> subjectData = odmContainer.getCrfDataPostImportContainer().getSubjectData();
        if (!hardValidationErrors.isEmpty()) {
            // check here where to get group repeat key
            errors.add(triggerService.generateHardValidationErrorMessage(subjectData, hardValidationErrors, "1"));
        }
        if (!totalValidationErrors.isEmpty()) {
            errors.add(triggerService.generateHardValidationErrorMessage(subjectData, totalValidationErrors, "1"));
        }
    } catch (NullPointerException npe1) {
        // what if you have 2 event crfs but the third is a fake?
        npe1.printStackTrace();
        errors.add(respage.getString("an_error_was_thrown_while_validation_errors"));
        logger.debug("=== threw the null pointer, import === " + npe1.getMessage());
    } catch (OpenClinicaException oce1) {
        errors.add(oce1.getOpenClinicaMessage());
        logger.debug("=== threw the openclinica message, import === " + oce1.getOpenClinicaMessage());
    }
    auditMsg.append(respage.getString("passing_crf_edit_checks") + " ");
    return errors;
}
Also used : Status(org.akaza.openclinica.bean.core.Status) ResolutionStatus(org.akaza.openclinica.bean.core.ResolutionStatus) HashMap(java.util.HashMap) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) ArrayList(java.util.ArrayList) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) DataEntryStage(org.akaza.openclinica.bean.core.DataEntryStage) TriggerService(org.akaza.openclinica.web.job.TriggerService) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) ResourceBundle(java.util.ResourceBundle) DisplayItemBeanWrapper(org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper)

Example 9 with SubjectDataBean

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

the class ImportCRFDataService method generateSummaryStatsBean.

public SummaryStatsBean generateSummaryStatsBean(ODMContainer odmContainer, List<DisplayItemBeanWrapper> wrappers, ImportCRFInfoContainer importCrfInfo) {
    int countSubjects = 0;
    int countEventCRFs = 0;
    int discNotesGenerated = 0;
    for (DisplayItemBeanWrapper wr : wrappers) {
        HashMap validations = wr.getValidationErrors();
        discNotesGenerated += validations.size();
    }
    ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
    countSubjects += subjectDataBeans.size();
    for (SubjectDataBean subjectDataBean : subjectDataBeans) {
        ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
        for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
            ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
            // this would be the place to add more stats
            for (FormDataBean formDataBean : formDataBeans) {
                countEventCRFs += 1;
            }
        }
    }
    SummaryStatsBean ssBean = new SummaryStatsBean();
    ssBean.setDiscNoteCount(discNotesGenerated);
    ssBean.setEventCrfCount(countEventCRFs);
    ssBean.setStudySubjectCount(countSubjects);
    ssBean.setSkippedCrfCount(importCrfInfo.getCountSkippedEventCrfs());
    return ssBean;
}
Also used : HashMap(java.util.HashMap) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) SummaryStatsBean(org.akaza.openclinica.bean.submit.crfdata.SummaryStatsBean) DisplayItemBeanWrapper(org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper)

Example 10 with SubjectDataBean

use of org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean 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

SubjectDataBean (org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean)15 ArrayList (java.util.ArrayList)10 FormDataBean (org.akaza.openclinica.bean.submit.crfdata.FormDataBean)9 StudyEventDataBean (org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean)9 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)7 EventCRFBean (org.akaza.openclinica.bean.submit.EventCRFBean)7 HashMap (java.util.HashMap)6 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)6 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)6 StudyDAO (org.akaza.openclinica.dao.managestudy.StudyDAO)6 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)6 StudySubjectDAO (org.akaza.openclinica.dao.managestudy.StudySubjectDAO)6 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)5 DisplayItemBeanWrapper (org.akaza.openclinica.bean.submit.DisplayItemBeanWrapper)5 StudyEventDAO (org.akaza.openclinica.dao.managestudy.StudyEventDAO)5 EventCRFDAO (org.akaza.openclinica.dao.submit.EventCRFDAO)5 ImportDataRuleRunnerContainer (org.akaza.openclinica.logic.rulerunner.ImportDataRuleRunnerContainer)5 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)4 ImportItemDataBean (org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean)4 ImportItemGroupDataBean (org.akaza.openclinica.bean.submit.crfdata.ImportItemGroupDataBean)4