Esempio n. 1
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 ISegment MakeControlMSH(string version, IModelClassFactory factory)
        {
            ISegment msh;

            try
            {
                var dummy =
                    (IMessage)GenericMessage
                    .GetGenericMessageClass(version)
                    .GetConstructor(new Type[] { typeof(IModelClassFactory) })
                    .Invoke(new object[] { factory });

                var constructorParamTypes = new Type[] { typeof(IGroup), typeof(IModelClassFactory) };
                var constructorParamArgs  = new object[] { dummy, factory };
                var c           = factory.GetSegmentClass("MSH", version);
                var constructor = c.GetConstructor(constructorParamTypes);
                msh = (ISegment)constructor.Invoke(constructorParamArgs);
            }
            catch (Exception e)
            {
                throw new HL7Exception(
                          $"Couldn't create MSH for version {version} (does your class path include this version?) ... ",
                          ErrorCode.APPLICATION_INTERNAL_ERROR,
                          e);
            }

            return(msh);
        }
Esempio n. 2
0
        public void GetGenericMessageClass_ValidVersion_ReturnsExpectedGenericMessageType(string version, Type expected)
        {
            // Arrange / Act
            var genericMessageType = GenericMessage.GetGenericMessageClass(version);

            // Assert
            Assert.AreEqual(expected, genericMessageType);
        }
Esempio n. 3
0
        /// <summary>
        /// <para>
        /// 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.
        /// </para>
        /// <para>
        /// 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().
        /// </para>
        /// <para>
        /// 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.
        /// </para>
        /// </summary>
        /// <param name="theName">name of the desired structure in the form XXX_YYY.</param>
        /// <param name="theVersion">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 Type GetMessageClass(string theName, string theVersion, bool isExplicit)
        {
            Type mc = null;

            if (!isExplicit)
            {
                theName = ParserBase.GetMessageStructureForEvent(theName, theVersion);
            }

            mc = FindClass(theName, theVersion, ClassType.Message);
            if (mc == null)
            {
                mc = GenericMessage.GetGenericMessageClass(theVersion);
            }

            return(mc);
        }
Esempio n. 4
0
 public void GetGenericMessageClass_InValidVersion_ThrowsArgumentException()
 {
     // Arrange / Act / Assert
     Assert.Throws <ArgumentException>(
         () => GenericMessage.GetGenericMessageClass("unknown"));
 }