Search in sources :

Example 1 with CRFVersionBean

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

the class ExtractBean method getMetadata.

/**
     * Implements the Column algorithm in "Dataset Export Algorithms" Must be
     * called after DatasetDAO.getDatasetData();
     */
public void getMetadata() {
    StudyEventDefinitionDAO seddao = new StudyEventDefinitionDAO(ds);
    CRFDAO cdao = new CRFDAO(ds);
    CRFVersionDAO cvdao = new CRFVersionDAO(ds);
    ItemDAO idao = new ItemDAO(ds);
    ItemFormMetadataDAO ifmDAO = new ItemFormMetadataDAO(this.ds);
    StudyGroupDAO studygroupDAO = new StudyGroupDAO(ds);
    StudyGroupClassDAO studygroupclassDAO = new StudyGroupClassDAO(ds);
    // SubjectGroupMapDAO subjectGroupMapDAO = new SubjectGroupMapDAO(ds);
    studyGroupClasses = new ArrayList();
    studyGroupMap = new HashMap();
    studyGroupMaps = new HashMap<Integer, ArrayList>();
    sedCrfColumns = new HashMap();
    displayed = new HashMap();
    sedCrfItemFormMetadataBeans = new HashMap();
    studyEvents = seddao.findAllByStudy(study);
    ArrayList finalStudyEvents = new ArrayList();
    if (dataset.isShowSubjectGroupInformation()) {
        // logger.info("found study id for maps: "+study.getId());
        studyGroupMaps = studygroupDAO.findSubjectGroupMaps(study.getId());
        // below is for a given subject; we need a data structure for
        // all subjects
        // studyGroupMap = studygroupDAO.findByStudySubject(currentSubject);
        // problem: can't use currentSubject here, since it's not 'set up'
        // properly
        // how to get the current subject?
        logger.info("found subject group ids: " + dataset.getSubjectGroupIds().toString());
        // studyGroupClasses = dataset.getSubjectGroupIds();
        for (int h = 0; h < dataset.getSubjectGroupIds().size(); h++) {
            Integer groupId = (Integer) dataset.getSubjectGroupIds().get(h);
            StudyGroupClassBean sgclass = (StudyGroupClassBean) studygroupclassDAO.findByPK(groupId.intValue());
            // logger.info();
            // hmm how to link groups to subjects though? only through
            // subject group map
            logger.info("found a studygroupclass bean: " + sgclass.getName());
            studyGroupClasses.add(sgclass);
        }
    }
    for (int i = 0; i < studyEvents.size(); i++) {
        StudyEventDefinitionBean sed = (StudyEventDefinitionBean) studyEvents.get(i);
        if (!selectedSED(sed)) {
            continue;
        }
        ArrayList CRFs = (ArrayList) cdao.findAllActiveByDefinition(sed);
        ArrayList CRFsDisplayedInThisSED = new ArrayList();
        for (int j = 0; j < CRFs.size(); j++) {
            CRFBean cb = (CRFBean) CRFs.get(j);
            if (!selectedSEDCRF(sed, cb)) {
                continue;
            } else {
                CRFsDisplayedInThisSED.add(cb);
                ArrayList CRFVersions = cvdao.findAllByCRFId(cb.getId());
                for (int k = 0; k < CRFVersions.size(); k++) {
                    CRFVersionBean cvb = (CRFVersionBean) CRFVersions.get(k);
                    ArrayList Items = idao.findAllItemsByVersionId(cvb.getId());
                    // sort by ordinal/name
                    Collections.sort(Items);
                    for (int l = 0; l < Items.size(); l++) {
                        ItemBean ib = (ItemBean) Items.get(l);
                        if (selected(ib) && !getDisplayed(sed, cb, ib)) {
                            // logger.info("found at
                            // itemformmetadatadao: "+ib.getId()+",
                            // "+cvb.getId());
                            ItemFormMetadataBean ifmb = ifmDAO.findByItemIdAndCRFVersionId(ib.getId(), cvb.getId());
                            addColumn(sed, cb, ib);
                            addItemFormMetadataBeans(sed, cb, ifmb);
                            markDisplayed(sed, cb, ib);
                        }
                    }
                }
            }
        // else
        }
        // for
        sed.setCrfs(CRFsDisplayedInThisSED);
        // make the setCrfs call "stick"
        finalStudyEvents.add(sed);
    }
    this.studyEvents = finalStudyEvents;
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) ItemBean(org.akaza.openclinica.bean.submit.ItemBean) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) ItemDAO(org.akaza.openclinica.dao.submit.ItemDAO) HashMap(java.util.HashMap) StudyGroupClassDAO(org.akaza.openclinica.dao.managestudy.StudyGroupClassDAO) ArrayList(java.util.ArrayList) StudyEventDefinitionBean(org.akaza.openclinica.bean.managestudy.StudyEventDefinitionBean) StudyGroupDAO(org.akaza.openclinica.dao.managestudy.StudyGroupDAO) EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) StudyEventDefinitionDAO(org.akaza.openclinica.dao.managestudy.StudyEventDefinitionDAO) StudyGroupClassBean(org.akaza.openclinica.bean.managestudy.StudyGroupClassBean) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ItemFormMetadataDAO(org.akaza.openclinica.dao.submit.ItemFormMetadataDAO) ItemFormMetadataBean(org.akaza.openclinica.bean.submit.ItemFormMetadataBean)

