Search in sources :

Example 1 with FormDefBean

use of org.akaza.openclinica.bean.odmbeans.FormDefBean in project OpenClinica by OpenClinica.

the class OdmExtractDAO method fetchItemGroupMetaData.

private void fetchItemGroupMetaData(MetaDataVersionBean metadata, String cvIds, String odmVersion) {
    ArrayList rows = select(this.getItemDataMaxLengths(cvIds));
    Iterator it = rows.iterator();
    HashMap maxLengths = null;
    // while (it.hasNext()) {
    // HashMap row = (HashMap) it.next();
    // maxLengths.put((Integer) row.get("item_id"), (Integer) row.get("max_length"));
    // }
    this.setItemGroupAndItemMetaWithUnitTypesExpected();
    rows.clear();
    logger.debug("Begin to execute GetItemGroupAndItemMetaWithUnitSql");
    logger.debug("getItemGroupandItemMetaWithUnitsql= " + this.getItemGroupAndItemMetaWithUnitSql(cvIds));
    rows = select(this.getItemGroupAndItemMetaWithUnitSql(cvIds));
    it = rows.iterator();
    ArrayList<ItemGroupDefBean> itemGroupDefs = (ArrayList<ItemGroupDefBean>) metadata.getItemGroupDefs();
    ArrayList<ItemDefBean> itemDefs = (ArrayList<ItemDefBean>) metadata.getItemDefs();
    ArrayList<CodeListBean> codeLists = (ArrayList<CodeListBean>) metadata.getCodeLists();
    ArrayList<MultiSelectListBean> multiSelectLists = (ArrayList<MultiSelectListBean>) metadata.getMultiSelectLists();
    ArrayList<ElementRefBean> itemGroupRefs = new ArrayList<ElementRefBean>();
    Set<String> igset = new HashSet<String>();
    HashMap<String, Integer> igdPos = new HashMap<String, Integer>();
    Set<String> itset = new HashSet<String>();
    Set<Integer> itdset = new HashSet<Integer>();
    Set<Integer> clset = new HashSet<Integer>();
    Set<Integer> mslset = new HashSet<Integer>();
    ItemGroupDefBean igdef = new ItemGroupDefBean();
    HashMap<String, String> igMandatories = new HashMap<String, String>();
    boolean isLatest = false;
    int cvprev = -1;
    String igrprev = "";
    String igdprev = "";
    String itMandatory = "No";
    int itOrder = 0;
    Integer igId = -1;
    String sectionIds = ",";
    while (it.hasNext()) {
        HashMap row = (HashMap) it.next();
        Integer cId = (Integer) row.get("crf_id");
        Integer cvId = (Integer) row.get("crf_version_id");
        igId = (Integer) row.get("item_group_id");
        Integer itId = (Integer) row.get("item_id");
        Integer rsId = (Integer) row.get("response_set_id");
        String cvOID = (String) row.get("crf_version_oid");
        String igOID = (String) row.get("item_group_oid");
        String itOID = (String) row.get("item_oid");
        String igName = (String) row.get("item_group_name");
        String itName = (String) row.get("item_name");
        Integer dataTypeId = (Integer) row.get("item_data_type_id");
        Integer secId = (Integer) row.get("section_id");
        String header = (String) row.get("item_header");
        String left = (String) row.get("left_item_text");
        String right = (String) row.get("right_item_text");
        Boolean itRequired = (Boolean) row.get("item_required");
        String regexp = (String) row.get("regexp");
        String regexpErr = (String) row.get("regexp_error_msg");
        String widthDecimal = (String) row.get("width_decimal");
        Integer rsTypeId = (Integer) row.get("response_type_id");
        String rsText = (String) row.get("options_text");
        String rsValue = (String) row.get("options_values");
        String rsLabel = (String) row.get("response_label");
        String igHeader = (String) row.get("item_group_header");
        Boolean isRepeating = (Boolean) row.get("repeating_group");
        String itDesc = (String) row.get("item_description");
        String itQuesNum = (String) row.get("question_number_label");
        String muOid = (String) row.get("mu_oid");
        if (cvprev != cvId) {
            // at this point, itemGroupRefs is for old cvId
            if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
                String temp = igMandatories.containsKey(igdprev) ? igMandatories.get(igdprev) : itMandatory;
                itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(temp);
            }
            itMandatory = "No";
            // now update to new cvId
            cvprev = cvId;
            FormDefBean formDef = new FormDefBean();
            HashMap cvIdPoses = null;
            // if (cvIdPoses.containsKey(cvId)) {
            // int p = (Integer) cvIdPoses.get(cvId);
            // formDef = metadata.getFormDefs().get(p);
            // } else {
            // logger.debug("crf_version_id=" + cvId + " couldn't find from studyEventAndFormMetaSql");
            // }
            itemGroupRefs = (ArrayList<ElementRefBean>) formDef.getItemGroupRefs();
        }
        // mandatory is based on the last crf-version
        String igDefKey = igId + "";
        if (!igdprev.equals(igDefKey)) {
            if (igdPos.containsKey(igDefKey)) {
                igdef = itemGroupDefs.get(igdPos.get(igDefKey));
                isLatest = false;
                itOrder = igdef.getItemRefs().size();
            } else {
                igdef = new ItemGroupDefBean();
                itOrder = 0;
                igMandatories.put(igdprev, itMandatory);
                isLatest = true;
                igdef.setOid(igOID);
                igdef.setName("ungrouped".equalsIgnoreCase(igName) ? igOID : igName);
                // igdef.setName(igName);
                igdef.setRepeating(isRepeating ? "Yes" : "No");
                igdef.setComment(igHeader);
                igdef.setPreSASDatasetName(igName.toUpperCase());
                itemGroupDefs.add(igdef);
                igdPos.put(igDefKey, itemGroupDefs.size() - 1);
            }
            igdprev = igDefKey;
        }
        String igRefKey = igId + "-" + cvId;
        if (igrprev.equals(igRefKey)) {
            itMandatory = isLatest && itRequired && "No".equals(itMandatory) ? "Yes" : itMandatory;
        } else {
            if (!igset.contains(igRefKey)) {
                igset.add(igRefKey);
                ElementRefBean igref = new ElementRefBean();
                igref.setElementDefOID(igOID);
                int size = itemGroupRefs.size();
                if (size > 0) {
                    String prev = igrprev.split("-")[0].trim();
                    String temp = igMandatories.containsKey(prev) ? igMandatories.get(prev) : itMandatory;
                    itemGroupRefs.get(size - 1).setMandatory(temp);
                }
                itemGroupRefs.add(igref);
                itMandatory = "No";
            }
            igrprev = igRefKey;
        }
        String mandatory = itRequired ? "Yes" : "No";
        if (!itset.contains(igDefKey + "-" + itId)) {
            ++itOrder;
            itset.add(igDefKey + "-" + itId);
            ElementRefBean itemRef = new ElementRefBean();
            itemRef.setElementDefOID(itOID);
            if (itemRef.getMandatory() == null || itemRef.getMandatory().length() <= 0) {
                itemRef.setMandatory(mandatory);
            }
            itemRef.setOrderNumber(itOrder);
            igdef.getItemRefs().add(itemRef);
        }
        boolean hasCode = MetadataUnit.needCodeList(rsTypeId, dataTypeId);
        LinkedHashMap<String, String> codes = new LinkedHashMap<String, String>();
        if (hasCode) {
            /*
                 * //null value will not be added to codelist if (nullMap.containsKey(cvId)) { codes =
                 * MetadataUnit.parseCode(rsText, rsValue,
                 * nullMap.get(cvId)); } else { codes = MetadataUnit.parseCode(rsText, rsValue); }
                 */
            codes = MetadataUnit.parseCode(rsText, rsValue);
        // no action has been taken if rsvalue/rstext go wrong,
        // since they have been validated when uploading crf.
        }
        boolean hasMultiSelect = MetadataUnit.needMultiSelectList(rsTypeId);
        LinkedHashMap<String, String> multi = new LinkedHashMap<String, String>();
        if (hasMultiSelect) {
            multi = MetadataUnit.parseCode(rsText, rsValue);
        // no action has been taken if rsvalue/rstext go wrong,
        // since they have been validated when uploading crf.
        }
        String datatype = MetadataUnit.getOdmItemDataType(rsTypeId, dataTypeId, odmVersion);
        if (sectionIds.contains("," + secId + ",")) {
        } else {
            sectionIds += secId + ",";
        }
        if (!itdset.contains(itId)) {
            itdset.add(itId);
            ItemDefBean idef = new ItemDefBean();
            idef.setOid(itOID);
            idef.setName(itName);
            idef.setComment(itDesc);
            if (muOid != null && muOid.length() > 0) {
                ElementRefBean measurementUnitRef = new ElementRefBean();
                measurementUnitRef.setElementDefOID(muOid);
                idef.setMeasurementUnitRef(measurementUnitRef);
            }
            idef.setPreSASFieldName(itName);
            idef.setCodeListOID(hasCode ? "CL_" + rsId : "");
            if (hasMultiSelect) {
                ElementRefBean multiSelectListRef = new ElementRefBean();
                multiSelectListRef.setElementDefOID("MSL_" + rsId);
                idef.setMultiSelectListRef(multiSelectListRef);
            }
            // if(nullMap.containsKey(cvId)) {
            // }
            idef.getQuestion().setQuestionNumber(itQuesNum);
            idef.getQuestion().getQuestion().setText(MetadataUnit.getItemQuestionText(header, left, right));
            if (regexp != null && regexp.startsWith("func:")) {
                idef.setRangeCheck(MetadataUnit.getItemRangeCheck(regexp.substring(5).trim(), metadata.getSoftHard(), regexpErr, muOid));
            }
            idef.setDataType(datatype);
            int len = 0;
            int sig = 0;
            if (widthDecimal != null && widthDecimal.length() > 0) {
                // now there is no validation for width_decimal here.
                len = parseWidth(widthDecimal);
                sig = parseDecimal(widthDecimal);
            }
            if (rsTypeId == 3 || rsTypeId == 7) {
                // 3:checkbox;
                // //7:multi-select
                // len = maxLengths.containsKey(itId) ? maxLengths.get(itId) : 0;
                // len = Math.max(len, Math.max(rsText.length(), rsValue.length()));
                Iterator<String> iter = multi.keySet().iterator();
                String temp = "";
                while (iter.hasNext()) {
                    temp += iter.next();
                    temp += ",";
                }
                idef.setLength(temp.length());
            } else if ("text".equalsIgnoreCase(datatype)) {
                if (len > 0) {
                    idef.setLength(len);
                } else {
                    // idef.setLength((Integer) (hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) :
                    // maxLengths.containsKey(itId) ? maxLengths.get(itId) : MetaDataCollector.getTextLength()));
                    idef.setLength(0);
                }
            } else if ("integer".equalsIgnoreCase(datatype)) {
                if (len > 0) {
                    idef.setLength(len);
                } else {
                    idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 10);
                }
            } else if ("float".equalsIgnoreCase(datatype)) {
                if (len > 0) {
                    idef.setLength(len);
                } else {
                    // idef.setLength(hasCode ?
                    // MetadataUnit.getDataTypeLength(codes.keySet()) : 32);
                    idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 25);
                }
            } else {
                idef.setLength(0);
            }
            idef.setSignificantDigits(sig > 0 ? sig : MetadataUnit.getSignificantDigits(datatype, codes.keySet(), hasCode));
            itemDefs.add(idef);
        }
        if (hasCode && !clset.contains(rsId)) {
            clset.add(rsId);
            CodeListBean cl = new CodeListBean();
            cl.setOid("CL_" + rsId);
            cl.setName(rsLabel);
            cl.setPreSASFormatName(rsLabel);
            cl.setDataType(datatype);
            Iterator<String> iter = codes.keySet().iterator();
            while (iter.hasNext()) {
                String de = iter.next();
                CodeListItemBean cli = new CodeListItemBean();
                cli.setCodedValue(de);
                TranslatedTextBean tt = cli.getDecode();
                // cli.getDecode().setText(codes.get(de));
                tt.setText(codes.get(de));
                tt.setXmlLang(CoreResources.getField("translated_text_language"));
                cli.setDecode(tt);
                cl.getCodeListItems().add(cli);
            }
            codeLists.add(cl);
        }
        if (odmVersion.startsWith("oc") && hasMultiSelect && !mslset.contains(rsId)) {
            mslset.add(rsId);
            MultiSelectListBean msl = new MultiSelectListBean();
            msl.setOid("MSL_" + rsId);
            msl.setName(rsLabel);
            msl.setDataType(datatype);
            msl.setActualDataType(datatype);
            Iterator<String> iter = multi.keySet().iterator();
            while (iter.hasNext()) {
                String de = iter.next();
                MultiSelectListItemBean msli = new MultiSelectListItemBean();
                msli.setCodedOptionValue(de);
                TranslatedTextBean tt = new TranslatedTextBean();
                String t = multi.get(de);
                tt.setText(t);
                tt.setXmlLang(CoreResources.getField("translated_text_language"));
                msli.setDecode(tt);
                msl.getMultiSelectListItems().add(msli);
            }
            multiSelectLists.add(msl);
        }
    }
    if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
        String last = igMandatories.containsKey(igId + "") ? igMandatories.get(igId + "") : itMandatory;
        itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(last);
    }
    sectionIds = sectionIds.length() > 0 ? sectionIds.substring(1, sectionIds.length() - 1) : "";
    metadata.setSectionIds(sectionIds);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CodeListBean(org.akaza.openclinica.bean.odmbeans.CodeListBean) ArrayList(java.util.ArrayList) TranslatedTextBean(org.akaza.openclinica.bean.odmbeans.TranslatedTextBean) LinkedHashMap(java.util.LinkedHashMap) MultiSelectListItemBean(org.akaza.openclinica.bean.odmbeans.MultiSelectListItemBean) Iterator(java.util.Iterator) HashSet(java.util.HashSet) MultiSelectListBean(org.akaza.openclinica.bean.odmbeans.MultiSelectListBean) ItemGroupDefBean(org.akaza.openclinica.bean.odmbeans.ItemGroupDefBean) ElementRefBean(org.akaza.openclinica.bean.odmbeans.ElementRefBean) FormDefBean(org.akaza.openclinica.bean.odmbeans.FormDefBean) ItemDefBean(org.akaza.openclinica.bean.odmbeans.ItemDefBean) CodeListItemBean(org.akaza.openclinica.bean.odmbeans.CodeListItemBean)

