I had a look to the source code and did exactly what you say, it works now !
...next time I'll browse the source before posting !!

Regards

FJ

Marco Montel a écrit :
Frederic JECKER ha scritto:
Hi,

It seems that hapi is validating phone numbers using US/Canada phone 
number format ((\d{1,2} 
)?(\(\d{3}\))?\d{3}-\d{4}(X\d{1,5})?(B\d{1,5})?(C.*)?)
Is there a way to disable/change this validation ?
  
You should implement your own ValidationContext and set it to the parser

PipeParser parser = new PipeParser();
parser.setValidationContext(myValidationContext);


For example you can rewrite the default one provided by HAPI, and remove the telephoneNumber Rule:

public class MyValidationContext extends ValidationContextImpl {
   
    public MyValidationContext () {
        Rule trim = new TrimLeadingWhitespace();
        getPrimitiveRuleBindings().add(new RuleBinding("*", "FT", trim));
        getPrimitiveRuleBindings().add(new RuleBinding("*", "ST", trim));
        getPrimitiveRuleBindings().add(new RuleBinding("*", "TX", trim));

        Rule size200 = new SizeRule(200);
        Rule size32000 = new SizeRule(32000);
        getPrimitiveRuleBindings().add(new RuleBinding("*", "FT", size32000));
        getPrimitiveRuleBindings().add(new RuleBinding("*", "ID", size200));
        getPrimitiveRuleBindings().add(new RuleBinding("*", "IS", size200));

        Rule nonNegativeInteger = new RegexPrimitiveRule("\\d*", "");
        getPrimitiveRuleBindings().add(
                new RuleBinding("*", "SI", nonNegativeInteger));

        Rule number = new RegexPrimitiveRule("(\\+|\\-)?\\d*\\.?\\d*", "");
        getPrimitiveRuleBindings().add(new RuleBinding("*", "NM", number));

        /*
         Rule telephoneNumber
         = new RegexPrimitiveRule("(\\d{1,2} )?(\\(\\d{3}\\))?\\d{3}-\\d{4}(X\\d{1,5})?(B\\d{1,5})?(C.*)?",
         "Version 2.4 Section 2.9.45");
         getPrimitiveRuleBindings().add(new RuleBinding("*", "TN", telephoneNumber));       
         */

        getPrimitiveRuleBindings().add(new RuleBinding("*", "TN", size200));

        String datePattern = "(\\d{4}([01]\\d(\\d{2})?)?)?"; //YYYY[MM[DD]]
        Rule date = new RegexPrimitiveRule(datePattern,
                "Version 2.5 Section 2.16.24");
        getPrimitiveRuleBindings().add(new RuleBinding("*", "DT", date));

        String timePattern //HH[MM[SS[.S[S[S[S]]]]]][+/-ZZZZ]
        = "([012]\\d([0-5]\\d([0-5]\\d(\\.\\d(\\d(\\d(\\d)?)?)?)?)?)?)?([\\+\\-]\\d{4})?";
        Rule time = new RegexPrimitiveRule(timePattern,
                "Version 2.5 Section 2.16.79");
        getPrimitiveRuleBindings().add(new RuleBinding("*", "TM", time));

        String datetimePattern = "(\\d{4}([01]\\d(\\d{2}([012]\\d([0-5]\\d([0-5]\\d(\\.\\d(\\d(\\d(\\d)?)?)?)?)?)?)?)?)?)?([\\+\\-]\\d{4})?";
        Rule datetime = new RegexPrimitiveRule(datetimePattern,
                "Version 2.5 Section 2.16.25");
        getPrimitiveRuleBindings().add(
                new RuleBinding("*", "TSComponentOne", datetime));
        getPrimitiveRuleBindings().add(new RuleBinding("*", "DTM", datetime));

    }
}






-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Hl7api-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to