예제 #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);
        }
예제 #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 ISegment MakeControlMSH(String version, IModelClassFactory factory)
        {
            ISegment msh = null;

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

                Type[]          constructorParamTypes = new Type[] { typeof(IGroup), typeof(IModelClassFactory) };
                Object[]        constructorParamArgs  = new Object[] { dummy, factory };
                Type            c           = factory.GetSegmentClass("MSH", version);
                ConstructorInfo constructor = c.GetConstructor(constructorParamTypes);
                msh = (ISegment)constructor.Invoke(constructorParamArgs);
            }
            catch (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);
        }
예제 #3
0
        /// <inheritdoc />
        public virtual string AddNonstandardSegment(string name)
        {
            var version = Message.Version;

            if (version == null)
            {
                throw new HL7Exception("Need message version to add segment by name; message.Version returns null");
            }

            var c = myFactory.GetSegmentClass(name, version) ?? typeof(GenericSegment);

            var index = Names.Length;

            TryToInstantiateStructure(c, name); // may throw exception

            return(Insert(c, false, true, false, index, name));
        }
예제 #4
0
        /// <summary> Expands the group definition to include a segment that is not
        /// defined by HL7 to be part of this group (e.g. an unregistered Z segment).
        /// The new segment is slotted at the end of the group.  Thenceforward if
        /// such a segment is encountered it will be parsed into this location.
        /// If the segment name is unrecognized a GenericSegment is used.  The
        /// segment is defined as repeating and not required.
        /// </summary>
        public virtual System.String addNonstandardSegment(System.String name)
        {
            System.String version = this.Message.Version;
            if (version == null)
            {
                throw new HL7Exception("Need message version to add segment by name; message.getVersion() returns null");
            }
            System.Type c = myFactory.GetSegmentClass(name, version);
            if (c == null)
            {
                c = typeof(GenericSegment);
            }

            int index = this.Names.Length;

            tryToInstantiateStructure(c, name); //may throw exception

            return(insert(c, false, true, index, name));
        }
예제 #5
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 = null;

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

				Type[] constructorParamTypes = new Type[] {typeof (IGroup), typeof (IModelClassFactory)};
				Object[] constructorParamArgs = new Object[] {dummy, factory};
				Type c = factory.GetSegmentClass("MSH", version);
				ConstructorInfo constructor = c.GetConstructor(constructorParamTypes);
				msh = (ISegment) constructor.Invoke(constructorParamArgs);
			}
			catch (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;
		}