001 /** 002 The contents of this file are subject to the Mozilla Public License Version 1.1 003 (the "License"); you may not use this file except in compliance with the License. 004 You may obtain a copy of the License at http://www.mozilla.org/MPL/ 005 Software distributed under the License is distributed on an "AS IS" basis, 006 WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the 007 specific language governing rights and limitations under the License. 008 009 The Original Code is "Defaultalidation.java". Description: 010 "A ValidationContext with a default set of rules initially defined." 011 012 The Initial Developer of the Original Code is University Health Network. Copyright (C) 013 2004. All Rights Reserved. 014 015 Contributor(s): ______________________________________. 016 017 Alternatively, the contents of this file may be used under the terms of the 018 GNU General Public License (the ???GPL???), in which case the provisions of the GPL are 019 applicable instead of those above. If you wish to allow use of your version of this 020 file only under the terms of the GPL and not to allow others to use your version 021 of this file under the MPL, indicate your decision by deleting the provisions above 022 and replace them with the notice and other provisions required by the GPL License. 023 If you do not delete the provisions above, a recipient may use your version of 024 this file under either the MPL or the GPL. 025 */ 026 package ca.uhn.hl7v2.validation.impl; 027 028 import ca.uhn.hl7v2.validation.Rule; 029 030 031 /** 032 * A <code>ValidationContext</code> with a default set of rules initially defined. 033 * This can be used as-is for a reasonable level of primitive type validation. 034 * 035 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a> 036 * @version $Revision: 1.2 $ updated on $Date: 2009/03/26 00:39:49 $ by $Author: jamesagnew $ 037 */ 038 public class DefaultValidation extends ValidationContextImpl { 039 public DefaultValidation() { 040 Rule trim = new TrimLeadingWhitespace(); 041 getPrimitiveRuleBindings().add(new RuleBinding("*", "FT", trim)); 042 getPrimitiveRuleBindings().add(new RuleBinding("*", "ST", trim)); 043 getPrimitiveRuleBindings().add(new RuleBinding("*", "TX", trim)); 044 045 Rule size200 = new SizeRule(200); 046 Rule size32000 = new SizeRule(32000); 047 getPrimitiveRuleBindings().add(new RuleBinding("*", "FT", size32000)); 048 getPrimitiveRuleBindings().add(new RuleBinding("*", "ID", size200)); 049 getPrimitiveRuleBindings().add(new RuleBinding("*", "IS", size200)); 050 051 Rule nonNegativeInteger = new RegexPrimitiveRule("\\d*", ""); 052 getPrimitiveRuleBindings().add(new RuleBinding("*", "SI", nonNegativeInteger)); 053 054 Rule number = new RegexPrimitiveRule("(\\+|\\-)?\\d*\\.?\\d*", ""); 055 getPrimitiveRuleBindings().add(new RuleBinding("*", "NM", number)); 056 057 Rule telephoneNumber 058 = new RegexPrimitiveRule("(\\d{1,2} )?(\\(\\d{3}\\))?\\d{3}-\\d{4}(X\\d{1,5})?(B\\d{1,5})?(C.*)?", 059 "Version 2.4 Section 2.9.45"); 060 getPrimitiveRuleBindings().add(new RuleBinding("*", "TN", telephoneNumber)); 061 062 String datePattern = "(\\d{4}([01]\\d(\\d{2})?)?)?"; //YYYY[MM[DD]] 063 Rule date = new RegexPrimitiveRule(datePattern, "Version 2.5 Section 2.16.24"); 064 getPrimitiveRuleBindings().add(new RuleBinding("*", "DT", date)); 065 066 String timePattern //HH[MM[SS[.S[S[S[S]]]]]][+/-ZZZZ] 067 = "([012]\\d([0-5]\\d([0-5]\\d(\\.\\d(\\d(\\d(\\d)?)?)?)?)?)?)?([\\+\\-]\\d{4})?"; 068 Rule time = new RegexPrimitiveRule(timePattern, "Version 2.5 Section 2.16.79"); 069 getPrimitiveRuleBindings().add(new RuleBinding("*", "TM", time)); 070 071 String datetimePattern 072 = "(\\d{4}([01]\\d(\\d{2}([012]\\d([0-5]\\d([0-5]\\d(\\.\\d(\\d(\\d(\\d)?)?)?)?)?)?)?)?)?)?([\\+\\-]\\d{4})?"; 073 Rule datetime = new RegexPrimitiveRule(datetimePattern, "Version 2.5 Section 2.16.25"); 074 getPrimitiveRuleBindings().add(new RuleBinding("*", "TSComponentOne", datetime)); 075 getPrimitiveRuleBindings().add(new RuleBinding("*", "DTM", datetime)); 076 077 // NULLDT shouldn't have a value 078 getPrimitiveRuleBindings().add(new RuleBinding("*", "NULLDT", new SizeRule(0))); 079 } 080 }