Example 2 with CRFVersionBean

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

the class ExtractBean method addStudyEventDataOld.

// addStudyEventData
/*
     * addStudyEventData, a function which puts information about a
     * study-subject taking an event-crf into the ExtractBean's interface.
     */
public void addStudyEventDataOld(Integer studySubjectId, String studyEventDefinitionName, Integer studyEventDefinitionId, Integer sampleOrdinal, String studyEventLocation, Date studyEventStart, Date studyEventEnd, String crfVersionName, Integer crfVersionStatusId, Date dateInterviewed, String interviewerName, Date dateCompleted, Date dateValidateCompleted, Integer completionStatusId) {
    if (studySubjectId == null || studyEventDefinitionId == null || sampleOrdinal == null || studyEventLocation == null || studyEventStart == null) {
        return;
    }
    if (studyEventDefinitionId.intValue() <= 0 || studySubjectId.intValue() <= 0 || sampleOrdinal.intValue() <= 0) {
        return;
    }
    // YW 08-21-2007 << fetch start_time_flag and end_time_flag
    StudyEventDAO sedao = new StudyEventDAO(ds);
    StudyEventBean se = (StudyEventBean) sedao.findByStudySubjectIdAndDefinitionIdAndOrdinal(studySubjectId, studyEventDefinitionId, sampleOrdinal);
    // YW >>
    if (se == null) {
        se.setStatus(Status.INVALID);
    }
    StudyEventBean event = new StudyEventBean();
    EventCRFBean eventCRF = new EventCRFBean();
    event.setName(studyEventDefinitionName);
    event.setDateStarted(studyEventStart);
    event.setDateEnded(studyEventEnd);
    event.setLocation(studyEventLocation);
    event.setSampleOrdinal(sampleOrdinal.intValue());
    event.setStudyEventDefinitionId(studyEventDefinitionId.intValue());
    event.setStudySubjectId(studySubjectId.intValue());
    event.setStartTimeFlag(se.getStartTimeFlag());
    event.setEndTimeFlag(se.getEndTimeFlag());
    // below needs to be added, tbh
    event.setStatus(se.getStatus());
    event.setSubjectEventStatus(se.getSubjectEventStatus());
    event.setStage(se.getStage());
    logger.info("found stage: " + se.getStage().getName());
    event.setId(se.getId());
    // end tbh, 03/08
    //
    eventCRF.setCompletionStatusId(completionStatusId.intValue());
    eventCRF.setInterviewerName(interviewerName);
    eventCRF.setDateCompleted(dateCompleted);
    eventCRF.setDateValidateCompleted(dateValidateCompleted);
    // eventCRF.setCreatedDate();//same as interviewed date? NO
    eventCRF.setDateInterviewed(dateInterviewed);
    // eventCRF.setStatus(status); //this is the one that we want, tbh
    // EventCRFDAO ecrfdao = new EventCRFDAO(ds);
    // ArrayList events = ecrfdao.findAllByStudyEvent(se);
    CRFVersionBean crfVersion = new CRFVersionBean();
    crfVersion.setName(crfVersionName);
    crfVersion.setStatus(Status.get(crfVersionStatusId.intValue()));
    crfVersion.setStatusId(crfVersionStatusId.intValue());
    eventCRF.setCrfVersion(crfVersion);
    // logger.info();
    ArrayList events = new ArrayList();
    events.add(eventCRF);
    // logger.info("///adding an event CRF..."
    // + eventCRF.getInterviewerName());
    // hmm, one to one relationship?
    event.setEventCRFs(events);
    // guard clause to see if it's in there already?
    // not rly, the above is only used in auditlogging
    // could fit in crf and crf version ids here, though
    // FIXME def not one to one relationship, tbh, 03.08
    String key = getStudyEventDataKey(studySubjectId.intValue(), studyEventDefinitionId.intValue(), sampleOrdinal.intValue());
    if (eventData == null) {
        eventData = new HashMap();
    }
    StudyEventBean checkEvent = (StudyEventBean) eventData.get(key);
    if (checkEvent == null) {
        eventData.put(key, event);
        logger.info("###just CREATED key: " + key + " event: " + event.getName() + " int.name: " + eventCRF.getInterviewerName());
    } else {
    // ArrayList eventCRFs = checkEvent.getEventCRFs();
    // eventCRFs.add(eventCRF);
    // checkEvent.setEventCRFs(eventCRFs);
    // eventData.put(key, checkEvent);
    // logger.info("count of eventcrfs "+eventCRFs.size());
    // logger.info("other things about the event crf: int.name
    // "+eventCRF.getInterviewerName()+" comp status id
    // "+eventCRF.getCompletionStatusId()+" version name
    // "+eventCRF.getCrfVersion().getName());
    // logger.info("###just UPDATED key: "+key+" event:
    // "+event.getName()+" int.name: "+eventCRF.getInterviewerName());
    }
// the problem: we want to order by start date
// but hashmaps are by their very nature hard to order
// and there is no contigous start date that we can sort on, i.e. we
// only
// look at one at a time.
}
Also used : EventCRFBean(org.akaza.openclinica.bean.submit.EventCRFBean) HashMap(java.util.HashMap) StudyEventDAO(org.akaza.openclinica.dao.managestudy.StudyEventDAO) ArrayList(java.util.ArrayList) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) StudyEventBean(org.akaza.openclinica.bean.managestudy.StudyEventBean)

