How do I validate a CCD HL7 document?

6.5k views Asked by At

When I have an example CCD, should I use:

  1. An XSD schema and conclude that I have a valid CCD.

    or

  2. I use some other (non-schema based) method. (UML model rules in addition to a valid XML document.)

Is there even such a thing as ccd.xsd? Even if it only partially guides me to create a valid CCD.

4

There are 4 answers

1
Coder Panda On

Old question, but I still thought I would answer it because I was looking for a solution to this problem recently and ended up doing a fair amount of research.

I tried using the Everest API which has a built in API to validate various HL7 documents. This is a great way to test within your code if you have generated a valid document.

NIST provides a webservice (and a sample client too!) that can be used (within your code again) to validate documents like CCD/CCDA etc.

If you just need to manually validate a generated document then NIST has another one.

I hope it helps...

0
Matt On

I realize this is a pretty old question, but I wanted to add my two cents as well.

cdatools.org has some great tools for validating CDA documents. Since you're creating a CCD, the validation process will be the same.

Furthermore, the cdatools infocenter has fantastic information about different documents and their requirements.

6
Eric On

To quickly answer your questions:

A: There is an XSD schema, but only to ensure if the document is a valid CDA document (this means it only validates the CDA RIM, not the CCD Implementation Guide)

B: The non-schema based method is to use schematron, and a ccd.sch does come shipped with the standard provided by HL7. This is the best way to validate it as a valid CCD document.

C: There is no such thing as a ccd.xsd that I'm aware of.


Background

Here's a bit of background and instructions on how to acquire the CCD standard from HL7. Acquiring the Standard would also provide you with the CDA.xsd and CCD.sch for file validation.

CCD is a specific implementation derived from the CDA RIM. Both CCD and CDA are standards that are maintained by HL7. CCD is currently a “Section 1” type standard by HL7.

The full standard can be downloaded from the HL7 website. The full standard is full standard is free to download - Although you may have to register to the site (also free). http://www.hl7.org/implement/standards/product_brief.cfm?product_id=6

Because I don’t know what other resources you have available, I am going to only use supporting documents that can be acquired from the HL7 website.

There are two layers when it comes to validating a CCD document. First, you have to validate to make sure that the document is a valid CDA file, and then you have to validate to ensure it follows the implementation constraints outlined in the CCD Implementation Guide.

To make sure it is a valid CDA file, there is a CDA.xsd schema that comes with the full CCD spec download.

The standard also comes with a schematron file to validate it as a CCD document.

In the unlikely scenario that there is a disagreement between the schematron validator and the Implementation Guide, always go with the Implementation Guide.


Acronyms

CCD – Continuity of Care Document

CDA – Clinical Document Architecture

RIM – Reference Information Model

As a supplementary link, a pretty handy online tool for CCD document validation can be found here: https://www.lantanagroup.com/validator/

0
Seth Rylan On

Option A is more recommended, which involves parsing the XML document with a DocumentBuilder that has a specific CCD schema source and then checking for validation errors. I recommend looking at the XMLValidation class in the SchematronValidator project; the validXMLUsingXSD(...) method does what you are describing. There are several places to find an XSD for valid CCD XML, but if you don't know where to start, you can find most of the XSDs for CDA/CCR schemas at Microsoft HealthVault. There are some additional ways to use schematron rules to further validate your CCD document (see the Meaningful Use Validator from NIST).

The code for what you are doing will look like the snippet below, where schemaLocation is your XSD file location. The ErrorHandler will store any validation errors.

DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
docFactory.setNamespaceAware(true);
docFactory.setValidating(true);
docFactory.setAttribute(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
docFactory.setAttribute(JAXP_SCHEMA_SOURCE, schemaLocation);
docFactory.setIgnoringElementContentWhitespace(true);
DocumentBuilder builder = null;
try {
    builder = docFactory.newDocumentBuilder();
} catch (ParserConfigurationException pce) {
    pce.printStackTrace();
    return null;
}

builder.setErrorHandler(handler);
Document doc = null;
try {
   doc = builder.parse(xml);
} catch (SAXException e) {
    System.out.println("Message is not valid XML.");
    handler.addError("Message is not valid XML.", null);
    e.printStackTrace();
} catch (IOException e) {
    System.out.println("Message is not valid XML.  Possible empty message.");
    handler.addError("Message is not valid XML.  Possible empty message.", null);
    e.printStackTrace();
}
return doc;