Search in sources :

Example 1 with MultiSelectListItemBean

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

the class MetaDataReportBean method addMultiSelectList.

public void addMultiSelectList(String currentIndent) {
    StringBuffer xml = this.getXmlOutput();
    String indent = this.getIndent();
    ArrayList<MultiSelectListBean> lists = (ArrayList<MultiSelectListBean>) odmstudy.getMetaDataVersion().getMultiSelectLists();
    if (lists != null) {
        if (lists.size() > 0) {
            for (MultiSelectListBean l : lists) {
                xml.append(currentIndent + "<OpenClinica:MultiSelectList ID=\"" + StringEscapeUtils.escapeXml(l.getOid()) + "\" ");
                if (l.getName() != null) {
                    xml.append("Name=\"" + StringEscapeUtils.escapeXml(l.getName()) + "\" ");
                }
                if (l.getDataType() != null) {
                    xml.append("DataType=\"" + l.getDataType() + "\" ");
                }
                if (l.getActualDataType() != null) {
                    xml.append("ActualDataType=\"" + StringEscapeUtils.escapeXml(l.getActualDataType()) + "\" ");
                }
                xml.append(">");
                xml.append(nls);
                ArrayList<MultiSelectListItemBean> mslis = (ArrayList<MultiSelectListItemBean>) l.getMultiSelectListItems();
                if (mslis != null && mslis.size() > 0) {
                    for (MultiSelectListItemBean msli : mslis) {
                        xml.append(currentIndent + indent + "<OpenClinica:MultiSelectListItem CodedOptionValue=\"" + StringEscapeUtils.escapeXml(msli.getCodedOptionValue()) + "\">");
                        xml.append(nls);
                        xml.append(currentIndent + indent + indent + "<Decode>");
                        xml.append(nls);
                        TranslatedTextBean tt = msli.getDecode();
                        if (tt.getXmlLang().length() > 0) {
                            xml.append(currentIndent + indent + indent + indent + "<TranslatedText xml:lang=\"" + tt.getXmlLang() + "\">" + StringEscapeUtils.escapeXml(msli.getDecode().getText()) + "</TranslatedText>");
                        } else {
                            xml.append(currentIndent + indent + indent + indent + "<TranslatedText>" + StringEscapeUtils.escapeXml(msli.getDecode().getText()) + "</TranslatedText>");
                        }
                        xml.append(nls);
                        xml.append(currentIndent + indent + indent + "</Decode>");
                        xml.append(nls);
                        xml.append(currentIndent + indent + "</OpenClinica:MultiSelectListItem>");
                        xml.append(nls);
                    }
                }
                xml.append(currentIndent + "</OpenClinica:MultiSelectList>");
                xml.append(nls);
            }
        }
    }
}
Also used : MultiSelectListBean(org.akaza.openclinica.bean.odmbeans.MultiSelectListBean) MultiSelectListItemBean(org.akaza.openclinica.bean.odmbeans.MultiSelectListItemBean) ArrayList(java.util.ArrayList) TranslatedTextBean(org.akaza.openclinica.bean.odmbeans.TranslatedTextBean)

Example 2 with MultiSelectListItemBean

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

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

Aggregations

ArrayList (java.util.ArrayList)3 MultiSelectListBean (org.akaza.openclinica.bean.odmbeans.MultiSelectListBean)3 MultiSelectListItemBean (org.akaza.openclinica.bean.odmbeans.MultiSelectListItemBean)3 TranslatedTextBean (org.akaza.openclinica.bean.odmbeans.TranslatedTextBean)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 CodeListBean (org.akaza.openclinica.bean.odmbeans.CodeListBean)2 CodeListItemBean (org.akaza.openclinica.bean.odmbeans.CodeListItemBean)2 ElementRefBean (org.akaza.openclinica.bean.odmbeans.ElementRefBean)2 FormDefBean (org.akaza.openclinica.bean.odmbeans.FormDefBean)2 ItemDefBean (org.akaza.openclinica.bean.odmbeans.ItemDefBean)2 ItemGroupDefBean (org.akaza.openclinica.bean.odmbeans.ItemGroupDefBean)2 MetaDataVersionProtocolBean (org.akaza.openclinica.bean.odmbeans.MetaDataVersionProtocolBean)1 StudyEventDefBean (org.akaza.openclinica.bean.odmbeans.StudyEventDefBean)1