Example 3 with CRFVersionBean

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

the class OdmExtractDAO method getODMMetadataForForm.

/**
     * Metadata to be obtained based on formVersionOID. The studyOID and studyEventOID are irrelevant as these are the
     * global crfs, i.e crfs that do not belong to
     * any particular CRF. In order to comply with cdisc ODM, the studyOID, studyeventDefOID etc will be static values
     * which do not exist in the database.
     * 
     * @param metadata
     * @param formVersionOID
     */
// The method underneath tries to reuse the code based on getODMMetadata
public void getODMMetadataForForm(MetaDataVersionBean metadata, String formOID, String odmVersion) {
    FormDefBean formDef = new FormDefBean();
    String cvIds = new String("");
    CRFBean crfBean = crfdao.findByOid(formOID);
    List<CRFVersionBean> crfVersions = (List<CRFVersionBean>) cvdao.findAllActiveByCRF(crfBean.getId());
    CRFVersionBean crfVersionBean = crfVersions.get(0);
    cvIds = crfVersionBean.getId() + "";
    applyStudyEventDef(metadata, formOID);
    fetchItemGroupMetaData(metadata, cvIds, odmVersion);
    getOCMetadataForGlobals(crfVersionBean.getId(), metadata, odmVersion);
    ArrayList rows = new ArrayList();
    ArrayList<ItemGroupDefBean> igs = (ArrayList<ItemGroupDefBean>) metadata.getItemGroupDefs();
    HashMap<String, Integer> igPoses = getItemGroupOIDPos(metadata);
    ArrayList<ItemDefBean> its = (ArrayList<ItemDefBean>) metadata.getItemDefs();
    HashMap<String, Integer> itPoses = getItemOIDPos(metadata);
    HashMap<String, Integer> inPoses = new HashMap<String, Integer>();
    ItemGroupDefBean ig = new ItemGroupDefBean();
    Iterator it;
    metadata.setCvIds(cvIds);
    HashMap<Integer, Integer> maxLengths = new HashMap<Integer, Integer>();
    this.setItemDataMaxLengthTypesExpected();
    rows.clear();
    logger.debug("Begin to execute GetItemDataMaxLengths");
    rows = select(this.getItemDataMaxLengths(cvIds));
    it = rows.iterator();
    while (it.hasNext()) {
        HashMap row = (HashMap) it.next();
        maxLengths.put((Integer) row.get("item_id"), (Integer) row.get("max_length"));
    }
    ItemDefBean itDef = new ItemDefBean();
    formDef = fetchFormDetails(crfBean, formDef);
    this.setItemGroupAndItemMetaWithUnitTypesExpected();
    rows.clear();
    String prevCvIg = "";
    logger.debug("Begin to execute GetItemGroupAndItemMetaWithUnitSql");
    logger.debug("getItemGroupandItemMetaWithUnitsql= " + this.getItemGroupAndItemMetaWithUnitSql(cvIds));
    HashMap<Integer, String> sectionLabels = this.getSectionLabels(metadata.getSectionIds());
    HashMap<Integer, String> parentItemOIDs = this.getParentItemOIDs(cvIds);
    this.setItemGroupAndItemMetaOC1_3TypesExpected();
    logger.debug("Begin to execute GetItemGroupAndItemMetaWithUnitSql");
    logger.debug("getItemGroupandItemMetaWithUnitsql= " + this.getItemGroupAndItemMetaOC1_3Sql(cvIds));
    rows = select(this.getItemGroupAndItemMetaOC1_3Sql(cvIds));
    Iterator iter = rows.iterator();
    while (iter.hasNext()) {
        HashMap row = (HashMap) iter.next();
        Integer cvId = (Integer) row.get("crf_version_id");
        Integer igId = (Integer) row.get("item_group_id");
        String cvOID = (String) row.get("crf_version_oid");
        String igOID = (String) row.get("item_group_oid");
        String itOID = (String) row.get("item_oid");
        Integer igRepeatNum = (Integer) row.get("repeat_number");
        Integer igRepeatMax = (Integer) row.get("repeat_max");
        Boolean showGroup = (Boolean) row.get("show_group");
        String itemGroupHeader = (String) row.get("item_group_header");
        String itHeader = (String) row.get("item_header");
        String left = (String) row.get("left_item_text");
        String right = (String) row.get("right_item_text");
        String itSubheader = (String) row.get("subheader");
        Integer itSecId = (Integer) row.get("section_id");
        Integer itPId = (Integer) row.get("parent_id");
        Integer itColNum = (Integer) row.get("column_number");
        String itpgNum = (String) row.get("page_number_label");
        String layout = (String) row.get("response_layout");
        Integer rsTypeId = (Integer) row.get("response_type_id");
        String dfValue = (String) row.get("default_value");
        Boolean phi = (Boolean) row.get("phi_status");
        Boolean showItem = (Boolean) row.get("show_item");
        Integer orderInForm = (Integer) row.get("item_order");
        if ((cvId + "-" + igId).equals(prevCvIg)) {
        } else {
            prevCvIg = cvId + "-" + igId;
            ig = igs.get(igPoses.get(igOID));
            ItemGroupDetailsBean igDetail = ig.getItemGroupDetails();
            igDetail.setOid(igOID);
            PresentInFormBean inForm = new PresentInFormBean();
            inForm.setFormOid(cvOID);
            ItemGroupRepeatBean igr = new ItemGroupRepeatBean();
            igr.setRepeatMax(igRepeatMax);
            igr.setRepeatNumber(igRepeatNum);
            inForm.setItemGroupRepeatBean(igr);
            inForm.setShowGroup(showGroup == true ? "Yes" : "No");
            inForm.setItemGroupHeader(itemGroupHeader);
            igDetail.getPresentInForms().add(inForm);
            ig.setItemGroupDetails(igDetail);
        }
        itDef = its.get(itPoses.get(itOID));
        ItemDetailsBean itDetail = itDef.getItemDetails();
        itDetail.setOid(itOID);
        ItemPresentInFormBean itInForm = new ItemPresentInFormBean();
        itInForm.setFormOid(cvOID);
        itInForm.setColumnNumber(itColNum);
        itInForm.setDefaultValue(dfValue);
        itInForm.setItemHeader(itHeader);
        itInForm.setLeftItemText(left);
        itInForm.setRightItemText(right);
        itInForm.setItemSubHeader(itSubheader);
        itInForm.setPageNumber(itpgNum);
        itInForm.setParentItemOid(parentItemOIDs.get(itPId));
        itInForm.setSectionLabel(sectionLabels.get(itSecId));
        itInForm.setPhi(phi == false ? "No" : "Yes");
        itInForm.setOrderInForm(orderInForm);
        itInForm.setShowItem(showItem == true ? "Yes" : "No");
        ItemResponseBean itemResponse = new ItemResponseBean();
        itemResponse.setResponseLayout(layout);
        itemResponse.setResponseType(ResponseType.get(rsTypeId).getName());
        itInForm.setItemResponse(itemResponse);
        itDetail.getItemPresentInForm().add(itInForm);
        inPoses.put(itOID + "-" + cvOID, itDetail.getItemPresentInForm().size() - 1);
    }
    this.getSCDs(cvIds, its, itPoses, inPoses);
    metadata.getFormDefs().add(formDef);
}
Also used : ItemGroupDefBean(org.akaza.openclinica.bean.odmbeans.ItemGroupDefBean) ItemGroupDetailsBean(org.akaza.openclinica.bean.odmbeans.ItemGroupDetailsBean) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) FormDefBean(org.akaza.openclinica.bean.odmbeans.FormDefBean) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) ItemGroupRepeatBean(org.akaza.openclinica.bean.odmbeans.ItemGroupRepeatBean) ItemPresentInFormBean(org.akaza.openclinica.bean.odmbeans.ItemPresentInFormBean) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ItemDefBean(org.akaza.openclinica.bean.odmbeans.ItemDefBean) ItemResponseBean(org.akaza.openclinica.bean.odmbeans.ItemResponseBean) ItemPresentInFormBean(org.akaza.openclinica.bean.odmbeans.ItemPresentInFormBean) PresentInFormBean(org.akaza.openclinica.bean.odmbeans.PresentInFormBean) ItemDetailsBean(org.akaza.openclinica.bean.odmbeans.ItemDetailsBean)

