javascriptxmlmirthhl7-v3

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


Solution

  • 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("http://www.w3.org/2001/XMLSchema");
    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