Mirth Connect and HL7 v3 message validation

I'm using Mirth Connect (stable version) to create interfaces for HL7v3. I've created an interface to recieve a PRPA_IN201305UV02 message.

At this point I want to do some sort of validation of the incoming XML message. After some search I discovered that HL7 has schemas files (xsd) to verify the correctness of the messages.

So, I'm trying to implement the validation against a xsd file. Searching the mirth forum one of the administrators posted a link to a java library for xml validation.

In my channel source transformer I wrote the javascript based on that link.

// parse an XML document into a DOM tree var parser = Packages.javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder(); var document = parser.parse(msg); 

The last line of code is getting me an error when I recieve a message

Wrapped java.net.MalformedURLException: no protocol 

I tried also with

var document = parser.parse(messageObject.getRawData()); 

But I get the same error.

What is missing here? Is this the best way to do a XML validation on Mirth Connect?

Thank you

1

1 Answer

I have found this answer

And I transformed that to Javascript in Mirth

var schemaFile = new Packages.java.io.File("C:\\schema.xsd"); var url = new Packages.java.net.URL("file:C:\\input.xml"); var xmlFile = new Packages.javax.xml.transform.stream.StreamSource(url); var schemaFactory = Packages.javax.xml.validation.SchemaFactory.newInstance(""); var schema = schemaFactory.newSchema(schemaFile); var validator = schema.newValidator(); try { validator.validate(xmlFile); logger.info('valid'); } catch (err) { logger.error(err.toString()); } 

You need to download JAXP (Java API for XML Processing) from here

I hope it helps others

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like