Search in sources :

Example 1 with ImportItemDataBean

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

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

the class OdmExtractDAO method getClinicalData.

public void getClinicalData(StudyBean study, DatasetBean dataset, OdmClinicalDataBean data, String odmVersion, String studySubjectIds, String odmType) {
    String dbName = CoreResources.getDBName();
    String subprev = "";
    HashMap<String, Integer> sepos = new HashMap<String, Integer>();
    String seprev = "";
    String formprev = "";
    HashMap<String, Integer> igpos = new HashMap<String, Integer>();
    String igprev = "";
    String oidPos = "";
    HashMap<Integer, String> oidPoses = new HashMap<Integer, String>();
    HashMap<Integer, String> idataOidPoses = new HashMap<Integer, String>();
    // String studyIds = "";
    // if (study.getParentStudyId() > 0) {
    // studyIds += study.getId();
    // } else {
    // ArrayList<Integer> ids = (ArrayList<Integer>) (new
    // StudyDAO(this.ds)).findAllSiteIdsByStudy(study);
    // for (int i = 0; i < ids.size() - 1; ++i) {
    // studyIds += ids.get(i) + ",";
    // }
    // studyIds += ids.get(ids.size() - 1);
    // }
    String studyIds = study.getId() + "";
    int datasetItemStatusId = dataset.getDatasetItemStatus().getId();
    String sql = dataset.getSQLStatement().split("order by")[0].trim();
    sql = sql.split("study_event_definition_id in")[1];
    String[] ss = sql.split("and item_id in");
    String sedIds = ss[0];
    String[] sss = ss[1].split("and");
    String itemIds = sss[0];
    String dateConstraint = "";
    if ("postgres".equalsIgnoreCase(dbName)) {
        dateConstraint = "and (ss.enrollment_date is NULL OR (" + sss[1] + " and " + sss[2] + "))";
        dateConstraint = dateConstraint.replace("date_created", "ss.enrollment_date");
    } else if ("oracle".equalsIgnoreCase(dbName)) {
        String[] os = (sss[1] + sss[2]).split("'");
        dateConstraint = "and trunc(ss.enrollment_date) >= to_date('" + os[1] + "') and trunc(ss.enrollment_date) <= to_date('" + os[3] + "')";
    }
    logger.debug("Begin to GetSubjectEventFormSql");
    if (odmVersion.startsWith("oc")) {
        logger.debug("getOCSubjectEventFormSql=" + getOCSubjectEventFormSqlSS(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
        this.setSubjectEventFormDataTypesExpected(odmVersion);
        ArrayList viewRows = select(getOCSubjectEventFormSqlSS(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
        Iterator iter = viewRows.iterator();
        this.setDataWithOCAttributes(study, dataset, data, odmVersion, iter, oidPoses, odmType);
    } else {
        logger.debug("getSubjectEventFormSql=" + getSubjectEventFormSqlSS(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
        this.setSubjectEventFormDataTypesExpected();
        ArrayList viewRows = select(getSubjectEventFormSqlSS(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
        Iterator iter = viewRows.iterator();
        // updated as well because this method came from here.
        while (iter.hasNext()) {
            JobTerminationMonitor.check();
            HashMap row = (HashMap) iter.next();
            String studySubjectLabel = (String) row.get("study_subject_oid");
            String sedOID = (String) row.get("definition_oid");
            Boolean studyEventRepeating = (Boolean) row.get("definition_repeating");
            Integer sampleOrdinal = (Integer) row.get("sample_ordinal");
            String cvOID = (String) row.get("crf_version_oid");
            // ecId
            Integer ecId = (Integer) row.get("event_crf_id");
            // should
            // be unique;
            String key = studySubjectLabel;
            ExportSubjectDataBean sub = new ExportSubjectDataBean();
            if (subprev.equals(studySubjectLabel)) {
                int p = data.getExportSubjectData().size() - 1;
                sub = data.getExportSubjectData().get(p);
            } else {
                subprev = studySubjectLabel;
                sub.setSubjectOID(studySubjectLabel);
                data.getExportSubjectData().add(sub);
                seprev = "";
                formprev = "";
                igprev = "";
            }
            oidPos = data.getExportSubjectData().size() - 1 + "";
            ExportStudyEventDataBean se = new ExportStudyEventDataBean();
            // key += sedOID + sampleOrdinal;
            key += sedOID;
            if (!seprev.equals(key) || !sepos.containsKey(key + sampleOrdinal)) {
                sepos.put(key + sampleOrdinal, sub.getExportStudyEventData().size());
                seprev = key;
                se.setStudyEventOID(sedOID);
                se.setStudyEventRepeatKey(studyEventRepeating ? sampleOrdinal + "" : "-1");
                sub.getExportStudyEventData().add(se);
                formprev = "";
                igprev = "";
            } else {
                se = sub.getExportStudyEventData().get(sepos.get(key + sampleOrdinal));
            }
            oidPos += "---" + (sub.getExportStudyEventData().size() - 1);
            ExportFormDataBean form = new ExportFormDataBean();
            key += cvOID;
            if (formprev.equals(key)) {
                form = se.getExportFormData().get(se.getExportFormData().size() - 1);
            } else {
                formprev = key;
                form.setFormOID(cvOID);
                se.getExportFormData().add(form);
                igprev = "";
            }
            oidPos += "---" + (se.getExportFormData().size() - 1);
            // ecId should be distinct
            oidPoses.put(ecId, oidPos);
            oidPos = "";
        }
    }
    this.setEventGroupItemDataWithUnitTypesExpected();
    logger.debug("Begin to GetEventGroupItemWithUnitSql");
    ArrayList viewRows = select(getEventGroupItemWithUnitSql(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
    logger.debug("getEventGroupItemWithUnitSql : " + getEventGroupItemWithUnitSql(studyIds, sedIds, itemIds, dateConstraint, datasetItemStatusId, studySubjectIds));
    String idataIds = "";
    if (viewRows.size() > 0) {
        Iterator iter = viewRows.iterator();
        ExportSubjectDataBean sub = new ExportSubjectDataBean();
        ExportStudyEventDataBean se = new ExportStudyEventDataBean();
        ExportFormDataBean form = new ExportFormDataBean();
        int ecprev = -1;
        igprev = "";
        boolean goon = true;
        String itprev = "";
        // HashMap<String, String> nullValueMap =
        // ClinicalDataUnit.getNullValueMap();
        HashMap<String, String> nullValueCVs = this.getNullValueCVs(study);
        HashSet<Integer> itemDataIds = new HashSet<Integer>();
        String yearMonthFormat = StringUtil.parseDateFormat(ResourceBundleProvider.getFormatBundle(locale).getString("date_format_year_month"));
        String yearFormat = StringUtil.parseDateFormat(ResourceBundleProvider.getFormatBundle(locale).getString("date_format_year"));
        while (iter.hasNext()) {
            JobTerminationMonitor.check();
            HashMap row = (HashMap) iter.next();
            Integer ecId = (Integer) row.get("event_crf_id");
            Integer igId = (Integer) row.get("item_group_id");
            String igOID = (String) row.get("item_group_oid");
            String igName = (String) row.get("item_group_name");
            Integer itId = (Integer) row.get("item_id");
            String itOID = (String) row.get("item_oid");
            Integer itDataOrdinal = (Integer) row.get("item_data_ordinal");
            String itValue = (String) row.get("value");
            Integer datatypeid = (Integer) row.get("item_data_type_id");
            Integer idataId = (Integer) row.get("item_data_id");
            String muOid = (String) row.get("mu_oid");
            String key = "";
            if (ecId != ecprev) {
                logger.debug("Found ecId=" + ecId + " in subjectEventFormSql is:" + oidPoses.containsKey(ecId));
                if (oidPoses.containsKey(ecId)) {
                    goon = true;
                    String[] poses = oidPoses.get(ecId).split("---");
                    sub = data.getExportSubjectData().get(Integer.valueOf(poses[0]));
                    se = sub.getExportStudyEventData().get(Integer.valueOf(poses[1]));
                    form = se.getExportFormData().get(Integer.valueOf(poses[2]));
                } else {
                    goon = false;
                }
                ecprev = ecId;
            }
            if (goon) {
                ImportItemGroupDataBean ig = new ImportItemGroupDataBean();
                // key = ecId + igOID;
                key = ecId + "-" + igId;
                if (!igprev.equals(key) || !igpos.containsKey(key + itDataOrdinal)) {
                    igpos.put(key + itDataOrdinal, form.getItemGroupData().size());
                    igprev = key;
                    ig.setItemGroupOID(igOID + "");
                    ig.setItemGroupRepeatKey("ungrouped".equalsIgnoreCase(igName) ? "-1" : itDataOrdinal + "");
                    form.getItemGroupData().add(ig);
                } else {
                    ig = form.getItemGroupData().get(igpos.get(key + itDataOrdinal));
                }
                String newpos = oidPoses.get(ecId) + "---" + igpos.get(key + itDataOrdinal);
                // item should be distinct; but duplicated item data have
                // been reported because "save" have been clicked twice.
                // those duplicated item data have been arranged together by
                // "distinct" because of their same
                // ecId+igOID+itOID+itDataOrdinal (08-2008)
                key = itId + "_" + itDataOrdinal + key;
                if (!itprev.equals(key)) {
                    itprev = key;
                    ImportItemDataBean it = new ImportItemDataBean();
                    it.setItemOID(itOID);
                    it.setTransactionType("Insert");
                    String nullKey = study.getId() + "-" + se.getStudyEventOID() + "-" + form.getFormOID();
                    if (ClinicalDataUtil.isNull(itValue, nullKey, nullValueCVs)) {
                        // if
                        // (nullValueMap.containsKey(itValue.trim().toUpperCase()))
                        // {
                        // itValue =
                        // nullValueMap.get(itValue.trim().toUpperCase());
                        it.setIsNull("Yes");
                        String nullvalues = ClinicalDataUtil.presetNullValueStr(nullValueCVs.get(nullKey));
                        boolean hasValueWithNull = ClinicalDataUtil.isValueWithNull(itValue, nullvalues);
                        it.setHasValueWithNull(hasValueWithNull);
                        if (hasValueWithNull) {
                            it.setValue(itValue);
                            it.setReasonForNull(ClinicalDataUtil.getNullsInValue(itValue, nullvalues));
                        } else {
                            it.setReasonForNull(itValue.trim());
                        }
                    } else {
                        if (datatypeid == 9) {
                            try {
                                itValue = new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat(oc_df_string).parse(itValue));
                            } catch (Exception fe) {
                                logger.debug("Item -" + itOID + " value " + itValue + " might not be ODM date format yyyy-MM-dd.");
                            }
                        }
                        /* not be supported in openclinica-3.0.40.1
                            else if (datatypeid == 10 && odmVersion.contains("1.3")) {
                                if (StringUtil.isFormatDate(itValue, oc_df_string)) {
                                    try {
                                        itValue = new SimpleDateFormat("yyyy-MM-dd").format(new SimpleDateFormat(oc_df_string).parse(itValue));
                                    } catch (Exception e) {
                                        logger.info("Item -" + itOID + " value " + itValue + " might not be ODM partialDate format yyyy[-MM[-dd]].");
                                    }
                                } else {
                                    if (StringUtil.isPartialYearMonth(itValue, yearMonthFormat)) {
                                        try {
                                            itValue = new SimpleDateFormat("yyyy-MM").format(new SimpleDateFormat(yearMonthFormat).parse(itValue));
                                        } catch (Exception e) {
                                            logger.info("Item -" + itOID + " value " + itValue + " might not be ODM partialDate format yyyy[-MM[-dd]].");
                                        }
                                    } else {
                                        try {
                                            itValue = new SimpleDateFormat("yyyy").format(new SimpleDateFormat(yearFormat).parse(itValue));
                                        } catch (Exception e) {
                                            logger.info("Item -" + itOID + " value " + itValue + " might not be ODM partialDate format yyyy[-MM[-dd]].");
                                        }
                                    }
                                }
                            }
                            */
                        it.setValue(itValue);
                    }
                    if (muOid != null && muOid.length() > 0) {
                        ElementRefBean measurementUnitRef = new ElementRefBean();
                        measurementUnitRef.setElementDefOID(muOid);
                        it.setMeasurementUnitRef(measurementUnitRef);
                    }
                    ig.getItemData().add(it);
                    newpos += "---" + (ig.getItemData().size() - 1);
                    idataOidPoses.put(idataId, newpos);
                }
                idataIds += "'" + idataId + "', ";
            }
        }
    }
    idataIds = idataIds.length() > 0 ? idataIds.substring(0, idataIds.length() - 2) : idataIds;
    if (idataIds.length() > 0 && itemIds.length() > 0) {
        this.setErasedScoreItemDataValues(data, itemIds, idataIds, idataOidPoses, odmVersion);
    } else {
        logger.info("OdmExtractDAO.setScoreItemDataNullValues was not called because of empty item_data_ids or/and item_ids");
    }
    if (odmType != null && odmType.equalsIgnoreCase("clinical_data")) {
        logger.debug("Do not create discrepancy notes");
    } else if (odmVersion.startsWith("oc")) {
        if (idataIds.length() > 0) {
            setOCItemDataAuditLogs(study, data, idataIds, idataOidPoses);
            setOCItemDataDNs(data, idataIds, idataOidPoses);
        } else {
            logger.info("OdmExtractDAO.setOCItemDataAuditLogs & setOCItemDataDNs weren't called because of empty idataIds");
        }
    }
}
Also used : ExportFormDataBean(org.akaza.openclinica.bean.submit.crfdata.ExportFormDataBean) ImportItemGroupDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemGroupDataBean) ElementRefBean(org.akaza.openclinica.bean.odmbeans.ElementRefBean) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) ImportItemDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean) ExportStudyEventDataBean(org.akaza.openclinica.bean.submit.crfdata.ExportStudyEventDataBean) Iterator(java.util.Iterator) ExportSubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.ExportSubjectDataBean) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet)

Example 3 with ImportItemDataBean

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

the class OdmExtractDAO method setOCItemDataAuditLogs.

protected void setOCItemDataAuditLogs(StudyBean study, OdmClinicalDataBean data, String idataIds, HashMap<Integer, String> idataOidPoses) {
    this.setOCItemDataAuditsTypesExpected();
    logger.debug("Begin to execute GetOCItemDataAuditsSql");
    logger.debug("getOCItemDataAuditsSql= " + this.getOCItemDataAuditsSql(idataIds));
    ArrayList rows = select(this.getOCItemDataAuditsSql(idataIds));
    Iterator iter = rows.iterator();
    while (iter.hasNext()) {
        HashMap row = (HashMap) iter.next();
        Integer idataId = (Integer) row.get("item_data_id");
        Integer auditId = (Integer) row.get("audit_id");
        String type = (String) row.get("name");
        Integer userId = (Integer) row.get("user_id");
        Date auditDate = (Date) row.get("audit_date");
        String auditReason = (String) row.get("reason_for_change");
        String oldValue = (String) row.get("old_value");
        String newValue = (String) row.get("new_value");
        Integer typeId = (Integer) row.get("audit_log_event_type_id");
        if (idataOidPoses.containsKey(idataId)) {
            String[] poses = idataOidPoses.get(idataId).split("---");
            ImportItemDataBean idata = data.getExportSubjectData().get(Integer.parseInt(poses[0])).getExportStudyEventData().get(Integer.parseInt(poses[1])).getExportFormData().get(Integer.parseInt(poses[2])).getItemGroupData().get(Integer.parseInt(poses[3])).getItemData().get(Integer.parseInt(poses[4]));
            AuditLogBean auditLog = new AuditLogBean();
            auditLog.setOid("AL_" + auditId);
            auditLog.setUserId("USR_" + userId);
            auditLog.setDatetimeStamp(auditDate);
            auditLog.setType(type);
            auditLog.setReasonForChange(auditReason);
            if (typeId == 12) {
                if ("0".equals(newValue)) {
                    auditLog.setOldValue(Status.INVALID.getName());
                } else {
                    auditLog.setNewValue(Status.getFromMap(Integer.parseInt(newValue)).getName());
                }
                if ("0".equals(oldValue)) {
                    auditLog.setOldValue(Status.INVALID.getName());
                } else {
                    auditLog.setOldValue(Status.getFromMap(Integer.parseInt(oldValue)).getName());
                }
            } else {
                auditLog.setNewValue(newValue);
                auditLog.setOldValue(oldValue);
            }
            AuditLogsBean logs = idata.getAuditLogs();
            if (logs.getEntityID() == null || logs.getEntityID().length() <= 0) {
                logs.setEntityID(idata.getItemOID());
            }
            logs.getAuditLogs().add(auditLog);
            idata.setAuditLogs(logs);
        }
    }
}
Also used : AuditLogBean(org.akaza.openclinica.bean.odmbeans.AuditLogBean) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) AuditLogsBean(org.akaza.openclinica.bean.odmbeans.AuditLogsBean) ImportItemDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean) Date(java.util.Date)

Example 4 with ImportItemDataBean

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

the class OdmExtractDAO method setErasedScoreItemDataValues.

protected void setErasedScoreItemDataValues(OdmClinicalDataBean data, String itemIds, String itemDataIds, HashMap<Integer, String> idataOidPoses, String odmVersion) {
    this.setErasedScoreItemDataIdsTypesExpected();
    ArrayList<Integer> rows = this.select(this.getErasedScoreItemDataIdsSql(itemIds, itemDataIds));
    if (rows == null || rows.size() < 1) {
        logger.debug("OdmExtractDAO.getErasedScoreItemDataIdsSql return no erased score item_data_id");
    } else {
        Iterator iter = rows.iterator();
        while (iter.hasNext()) {
            HashMap row = (HashMap) iter.next();
            Integer idataId = (Integer) row.get("item_data_id");
            if (idataOidPoses.containsKey(idataId)) {
                String[] poses = idataOidPoses.get(idataId).split("---");
                ImportItemDataBean idata = data.getExportSubjectData().get(Integer.parseInt(poses[0])).getExportStudyEventData().get(Integer.parseInt(poses[1])).getExportFormData().get(Integer.parseInt(poses[2])).getItemGroupData().get(Integer.parseInt(poses[3])).getItemData().get(Integer.parseInt(poses[4]));
                idata.setIsNull("Yes");
                idata.setValue("");
                idata.setReasonForNull("Erased");
            } else {
                logger.info("There is no erased score item data with item_data_id =" + idataId + " found in OdmClinicalData");
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Iterator(java.util.Iterator) ImportItemDataBean(org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean)

Example 5 with ImportItemDataBean

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

Aggregations

ImportItemDataBean (org.akaza.openclinica.bean.submit.crfdata.ImportItemDataBean)10 ImportItemGroupDataBean (org.akaza.openclinica.bean.submit.crfdata.ImportItemGroupDataBean)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)5 FormDataBean (org.akaza.openclinica.bean.submit.crfdata.FormDataBean)5 StudyEventDataBean (org.akaza.openclinica.bean.submit.crfdata.StudyEventDataBean)5 SubjectDataBean (org.akaza.openclinica.bean.submit.crfdata.SubjectDataBean)4 Iterator (java.util.Iterator)3 LinkedHashMap (java.util.LinkedHashMap)3 StudyEventDefinitionBean (org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean)3 StudySubjectBean (org.akaza.openclinica.bean.managestudy.StudySubjectBean)3 CRFVersionBean (org.akaza.openclinica.bean.submit.CRFVersionBean)3 ItemBean (org.akaza.openclinica.bean.submit.ItemBean)3 StudyEventDefinitionDAO (org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO)3 CRFVersionDAO (org.akaza.openclinica.dao.submit.CRFVersionDAO)3 MessageFormat (java.text.MessageFormat)2 StudyBean (org.akaza.openclinica.bean.managestudy.StudyBean)2 StudyEventBean (org.akaza.openclinica.bean.managestudy.StudyEventBean)2 DisplayItemBean (org.akaza.openclinica.bean.submit.DisplayItemBean)2 ItemGroupBean (org.akaza.openclinica.bean.submit.ItemGroupBean)2