Class ProfileParser
Parses a Message Profile XML document into a RuntimeProfile object. A Message Profile is a formal description of additional constraints on a message (beyond what is specified in the HL7 specification), usually for a particular system, region, etc. Message profiles are introduced in HL7 version 2.5 section 2.12. The RuntimeProfile object is simply an object representation of the profile, which may be used for validating messages or editing the profile.
Example usage:
// Load the profile from the classpath
ProfileParser parser = new ProfileParser(false);
RuntimeProfile profile = parser.parseClasspath("ca/uhn/hl7v2/conf/parser/example_ack.xml");
// Create a message to validate
String message = "MSH|^~\\&|||||||ACK^A01|1|D|2.4|||||CAN|wrong|F^^HL70001^x^^HL78888|\r"; //note HL7888 doesn't exist
ACK msg = (ACK) (new PipeParser()).parse(message);
// Validate
HL7Exception[] errors = new DefaultValidator().validate(msg, profile.getMessage());
// Each exception is a validation error
System.out.println("Validation errors: " + Arrays.asList(errors));
- Author:
- Bryan Tripp
-
Constructor Summary
ConstructorsConstructorDescriptionProfileParser(boolean alwaysValidate) Creates a new instance of ProfileParser -
Method Summary
Modifier and TypeMethodDescriptionstatic voidParses an XML profile string into a RuntimeProfile object.parseClasspath(String classPath) Parses an XML profile string into a RuntimeProfile object.
-
Constructor Details
-
ProfileParser
Creates a new instance of ProfileParser- Parameters:
alwaysValidate- if true, validates all profiles against a local copy of the profile XSD; if false, validates against declared grammar (if any)
-
-
Method Details
-
parseClasspath
Parses an XML profile string into a RuntimeProfile object. Input is a path pointing to a textual file on the classpath. Note that the file will be read using the thread context class loader. For example, if you had a file called PROFILE.TXT in package com.foo.stuff, you would pass in "com/foo/stuff/PROFILE.TXT"- Throws:
IOException- If the resource can't be readProfileException
-
parse
Parses an XML profile string into a RuntimeProfile object.- Throws:
ProfileException
-
main
-