Example 2 with FormDefBean

use of org.akaza.openclinica.bean.odmbeans.FormDefBean in project OpenClinica by OpenClinica.

the class OdmExtractDAO method getODMMetadata.

/**
     * metadata for ODM extraction only
     */
public void getODMMetadata(int parentStudyId, int studyId, MetaDataVersionBean metadata, String odmVersion) {
    String cvIds = "";
    HashMap<Integer, Integer> cvIdPoses = new HashMap<Integer, Integer>();
    this.setStudyEventAndFormMetaTypesExpected();
    logger.debug("Begin to execute GetStudyEventAndFormMetaSql");
    logger.debug("getStudyEventAndFormMetaSQl= " + this.getStudyEventAndFormMetaSql(parentStudyId, studyId, false));
    ArrayList rows = this.select(this.getStudyEventAndFormMetaSql(parentStudyId, studyId, false));
    Iterator it = rows.iterator();
    String sedprev = "";
    MetaDataVersionProtocolBean protocol = metadata.getProtocol();
    HashMap<Integer, String> nullMap = new HashMap<Integer, String>();
    HashMap<String, String> nullValueCVs = new HashMap<String, String>();
    while (it.hasNext()) {
        HashMap row = (HashMap) it.next();
        Integer sedOrder = (Integer) row.get("definition_order");
        Integer cvId = (Integer) row.get("crf_version_id");
        String sedOID = (String) row.get("definition_oid");
        String sedName = (String) row.get("definition_name");
        Boolean sedRepeat = (Boolean) row.get("definition_repeating");
        String sedType = (String) row.get("definition_type");
        String cvOID = (String) row.get("cv_oid");
        String cvName = (String) row.get("cv_name");
        Boolean cvRequired = (Boolean) row.get("cv_required");
        String nullValue = (String) row.get("null_values");
        String crfName = (String) row.get("crf_name");
        String crfOid = (String) row.get("crf_oid");
        StudyEventDefBean sedef = new StudyEventDefBean();
        if (sedprev.equals(sedOID)) {
            int p = metadata.getStudyEventDefs().size() - 1;
            sedef = metadata.getStudyEventDefs().get(p);
        } else {
            sedprev = sedOID;
            ElementRefBean sedref = new ElementRefBean();
            sedref.setElementDefOID(sedOID);
            sedref.setMandatory("Yes");
            sedref.setOrderNumber(sedOrder);
            protocol.getStudyEventRefs().add(sedref);
            sedef.setOid(sedOID);
            sedef.setName(sedName);
            sedef.setRepeating(sedRepeat ? "Yes" : "No");
            String type = sedType.toLowerCase();
            type = type.substring(0, 1).toUpperCase() + type.substring(1);
            sedef.setType(type);
            metadata.getStudyEventDefs().add(sedef);
        }
        ElementRefBean formref = new ElementRefBean();
        formref.setElementDefOID(crfOid);
        formref.setMandatory(cvRequired ? "Yes" : "No");
        sedef.getFormRefs().add(formref);
        if (!cvIdPoses.containsKey(cvId)) {
            FormDefBean formdef = new FormDefBean();
            formdef.setOid(crfOid);
            formdef.setName(crfName);
            formdef.setRepeating("No");
            metadata.getFormDefs().add(formdef);
            cvIdPoses.put(cvId, metadata.getFormDefs().size() - 1);
            cvIds += cvId + ",";
            if (nullValue != null && nullValue.length() > 0) {
                nullMap.put(cvId, nullValue);
                nullValueCVs.put(sedOID + "-" + cvOID, nullValue);
            }
        }
    }
    cvIds = cvIds.substring(0, cvIds.length() - 1);
    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"));
    }
    this.setItemGroupAndItemMetaWithUnitTypesExpected();
    rows.clear();
    logger.debug("Begin to execute GetItemGroupAndItemMetaWithUnitSql");
    logger.debug("getItemGroupandItemMetaWithUnitsql= " + this.getItemGroupAndItemMetaWithUnitSql(cvIds));
    rows = select(this.getItemGroupAndItemMetaWithUnitSql(cvIds));
    it = rows.iterator();
    ArrayList<ItemGroupDefBean> itemGroupDefs = (ArrayList<ItemGroupDefBean>) metadata.getItemGroupDefs();
    ArrayList<ItemDefBean> itemDefs = (ArrayList<ItemDefBean>) metadata.getItemDefs();
    ArrayList<CodeListBean> codeLists = (ArrayList<CodeListBean>) metadata.getCodeLists();
    ArrayList<MultiSelectListBean> multiSelectLists = (ArrayList<MultiSelectListBean>) metadata.getMultiSelectLists();
    ArrayList<ElementRefBean> itemGroupRefs = new ArrayList<ElementRefBean>();
    Set<String> igset = new HashSet<String>();
    HashMap<String, Integer> igdPos = new HashMap<String, Integer>();
    Set<String> itset = new HashSet<String>();
    Set<Integer> itdset = new HashSet<Integer>();
    Set<Integer> clset = new HashSet<Integer>();
    Set<Integer> mslset = new HashSet<Integer>();
    ItemGroupDefBean igdef = new ItemGroupDefBean();
    HashMap<String, String> igMandatories = new HashMap<String, String>();
    boolean isLatest = false;
    int cvprev = -1;
    String igrprev = "";
    String igdprev = "";
    String itMandatory = "No";
    int itOrder = 0;
    Integer igId = -1;
    String sectionIds = ",";
    while (it.hasNext()) {
        HashMap row = (HashMap) it.next();
        Integer cId = (Integer) row.get("crf_id");
        Integer cvId = (Integer) row.get("crf_version_id");
        igId = (Integer) row.get("item_group_id");
        Integer itId = (Integer) row.get("item_id");
        Integer rsId = (Integer) row.get("response_set_id");
        String cvOID = (String) row.get("crf_version_oid");
        String igOID = (String) row.get("item_group_oid");
        String itOID = (String) row.get("item_oid");
        String igName = (String) row.get("item_group_name");
        String itName = (String) row.get("item_name");
        Integer dataTypeId = (Integer) row.get("item_data_type_id");
        Integer secId = (Integer) row.get("section_id");
        String header = (String) row.get("item_header");
        String left = (String) row.get("left_item_text");
        String right = (String) row.get("right_item_text");
        Boolean itRequired = (Boolean) row.get("item_required");
        String regexp = (String) row.get("regexp");
        String regexpErr = (String) row.get("regexp_error_msg");
        String widthDecimal = (String) row.get("width_decimal");
        Integer rsTypeId = (Integer) row.get("response_type_id");
        String rsText = (String) row.get("options_text");
        String rsValue = (String) row.get("options_values");
        String rsLabel = (String) row.get("response_label");
        String igHeader = (String) row.get("item_group_header");
        Boolean isRepeating = (Boolean) row.get("repeating_group");
        String itDesc = (String) row.get("item_description");
        String itQuesNum = (String) row.get("question_number_label");
        String muOid = (String) row.get("mu_oid");
        if (cvprev != cvId) {
            // at this point, itemGroupRefs is for old cvId
            if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
                String temp = igMandatories.containsKey(igdprev) ? igMandatories.get(igdprev) : itMandatory;
                itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(temp);
            }
            itMandatory = "No";
            // now update to new cvId
            cvprev = cvId;
            FormDefBean formDef = new FormDefBean();
            if (cvIdPoses.containsKey(cvId)) {
                int p = cvIdPoses.get(cvId);
                formDef = metadata.getFormDefs().get(p);
            } else {
                logger.debug("crf_version_id=" + cvId + " couldn't find from studyEventAndFormMetaSql");
            }
            itemGroupRefs = (ArrayList<ElementRefBean>) formDef.getItemGroupRefs();
        }
        // mandatory is based on the last crf-version
        String igDefKey = igId + "";
        if (!igdprev.equals(igDefKey)) {
            if (igdPos.containsKey(igDefKey)) {
                igdef = itemGroupDefs.get(igdPos.get(igDefKey));
                isLatest = false;
                itOrder = igdef.getItemRefs().size();
            } else {
                igdef = new ItemGroupDefBean();
                itOrder = 0;
                igMandatories.put(igdprev, itMandatory);
                isLatest = true;
                igdef.setOid(igOID);
                igdef.setName("ungrouped".equalsIgnoreCase(igName) ? igOID : igName);
                // igdef.setName(igName);
                igdef.setRepeating(isRepeating ? "Yes" : "No");
                igdef.setComment(igHeader);
                igdef.setPreSASDatasetName(igName.toUpperCase());
                itemGroupDefs.add(igdef);
                igdPos.put(igDefKey, itemGroupDefs.size() - 1);
            }
            igdprev = igDefKey;
        }
        String igRefKey = igId + "-" + cvId;
        if (igrprev.equals(igRefKey)) {
            itMandatory = isLatest && itRequired && "No".equals(itMandatory) ? "Yes" : itMandatory;
        } else {
            if (!igset.contains(igRefKey)) {
                igset.add(igRefKey);
                ElementRefBean igref = new ElementRefBean();
                igref.setElementDefOID(igOID);
                int size = itemGroupRefs.size();
                if (size > 0) {
                    String prev = igrprev.split("-")[0].trim();
                    String temp = igMandatories.containsKey(prev) ? igMandatories.get(prev) : itMandatory;
                    itemGroupRefs.get(size - 1).setMandatory(temp);
                }
                itemGroupRefs.add(igref);
                itMandatory = "No";
            }
            igrprev = igRefKey;
        }
        String mandatory = itRequired ? "Yes" : "No";
        if (!itset.contains(igDefKey + "-" + itId)) {
            ++itOrder;
            itset.add(igDefKey + "-" + itId);
            ElementRefBean itemRef = new ElementRefBean();
            itemRef.setElementDefOID(itOID);
            if (itemRef.getMandatory() == null || itemRef.getMandatory().length() <= 0) {
                itemRef.setMandatory(mandatory);
            }
            itemRef.setOrderNumber(itOrder);
            igdef.getItemRefs().add(itemRef);
        }
        boolean hasCode = MetadataUnit.needCodeList(rsTypeId, dataTypeId);
        LinkedHashMap<String, String> codes = new LinkedHashMap<String, String>();
        if (hasCode) {
            /*
                 * //null value will not be added to codelist if (nullMap.containsKey(cvId)) { codes =
                 * MetadataUnit.parseCode(rsText, rsValue,
                 * nullMap.get(cvId)); } else { codes = MetadataUnit.parseCode(rsText, rsValue); }
                 */
            codes = MetadataUnit.parseCode(rsText, rsValue);
        // no action has been taken if rsvalue/rstext go wrong,
        // since they have been validated when uploading crf.
        }
        boolean hasMultiSelect = MetadataUnit.needMultiSelectList(rsTypeId);
        LinkedHashMap<String, String> multi = new LinkedHashMap<String, String>();
        if (hasMultiSelect) {
            multi = MetadataUnit.parseCode(rsText, rsValue);
        // no action has been taken if rsvalue/rstext go wrong,
        // since they have been validated when uploading crf.
        }
        String datatype = MetadataUnit.getOdmItemDataType(rsTypeId, dataTypeId, odmVersion);
        if (sectionIds.contains("," + secId + ",")) {
        } else {
            sectionIds += secId + ",";
        }
        if (!itdset.contains(itId)) {
            itdset.add(itId);
            ItemDefBean idef = new ItemDefBean();
            idef.setOid(itOID);
            idef.setName(itName);
            idef.setComment(itDesc);
            if (muOid != null && muOid.length() > 0) {
                ElementRefBean measurementUnitRef = new ElementRefBean();
                measurementUnitRef.setElementDefOID(muOid);
                idef.setMeasurementUnitRef(measurementUnitRef);
            }
            idef.setPreSASFieldName(itName);
            idef.setCodeListOID(hasCode ? "CL_" + rsId : "");
            if (hasMultiSelect) {
                ElementRefBean multiSelectListRef = new ElementRefBean();
                multiSelectListRef.setElementDefOID("MSL_" + rsId);
                idef.setMultiSelectListRef(multiSelectListRef);
            }
            // if(nullMap.containsKey(cvId)) {
            // }
            idef.getQuestion().setQuestionNumber(itQuesNum);
            idef.getQuestion().getQuestion().setText(MetadataUnit.getItemQuestionText(header, left, right));
            if (regexp != null && regexp.startsWith("func:")) {
                idef.setRangeCheck(MetadataUnit.getItemRangeCheck(regexp.substring(5).trim(), metadata.getSoftHard(), regexpErr, muOid));
            }
            idef.setDataType(datatype);
            int len = 0;
            int sig = 0;
            if (widthDecimal != null && widthDecimal.length() > 0) {
                // now there is no validation for width_decimal here.
                len = parseWidth(widthDecimal);
                sig = parseDecimal(widthDecimal);
            }
            if (rsTypeId == 3 || rsTypeId == 7) {
                // 3:checkbox;
                // //7:multi-select
                // len = maxLengths.containsKey(itId) ? maxLengths.get(itId) : 0;
                // len = Math.max(len, Math.max(rsText.length(), rsValue.length()));
                Iterator<String> iter = multi.keySet().iterator();
                String temp = "";
                while (iter.hasNext()) {
                    temp += iter.next();
                    temp += ",";
                }
                idef.setLength(temp.length());
            } else if ("text".equalsIgnoreCase(datatype)) {
                if (len > 0) {
                    idef.setLength(len);
                } else {
                    idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : maxLengths.containsKey(itId) ? maxLengths.get(itId) : MetaDataCollector.getTextLength());
                }
            } else if ("integer".equalsIgnoreCase(datatype)) {
                if (len > 0) {
                    idef.setLength(len);
                } else {
                    idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 10);
                }
            } else if ("float".equalsIgnoreCase(datatype)) {
                if (len > 0) {
                    idef.setLength(len);
                } else {
                    // idef.setLength(hasCode ?
                    // MetadataUnit.getDataTypeLength(codes.keySet()) : 32);
                    idef.setLength(hasCode ? MetadataUnit.getDataTypeLength(codes.keySet()) : 25);
                }
            } else {
                idef.setLength(0);
            }
            idef.setSignificantDigits(sig > 0 ? sig : MetadataUnit.getSignificantDigits(datatype, codes.keySet(), hasCode));
            itemDefs.add(idef);
        }
        if (hasCode && !clset.contains(rsId)) {
            clset.add(rsId);
            CodeListBean cl = new CodeListBean();
            cl.setOid("CL_" + rsId);
            cl.setName(rsLabel);
            cl.setPreSASFormatName(rsLabel);
            cl.setDataType(datatype);
            Iterator<String> iter = codes.keySet().iterator();
            while (iter.hasNext()) {
                String de = iter.next();
                CodeListItemBean cli = new CodeListItemBean();
                cli.setCodedValue(de);
                TranslatedTextBean tt = cli.getDecode();
                // cli.getDecode().setText(codes.get(de));
                tt.setText(codes.get(de));
                tt.setXmlLang(CoreResources.getField("translated_text_language"));
                cli.setDecode(tt);
                cl.getCodeListItems().add(cli);
            }
            codeLists.add(cl);
        }
        if (odmVersion.startsWith("oc") && hasMultiSelect && !mslset.contains(rsId)) {
            mslset.add(rsId);
            MultiSelectListBean msl = new MultiSelectListBean();
            msl.setOid("MSL_" + rsId);
            msl.setName(rsLabel);
            msl.setDataType(datatype);
            msl.setActualDataType(datatype);
            Iterator<String> iter = multi.keySet().iterator();
            while (iter.hasNext()) {
                String de = iter.next();
                MultiSelectListItemBean msli = new MultiSelectListItemBean();
                msli.setCodedOptionValue(de);
                TranslatedTextBean tt = new TranslatedTextBean();
                String t = multi.get(de);
                tt.setText(t);
                tt.setXmlLang(CoreResources.getField("translated_text_language"));
                msli.setDecode(tt);
                msl.getMultiSelectListItems().add(msli);
            }
            multiSelectLists.add(msl);
        }
    }
    if (itemGroupRefs != null && itemGroupRefs.size() > 0) {
        String last = igMandatories.containsKey(igId + "") ? igMandatories.get(igId + "") : itMandatory;
        itemGroupRefs.get(itemGroupRefs.size() - 1).setMandatory(last);
    }
    sectionIds = sectionIds.length() > 0 ? sectionIds.substring(1, sectionIds.length() - 1) : "";
    metadata.setSectionIds(sectionIds);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) CodeListBean(org.akaza.openclinica.bean.odmbeans.CodeListBean) ArrayList(java.util.ArrayList) TranslatedTextBean(org.akaza.openclinica.bean.odmbeans.TranslatedTextBean) LinkedHashMap(java.util.LinkedHashMap) StudyEventDefBean(org.akaza.openclinica.bean.odmbeans.StudyEventDefBean) MultiSelectListItemBean(org.akaza.openclinica.bean.odmbeans.MultiSelectListItemBean) Iterator(java.util.Iterator) HashSet(java.util.HashSet) MultiSelectListBean(org.akaza.openclinica.bean.odmbeans.MultiSelectListBean) ItemGroupDefBean(org.akaza.openclinica.bean.odmbeans.ItemGroupDefBean) ElementRefBean(org.akaza.openclinica.bean.odmbeans.ElementRefBean) FormDefBean(org.akaza.openclinica.bean.odmbeans.FormDefBean) MetaDataVersionProtocolBean(org.akaza.openclinica.bean.odmbeans.MetaDataVersionProtocolBean) ItemDefBean(org.akaza.openclinica.bean.odmbeans.ItemDefBean) CodeListItemBean(org.akaza.openclinica.bean.odmbeans.CodeListItemBean)

