Search in sources :

Example 6 with ItemDefBean

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

the class MetaDataReportBean method addItemDef.

public void addItemDef(boolean isStudy, String currentIndent) {
    StringBuffer xml = this.getXmlOutput();
    String indent = this.getIndent();
    ArrayList<ItemDefBean> items = (ArrayList<ItemDefBean>) odmstudy.getMetaDataVersion().getItemDefs();
    String ODMVersion = this.getODMVersion();
    for (ItemDefBean item : items) {
        xml.append(currentIndent + "<ItemDef OID=\"" + StringEscapeUtils.escapeXml(item.getOid()) + "\" Name=\"" + StringEscapeUtils.escapeXml(item.getName()) + "\" DataType=\"" + item.getDateType() + "\"");
        int len = item.getLength();
        if (len > 0) {
            xml.append(" Length=\"" + len + "\"");
        }
        len = item.getSignificantDigits();
        if (len > 0) {
            xml.append(" SignificantDigits=\"" + len + "\"");
        }
        xml.append(" SASFieldName=\"" + this.getSasNameValidator().getValidName(item.getPreSASFieldName()) + "\"");
        if (item.getComment().length() > 0) {
            xml.append(" Comment=\"" + StringEscapeUtils.escapeXml(item.getComment()) + "\"");
        }
        if ("oc1.2".equalsIgnoreCase(ODMVersion) || "oc1.3".equalsIgnoreCase(ODMVersion)) {
            xml.append(" OpenClinica:FormOID=\"" + item.getFormOIDs() + "\"");
        }
        boolean hasNode = false;
        // add question
        TranslatedTextBean t = item.getQuestion().getQuestion();
        if (t != null && t.getText() != null && t.getText().length() > 0) {
            if (!hasNode) {
                hasNode = true;
                xml.append(">");
                xml.append(nls);
            }
            if ("oc1.3".equalsIgnoreCase(ODMVersion)) {
                String qn = item.getQuestion().getQuestionNumber();
                if (qn != null && qn.length() > 0) {
                    xml.append(currentIndent + indent + "<Question OpenClinica:QuestionNumber=\"" + item.getQuestion().getQuestionNumber() + "\">");
                } else {
                    xml.append(currentIndent + indent + "<Question>");
                }
            } else {
                xml.append(currentIndent + indent + "<Question>");
            }
            xml.append(nls);
            xml.append(currentIndent + indent + indent + "<TranslatedText>");
            xml.append(nls);
            xml.append(currentIndent + indent + indent + StringEscapeUtils.escapeXml(t.getText()));
            xml.append(nls);
            xml.append(currentIndent + indent + indent + "</TranslatedText>");
            xml.append(nls);
            xml.append(currentIndent + indent + "</Question>");
            xml.append(nls);
        }
        // add MeasurementUnitRef
        String muRefOid = item.getMeasurementUnitRef().getElementDefOID();
        if (muRefOid != null && muRefOid.length() > 0) {
            if (!hasNode) {
                hasNode = true;
                xml.append(">");
                xml.append(nls);
            }
            xml.append(currentIndent + indent + this.measurementUnitRefString(muRefOid));
            xml.append(nls);
        }
        // add RangeCheck
        if (item.getRangeCheck() != null) {
            ArrayList<RangeCheckBean> rcs = (ArrayList<RangeCheckBean>) item.getRangeCheck();
            for (RangeCheckBean rc : rcs) {
                if (rc.getComparator().length() > 0) {
                    if (!hasNode) {
                        hasNode = true;
                        xml.append(">");
                        xml.append(nls);
                    }
                    xml.append(currentIndent + indent + "<RangeCheck Comparator=\"" + StringEscapeUtils.escapeXml(rc.getComparator()) + "\" SoftHard=\"" + rc.getSoftHard() + "\">");
                    xml.append(nls);
                    xml.append(currentIndent + indent + indent + "<CheckValue>" + StringEscapeUtils.escapeXml(rc.getCheckValue()) + "</CheckValue>");
                    xml.append(nls);
                    // supported
                    if (muRefOid != null && muRefOid.length() > 0) {
                        xml.append(currentIndent + indent + indent + this.measurementUnitRefString(muRefOid));
                        xml.append(nls);
                    }
                    xml.append(currentIndent + indent + indent + "<ErrorMessage><TranslatedText>" + StringEscapeUtils.escapeXml(rc.getErrorMessage().getText()) + "</TranslatedText></ErrorMessage>");
                    xml.append(nls);
                    xml.append(currentIndent + indent + "</RangeCheck>");
                    xml.append(nls);
                }
            }
        }
        // add CodeListRef
        String clOid = item.getCodeListOID();
        if (clOid != null && clOid.length() > 0) {
            if (!hasNode) {
                hasNode = true;
                xml.append(">");
                xml.append(nls);
            }
            xml.append(currentIndent + indent + "<CodeListRef CodeListOID=\"" + StringEscapeUtils.escapeXml(clOid) + "\"/>");
            xml.append(nls);
        }
        // add MultiSelectListRef
        if ("oc1.2".equalsIgnoreCase(ODMVersion) || "oc1.3".equalsIgnoreCase(ODMVersion)) {
            if (item.getMultiSelectListRef() != null) {
                String mslOid = item.getMultiSelectListRef().getElementDefOID();
                if (mslOid != null && mslOid.length() > 0) {
                    if (!hasNode) {
                        hasNode = true;
                        xml.append(">");
                        xml.append(nls);
                    }
                    // xml.append(currentIndent + indent +
                    // "<OpenClinica:MultiSelectListRef OpenClinica:MultiSelectListID=\""
                    xml.append(currentIndent + indent + "<OpenClinica:MultiSelectListRef MultiSelectListID=\"" + StringEscapeUtils.escapeXml(mslOid) + "\"/>");
                    xml.append(nls);
                }
            }
        }
        // add ItemDetails for oc1.3
        if ("oc1.3".equals(ODMVersion)) {
            if (!hasNode) {
                hasNode = true;
                xml.append(">");
                xml.append(nls);
            }
        // this.addItemDetails(item.getItemDetails(), currentIndent + indent);
        }
        if (hasNode) {
            xml.append(currentIndent + "</ItemDef>");
            xml.append(nls);
            hasNode = false;
        } else {
            xml.append("/>");
            xml.append(nls);
        }
    }
}
Also used : RangeCheckBean(org.akaza.openclinica.bean.odmbeans.RangeCheckBean) ArrayList(java.util.ArrayList) ItemDefBean(org.akaza.openclinica.bean.odmbeans.ItemDefBean) TranslatedTextBean(org.akaza.openclinica.bean.odmbeans.TranslatedTextBean)

