What's New in the Sun TCP/IP HL7 Adapter

Schematron Validation Inside the JCD

The schematron validation API is invoked from the JCD. This validation follows the normal HL7 V3 validation. It is invoked only when the Enable Schematron Validation property is true. This validation scans the schematronfiles list and invokes the method validateWithSchematron() depending on the value set forth for the property.

Validating the Code Snippet


boolean validated = validateHL7Message( HL7message );
java.util.ArrayList outputList = new java.util.ArrayList();
if (validated) {
boolean schematronValidationEnabled =
input.getHL7v3MessageInfo().getSchematronValidationInfo().
isSchematronValidationEnabled();
log( LOG_LEVEL_INFO, "SchematronEnabled = " + schematronValidationEnabled );
if (schematronValidationEnabled) {
String[] schFiles =
input.getHL7v3MessageInfo().getSchematronValidationInfo().getSchematronFilesList();
log( LOG_LEVEL_INFO, "schFilesList  = " + schFiles );
for (int i = 0; i < schFiles.length; i++) {
log( LOG_LEVEL_INFO, "Adding schematron file for validation  = " + schFiles[i] );
com.stc.connector.hl7.schematron.ValidationOutput output =
validateWithSchematron( "/" + schFiles[i], HL7message );
outputList.add( output );
}

for (int i = 0; i < outputList.size(); i++) {
com.stc.connector.hl7.schematron.ValidationOutput output =
(com.stc.connector.hl7.schematron.ValidationOutput) outputList.get( i );
if (!output.isValid()) {
validated = false;
schematronValidationError = true;
log( LOG_LEVEL_INFO, "Schematron Validation failed." );
break;
} else {
validated = true;
}
}

The illustrations are as shown.

Figure1 Inside the JCDFigure2 Inside the JCD

Validating With Schematron Method

The Schematron method invokes the Schematron API. It reads the schematron files from classpath and constructs a DOM source. The DOM source passes it to obtain the SchematronValidator object. The object invokes the validate() method to pass the hl7payload.

validateWithSchematron() method


private com.stc.connector.hl7.schematron.
ValidationOutput validateWithSchematron( String
 schematronFile, byte[] hl7payload )
throws Exception
{
com.stc.connector.hl7.schematron.SchematronValidatorFactory 
factory =
com.stc.connector.hl7.schematron.SchematronValidatorFactory.
getSchematronValidatorFactory();
log( LOG_LEVEL_INFO, "Schematron URI :" +
this.getClass().getResource( schematronFile ).toString() );
java.io.InputStream in = this.getClass().
getResourceAsStream( schematronFile );
java.io.BufferedReader bufReader = new java.io.
BufferedReader( new
java.io.InputStreamReader( in ) );
StringBuffer schematronXml = new StringBuffer();
String line = bufReader.readLine();
while (line != null) {
schematronXml.append( line );
line = bufReader.readLine();
}

bufReader.close();

javax.xml.parsers.DocumentBuilderFactory 
domBuilderFactory =
javax.xml.parsers.DocumentBuilderFactory.
newInstance();
domBuilderFactory.setNamespaceAware( true );
org.w3c.dom.Document doc = domBuilderFactory.
newDocumentBuilder().parse( new
org.xml.sax.InputSource( new java.io.ByteArrayInputStream
( schematronXml.toString().getBytes() ) ) );
javax.xml.transform.dom.DOMSource domSource = new
javax.xml.transform.dom.DOMSource( doc.
getDocumentElement() );
com.stc.connector.hl7.schematron.SchematronValidator 
validator =
factory.getDefaultValidator( domSource );
javax.xml.transform.stream.StreamSource dataSrc = new javax.xml.
transform.stream.StreamSource(
new java.io.ByteArrayInputStream( hl7payload ) );
com.stc.connector.hl7.schematron.ValidationOutput output = 
validator.validate( dataSrc );
return output;
}

The illustrations are as shown.

Validate With SchematronFigure2 Validate With Schematron

Retrieving the Resultant XML Document

The makeNAK() method retrieves the Resultant XML document generated from the Schematron validation. The XML document is embedded in the AcknowledgementDetail section of HL7V3 Acknowledgement XML.

makeNAK() method


if (schematronValidationError) {
log( LOG_LEVEL_INFO, "Schematron validationOutputList.size=" 
+ validationOutputList.size()
);
or (int i = 0; i < validationOutputList.size(); i++) {
// otd_MCCI_IN000004UV01_1.getAcknowledgement(0).
addAcknowledgementDetail();
com.stc.connector.hl7.schematron.ValidationOutput output =
(com.stc.connector.hl7.schematron.ValidationOutput) 
validationOutputList.get( i );
String outputStr = output.getOutputAsString();
otd_MCCI_IN000004UV01_1.getAcknowledgement( 0 ).
getAcknowledgementDetail( i ).getTypeCode().setCode( "E" );
otd_MCCI_IN000004UV01_1.getAcknowledgement( 0 ).
getAcknowledgementDetail( i ).getCode().setCode
( "Validation Failure: Schematron Validation Failed" );
otd_MCCI_IN000004UV01_1.getAcknowledgement( 0 ).
getAcknowledgementDetail( i ).getText().setMediaType( "text/xml" );
otd_MCCI_IN000004UV01_1.getAcknowledgement( 0 ).
getAcknowledgementDetail( i ).getText().setX__PCDATA__MX( outputStr );
log( LOG_LEVEL_INFO, "Schematron Validation Output = " 
+ outputStr );
}
}
Properties of makeNAK