Package ca.uhn.hl7v2.conf.check
Class DefaultValidator
java.lang.Object
ca.uhn.hl7v2.HapiContextSupport
ca.uhn.hl7v2.conf.check.DefaultValidator
- All Implemented Interfaces:
Validator
A default conformance profile validator.
Note: this class is currently NOT thread-safe!
- Author:
- Bryan Tripp
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of DefaultValidatorDefaultValidator(HapiContext context) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddTableTestResult(String profileID, String codeSystem, String value, List<HL7Exception> exList) protected voidcheckConstantValue(String value, String encoded, List<HL7Exception> exList) protected voidcheckDataType(String dataType, Type type, List<HL7Exception> exList) protected voidcheckEventType(String evType, StaticDef profile, List<HL7Exception> exList) protected voidcheckExtraComponents(Composite comp, int numInProfile, List<HL7Exception> exList) Tests for extra components (ie any not defined in the profile)protected voidcheckForExtraFields(Segment segment, List<Integer> allowedFields, List<HL7Exception> exList) Checks a segment against a list of allowed fields (ie those mentioned in the profile with usage other than X).protected voidcheckForExtraStructures(Group group, List<String> allowedStructures, List<HL7Exception> exList) 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).protected voidcheckLength(long length, String name, String encoded, List<HL7Exception> exList) protected voidcheckMessageStructure(String msgStruct, StaticDef profile, List<HL7Exception> exList) protected voidcheckMessageType(String msgType, StaticDef profile, List<HL7Exception> exList) protected List<HL7Exception>doTestComponent(Type type, Component profile, String profileID, boolean theValidateChildren) protected List<HL7Exception>doTestField(Type type, Field profile, boolean escape, String profileID, boolean theValidateChildren) protected List<HL7Exception>doTestGroup(Group group, AbstractSegmentContainer profile, String profileID, boolean theValidateChildren) protected List<HL7Exception>doTestSegment(Segment segment, Seg profile, String profileID, boolean theValidateChildren) static voidvoidsetCodeStore(CodeStore theCodeStore) Provides a code store to use to provide the code tables which will be used to validate coded value types.voidsetValidateChildren(boolean validateChildren) If set to false (default is true), each testXX and validateXX method will only test the direct object it is responsible for, not its children.protected HL7ExceptiontestCardinality(int reps, int min, int max, String usage, String name, List<HL7Exception> exList) Checks cardinality and creates an appropriate exception if out of bounds.testComponent(Type type, Component profile, String profileID) Tests a group against a group section of a profile.testLength(Type type, int maxLength) Tests whether the given type falls within a maximum length.testSegment(Segment segment, Seg profile, String profileID) Tests a segment against a segment section of a profile.testStructure(Structure s, ProfileStructure profile, String profileID) Tests a structure (segment or group) against the corresponding part of a profile.testType(Type type, AbstractComponent<?> profile, String encoded, String profileID) Tests a Type against the corresponding section of a profile.protected voidtestTypeAgainstTable(Type type, AbstractComponent<?> profile, String profileID, List<HL7Exception> exList) Tests table values for ID, IS, and CE types.protected voidTests an element against the corresponding usage code.protected voidtestValueAgainstTable(String profileID, String codeSystem, String value, List<HL7Exception> exList) Validates the given message against the given static definition from a conformance profile.Methods inherited from class ca.uhn.hl7v2.HapiContextSupport
getHapiContext, setHapiContext
-
Constructor Details
-
DefaultValidator
public DefaultValidator()Creates a new instance of DefaultValidator -
DefaultValidator
-
-
Method Details
-
setValidateChildren
If set to false (default is true), each testXX and validateXX method will only test the direct object it is responsible for, not its children. -
setCodeStore
Provides a code store to use to provide the code tables which will be used to validate coded value types. If a code store has not been set (which is the default),
ProfileStoreFactorywill be checked for an appropriate code store, and if none is found then coded values will not be validated. -
validate
public HL7Exception[] validate(Message message, StaticDef profile) throws ProfileException, HL7Exception Description copied from interface:ValidatorValidates the given message against the given static definition from a conformance profile. Conformance profiles are XML representations of domain-specific constraints on a message (see HL7 2.5 section 2.12).- Specified by:
validatein interfaceValidator- Returns:
- a list of exceptions representing points of non-conformance (may not be a complete list)
- Throws:
ProfileException- if a problem is encountered that interferes with evaluationHL7Exception- See Also:
-
checkEventType
-
checkMessageType
-
checkMessageStructure
protected void checkMessageStructure(String msgStruct, StaticDef profile, List<HL7Exception> exList) -
testGroup
public List<HL7Exception> testGroup(Group group, SegGroup profile, String profileID) throws ProfileException Tests a group against a group section of a profile.- Throws:
ProfileException
-
doTestGroup
protected List<HL7Exception> doTestGroup(Group group, AbstractSegmentContainer profile, String profileID, boolean theValidateChildren) throws ProfileException - Throws:
ProfileException
-
checkForExtraStructures
protected void checkForExtraStructures(Group group, List<String> allowedStructures, List<HL7Exception> exList) throws 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:
ProfileException
-
testCardinality
protected HL7Exception testCardinality(int reps, int min, int max, String usage, String name, List<HL7Exception> exList) 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 repsmin- the minimum number of repsmax- the maximum number of reps (-1 means *)usage- the usage codename- the name of the repeating structure (used in exception msg)- Returns:
- null if cardinality OK, exception otherwise
-
testStructure
public List<HL7Exception> testStructure(Structure s, ProfileStructure profile, String profileID) throws ProfileException Tests a structure (segment or group) against the corresponding part of a profile.- Throws:
ProfileException
-
testSegment
public List<HL7Exception> testSegment(Segment segment, Seg profile, String profileID) throws ProfileException Tests a segment against a segment section of a profile.- Throws:
ProfileException
-
doTestSegment
protected List<HL7Exception> doTestSegment(Segment segment, Seg profile, String profileID, boolean theValidateChildren) throws ProfileException - Throws:
ProfileException
-
checkForExtraFields
protected void checkForExtraFields(Segment segment, List<Integer> allowedFields, List<HL7Exception> exList) throws 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:
ProfileException
-
testType
public List<HL7Exception> testType(Type type, AbstractComponent<?> profile, String encoded, 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)
-
checkConstantValue
-
checkLength
-
checkDataType
-
testLength
Tests whether the given type falls within a maximum length.- Returns:
- null of OK, an HL7Exception otherwise
-
testUsage
Tests an element against the corresponding usage code. The element is required in its encoded form.- Parameters:
encoded- the pipe-encoded message elementusage- the usage code (e.g. "CE")name- the name of the element (for use in exception messages)
-
testTypeAgainstTable
protected void testTypeAgainstTable(Type type, AbstractComponent<?> profile, String profileID, List<HL7Exception> exList) Tests table values for ID, IS, and CE types. An empty list is returned for all other types or if the table name or number is missing. -
addTableTestResult
protected void addTableTestResult(String profileID, String codeSystem, String value, List<HL7Exception> exList) -
testValueAgainstTable
protected void testValueAgainstTable(String profileID, String codeSystem, String value, List<HL7Exception> exList) -
testField
public List<HL7Exception> testField(Type type, Field profile, boolean escape, String profileID) throws ProfileException, HL7Exception - Throws:
ProfileExceptionHL7Exception
-
doTestField
protected List<HL7Exception> doTestField(Type type, Field profile, boolean escape, String profileID, boolean theValidateChildren) throws ProfileException, HL7Exception - Throws:
ProfileExceptionHL7Exception
-
testComponent
public List<HL7Exception> testComponent(Type type, Component profile, String profileID) throws ProfileException, HL7Exception - Throws:
ProfileExceptionHL7Exception
-
doTestComponent
protected List<HL7Exception> doTestComponent(Type type, Component profile, String profileID, boolean theValidateChildren) throws ProfileException, HL7Exception - Throws:
ProfileExceptionHL7Exception
-
checkExtraComponents
protected void checkExtraComponents(Composite comp, int numInProfile, List<HL7Exception> exList) throws ProfileException Tests for extra components (ie any not defined in the profile)- Throws:
ProfileException
-
main
-