我正在使用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>
`
任何网址或引用都将不胜感激。
答案 0 :(得分: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 }
参考:Link