Hi Nicolas,

Thanks very much for offering the patch. I see you have contacted
James as well. He is in charge of the project and is the right person
to follow up with.

I should probably take my ID off the administrators' list, as I
haven't been involved in the project for several years.

All the best,
Bryan

On Mon, Jul 4, 2011 at 7:51 AM, Nicolas Lefebvre
<nicolas.lefeb...@inria.fr> wrote:
> Hi Brian,
>
> I have some questions about the Hapi Validator Service. As it is written in
> the Hapi documentation (http://hl7api.sourceforge.net/conformance.html in
> the Message Validator section of that page), before the call to the
> DefaultValidation.validate(Message msg, Profile profile) method, one needs
> to parse the message (msg) with, for example the PipeParser.
>
> We have a problem when we try to parse an HL7 message for which the
> structure is different from the message structure pre-loaded with Hapi. This
> is typically the case for messages that contains segment with a data type
> "varies". A good example concerns the case of the message  QBP_Q11. Within
> IHE we have specified the content of the "varies" part of that message
> structure.
> We have generated the class corresponding to the IHE definition of the
> QBP_Q11 message using the Conformance Class Generator V2 (as specified in
> the page mentioned above). When we tried to use that class for the
> validation of QBP_Q11 messages, we do not know how to specify which of the 2
> QBP_Q11 class to use.
> In order to resolve this problem, I have created my own parser, that parses
> HL7 messages specifying the package name of the conformance class to be used
> for the parsing.
> I tested this patch and using it we are now able to validate messages that
> are redefined by a project (IHE or others).
> I'd like to contribute this back to the Hapi project, so that others could
> benefit from it. It indeed will allow users of hapi to parse messages that
> are redefined or different from the structure defined in hapi.
> Please let me know how to best contribute. Here is the patch. If you need
> anything else, please do not hesitate to contact me.
> Best regards
> Nicolas
>
>
> To specify the package name, some changes have been done in the Hapi Base
> Library (for the Hapi.1.2-beta1 version) in the "ca.uhn.hl7v2.parser"
> package :
>
> - Add 2 new methods in the DefaultModelClassFactory.java :
>
> public Class<? extends Message> getMessageClassInASpecificPackage(String
> theName, String theVersion, boolean isExplicit, String packageName) throws
> HL7Exception {
>         Class<? extends Message> mc = null;
>         if (!isExplicit) {
>             theName = Parser.getMessageStructureForEvent(theName,
> theVersion);
>         }
>         mc = (Class<? extends Message>) findClassInASpecificPackage(theName,
> theVersion, "message", packageName);
>         if (mc == null)
>             mc = GenericMessage.getGenericMessageClass(theVersion);
>         return mc;
>     }
>
>
> private static Class<?> findClassInASpecificPackage(String name, String
> version, String type, String packageName) throws HL7Exception {
>
>      if (packageName == null || packageName.isEmpty())
>      return findClass(name, version, type);
>
>       Class<?> compClass = null;
>       String classNameToTry = packageName + "." + name;
>
>         try {
> compClass = Class.forName(classNameToTry);
> } catch (ClassNotFoundException e) {
> // TODO Auto-generated catch block
> e.printStackTrace();
> return findClass(name, version, type);
> }
>
>         return compClass;
>     }
>
>
>
> - Add 3 new methods in the Parser.java :
>
> public Message parseForSpecificPackage(String message, String packageName)
> throws HL7Exception, EncodingNotSupportedException {
>         String encoding = getEncoding(message);
>         if (!supportsEncoding(encoding)) {
>             throw new EncodingNotSupportedException(
>                     "Can't parse message beginning " + message.substring(0,
> Math.min(message.length(), 50)));
>         }
>
>         String version = getVersion(message);
>         if (!validVersion(version)) {
>             throw new HL7Exception("Can't process message of version '" +
> version + "' - version not recognized",
>                     HL7Exception.UNSUPPORTED_VERSION_ID);
>         }
>
>         myValidator.validate(message, encoding.equals("XML"), version);
>
>         Message result = doParseForSpecificPackage(message, version,
> packageName);
>
>         myValidator.validate(result);
>
>         result.setParser(this);
>
>         return result;
>     }
>
>
> public Message doParseForSpecificPackage(String message, String version,
> String packageName) throws HL7Exception, EncodingNotSupportedException {
>
>         Message m = null;
>         return m;
>     }
>
>
> protected Message instantiateMessageInASpecificPackage(String theName,
> String theVersion, boolean isExplicit, String packageName) throws
> HL7Exception {
>         Message result = null;
>
>         try {
>          DefaultModelClassFactory localIHEFactory = new
> DefaultModelClassFactory();
>             Class messageClass = localIHEFactory
> .getMessageClassInASpecificPackage(theName, theVersion, isExplicit,
> packageName);
>             if (messageClass == null)
>                 throw new ClassNotFoundException("Can't find message class
> in current package list: "
>                     + theName);
>             log.info("Instantiating msg of class " +
> messageClass.getName());
>             Constructor constructor = messageClass.getConstructor(new
> Class[]{ModelClassFactory.class});
>             result = (Message) constructor.newInstance(new
> Object[]{myFactory});
>         } catch (Exception e) {
>             throw new HL7Exception("Couldn't create Message object of type "
> + theName,
>                 HL7Exception.UNSUPPORTED_MESSAGE_TYPE, e);
>         }
>
>         result.setValidationContext(myContext);
>
>         return result;
>     }
>
>
> - Add 1 new method in the PipeParser.java :
>
>
> @Override
>     public Message doParseForSpecificPackage(String message, String version,
> String packageName) throws HL7Exception, EncodingNotSupportedException {
>
>         // try to instantiate a message object of the right class
>         MessageStructure structure = getStructure(message);
>         Message m =
> instantiateMessageInASpecificPackage(structure.messageStructure, version,
> structure.explicitlyDefined, packageName);
>
>         parse(m, message);
>
>         return m;
>     }
>
>
>
>
>
> Nicolas Lefebvre
>
> Engineer in the IHE-Development Project
>
> INRIA Rennes
> Campus Universitaire de Beaulieu
> F-35042 Rennes Cedex FRANCE
>
> Cell : (+33)6 72 05 40 18
>
> Phone : (+33)2 99 84 74 56 / Fax: (+33)2 99 84 71 71
> Mail : nicolas.lefeb...@inria.com
>
>
>
>

------------------------------------------------------------------------------
All of the data generated in your IT infrastructure is seriously valuable.
Why? It contains a definitive record of application performance, security 
threats, fraudulent activity, and more. Splunk takes this data and makes 
sense of it. IT sense. And common sense.
http://p.sf.net/sfu/splunk-d2d-c2
_______________________________________________
Hl7api-devel mailing list
Hl7api-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/hl7api-devel

Reply via email to