How to read <text> node values from CCDA xml file using MDHT

2.8k views Asked by At

I am using MDHT to parse the xml values of CCDA file. But i am not able to read value Non-contributory form <text> <paragraph>Non-contributory</paragraph></text>. Consider following xml content : `


FAMILY HISTORY


  <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>

`

Any url or reference will be appreciated.

1

There are 1 answers

1
Jeyasithar On

You do not need to parse Text element. Text elements in CCDA document are used to make it human readable format. The same values will also be present in entry elements of the sections.

EDIT: Following code may help

    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());
        }
    }
}

// The console output for this code is:

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 }

Ref: Link