Search in sources :

Example 1 with FormDataBean

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

the class ImportDataRuleRunnerContainer method initRuleSetsAndTargets.

/**
     * Populate importDataTrueRuleSets and variableAndValue.
     * Precondition: import data file passed validation which means all OIDs are not empty.
     * @param ds
     * @param studyBean
     * @param subjectDataBean
     * @param ruleSetService
     */
@Transactional
public void initRuleSetsAndTargets(DataSource ds, StudyBean studyBean, SubjectDataBean subjectDataBean, RuleSetServiceInterface ruleSetService) {
    this.shouldRunRules = this.shouldRunRules == null ? Boolean.FALSE : this.shouldRunRules;
    this.importDataTrueRuleSets = this.importDataTrueRuleSets == null ? new ArrayList<RuleSetBean>() : this.importDataTrueRuleSets;
    this.variableAndValue = this.variableAndValue == null ? new HashMap<String, String>() : this.variableAndValue;
    studyOid = studyBean.getOid();
    studySubjectOid = subjectDataBean.getSubjectOID();
    StudySubjectBean studySubject = new StudySubjectDAO<String, ArrayList>(ds).findByOid(studySubjectOid);
    HashMap<String, StudyEventDefinitionBean> seds = new HashMap<String, StudyEventDefinitionBean>();
    HashMap<String, CRFVersionBean> cvs = new HashMap<String, CRFVersionBean>();
    ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
    for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
        String sedOid = studyEventDataBean.getStudyEventOID();
        StudyEventDefinitionBean sed;
        if (seds.containsKey(sedOid))
            sed = seds.get(sedOid);
        else {
            sed = new StudyEventDefinitionDAO<String, ArrayList>(ds).findByOid(sedOid);
            seds.put(sedOid, sed);
        }
        ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
        for (FormDataBean formDataBean : formDataBeans) {
            String cvOid = formDataBean.getFormOID();
            CRFVersionBean crfVersion;
            if (cvs.containsKey(cvOid))
                crfVersion = cvs.get(cvOid);
            else {
                crfVersion = new CRFVersionDAO<String, ArrayList>(ds).findByOid(cvOid);
                cvs.put(cvOid, crfVersion);
            }
            String sedOrd = studyEventDataBean.getStudyEventRepeatKey();
            Integer sedOrdinal = sedOrd != null && !sedOrd.isEmpty() ? Integer.valueOf(sedOrd) : 1;
            StudyEventBean studyEvent = (StudyEventBean) new StudyEventDAO(ds).findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubject.getId(), sed.getId(), sedOrdinal);
            List<RuleSetBean> ruleSets = ruleSetService.getRuleSetsByCrfStudyAndStudyEventDefinition(studyBean, sed, crfVersion);
            //Set<String> targetItemOids = new HashSet<String>();
            if (ruleSets != null && !ruleSets.isEmpty()) {
                ruleSets = filterByImportDataEntryTrue(ruleSets);
                if (ruleSets != null && !ruleSets.isEmpty()) {
                    ruleSets = ruleSetService.filterByStatusEqualsAvailable(ruleSets);
                    ruleSets = ruleSetService.filterRuleSetsByStudyEventOrdinal(ruleSets, studyEvent, crfVersion, sed);
                    //ruleSets = ruleSetService.filterRuleSetsByHiddenItems(ruleSets, eventCrfBean, crfVersion, new ArrayList<ItemBean>());
                    shouldRunRules = ruleSetService.shouldRunRulesForRuleSets(ruleSets, Phase.IMPORT);
                    if (shouldRunRules != null && shouldRunRules == Boolean.TRUE) {
                        //targetItemOids = collectTargetItemOids(ruleSets);
                        HashMap<String, Integer> grouped = new HashMap<String, Integer>();
                        ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
                        for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
                            ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
                            for (ImportItemDataBean importItemDataBean : itemDataBeans) {
                                //if(targetItemOids.contains(importItemDataBean.getItemOID())) {
                                ItemBean item = new ItemDAO<String, ArrayList>(ds).findByOid(importItemDataBean.getItemOID()).get(0);
                                String igOid = itemGroupDataBean.getItemGroupOID();
                                String igOrd = itemGroupDataBean.getItemGroupRepeatKey();
                                Integer igOrdinal = igOrd != null && !igOrd.isEmpty() ? Integer.valueOf(igOrd) : 1;
                                //logic from DataEntryServlet method: populateRuleSpecificHashMaps()
                                if (isRepeatIGForSure(ds, crfVersion.getId(), igOid, igOrdinal, item.getId())) {
                                    String key1 = igOid + "[" + igOrdinal + "]." + importItemDataBean.getItemOID();
                                    String key = igOid + "." + importItemDataBean.getItemOID();
                                    variableAndValue.put(key1, importItemDataBean.getValue());
                                    if (grouped.containsKey(key)) {
                                        grouped.put(key, grouped.get(key) + 1);
                                    } else {
                                        grouped.put(key, 1);
                                    }
                                } else {
                                    variableAndValue.put(importItemDataBean.getItemOID(), importItemDataBean.getValue());
                                    grouped.put(importItemDataBean.getItemOID(), 1);
                                }
                            //
                            //}
                            }
                        }
                        ruleSets = ruleSetService.solidifyGroupOrdinalsUsingFormProperties(ruleSets, grouped);
                        importDataTrueRuleSets.addAll(ruleSets);
                    }
                }
            }
        }
    }
}
Also used : ImportItemGroupDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemGroupDataBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) HashMap(java.util.HashMap) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) ImportItemDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) RuleSetBean(org.akaza.openclinica.domain.rule.RuleSetBean) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with FormDataBean

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