Example 3 with FormDefBean

use of org.akaza.openclinica.bean.odmbeans.FormDefBean 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 FormDefBean

use of org.akaza.openclinica.bean.odmbeans.FormDefBean in project OpenClinica by OpenClinica.

the class OdmExtractDAO method getUpdatedSiteMetadata.

public void getUpdatedSiteMetadata(int parentStudyId, int studyId, MetaDataVersionBean metadata, String odmVersion) {
    HashMap<Integer, Integer> cvIdPoses = new HashMap<Integer, Integer>();
    this.setStudyEventAndFormMetaTypesExpected();
    ArrayList rows = this.select(this.getStudyEventAndFormMetaSql(parentStudyId, studyId, true));
    Iterator it = rows.iterator();
    String sedprev = "";
    MetaDataVersionProtocolBean protocol = metadata.getProtocol();
    while (it.hasNext()) {
        HashMap row = (HashMap) it.next();
        Integer sedOrder = (Integer) row.get("definition_order");
        Integer cvId = (Integer) row.get("crf_version_id");
        String sedOID = (String) row.get("definition_oid");
        String sedName = (String) row.get("definition_name");
        Boolean sedRepeat = (Boolean) row.get("definition_repeating");
        String sedType = (String) row.get("definition_type");
        String cvOID = (String) row.get("cv_oid");
        String cvName = (String) row.get("cv_name");
        Boolean cvRequired = (Boolean) row.get("cv_required");
        String nullValue = (String) row.get("null_values");
        String crfName = (String) row.get("crf_name");
        String crfOid = (String) row.get("crf_oid");
        StudyEventDefBean sedef = new StudyEventDefBean();
        if (sedprev.equals(sedOID)) {
            int p = metadata.getStudyEventDefs().size() - 1;
            sedef = metadata.getStudyEventDefs().get(p);
        } else {
            sedprev = sedOID;
            ElementRefBean sedref = new ElementRefBean();
            sedref.setElementDefOID(sedOID);
            sedref.setMandatory("Yes");
            sedref.setOrderNumber(sedOrder);
            protocol.getStudyEventRefs().add(sedref);
            sedef.setOid(sedOID);
            sedef.setName(sedName);
            sedef.setRepeating(sedRepeat ? "Yes" : "No");
            String type = sedType.toLowerCase();
            type = type.substring(0, 1).toUpperCase() + type.substring(1);
            sedef.setType(type);
            metadata.getStudyEventDefs().add(sedef);
        }
        ElementRefBean formref = new ElementRefBean();
        formref.setElementDefOID(crfOid);
        formref.setMandatory(cvRequired ? "Yes" : "No");
        sedef.getFormRefs().add(formref);
        if (!cvIdPoses.containsKey(cvId)) {
            FormDefBean formdef = new FormDefBean();
            formdef.setOid(crfOid);
            formdef.setName(crfName);
            formdef.setRepeating("No");
            metadata.getFormDefs().add(formdef);
            cvIdPoses.put(cvId, metadata.getFormDefs().size() - 1);
            if (nullValue != null && nullValue.length() > 0) {
            }
        }
    }
}
Also used : StudyEventDefBean(org.akaza.openclinica.bean.odmbeans.StudyEventDefBean) ElementRefBean(org.akaza.openclinica.bean.odmbeans.ElementRefBean) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) FormDefBean(org.akaza.openclinica.bean.odmbeans.FormDefBean) MetaDataVersionProtocolBean(org.akaza.openclinica.bean.odmbeans.MetaDataVersionProtocolBean)

