eu.ihe.validator
Class MessageValidator

java.lang.Object
  extended by eu.ihe.validator.MessageValidator
All Implemented Interfaces:
ca.uhn.hl7v2.conf.check.Validator

public class MessageValidator
extends java.lang.Object
implements ca.uhn.hl7v2.conf.check.Validator

This class is almost the same of HAPI one, unless here we validate against Schemas and not DTD: ProfileParser profParser = new ProfileParser(false); and just add how to retrieve the warning of the validation which aren't in the HAPI one.

Author:
jfrancis

Field Summary
private  ca.uhn.hl7v2.parser.EncodingCharacters enc
           
private static ca.uhn.log.HapiLog log
           
 
Constructor Summary
MessageValidator()
          Creates a new instance of DefaultValidator
 
Method Summary
private  void addTableTestResult(java.util.ArrayList exList, java.lang.String profileID, java.lang.String codeSystem, java.lang.String value)
           
private  void addToList(ca.uhn.hl7v2.HL7Exception[] exceptions, java.util.ArrayList list)
          Appends an array of HL7 exceptions to a list
private  ca.uhn.hl7v2.HL7Exception[] checkExtraComponents(ca.uhn.hl7v2.model.Composite comp, int numInProfile)
          Tests for extra components (ie any not defined in the profile)
private  ca.uhn.hl7v2.HL7Exception[] checkForExtraFields(ca.uhn.hl7v2.model.Segment segment, java.util.ArrayList allowedFields)
          Checks a segment against a list of allowed fields (ie those mentioned in the profile with usage other than X).
private  ca.uhn.hl7v2.HL7Exception[] checkForExtraStructures(ca.uhn.hl7v2.model.Group group, java.util.ArrayList allowedStructures)
          Checks a group's children against a list of allowed structures for the group (ie those mentioned in the profile with usage other than X).
private  boolean hasContent(ca.uhn.hl7v2.model.Group group)
          Returns true is there is content in the given group
private  boolean hasContent(ca.uhn.hl7v2.model.Segment segment)
          Returns true is there is content in the given segment
private  boolean hasContent(ca.uhn.hl7v2.model.Structure struct)
          Returns true is there is content in the given structure
private  boolean hasContent(ca.uhn.hl7v2.model.Type type)
          Returns true is there is content in the given type
private static java.lang.String loadFile(java.lang.String path)
          loads file at the given path
static void main(java.lang.String[] args)
           
private  java.lang.String makeTableName(java.lang.String hl7Table)
           
protected  ca.uhn.hl7v2.HL7Exception testCardinality(int reps, int min, int max, java.lang.String usage, java.lang.String name)
          Checks cardinality and creates an appropriate exception if out of bounds.
 ca.uhn.hl7v2.HL7Exception[] testComponent(ca.uhn.hl7v2.model.Type type, ca.uhn.hl7v2.conf.spec.message.Component profile, java.lang.String profileID)
           
 ca.uhn.hl7v2.HL7Exception[] testField(ca.uhn.hl7v2.model.Type type, ca.uhn.hl7v2.conf.spec.message.Field profile, boolean escape, java.lang.String profileID)
           
 ca.uhn.hl7v2.HL7Exception[] testGroup(ca.uhn.hl7v2.model.Group group, ca.uhn.hl7v2.conf.spec.message.AbstractSegmentContainer profile, java.lang.String profileID)
          Tests a group against a group section of a profile.
 ca.uhn.hl7v2.HL7Exception testLength(ca.uhn.hl7v2.model.Type type, int maxLength)
          Tests whether the given type falls within a maximum length.
 ca.uhn.hl7v2.HL7Exception[] testSegment(ca.uhn.hl7v2.model.Segment segment, ca.uhn.hl7v2.conf.spec.message.Seg profile, java.lang.String profileID)
          Tests a segment against a segment section of a profile.
 ca.uhn.hl7v2.HL7Exception[] testStructure(ca.uhn.hl7v2.model.Structure s, ca.uhn.hl7v2.conf.spec.message.ProfileStructure profile, java.lang.String profileID)
          Tests a structure (segment or group) against the corresponding part of a profile.
 ca.uhn.hl7v2.HL7Exception[] testType(ca.uhn.hl7v2.model.Type type, ca.uhn.hl7v2.conf.spec.message.AbstractComponent profile, java.lang.String encoded, java.lang.String profileID)
          Tests a Type against the corresponding section of a profile.
private  ca.uhn.hl7v2.HL7Exception[] testTypeAgainstTable(ca.uhn.hl7v2.model.Type type, ca.uhn.hl7v2.conf.spec.message.AbstractComponent profile, java.lang.String profileID)
          Tests table values for ID, IS, and CE types.