Example 4 with CRFVersionBean

use of org.akaza.openclinica.bean.submit.CRFVersionBean 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 " + 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");
            CRFVersionBean cvBean = cvdao.findByOid(cvOID);
            CRFBean cBean = (CRFBean) crfdao.findByPK(cvBean.getCrfId());
            // 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(cBean.getOid());
                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) EventDefinitionCRFBean(org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) Iterator(java.util.Iterator) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) ExportSubjectDataBean(org.akaza.openclinica.bean.submit.crfdata.ExportSubjectDataBean) SimpleDateFormat(java.text.SimpleDateFormat) HashSet(java.util.HashSet)

Example 5 with CRFVersionBean

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

the class StudyEventDAO method findCRFsByStudyEvent.

public HashMap findCRFsByStudyEvent(StudyEventBean seb) {
    // Soon-to-be-depreciated, replaced by find crfs by study, tbh 11-26
    // returns a hashmap of crfs + arraylist of crfversions,
    // for creating a checkbox list of crf versions all collected by
    // the study event primary key, tbh
    HashMap crfs = new HashMap();
    this.setCRFTypesExpected();
    HashMap variables = new HashMap();
    variables.put(Integer.valueOf(1), Integer.valueOf(seb.getStudyEventDefinitionId()));
    ArrayList alist = this.select(digester.getQuery("findCRFsByStudyEvent"), variables);
    Iterator it = alist.iterator();
    CRFDAO cdao = new CRFDAO(this.ds);
    CRFVersionDAO cvdao = new CRFVersionDAO(this.ds);
    while (it.hasNext()) {
        HashMap answers = (HashMap) it.next();
        logger.warn("***First CRF ID: " + answers.get("crf_id"));
        logger.warn("***Next CRFVersion ID: " + answers.get("crf_version_id"));
        // here's the logic:
        // grab a crf,
        // iterate through crfs in hashmap,
        // if one matches, grab it;
        // take a look at its arraylist of versions;
        // if there is no version correlating, add it;
        // else, add the crf with a fresh arraylist + one version.
        // how long could this take to run???
        CRFBean cbean = (CRFBean) cdao.findByPK(((Integer) answers.get("crf_id")).intValue());
        CRFVersionBean cvb = (CRFVersionBean) cvdao.findByPK(((Integer) answers.get("crf_version_id")).intValue());
        Set se = crfs.entrySet();
        boolean found = false;
        boolean versionFound = false;
        for (Iterator itse = se.iterator(); itse.hasNext(); ) {
            Map.Entry me = (Map.Entry) itse.next();
            CRFBean checkCrf = (CRFBean) me.getKey();
            if (checkCrf.getId() == cbean.getId()) {
                found = true;
                ArrayList oldList = (ArrayList) me.getValue();
                Iterator itself = oldList.iterator();
                while (itself.hasNext()) {
                    CRFVersionBean cvbCheck = (CRFVersionBean) itself.next();
                    if (cvbCheck.getId() == cvb.getId()) {
                        versionFound = true;
                    }
                }
                // end of iteration through versions
                if (!versionFound) {
                    oldList.add(cvb);
                    crfs.put(cbean, oldList);
                }
            // end of adding new version to old crf
            }
        // end of check to see if current crf is in list
        }
        // end of iterating
        if (!found) {
            // add new crf here with version
            // CRFVersionBean cvb = (CRFVersionBean)cvdao.findByPK(
            // ((Integer)answers.get("crf_version_id")).intValue());
            ArrayList newList = new ArrayList();
            newList.add(cvb);
            crfs.put(cbean, newList);
        }
    }
    return crfs;
}
Also used : CRFDAO(org.akaza.openclinica.dao.admin.CRFDAO) Set(java.util.Set) CRFVersionDAO(org.akaza.openclinica.dao.submit.CRFVersionDAO) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CRFBean(org.akaza.openclinica.bean.admin.CRFBean) Iterator(java.util.Iterator) CRFVersionBean(org.akaza.openclinica.bean.submit.CRFVersionBean) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

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