Example 5 with FormDefBean

use of org.akaza.openclinica.bean.odmbeans.FormDefBean in project OpenClinica by OpenClinica.

the class MetaDataReportBean method addFormDef.

public void addFormDef(boolean isStudy, String currentIndent) {
    StringBuffer xml = this.getXmlOutput();
    String indent = this.getIndent();
    ArrayList<FormDefBean> forms = (ArrayList<FormDefBean>) odmstudy.getMetaDataVersion().getFormDefs();
    for (FormDefBean form : forms) {
        xml.append(currentIndent + "<FormDef OID=\"" + StringEscapeUtils.escapeXml(form.getOid()) + "\" Name=\"" + StringEscapeUtils.escapeXml(form.getName()) + "\" Repeating=\"" + form.getRepeating() + "\">");
        xml.append(nls);
        ArrayList<ElementRefBean> igs = (ArrayList<ElementRefBean>) form.getItemGroupRefs();
        for (ElementRefBean ig : igs) {
            xml.append(currentIndent + indent + "<ItemGroupRef ItemGroupOID=\"" + StringEscapeUtils.escapeXml(ig.getElementDefOID()) + "\" Mandatory=\"" + ig.getMandatory() + "\"/>");
            xml.append(nls);
        }
        ArrayList<ElementRefBean> formLayoutRefs = (ArrayList<ElementRefBean>) form.getFormLayoutRefs();
        for (ElementRefBean formLayoutRef : formLayoutRefs) {
            xml.append(currentIndent + indent + "<OpenClinica:FormLayoutDef OID=\"" + StringEscapeUtils.escapeXml(formLayoutRef.getName()) + "\">");
            xml.append(nls);
            xml.append(currentIndent + indent + "<OpenClinica:URL>" + StringEscapeUtils.escapeXml(formLayoutRef.getUrl()) + "</OpenClinica:URL>");
            xml.append(nls);
            xml.append(currentIndent + indent + "</OpenClinica:FormLayoutDef>");
            xml.append(nls);
        }
        // add FormDetails for oc1.3
        if ("oc1.3".equals(this.getODMVersion())) {
            this.addFormDetails(form.getFormDetails(), currentIndent + indent);
        }
        xml.append(currentIndent + "</FormDef>");
        xml.append(nls);
    }
}
Also used : ElementRefBean(org.akaza.openclinica.bean.odmbeans.ElementRefBean) ArrayList(java.util.ArrayList) FormDefBean(org.akaza.openclinica.bean.odmbeans.FormDefBean)

