Sunday, June 1, 2014

Database schema example to store QRDA-1 file

db schema for QRDA-1

How to parse QRDA-1 XML file using Jaxen XPath library

Parse QRDA-1 file using Jaxen XPath library
Before start you will need to download Jaxen or update pom.xml if you are using maven:
        <dependency>
            <groupId>jaxen</groupId>
            <artifactId>jaxen</artifactId>
            <version>1.1.6</version>
        </dependency>

Let's assume we have following QRDA-1(Controlling High Blood Pressure) format file to process:
Below is a part of QRDA-1 related to Encounter Performed
..............

QRDA-1 (Controlling High Blood Pressure) xml file

                    <entry>
                        <encounter classCode="ENC" moodCode="EVN">
                            <templateId root="2.16.840.1.113883.10.20.22.4.49"/>
                            <templateId root="2.16.840.1.113883.10.20.24.3.23"/>
                            <id root="1.3.6.1.4.1.115" extension="5177f5807938a7ce6100027f"/>
                            <code code="99201"
                    codeSystem="2.16.840.1.113883.6.12"
                    sdtc:valueSet="2.16.840.1.113883.3.464.1003.101.12.1001">
                                <originalText>Encounter, Performed:
                                    Office Visit</originalText>
                            </code>
                            <text>Encounter, Performed:
                                Office Visit</text>
                            <statusCode code="completed"/>
                            <effectiveTime>
                                <low value="20120301120000"/>
                                <high value="20120301130000"/>
                            </effectiveTime>
                        </encounter>
                    </entry>
...............
Number 2.16.840.1.113883.10.20.22.4.49 corresponds to Encounter Performed

Java code

import org.jaxen.JaxenException;
import org.jaxen.dom.DOMXPath;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import java.util.*;

DOMXPath xpath= new DOMXPath("/ClinicalDocument/component/structuredBody/component/section/entry/encounter/templateId[@root = '2.16.840.1.113883.10.20.22.4.49']");
    
 List<Node> nodes = (List<Node>)xpath.selectNodes(document);

for (Node node : nodes) { // iterate through the encounters
  Node nodeParent = node.getParentNode(); //get root document
  String code = getAttributeValueByName(nodeParent, "code", "code")); // Get code highlighted red color above
}

......


public static String getAttributeValueByName(Node document, String xpathExpression, String nameAttribute ) throws JaxenException {
        DOMXPath xpath = null;
        String value = null;
        try {
            xpath = new DOMXPath(xpathExpression);
            Node node = (Node)xpath.selectSingleNode(document);
            if(node != null){
                NamedNodeMap mapAttribute = node.getAttributes();
                for (int i = 0; i < mapAttribute.getLength(); i++){
                    if(nameAttribute.equalsIgnoreCase(mapAttribute.item(i).getNodeName()))  {  //compare current attribute name with the name to match
                        value = mapAttribute.item(i).getNodeValue();  // get attribute value
                        break;
                    }
                }
            }
        } catch (JaxenException e) {
            e.printStackTrace();
        }
        return value;
    }