2

我正在使用 MDHT 来解析 CCDA 文件的 xml 值。但我无法阅读价值Non-contributory形式<text> <paragraph>Non-contributory</paragraph></text>。考虑以下 xml 内容:`


家史


  <component>
    <section>
      <!--  Family history section template  -->
      <templateId root="2.16.840.1.113883.10.20.22.2.15"/>
      <code code="10157-6" displayName="Family History" codeSystem="2.16.840.1.113883.6.1" codeSystemName="LOINC"/>
      <title>FAMILY HISTORY</title>
      <text>
        <paragraph>Non-contributory</paragraph>
      </text>
    </section>
  </component>

`

任何网址或参考将不胜感激。

4

1 回答 1

3

您不需要解析 Text 元素。CCDA 文档中的文本元素用于使其成为人类可读的格式。相同的值也将出现在部分的条目元素中。

编辑:以下代码可能会有所帮助

    package org.openhealthtools.mdht.uml.cda.consol.tests;

import java.io.FileInputStream;
import java.util.Stack;

import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.util.FeatureMap.Entry;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.openhealthtools.mdht.uml.cda.ClinicalDocument;
import org.openhealthtools.mdht.uml.cda.StrucDocText;
import org.openhealthtools.mdht.uml.cda.consol.AllergiesSection;
import org.openhealthtools.mdht.uml.cda.consol.ConsolPackage;
import org.openhealthtools.mdht.uml.cda.consol.ContinuityOfCareDocument;
import org.openhealthtools.mdht.uml.cda.util.CDAUtil;
import org.openhealthtools.mdht.uml.cda.util.ValidationResult;

public class Main {
    public static void main(String[] args) throws Exception {
        ConsolPackage.eINSTANCE.eClass(); // static package registration

        ClinicalDocument clinicalDocument = CDAUtil.load(
            new FileInputStream("samples/CCD.sample.xml"), (ValidationResult) null);
        if (clinicalDocument instanceof ContinuityOfCareDocument) {
            ContinuityOfCareDocument ccd = (ContinuityOfCareDocument) clinicalDocument;

            AllergiesSection allergiesSection = ccd.getAllergiesSection();

            StrucDocText text = allergiesSection.getText();
            traverse(text.getMixed());
        }

    }

    private static void traverse(FeatureMap root) {
        Stack<FeatureMap> stack = new Stack<FeatureMap>();
        stack.push(root);
        while (!stack.isEmpty()) {
            FeatureMap featureMap = stack.pop();
            for (int i = featureMap.size() - 1; i >= 0; i--) {
                Entry entry = featureMap.get(i);
                if (entry.getEStructuralFeature() instanceof EReference) {
                    System.out.println(entry.getEStructuralFeature().getName() + " {");
                    AnyType anyType = (AnyType) entry.getValue();
                    traverseAttributes(anyType.getAnyAttribute());
                    stack.push(anyType.getMixed());
                } else {
                    if (entry.getValue() != null) {
                        String value = entry.getValue().toString();
                        if (value.trim().length() > 0) {
                            System.out.println(" " + value + " }");
                        }
                    } else {
                        System.out.println(" }");
                    }
                }
            }
        }
    }

    private static void traverseAttributes(FeatureMap anyAttribute) {
        for (Entry entry : anyAttribute) {
            System.out.println("attr name: " + entry.getEStructuralFeature().getName() + ", attr value: " +
                    entry.getValue().toString());
        }
    }
}

// 此代码的控制台输出为:

table {
attr name: border, attr value: 1
attr name: width, attr value: 100%
tbody {
thead {
tr {
th {
th {
th {
 Substance }
 Reaction }
 Status }
tr {
tr {
tr {
td {
td {
td {
 Penicillin }
content {
attr name: ID, attr value: reaction1
 Hives }
 Active }
td {
td {
td {
 Aspirin }
content {
attr name: ID, attr value: reaction2
 Wheezing }
 Active }
td {
td {
td {
 Codeine }
content {
attr name: ID, attr value: reaction3
 Nausea }
 Active }

参考:链接

于 2013-12-25T09:09:07.603 回答