the class ImportCRFDataService method eventCRFStatusesValid.

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

Example 3 with FormDataBean

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

the class ImportCRFDataService method fetchEventCRFBeans.

/*
     * purpose: look up EventCRFBeans by the following: Study Subject, Study Event, CRF Version, using the
     * findByEventSubjectVersion method in EventCRFDAO. May return more than one, hmm.
     */
public List<EventCRFBean> fetchEventCRFBeans(ODMContainer odmContainer, UserAccountBean ub) {
    ArrayList<EventCRFBean> eventCRFBeans = new ArrayList<EventCRFBean>();
    ArrayList<Integer> eventCRFBeanIds = new ArrayList<Integer>();
    EventCRFDAO eventCrfDAO = new EventCRFDAO(ds);
    StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
    StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
    StudyDAO studyDAO = new StudyDAO(ds);
    StudyEventDAO studyEventDAO = new StudyEventDAO(ds);
    UpsertOnBean upsert = odmContainer.getCrfDataPostImportContainer().getUpsertOn();
    // If Upsert bean is not present, create one with default settings
    if (upsert == null)
        upsert = new UpsertOnBean();
    String studyOID = odmContainer.getCrfDataPostImportContainer().getStudyOID();
    StudyBean studyBean = studyDAO.findByOid(studyOID);
    ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
    for (SubjectDataBean subjectDataBean : subjectDataBeans) {
        ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
        StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(subjectDataBean.getSubjectOID(), studyBean.getId());
        for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
            ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
            String sampleOrdinal = studyEventDataBean.getStudyEventRepeatKey() == null ? "1" : studyEventDataBean.getStudyEventRepeatKey();
            StudyEventDefinitionBean studyEventDefinitionBean = studyEventDefinitionDAO.findByOidAndStudy(studyEventDataBean.getStudyEventOID(), studyBean.getId(), studyBean.getParentStudyId());
            logger.info("find all by def and subject " + studyEventDefinitionBean.getName() + " study subject " + studySubjectBean.getName());
            for (FormDataBean formDataBean : formDataBeans) {
                CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
                ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formDataBean.getFormOID());
                // studySubjectBean.getId(),Integer.parseInt(sampleOrdinal));
                for (CRFVersionBean crfVersionBean : crfVersionBeans) {
                    // iterate the studyeventbeans here
                    // for (StudyEventBean studyEventBean : studyEventBeans) {
                    StudyEventBean studyEventBean = (StudyEventBean) studyEventDAO.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectBean.getId(), studyEventDefinitionBean.getId(), Integer.parseInt(sampleOrdinal));
                    // locked
                    if (studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.LOCKED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SIGNED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.STOPPED)) {
                        return null;
                    }
                    ArrayList<EventCRFBean> eventCrfBeans = eventCrfDAO.findByEventSubjectVersion(studyEventBean, studySubjectBean, crfVersionBean);
                    // event crf, yet.
                    if (eventCrfBeans.isEmpty()) {
                        logger.debug("   found no event crfs from Study Event id " + studyEventBean.getId() + ", location " + studyEventBean.getLocation());
                        // necessary, avoiding false-positives
                        if ((studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.SCHEDULED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.DATA_ENTRY_STARTED) || studyEventBean.getSubjectEventStatus().equals(SubjectEventStatus.COMPLETED)) && upsert.isNotStarted()) {
                            EventCRFBean newEventCrfBean = new EventCRFBean();
                            newEventCrfBean.setStudyEventId(studyEventBean.getId());
                            newEventCrfBean.setStudySubjectId(studySubjectBean.getId());
                            newEventCrfBean.setCRFVersionId(crfVersionBean.getId());
                            newEventCrfBean.setDateInterviewed(new Date());
                            newEventCrfBean.setOwner(ub);
                            newEventCrfBean.setInterviewerName(ub.getName());
                            // place
                            newEventCrfBean.setCompletionStatusId(1);
                            // filler
                            newEventCrfBean.setStatus(Status.AVAILABLE);
                            newEventCrfBean.setStage(DataEntryStage.INITIAL_DATA_ENTRY);
                            // these will be updated later in the
                            // workflow
                            newEventCrfBean = (EventCRFBean) eventCrfDAO.create(newEventCrfBean);
                            // eventCrfBeans.add(newEventCrfBean);
                            logger.debug("   created and added new event crf");
                            if (!eventCRFBeanIds.contains(newEventCrfBean.getId())) {
                                eventCRFBeans.add(newEventCrfBean);
                                eventCRFBeanIds.add(newEventCrfBean.getId());
                            }
                        }
                    } else {
                    }
                    for (EventCRFBean ecb : eventCrfBeans) {
                        Integer ecbId = new Integer(ecb.getId());
                        if ((upsert.isDataEntryStarted() && ecb.getStage().equals(DataEntryStage.INITIAL_DATA_ENTRY)) || (upsert.isDataEntryComplete() && ecb.getStage().equals(DataEntryStage.DOUBLE_DATA_ENTRY_COMPLETE)))
                            if (!eventCRFBeanIds.contains(ecbId)) {
                                eventCRFBeans.add(ecb);
                                eventCRFBeanIds.add(ecbId);
                            }
                    }
                }
            }
        }
    }
    // iteration one
    return eventCRFBeans;
}
Also used : UpsertOnBean(org.akaza.openclinica.bean.submit.crfdata.UpsertOnBean) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) EventCRFDAO(org.akaza.openclinica.dao.submit.EventCRFDAO) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) Date(java.util.Date) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean)

