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 "DefaultValidationWithoutTN.java". Description:
010 "A ValidationContext with a default set of rules initially defined except for
011 the TN data type."
012
013 The Initial Developer of the Original Code is University Health Network. Copyright (C)
014 2012. All Rights Reserved.
015
016 Contributor(s): ______________________________________.
017
018 Alternatively, the contents of this file may be used under the terms of the
019 GNU General Public License (the �GPL�), in which case the provisions of the GPL are
020 applicable instead of those above. If you wish to allow use of your version of this
021 file only under the terms of the GPL and not to allow others to use your version
022 of this file under the MPL, indicate your decision by deleting the provisions above
023 and replace them with the notice and other provisions required by the GPL License.
024 If you do not delete the provisions above, a recipient may use your version of
025 this file under either the MPL or the GPL.
026 */
027 package ca.uhn.hl7v2.validation.impl;
028
029 import ca.uhn.hl7v2.validation.PrimitiveTypeRule;
030
031 /**
032 * A <code>ValidationContext</code> with a default set of rules initially
033 * defined. This can be used as-is for a reasonable level of primitive type
034 * validation.
035 *
036 * @author <a href="mailto:bryan.tripp@uhn.on.ca">Bryan Tripp</a>
037 * @author Christian Ohr
038 */
039 @SuppressWarnings("serial")
040 public class DefaultValidationWithoutTN extends ValidationContextImpl {
041
042 public DefaultValidationWithoutTN() {
043 super();
044
045 PrimitiveTypeRule trim = new TrimLeadingWhitespace();
046 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "FT", trim));
047 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "ST", trim));
048 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "TX", trim));
049
050 PrimitiveTypeRule size200 = new SizeRule(200);
051 PrimitiveTypeRule size32000 = new SizeRule(32000);
052 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "FT", size32000));
053 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "ID", size200));
054 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "IS", size200));
055
056 PrimitiveTypeRule nonNegativeInteger = new RegexPrimitiveRule("\\d*", "");
057 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "SI", nonNegativeInteger));
058
059 PrimitiveTypeRule number = new RegexPrimitiveRule("(\\+|\\-)?\\d*\\.?\\d*", "");
060 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "NM", number));
061
062 String datePattern = "(\\d{4}([01]\\d(\\d{2})?)?)?"; // YYYY[MM[DD]]
063 PrimitiveTypeRule date = new RegexPrimitiveRule(datePattern, "Version 2.5 Section 2.A.21");
064 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "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 PrimitiveTypeRule time = new RegexPrimitiveRule(timePattern, "Version 2.5 Section 2.A.75");
069 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "TM", time));
070
071 String datetimePattern // YYYY[MM[DD[HHMM[SS[.S[S[S[S]]]]]]]][+/-ZZZZ]
072 = "(\\d{4}([01]\\d(\\d{2}([012]\\d[0-5]\\d([0-5]\\d(\\.\\d(\\d(\\d(\\d)?)?)?)?)?)?)?)?)?([\\+\\-]\\d{4})?";
073 PrimitiveTypeRule datetime = new RegexPrimitiveRule(datetimePattern, "Version 2.4 Section 2.9.47");
074 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("2.2", "TSComponentOne", datetime));
075 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("2.3", "TSComponentOne", datetime));
076 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("2.3.1", "TSComponentOne", datetime));
077 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("2.4", "TSComponentOne", datetime));
078
079 String datetimePattern25 // YYYY[MM[DD[HH[MM[SS[.S[S[S[S]]]]]]]]][+/-ZZZZ]
080 = "(\\d{4}([01]\\d(\\d{2}([012]\\d([0-5]\\d([0-5]\\d(\\.\\d(\\d(\\d(\\d)?)?)?)?)?)?)?)?)?)?([\\+\\-]\\d{4})?";
081 PrimitiveTypeRule datetime25 = new RegexPrimitiveRule(datetimePattern25, "Version 2.5 Section 2.A.22");
082 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("2.5", "TSComponentOne", datetime25));
083 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("2.5", "DTM", datetime25));
084 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("2.5.1", "TSComponentOne", datetime25));
085 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("2.5.1", "DTM", datetime25));
086 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("2.6", "TSComponentOne", datetime25));
087 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("2.6", "DTM", datetime25));
088
089 // NULLDT shouldn't have a value
090 getPrimitiveRuleBindings().add(new RuleBinding<PrimitiveTypeRule>("*", "NULLDT", new WithdrawnDatatypeRule()));
091 }
092 }