private  ca.uhn.hl7v2.HL7Exception testUsage(java.lang.String encoded, java.lang.String usage, java.lang.String name)
          Tests an element against the corresponding usage code.
private  ca.uhn.hl7v2.HL7Exception testValueAgainstTable(java.lang.String profileID, java.lang.String codeSystem, java.lang.String value)
           
private  ca.uhn.hl7v2.HL7Exception[] toArray(java.util.ArrayList list)
          Returns the HL7 exceptions in the given arraylist in an array
 ca.uhn.hl7v2.HL7Exception[] validate(ca.uhn.hl7v2.model.Message message, ca.uhn.hl7v2.conf.spec.message.StaticDef profile)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

enc

private ca.uhn.hl7v2.parser.EncodingCharacters enc

log

private static final ca.uhn.log.HapiLog log
Constructor Detail

MessageValidator

public MessageValidator()
Creates a new instance of DefaultValidator

Method Detail

validate

public ca.uhn.hl7v2.HL7Exception[] validate(ca.uhn.hl7v2.model.Message message,
                                            ca.uhn.hl7v2.conf.spec.message.StaticDef profile)
                                     throws ca.uhn.hl7v2.conf.ProfileException,
                                            ca.uhn.hl7v2.HL7Exception
Specified by:
validate in interface ca.uhn.hl7v2.conf.check.Validator
Throws:
ca.uhn.hl7v2.conf.ProfileException
ca.uhn.hl7v2.HL7Exception
See Also:
Validator.validate(ca.uhn.hl7v2.model.Message, ca.uhn.hl7v2.conf.spec.message.StaticDef)

testGroup

public ca.uhn.hl7v2.HL7Exception[] testGroup(ca.uhn.hl7v2.model.Group group,
                                             ca.uhn.hl7v2.conf.spec.message.AbstractSegmentContainer profile,
                                             java.lang.String profileID)
                                      throws ca.uhn.hl7v2.conf.ProfileException
Tests a group against a group section of a profile.

Throws:
ca.uhn.hl7v2.conf.ProfileException

checkForExtraStructures

private ca.uhn.hl7v2.HL7Exception[] checkForExtraStructures(ca.uhn.hl7v2.model.Group group,
                                                            java.util.ArrayList allowedStructures)
                                                     throws ca.uhn.hl7v2.conf.ProfileException
Checks a group's children against a list of allowed structures for the group (ie those mentioned in the profile with usage other than X). Returns a list of exceptions representing structures that appear in the message but are not supposed to.

Throws:
ca.uhn.hl7v2.conf.ProfileException

testCardinality

protected ca.uhn.hl7v2.HL7Exception testCardinality(int reps,
                                                    int min,
                                                    int max,
                                                    java.lang.String usage,
                                                    java.lang.String name)
Checks cardinality and creates an appropriate exception if out of bounds. The usage code is needed because if min cardinality is > 0, the min # of reps is only required if the usage code is 'R' (see HL7 v2.5 section 2.12.6.4).

Parameters:
reps - the number of reps
min - the minimum number of reps
max - the maximum number of reps (-1 means *)
usage - the usage code
name - the name of the repeating structure (used in exception msg)
Returns:
null if cardinality OK, exception otherwise

testStructure

public ca.uhn.hl7v2.HL7Exception[] testStructure(ca.uhn.hl7v2.model.Structure s,
                                                 ca.uhn.hl7v2.conf.spec.message.ProfileStructure profile,
                                                 java.lang.String profileID)
                                          throws ca.uhn.hl7v2.conf.ProfileException
Tests a structure (segment or group) against the corresponding part of a profile.

Throws:
ca.uhn.hl7v2.conf.ProfileException

testSegment

public ca.uhn.hl7v2.HL7Exception[] testSegment(ca.uhn.hl7v2.model.Segment segment,
                                               ca.uhn.hl7v2.conf.spec.message.Seg profile,
                                               java.lang.String profileID)
                                        throws ca.uhn.hl7v2.conf.ProfileException
Tests a segment against a segment section of a profile.

Throws:
ca.uhn.hl7v2.conf.ProfileException

checkForExtraFields

private ca.uhn.hl7v2.HL7Exception[] checkForExtraFields(ca.uhn.hl7v2.model.Segment segment,
                                                        java.util.ArrayList allowedFields)
                                                 throws ca.uhn.hl7v2.conf.ProfileException
