This sample project receives an HL7 V3 message, PRPA_IN403001UV01, and sends an HL7 V3 ACK or NAK, MCCI_IN000004UV01. This project is same as prjHL7V3Inbound except for the schematron validation for the input XML.
Follow these steps in the order given to complete the schematron sample:
In order to work with the sample project, you need to download it from the Repository using the Suite Uploader and then import it using NetBeans.
Make sure the required Message Libraries are installed. In addition to the HL7 OTD Library and HL7 OTD Generic Library, which are installed with the TCP/IP HL7 Adapter by default, you need to install the following two libraries:
HL7V32006PatientAdmin.sar
HL7V32006TransInfra.sar
If the TCP/IP HL7 Adapter is not already installed, install it now as described in Installing the TCP/IP HL7 Adapter and Installing the TCP/IP Adapter in the NetBeans IDE.
Download the schematron sample project and the HL7 V3 outbound project, as described in Downloading the Sample Projects.
Import the project file.
On the NetBeans IDE, save all unsaved work.
On the NetBeans menu bar, select Tools, point to CAPS Repository, and then select Import Project from the drop-down menu.
A confirmation dialog box appears asking if you need to save any changes.
Click Yes to proceed.
The Import Manager appears.
Click Browse, navigate to the location of the project ZIP files, and select prjHL7Inbound_WithSchematron.zip.
Click Import.
A warning message appears if you already have a project of the same name in the CAPS Repository. Determine whether you want to overwrite the existing project. In some cases the imported file will add files to an existing project. If you do not want to overwrite the existing project, cancel the import and exit the Import Manager. Rename and save the existing project, and attempt the import again.
It may take a few seconds to import the project. When the project is imported, the Import Status dialog box appears.
Click OK on the dialog box.
The CAPS Repository is refreshed.
Close the Import Manager.
You should now have two new projects in the tree structure of the Projects window.
In the current example, the JAR file (checkprofileid.jar) is bundled along with the sample project file imported from Java CAPS Repository, prjHL7V3Inbound_WithSchematron.
When you first import a project, all of its components are checked in to version control. This means you cannot edit the project. You need to check the components out first.
In the NetBeans Projects window, right–click prjHL7V3Inbound_WithSchematron .
Point to Version Control, and then select Check Out.
On the Version Control dialog box, click Recurse Project, and then click Select All.
Click Check Out.
On the NetBeans Projects window, double-click cmHL7V3Inbound.
The Connectivity Map appears in the Connectivity Map Editor.
Double-click the Adapter icon on the connecting line between the eaHL7V3Inbound External System and the jcdHL7V3Inbound1 service.
The Properties Editor appears.
Select Schematron Validation in the left panel.
Modify the properties as follows:
Enable Schematron Validation: true
Schematron Files: Provide a list of Schematron files. Use a comma to separate multiple files.
The JCD is edited as described in the steps below.
In the NetBeans Projects window, double-click jcdHL7V3Inbound.
The Collaboration appears in the Java Collaboration Editor.
Modify the Collaboration rules as needed.
The following sections describe parts of the JCD that define schematron validation.
The schematron validation API is invoked from the JCD. The JCD follows the standard HL7 V3 validation; the schematron validation API is only invoked if the Enable Schematron Validation property is true. Following is an excerpt from the JCD code that scans the schematron files list and calls the method validateWithSchematron() if schematron validation is enabled.
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 above text has been wrapped for display purposes. The images below show the code as it appears in the Collaboration Editor.
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. The following excerpt from the JCD defines the validation 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 above text has been wrapped for display purposes. The images below show the code as it appears in the Collaboration Editor.
The makeNAK() method retrieves the XML document generated from the schematron validation. The XML document is embedded in the AcknowledgementDetail section of HL7V3 Acknowledgement XML. The following excerpt defines the makeNAK() method.
makeNAK() method
if (schematronValidationError) { log( LOG_LEVEL_INFO, "Schematron validationOutputList.size=" + validationOutputList.size()); for (int i = 0; i < validationOutputList.size(); i++) { 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 ); } } |
The above text has been wrapped for display purposes. The image below shows the code as it appears in the Collaboration Editor.
This section provides sample schematron validation and input files, and also gives instructions on importing the validation file for use in the JCD.
Below is a sample schematron validation file that checks for the presence of the profileid field in the PRPA_IN403001UV01 OTD.
<?xml version="1.0" encoding="UTF-8"?> <sch:schema xmlns:sch="http://www.ascc.net/xml/schematron"> <sch:ns prefix="hl7v3" uri="urn:hl7-org:v3"/> <sch:pattern name="Check structure"> <sch:rule context="hl7v3:PRPA_IN403001UV01"> <sch:assert test="count(hl7v3:profileId) = 1">The profileId should be present. It is missing.</sch:assert> </sch:rule> </sch:pattern> </sch:schema> |
<PRPA_IN403001UV01 xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 PRPA_IN403001UV01.xsd"> <id root="1.1.2.3.4.6" extension="5929" assigningAuthorityName="Litware Inc."/> <creationTime value="20050303180027"/> <versionCode code="V3PR1"/> <interactionId root="1.1.6.7.8" extension="PRPA_IN403001UV01" assigningAuthorityName="HL7"/> <profileId root="1.1.1.1"/> <processingCode code="D"/> <processingModeCode code="T"/> <acceptAckCode code="AL"/> ... ... ... |
The above text has been wrapped for display purposes. It contains extra line breaks.
This tutorial includes a JAR file, checkprofileid.jar. which includes the sample schematron validation file described above. Follow this procedure if you want to create your own validation file and package it for the JCD.
Create a JAR file containing the schematron validation file in XML format.
Do the following to import the JAR file:
Open the Collaboration in the Collaboration Editor.
On the Collaboration Editor toolbar, click Add JAR.
On the Add/Remove Jar Files dialog box, click Add.
Navigate to and select he JAR file to add, and then click Import.
On the Add/Remove Jar Files dialog box, click Close.
Follow the steps below to create an Environment for the cmHL7V3Inbound Connectivity Map in the schematron sample project.
On the NetBeans Services window, right-click CAPS Environments, point to New, and then select Environment.
A new environment is created and is added to the CAPS Environment tree.
Rename the new environment to envHL7V3Outbound.
Right-click envHL7V3Outbound, point to New, and then select Logical Host from the drop-down menu.
It takes few seconds to process the Logical Host into the Environment.
Right-click LogicalHost1, point to New, and then select Sun Java System Application Server.
A new application server (SunJavaSystemApplicationServer1) is added to the Environment Explorer tree under LogicalHost1.
Right-click LogicalHost1, point to New, and then select Sun JMS IQ Manager.
A new JMS IQ Manager (SunJmsIQMgr1) is added to the Environment tree under LogicalHost1.
Right-click envHL7V3Outbound, point to New, and then select File External System.
The External System is added to the Environment tree.
Right-click envHL7V3Outbound, point to New, and then select HL7V3 External System.
The new External System is added to the Environment tree.
On the NetBeans toolbar, click Save All.
Once you create the Environment, you need to create a Deployment Profile in order to build and deploy the project.
Create a Deployment Profile.
Click Automap.
The Automap Results dialog box appears.
Click Close.
On the NetBeans toolbar, click Save All.
On the Deployment Editor toolbar, click Build.
When the Build confirmation dialog box appears, click OK.
On the Deployment Editor toolbar, click Deploy.
To run data through the sample project, you need to use an HL7 simulator or HL7 application.
Create a sample file named PRPA_IN403001UV01.xml.
Enter the following text into the file (you can copy and paste this excerpt).
<?xml version="1.0" encoding="UTF-8"?> <PRPA_IN403001UV01 xmlns="urn:hl7-org:v3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:hl7-org:v3 PRPA_IN403001UV01.xsd"> <id root="1.1.2.3.4.6" extension="5929" assigningAuthorityName="Litware Inc."/> <creationTime value="20050303180027"/> <versionCode code="V3PR1"/> <interactionId root="1.1.6.7.8" extension="PRPA_IN403001UV01" assigningAuthorityName="HL7"/> <!--profileId root="1.1.1.1"/--> <processingCode code="D"/> <processingModeCode code="T"/> <acceptAckCode code="AL"/> <receiver typeCode="RCV"> <device classCode="DEV" determinerCode="INSTANCE"> <id root="1.4.7.8.3"/> </device> </receiver> <sender typeCode="SND"> <device classCode="DEV" determinerCode="INSTANCE"> <id root="1.45.6.7.98"/> </device> </sender> <controlActProcess classCode="CACT" moodCode="EVN"> <subject typeCode="SUBJ" contextConductionInd="false"> <encounterEvent classCode="ENC" moodCode="EVN"> <id root="1.56.3.4.7.5" extension="122345" assigningAuthorityName="Maple Hospital Emergency"/> <code code="EMER" codeSystem="2.16.840.1.113883.5.4"/> <statusCode code="active"/> <subject contextControlCode="OP"> <patient classCode="PAT"> <id root="1.56.3.4.7.9" extension="55321" assigningAuthorityName="Maple Hospital Patients"/> <patientPerson classCode="PSN" determinerCode="INSTANCE"> <name> <given>Rob</given> <given>P</given> <family>Young</family> </name> <administrativeGenderCode code="M" codeSystem="2.16.840.1.113883.5.1"/> <birthTime value="19800309"/> </patientPerson> </patient> </subject> </encounterEvent> </subject> </controlActProcess> </PRPA_IN403001UV01> |
The above text has been wrapped to fit the page. The following image shows the text in an XML editor.
Copy the XML file to a location where the simulator or HL7 application will pick it up.
Open the server log file and check the results at the following location:
Drivename:\JavaCAPS6U1\appserver\domains\domian1\logs
This action displays the following message.
Schematron Validation Failed