Aggregations

ArrayList (java.util.ArrayList)6 FormDefBean (org.akaza.openclinica.bean.odmbeans.FormDefBean)6 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 LinkedHashMap (java.util.LinkedHashMap)5 ElementRefBean (org.akaza.openclinica.bean.odmbeans.ElementRefBean)5 ItemDefBean (org.akaza.openclinica.bean.odmbeans.ItemDefBean)3 ItemGroupDefBean (org.akaza.openclinica.bean.odmbeans.ItemGroupDefBean)3 StudyEventDefBean (org.akaza.openclinica.bean.odmbeans.StudyEventDefBean)3 HashSet (java.util.HashSet)2 CRFBean (org.akaza.openclinica.bean.admin.CRFBean)2 EventDefinitionCRFBean (org.akaza.openclinica.bean.managestudy.EventDefinitionCRFBean)2 CodeListBean (org.akaza.openclinica.bean.odmbeans.CodeListBean)2 CodeListItemBean (org.akaza.openclinica.bean.odmbeans.CodeListItemBean)2 MetaDataVersionProtocolBean (org.akaza.openclinica.bean.odmbeans.MetaDataVersionProtocolBean)2 MultiSelectListBean (org.akaza.openclinica.bean.odmbeans.MultiSelectListBean)2 MultiSelectListItemBean (org.akaza.openclinica.bean.odmbeans.MultiSelectListItemBean)2 TranslatedTextBean (org.akaza.openclinica.bean.odmbeans.TranslatedTextBean)2 List (java.util.List)1 ConfigurationParameters (org.akaza.openclinica.bean.odmbeans.ConfigurationParameters)1