Exemplo n.º 1
0
 /// <summary> <p>Attempts to return the message class corresponding to the given name, by
 /// searching through default and user-defined (as per packageList()) packages.
 /// Returns GenericMessage if the class is not found.</p>
 /// <p>It is important to note that there can only be one implementation of a particular message
 /// structure (i.e. one class with the message structure name, regardless of its package) among
 /// the packages defined as per the <code>packageList()</code> method.  If there are duplicates
 /// (e.g. two ADT_A01 classes) the first one in the search order will always be used.  However,
 /// this restriction only applies to message classes, not (normally) segment classes, etc.  This is because
 /// classes representing parts of a message are referenced explicitly in the code for the message
 /// class, rather than being looked up (using findMessageClass() ) based on the String value of MSH-9.
 /// The exception is that Segments may have to be looked up by name when they appear
 /// in unexpected locations (e.g. by local extension) -- see findSegmentClass().</p>
 /// <p>Note: the current implementation will be slow if there are multiple user-
 /// defined packages, because the JVM will try to load a number of non-existent
 /// classes every parse.  This should be changed so that specific classes, rather
 /// than packages, are registered by name.</p>
 ///
 /// </summary>
 /// <param name="name">name of the desired structure in the form XXX_YYY
 /// </param>
 /// <param name="version">HL7 version (e.g. "2.3")
 /// </param>
 /// <param name="isExplicit">true if the structure was specified explicitly in MSH-9-3, false if it
 /// was inferred from MSH-9-1 and MSH-9-2.  If false, a lookup may be performed to find
 /// an alternate structure corresponding to that message type and event.
 /// </param>
 /// <returns> corresponding message subclass if found; GenericMessage otherwise
 /// </returns>
 public virtual System.Type getMessageClass(System.String theName, System.String theVersion, bool isExplicit)
 {
     System.Type mc = null;
     if (!isExplicit)
     {
         theName = Parser.getMessageStructureForEvent(theName, theVersion);
     }
     mc = findClass(theName, theVersion, "message");
     if (mc == null)
     {
         mc = GenericMessage.getGenericMessageClass(theVersion);
     }
     return(mc);
 }
Exemplo n.º 2
0
        /// <summary> Creates a version-specific MSH object and returns it as a version-independent
        /// MSH interface.
        /// throws HL7Exception if there is a problem, e.g. invalid version, code not available
        /// for given version.
        /// </summary>
        public static Segment makeControlMSH(System.String version, ModelClassFactory factory)
        {
            Segment msh = null;

            try
            {
                Message dummy = (Message)GenericMessage.getGenericMessageClass(version).GetConstructor(new System.Type[] { typeof(ModelClassFactory) }).Invoke(new System.Object[] { factory });

                System.Type[]   constructorParamTypes = new System.Type[] { typeof(Group), typeof(ModelClassFactory) };
                System.Object[] constructorParamArgs  = new System.Object[] { dummy, factory };
                System.Type     c = factory.getSegmentClass("MSH", version);
                System.Reflection.ConstructorInfo constructor = c.GetConstructor(constructorParamTypes);
                msh = (Segment)constructor.Invoke(constructorParamArgs);
            }
            catch (System.Exception e)
            {
                throw new HL7Exception("Couldn't create MSH for version " + version + " (does your classpath include this version?) ... ", HL7Exception.APPLICATION_INTERNAL_ERROR, e);
            }
            return(msh);
        }