Example 4 with FormDataBean

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

the class ImportCRFDataService method validateStudyMetadata.

/*
     * meant to answer the following questions 3.a. is that study subject in that study? 3.b. is that study event def in
     * that study? 3.c. is that site in that study? 3.d. is that crf version in that study event def? 3.e. are those
     * item groups in that crf version? 3.f. are those items in that item group?
     */
public List<String> validateStudyMetadata(ODMContainer odmContainer, int currentStudyId) {
    List<String> errors = new ArrayList<String>();
    MessageFormat mf = new MessageFormat("");
    // throw new OpenClinicaException(mf.format(arguments), "");
    try {
        StudyDAO studyDAO = new StudyDAO(ds);
        String studyOid = odmContainer.getCrfDataPostImportContainer().getStudyOID();
        StudyBean studyBean = studyDAO.findByOid(studyOid);
        if (studyBean == null) {
            mf.applyPattern(respage.getString("your_study_oid_does_not_reference_an_existing"));
            Object[] arguments = { studyOid };
            errors.add(mf.format(arguments));
            // errors.add("Your Study OID " + studyOid + " does not
            // reference an existing Study or Site in the database. Please
            // check it and try again.");
            // throw an error here because getting the ID would be difficult
            // otherwise
            logger.debug("unknown study OID");
            throw new OpenClinicaException("Unknown Study OID", "");
        } else if (studyBean.getId() != currentStudyId) {
            mf.applyPattern(respage.getString("your_current_study_is_not_the_same_as"));
            Object[] arguments = { studyBean.getName() };
            //
            // errors.add("Your current study is not the same as the Study "
            // + studyBean.getName()
            // + ", for which you are trying to enter data. Please log out
            // of your current study and into the study for which the data
            // is keyed.");
            errors.add(mf.format(arguments));
        }
        ArrayList<SubjectDataBean> subjectDataBeans = odmContainer.getCrfDataPostImportContainer().getSubjectData();
        StudySubjectDAO studySubjectDAO = new StudySubjectDAO(ds);
        StudyEventDefinitionDAO studyEventDefinitionDAO = new StudyEventDefinitionDAO(ds);
        CRFVersionDAO crfVersionDAO = new CRFVersionDAO(ds);
        ItemGroupDAO itemGroupDAO = new ItemGroupDAO(ds);
        ItemDAO itemDAO = new ItemDAO(ds);
        if (subjectDataBeans != null) {
            // report all available errors, tbh
            for (SubjectDataBean subjectDataBean : subjectDataBeans) {
                String oid = subjectDataBean.getSubjectOID();
                StudySubjectBean studySubjectBean = studySubjectDAO.findByOidAndStudy(oid, studyBean.getId());
                if (studySubjectBean == null) {
                    mf.applyPattern(respage.getString("your_subject_oid_does_not_reference"));
                    Object[] arguments = { oid };
                    errors.add(mf.format(arguments));
                    // errors.add("Your Subject OID " + oid + " does not
                    // reference an existing Subject in the Study.");
                    logger.debug("logged an error with subject oid " + oid);
                }
                ArrayList<StudyEventDataBean> studyEventDataBeans = subjectDataBean.getStudyEventData();
                if (studyEventDataBeans != null) {
                    for (StudyEventDataBean studyEventDataBean : studyEventDataBeans) {
                        String sedOid = studyEventDataBean.getStudyEventOID();
                        StudyEventDefinitionBean studyEventDefintionBean = studyEventDefinitionDAO.findByOidAndStudy(sedOid, studyBean.getId(), studyBean.getParentStudyId());
                        if (studyEventDefintionBean == null) {
                            mf.applyPattern(respage.getString("your_study_event_oid_for_subject_oid"));
                            Object[] arguments = { sedOid, oid };
                            errors.add(mf.format(arguments));
                            // errors.add("Your Study Event OID " + sedOid +
                            // " for Subject OID " + oid
                            // + " does not reference an existing Study
                            // Event in the Study.");
                            logger.debug("logged an error with se oid " + sedOid + " and subject oid " + oid);
                        }
                        ArrayList<FormDataBean> formDataBeans = studyEventDataBean.getFormData();
                        if (formDataBeans != null) {
                            for (FormDataBean formDataBean : formDataBeans) {
                                String formOid = formDataBean.getFormOID();
                                ArrayList<CRFVersionBean> crfVersionBeans = crfVersionDAO.findAllByOid(formOid);
                                // right now just check nulls
                                if (crfVersionBeans != null) {
                                    for (CRFVersionBean crfVersionBean : crfVersionBeans) {
                                        if (crfVersionBean == null) {
                                            mf.applyPattern(respage.getString("your_crf_version_oid_for_study_event_oid"));
                                            Object[] arguments = { formOid, sedOid };
                                            errors.add(mf.format(arguments));
                                            // errors.add("Your CRF Version
                                            // OID " + formOid + " for Study
                                            // Event OID " + sedOid
                                            // + " does not reference a
                                            // proper CRF Version in that
                                            // Study Event.");
                                            logger.debug("logged an error with form " + formOid + " and se oid " + sedOid);
                                        }
                                    }
                                } else {
                                    mf.applyPattern(respage.getString("your_crf_version_oid_did_not_generate"));
                                    Object[] arguments = { formOid };
                                    errors.add(mf.format(arguments));
                                // errors.add("Your CRF Version OID " +
                                // formOid
                                // + " did not generate any results in
                                // the database. Please check it and try
                                // again.");
                                }
                                ArrayList<ImportItemGroupDataBean> itemGroupDataBeans = formDataBean.getItemGroupData();
                                if (itemGroupDataBeans != null) {
                                    for (ImportItemGroupDataBean itemGroupDataBean : itemGroupDataBeans) {
                                        String itemGroupOID = itemGroupDataBean.getItemGroupOID();
                                        List<ItemGroupBean> itemGroupBeans = itemGroupDAO.findAllByOid(itemGroupOID);
                                        if (itemGroupBeans != null) {
                                            logger.debug("number of item group beans: " + itemGroupBeans.size());
                                            logger.debug("item group oid: " + itemGroupOID);
                                            for (ItemGroupBean itemGroupBean : itemGroupBeans) {
                                                if (itemGroupBean == null) {
                                                    mf.applyPattern(respage.getString("your_item_group_oid_for_form_oid"));
                                                    Object[] arguments = { itemGroupOID, formOid };
                                                    errors.add(mf.format(arguments));
                                                // errors.add("Your Item
                                                // Group OID " +
                                                // itemGroupOID + " for
                                                // Form OID " + formOid
                                                // + " does not
                                                // reference a proper
                                                // Item Group in that
                                                // CRF Version.");
                                                }
                                            }
                                        } else {
                                            mf.applyPattern(respage.getString("the_item_group_oid_did_not"));
                                            Object[] arguments = { itemGroupOID };
                                            errors.add(mf.format(arguments));
                                        // errors.add("The Item Group
                                        // OID " + itemGroupOID
                                        // + " did not generate any
                                        // results in the database,
                                        // please check it and try
                                        // again.");
                                        }
                                        ArrayList<ImportItemDataBean> itemDataBeans = itemGroupDataBean.getItemData();
                                        if (itemDataBeans != null) {
                                            for (ImportItemDataBean itemDataBean : itemDataBeans) {
                                                String itemOID = itemDataBean.getItemOID();
                                                List<ItemBean> itemBeans = itemDAO.findByOid(itemOID);
                                                if (itemBeans != null) {
                                                    logger.debug("found itembeans: ");
                                                    for (ItemBean itemBean : itemBeans) {
                                                        if (itemBean == null) {
                                                            mf.applyPattern(respage.getString("your_item_oid_for_item_group_oid"));
                                                            Object[] arguments = { itemOID, itemGroupOID };
                                                            errors.add(mf.format(arguments));
                                                        // errors.add(
                                                        // "Your
                                                        // Item OID " +
                                                        // itemOID + "
                                                        // for Item
                                                        // Group OID " +
                                                        // itemGroupOID
                                                        // + " does not
                                                        // reference a
                                                        // proper Item
                                                        // in the Item
                                                        // Group.");
                                                        } else {
                                                            logger.debug("found " + itemBean.getOid() + ", passing");
                                                        }
                                                    }
                                                }
                                            }
                                        } else {
                                            mf.applyPattern(respage.getString("the_item_group_oid_did_not_contain_item_data"));
                                            Object[] arguments = { itemGroupOID };
                                            errors.add(mf.format(arguments));
                                        // errors.add("The Item Group
                                        // OID " + itemGroupOID
                                        // + " did not contain any Item
                                        // Data in the XML file, please
                                        // check it and try again.");
                                        }
                                    }
                                } else {
                                    mf.applyPattern(respage.getString("your_study_event_contains_no_form_data"));
                                    Object[] arguments = { sedOid };
                                    errors.add(mf.format(arguments));
                                // errors.add("Your Study Event " +
                                // sedOid
                                // + " contains no Form Data, or the
                                // Form OIDs are incorrect. Please check
                                // it and try again.");
                                }
                            }
                        }
                    }
                }
            }
        }
    } catch (OpenClinicaException oce) {
    } catch (NullPointerException npe) {
        logger.debug("found a nullpointer here");
    }
    // if errors == null you pass, if not you fail
    return errors;
}
Also used : ImportItemGroupDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemGroupDataBean) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) DisplayItemBean(org.akaza.openclinica.bean.submit.DisplayItemBean) 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) ImportItemDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean) OpenClinicaException(org.akaza.openclinica.exception.OpenClinicaException) StudyDAO(org.akaza.openclinica.dao.managestudy.StudyDAO) MessageFormat(java.text.MessageFormat) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) StudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean) StudySubjectDAO(org.akaza.openclinica.dao.managestudy.StudySubjectDAO) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudySubjectBean(org.akaza.openclinica.bean.managestudy.StudySubjectBean) SubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean) FormDataBean(org.akaza.openclinica.bean.submit.crfdata.FormDataBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ItemGroupBean(org.akaza.openclinica.bean.submit.ItemGroupBean)

Example 5 with FormDataBean

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

Aggregations

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