Craig,

This is the code we use when creating a hapi context. Note that we
typically lock in a structures version via the CanonicalModelClasFactory

        System.setProperty("ca.uhn.hl7v2.model.varies.default_obx2_type",
"ST");
        System.setProperty("ca.uhn.hl7v2.model.varies.invalid_obx2_type",
"ST");
        HapiContext hapiContext = new DefaultHapiContext();
        hapiContext.setModelClassFactory(new
CanonicalModelClassFactory("2.4"));
        hapiContext.setValidationRuleBuilder(new NoValidationBuilder());
        ParserConfiguration parserConfig = new ParserConfiguration();
        parserConfig.setEscaping(new EscapingQhImpl());
        hapiContext.setParserConfiguration(parserConfig);

As you point out we ignore all validation so we avoid issues with Phone
numbers and other formats but we have worked with that limitation for
several years.

-Mike


On 20 July 2017 at 00:51, McClendon, Craig <craig.mcclen...@accenture.com>
wrote:

> Thanks for the reply Mike.
>
> Yes in this case my goal is to have generic-ish code that can handle
> multiple v2 versions. So I’m “up-converting” to v26 using the
> CanonicalModelClassFactory. So far this works well except in cases where
> items have been withdrawn in v26 which fail validation.
>
>
>
> I tried to play around with getting the RuleBindings from the context to
> remove this particular rule, but was unable to find this one, and am not
> familiar enough with the underlying implementation to know where to find
> it.
>
> i.e., I tried finding this rule with these calls but no luck:
>
> List<RuleBinding<PrimitiveTypeRule>> rules = ((ValidationContextImpl)
> context.getValidationContext()).getPrimitiveRuleBindings();
>
> List<RuleBinding<MessageRule>> rules2 = ((ValidationContextImpl)
> context.getValidationContext()).getMessageRuleBindings();
>
> List<RuleBinding<EncodingRule>> rules3 = ((ValidationContextImpl)
> context.getValidationContext()).getEncodingRuleBindings();
>
>
>
>
>
> But perhaps what I could do is use the DefaultHapiContext to parse the
> message to achieve version-specific validation, then parse it again with a
> context using CanonicalModelClassFactory with validation disabled to get
> the data “de-serialized” and work with. It will obviously not be efficient,
> but at least it’s a work-around.
>
>
>
> -Craig
>
>
>
> *From:* Mike Mills
>
> *Sent:* Tuesday, July 18, 2017 9:21 PM
> *To:* McClendon, Craig <craig.mcclen...@accenture.com>
> *Subject:* [External] Re: [HAPI-devel] backward compatible message
> validation with CanonicalModelClassFactory
>
>
>
> Craig,
>
>
>
> If you are not using custom message structures then you can simply use the
> DefaultHapiContext and PipeParser to parse a message.
>
>
>
> The default PipeParser will use MSH-12 to locate the correct message class.
>
>
>
> You would need to have the HapiStructures 2.3 and 2.6 on your classpath,
> but this code should parse your message and return a class of the
> appropriate structure.
>
>
>
> The only issues is if you want to have code that processes both 2.3 and
> 2.6 messages in the same way.
>
>
>
> In those cases you need to create your own custom structure that can deal
> with your case.
>
>
>
> If you stick to HapiStructures then this code should process your message:
>
>
>
> Message msg = new DefaultHapiContext().getPipeParser().parse( .... your
> 2.3 message string here ... );
>
>
>
> The underlying java type of the msg variable will change depending on the
> value of MSH-12.
>
>
>
> -Mike
>
>
>
> ------------------------------
>
> This message is for the designated recipient only and may contain
> privileged, proprietary, or otherwise confidential information. If you have
> received it in error, please notify the sender immediately and delete the
> original. Any other use of the e-mail by you is prohibited. Where allowed
> by local law, electronic communications with Accenture and its affiliates,
> including e-mail and instant messaging (including content), may be scanned
> by our systems for the purposes of information security and assessment of
> internal compliance with Accenture policy.
> ____________________________________________________________
> __________________________
>
> www.accenture.com
>
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to