Example 7 with ItemDefBean

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

the class OdmExtractDAO method getOCMetadata.

/**
     * Metadata for ODM_1.2 OpenClinica extension and partial ODM_1.3 OpenClinica extension
     *
     * @param parentStudyId
     * @param studyId
     * @param metadata
     * @param odmVersion
     */
public void getOCMetadata(int parentStudyId, int studyId, MetaDataVersionBean metadata, String odmVersion) {
    this.getODMMetadata(parentStudyId, studyId, metadata, odmVersion);
    String cvIds = metadata.getCvIds();
    if (odmVersion.startsWith("oc")) {
        // add CRFVersions that itemDef belong to
        HashMap<String, String> itDefCVs = new HashMap<String, String>();
        this.setItemCVOIDsTypesExpected();
        ArrayList al = this.select(this.getItemCVOIDsSqlUpdated(cvIds));
        Iterator iter = al.iterator();
        while (iter.hasNext()) {
            HashMap row = (HashMap) iter.next();
            Integer cId = (Integer) row.get("crf_id");
            Integer cvId = (Integer) row.get("crf_version_id");
            Integer itId = (Integer) row.get("item_id");
            String cvOID = (String) row.get("cv_oid");
            String itOID = (String) row.get("item_oid");
            String crfOID = (String) row.get("crf_oid");
            if (itDefCVs.containsKey(itOID)) {
                String cvs = itDefCVs.get(itOID);
                if (!cvs.contains(crfOID + ",")) {
                    cvs += crfOID + ",";
                }
                itDefCVs.put(itOID, cvs);
            } else {
                itDefCVs.put(itOID, crfOID + ",");
            }
        }
        for (ItemDefBean itdef : metadata.getItemDefs()) {
            String key = itdef.getOid();
            if (itDefCVs.containsKey(key)) {
                String cvs = itDefCVs.get(key);
                itdef.setFormOIDs(cvs.substring(0, cvs.length() - 1));
            }
        }
        // add StudyGroupClassList
        this.setStudyGroupClassTypesExpected();
        logger.debug("Begin to execute GetStudyGroupClassSql");
        logger.debug("getStudyGroupClassSql=" + getStudyGroupClassSql(parentStudyId));
        ArrayList rows = select(this.getStudyGroupClassSql(parentStudyId));
        Iterator it = rows.iterator();
        ArrayList<StudyGroupClassListBean> sgcLists = (ArrayList<StudyGroupClassListBean>) metadata.getStudyGroupClassLists();
        String sgcprev = "";
        while (it.hasNext()) {
            HashMap row = (HashMap) it.next();
            Integer sgcid = (Integer) row.get("study_group_class_id");
            String sgcname = (String) row.get("sgc_name");
            String sgctype = (String) row.get("sgc_type");
            Integer statusid = (Integer) row.get("status_id");
            String subassign = (String) row.get("subject_assignment");
            String sgname = (String) row.get("sg_name");
            String des = (String) row.get("description");
            if (sgcprev.equals(sgcid + "")) {
                StudyGroupItemBean sg = new StudyGroupItemBean();
                sg.setName(sgname);
                sg.setDescription(des);
                StudyGroupClassListBean sgc = sgcLists.get(sgcLists.size() - 1);
                sgc.getStudyGroupItems().add(sg);
            } else {
                sgcprev = sgcid + "";
                StudyGroupClassListBean sgc = new StudyGroupClassListBean();
                sgc.setID("SGC_" + sgcid);
                sgc.setName(sgcname);
                sgc.setType(sgctype);
                sgc.setStatus(Status.get(statusid).getName());
                sgc.setSubjectAssignment(subassign);
                StudyGroupItemBean sg = new StudyGroupItemBean();
                sg.setName(sgname);
                sg.setDescription(des);
                sgc.getStudyGroupItems().add(sg);
                sgcLists.add(sgc);
            }
        }
    }
// return nullClSet;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) StudyGroupClassListBean(org.akaza.openclinica.bean.odmbeans.StudyGroupClassListBean) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ItemDefBean(org.akaza.openclinica.bean.odmbeans.ItemDefBean) StudyGroupItemBean(org.akaza.openclinica.bean.odmbeans.StudyGroupItemBean)

Aggregations

ArrayList (java.util.ArrayList)7 ItemDefBean (org.akaza.openclinica.bean.odmbeans.ItemDefBean)7 HashMap (java.util.HashMap)6 Iterator (java.util.Iterator)6 LinkedHashMap (java.util.LinkedHashMap)6 ItemGroupDefBean (org.akaza.openclinica.bean.odmbeans.ItemGroupDefBean)4 FormDefBean (org.akaza.openclinica.bean.odmbeans.FormDefBean)3 TranslatedTextBean (org.akaza.openclinica.bean.odmbeans.TranslatedTextBean)3 HashSet (java.util.HashSet)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 ItemDetailsBean (org.akaza.openclinica.bean.odmbeans.ItemDetailsBean)2 ItemGroupDetailsBean (org.akaza.openclinica.bean.odmbeans.ItemGroupDetailsBean)2 ItemGroupRepeatBean (org.akaza.openclinica.bean.odmbeans.ItemGroupRepeatBean)2 ItemPresentInFormBean (org.akaza.openclinica.bean.odmbeans.ItemPresentInFormBean)2 ItemResponseBean (org.akaza.openclinica.bean.odmbeans.ItemResponseBean)2 MultiSelectListBean (org.akaza.openclinica.bean.odmbeans.MultiSelectListBean)2 MultiSelectListItemBean (org.akaza.openclinica.bean.odmbeans.MultiSelectListItemBean)2 PresentInFormBean (org.akaza.openclinica.bean.odmbeans.PresentInFormBean)2