Sun Adapter for TCP/IP HL7 User's Guide

Schematron Support in the HL7 Adapter

Schematron is supported for HL7 V3 Message Libraries. The Schematron uses the concept of finding tree patterns in the parsed document rather than the grammar. This approach allows representation of numerous structures that are inconvenient and difficult in grammar-based schema languages.

For example, the following file defines a Person element that includes a Name field and a Gender field:


<?xml version="1.0" encoding="UTF-8"?>
<Person>
<Name>Eddie</Name>
<Gender>Male</Gender>
<Person>

The above XML document can be validated against the below schematron, which defines a test for a Title field, a test for Name and Gender, and a test for the order of fields:


<?xml version="1.0" encoding="UTF-8"?>
<sch:schema xmlns:sch="http://www.ascc.net/xml/schematron">
<sch:pattern name="Check structure">
<sch:rule context="Person">
<sch:assert test="@Title">The element Person must have a Title attribute<sch:assert>
<sch:assert test="count(*) = 2 and count(Name) = 1 and count(Gender) = 1">The element
 Person should have the child elements Name and Gender.<sch:assert>
<sch:assert test="*[1] = Name">The element Name must appear before element
Gender.</sch:assert>
</sch:rule>
</sch:pattern>
</sch:schema>

In the HL7 Adapter, this schematron is useful for validating an HL7 V3 document against predefined schematron schemas that you write. You can also obtain schemas from organizations such as NHS and HL7.org. For example, NHS provides schemas for CDA documents.

Schematron Configuration in HL7 Adapter

You configure the schematron validation from the Connectivity Map Properties Editor. The Properties Editor includes two properties to support schematron validation:

API for Schematron Validation

The HL7 Adapter includes an API specific to schematron validation. This API is a wrapper of the Open source XSLT-based API available at http://xml.ascc.net/schematron/1.5. The API is an XSL file called metastylesheet (skeleton1-5.xsl). Applying the metastylesheet to the schematron XML document generates another XSL file. This XSL file can be applied to the input XML document to validate, which produces the output XML document that contains the results of the validation. This document can be embedded inside the V3 acknowledgement and can be sent to the original sender.

The metastylesheet can be extended and overridden so that you can customize the output XML document.

Example,

The following is an example of an output document generated after invoking the API using the XML input document and the schematron validation document described above.


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<schematron-output phase="#ALL" schemaVersion="" title="" xmlns:
sch="http://www.ascc.net/xml/schematron">
<active-pattern name="Check structure"/>
<fired-rule context="Person" id="" role=""/>
<failed-assert id="" role="" test="@Title" location="/@Person[1]">
<text>The element Person must have a Title attribute</text>
</failed-assert>
<schematron-output>

Using the Schematron API

Perform the following to invoke the schematron API from a Java Collaboration:

Obtaining the Factory Object

Below is a sample call to the getSchematronValidatorFactory method.


com.stc.connector.hl7.schematron.SchematronValidatorFactory
  factory = com.stc.connector.hl7.schematron.SchematronValidatorFactory.
  getSchematronValidatorFactory();

Obtaining the Validator Object

Below is a sample call to the getDefaultValidator method.


com.stc.connector.hl7.schematron.SchematronValidator 
validator = factory.getDefaultValidator( domSource );

In the above example, domSource is the DOMSource object of the schematron XML.

Performing the Validation

Below is a sample call to the validate method.


com.stc.connector.hl7.schematron.ValidationOutput
   output = validator.validate( dataSrc );

In the above example, dataSrc is the source of the payload. The payload can be an entire V3 XML document or a CDA document.

The ValidationOutput object contains the resulting XML document as well as a method isValid(), which returns values when the validation has passed or failed.