Checks a segment against a list of allowed fields (ie those mentioned in the profile with usage other than X). Returns a list of exceptions representing field that appear but are not supposed to.

Parameters:
allowedFields - an array of Integers containing field #s of allowed fields
Throws:
ca.uhn.hl7v2.conf.ProfileException

testType

public ca.uhn.hl7v2.HL7Exception[] testType(ca.uhn.hl7v2.model.Type type,
                                            ca.uhn.hl7v2.conf.spec.message.AbstractComponent profile,
                                            java.lang.String encoded,
                                            java.lang.String profileID)
Tests a Type against the corresponding section of a profile.

Parameters:
encoded - optional encoded form of type (if you want to specify this -- if null, default pipe-encoded form is used to check length and constant val)

testLength

public ca.uhn.hl7v2.HL7Exception testLength(ca.uhn.hl7v2.model.Type type,
                                            int maxLength)
Tests whether the given type falls within a maximum length.

Returns:
null of OK, an HL7Exception otherwise

testUsage

private ca.uhn.hl7v2.HL7Exception testUsage(java.lang.String encoded,
                                            java.lang.String usage,
                                            java.lang.String name)
Tests an element against the corresponding usage code. The element is required in its encoded form.

Parameters:
encoded - the pipe-encoded message element
usage - the usage code (e.g. "CE")
name - the name of the element (for use in exception messages)

testTypeAgainstTable

private ca.uhn.hl7v2.HL7Exception[] testTypeAgainstTable(ca.uhn.hl7v2.model.Type type,
                                                         ca.uhn.hl7v2.conf.spec.message.AbstractComponent profile,
                                                         java.lang.String profileID)
Tests table values for ID, IS, and CE types. An empty list is returned for all other types.


addTableTestResult

private void addTableTestResult(java.util.ArrayList exList,
                                java.lang.String profileID,
                                java.lang.String codeSystem,
                                java.lang.String value)

testValueAgainstTable

private ca.uhn.hl7v2.HL7Exception testValueAgainstTable(java.lang.String profileID,
                                                        java.lang.String codeSystem,
                                                        java.lang.String value)

makeTableName

private java.lang.String makeTableName(java.lang.String hl7Table)

testField

public ca.uhn.hl7v2.HL7Exception[] testField(ca.uhn.hl7v2.model.Type type,
                                             ca.uhn.hl7v2.conf.spec.message.Field profile,
                                             boolean escape,
                                             java.lang.String profileID)
                                      throws ca.uhn.hl7v2.conf.ProfileException
Throws:
ca.uhn.hl7v2.conf.ProfileException

testComponent

public ca.uhn.hl7v2.HL7Exception[] testComponent(ca.uhn.hl7v2.model.Type type,
                                                 ca.uhn.hl7v2.conf.spec.message.Component profile,
                                                 java.lang.String profileID)
                                          throws ca.uhn.hl7v2.conf.ProfileException
Throws:
ca.uhn.hl7v2.conf.ProfileException

checkExtraComponents

private ca.uhn.hl7v2.HL7Exception[] checkExtraComponents(ca.uhn.hl7v2.model.Composite comp,
                                                         int numInProfile)
                                                  throws ca.uhn.hl7v2.conf.ProfileException
Tests for extra components (ie any not defined in the profile)

Throws:
ca.uhn.hl7v2.conf.ProfileException

hasContent

private boolean hasContent(ca.uhn.hl7v2.model.Structure struct)
                    throws ca.uhn.hl7v2.HL7Exception
Returns true is there is content in the given structure

Throws:
ca.uhn.hl7v2.HL7Exception

hasContent

private boolean hasContent(ca.uhn.hl7v2.model.Group group)
                    throws ca.uhn.hl7v2.HL7Exception
Returns true is there is content in the given group

Throws:
ca.uhn.hl7v2.HL7Exception

hasContent

private boolean hasContent(ca.uhn.hl7v2.model.Segment segment)
Returns true is there is content in the given segment


hasContent

private boolean hasContent(ca.uhn.hl7v2.model.Type type)
Returns true is there is content in the given type


addToList

private void addToList(ca.uhn.hl7v2.HL7Exception[] exceptions,
                       java.util.ArrayList list)
Appends an array of HL7 exceptions to a list


toArray

private ca.uhn.hl7v2.HL7Exception[] toArray(java.util.ArrayList list)
Returns the HL7 exceptions in the given arraylist in an array


loadFile

private static java.lang.String loadFile(java.lang.String path)
                                  throws java.io.IOException
loads file at the given path

Throws:
java.io.IOException

main

public static void main(java.lang.String[] args)
Parameters:
args -