Example #1
0
        private static Type GetObx5Type(IPrimitive obx2, ISegment segment, IModelClassFactory factory, ParserOptions parserOptions)
        {
            var type = factory.GetTypeClass(obx2.Value, segment.Message.Version);

            if (type == null)
            {
                if (parserOptions.InvalidObx2Type != null)
                {
                    type = factory.GetTypeClass(parserOptions.InvalidObx2Type, segment.Message.Version);
                }
            }

            return(type);
        }
Example #2
0
        /// <summary>
        /// Sets the data type of field 5 in the given OBX segment to the value of OBX-2.  The argument
        /// is a Segment as opposed to a particular OBX because it is meant to work with any version.
        /// </summary>
        ///
        /// <exception cref="HL7Exception"> Thrown when a HL 7 error condition occurs. </exception>
        ///
        /// <param name="segment">  The segment. </param>
        /// <param name="factory">  The factory. </param>

        public static void fixOBX5(ISegment segment, IModelClassFactory factory)
        {
            try
            {
                //get unqualified class name
                IPrimitive obx2 = (IPrimitive)segment.GetField(2, 0);
                Varies     v    = (Varies)segment.GetField(5, 0);

                if (obx2.Value == null)
                {
                    if (v.Data != null)
                    {
                        if (!(v.Data is IPrimitive) || ((IPrimitive)v.Data).Value != null)
                        {
                            throw new HL7Exception(
                                      "OBX-5 is valued, but OBX-2 is not.  A datatype for OBX-5 must be specified using OBX-2.",
                                      HL7Exception.REQUIRED_FIELD_MISSING);
                        }
                    }
                }
                else
                {
                    //set class
                    System.Type c = factory.GetTypeClass(obx2.Value, segment.Message.Version);
                    //                Class c = NHapi.Base.Parser.ParserBase.findClass(obx2.getValue(),
                    //                                                segment.getMessage().getVersion(),
                    //                                                "datatype");
                    v.Data =
                        (IType)c.GetConstructor(new[] { typeof(IMessage) }).Invoke(new System.Object[] { v.Message });
                }
            }
            catch (HL7Exception e)
            {
                throw e;
            }
            catch (System.Exception e)
            {
                throw new HL7Exception(
                          e.GetType().FullName + " trying to set data type of OBX-5",
                          HL7Exception.APPLICATION_INTERNAL_ERROR,
                          e);
            }
        }
Example #3
0
        /// <summary> Sets the data type of field 5 in the given OBX segment to the value of OBX-2.  The argument
        /// is a Segment as opposed to a particular OBX because it is meant to work with any version.
        /// </summary>
        public static void fixOBX5(ISegment segment, IModelClassFactory factory)
        {
            try
            {
                //get unqualified class name
                IPrimitive obx2 = (IPrimitive)segment.GetField(2, 0);

                foreach (IType repetition in segment.GetField(5))
                {
                    Varies v = (Varies)repetition;

                    if (obx2.Value == null)
                    {
                        if (v.Data != null)
                        {
                            if (!(v.Data is IPrimitive) || ((IPrimitive)v.Data).Value != null)
                            {
                                throw new HL7Exception(
                                          "OBX-5 is valued, but OBX-2 is not.  A datatype for OBX-5 must be specified using OBX-2.",
                                          ErrorCode.REQUIRED_FIELD_MISSING);
                            }
                        }
                    }
                    else
                    {
                        UseDTInsteadOfDTMForEarlierVersionsOfHL7(segment, obx2);

                        Type c = factory.GetTypeClass(obx2.Value, segment.Message.Version);
                        v.Data = (IType)c.GetConstructor(new [] { typeof(IMessage), typeof(String) }).Invoke(new Object[] { v.Message, v.Description });
                    }
                }
            }
            catch (HL7Exception e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new HL7Exception(e.GetType().FullName + " trying to set data type of OBX-5",
                                       ErrorCode.APPLICATION_INTERNAL_ERROR, e);
            }
        }
Example #4
0
		/// <summary> Sets the data type of field 5 in the given OBX segment to the value of OBX-2.  The argument 
		/// is a Segment as opposed to a particular OBX because it is meant to work with any version.  
		/// </summary>
		public static void fixOBX5(ISegment segment, IModelClassFactory factory)
		{
			try
			{
				//get unqualified class name
				IPrimitive obx2 = (IPrimitive) segment.GetField(2, 0);

				foreach (IType repetition in segment.GetField(5))
				{
					Varies v = (Varies) repetition;

					if (obx2.Value == null)
					{
						if (v.Data != null)
						{
							if (!(v.Data is IPrimitive) || ((IPrimitive) v.Data).Value != null)
							{
								throw new HL7Exception(
									"OBX-5 is valued, but OBX-2 is not.  A datatype for OBX-5 must be specified using OBX-2.",
									HL7Exception.REQUIRED_FIELD_MISSING);
							}
						}
					}
					else
					{
						Type c = factory.GetTypeClass(obx2.Value, segment.Message.Version);
						v.Data = (IType) c.GetConstructor(new [] {typeof (IMessage), typeof(String)}).Invoke(new Object[] {v.Message, v.Description});
					}
				}
			}
			catch (HL7Exception e)
			{
				throw e;
			}
			catch (Exception e)
			{
				throw new HL7Exception(e.GetType().FullName + " trying to set data type of OBX-5",
					HL7Exception.APPLICATION_INTERNAL_ERROR, e);
			}
		}
Example #5
0
        /// <summary> Sets the data type of field 5 in the given OBX segment to the value of OBX-2.  The argument
        /// is a Segment as opposed to a particular OBX because it is meant to work with any version.
        /// </summary>
        public static void fixOBX5(ISegment segment, IModelClassFactory factory)
        {
            try
            {
                //get unqualified class name
                IPrimitive obx2 = (IPrimitive)segment.GetField(2, 0);

                foreach (IType repetition in segment.GetField(5))
                {
                    Varies v = (Varies)repetition;

                    if (obx2.Value == null)
                    {
                        if (v.Data != null)
                        {
                            if (!(v.Data is IPrimitive) || ((IPrimitive)v.Data).Value != null)
                            {
                                throw new HL7Exception(
                                          "OBX-5 is valued, but OBX-2 is not.  A datatype for OBX-5 must be specified using OBX-2.",
                                          ErrorCode.REQUIRED_FIELD_MISSING);
                            }
                        }
                    }
                    else
                    {
                        UseDTInsteadOfDTMForEarlierVersionsOfHL7(segment, obx2);

                        Type type = factory.GetTypeClass(obx2.Value, segment.Message.Version);

                        if (type == null)
                        {
                            var obx1         = (IPrimitive)segment.GetField(1, 0);
                            var hl7Exception = new HL7Exception(
                                $"'{obx2.Value}' in record {obx1.Value} is invalid for version {segment.Message.Version}");

                            hl7Exception.SegmentName   = ((AbstractSegment)segment).GetStructureName();
                            hl7Exception.FieldPosition = 2;

                            throw hl7Exception;
                        }

                        try
                        {
                            var constructor = type.GetConstructor(new[] { typeof(IMessage), typeof(String) });
                            v.Data = (IType)constructor.Invoke(new Object[] { v.Message, v.Description });
                        }
                        catch (NullReferenceException _)
                        {
                            var constructor = type.GetConstructor(new[] { typeof(IMessage) });
                            v.Data = (IType)constructor.Invoke(new Object[] { v.Message });
                        }
                    }
                }
            }
            catch (HL7Exception e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new HL7Exception(
                          $"{e.GetType().FullName} trying to set data type of OBX-5",
                          ErrorCode.APPLICATION_INTERNAL_ERROR, e);
            }
        }
Example #6
0
        /// <summary> Sets the data type of field 5 in the given OBX segment to the value of OBX-2.  The argument 
        /// is a Segment as opposed to a particular OBX because it is meant to work with any version.  
        /// </summary>
        public static void fixOBX5(ISegment segment, IModelClassFactory factory)
        {
            try
            {
                //get unqualified class name
                IPrimitive obx2 = (IPrimitive)segment.GetField(2, 0);
                Varies v = (Varies)segment.GetField(5, 0);

                if (obx2.Value == null)
                {
                    if (v.Data != null)
                    {
                        if (!(v.Data is IPrimitive) || ((IPrimitive)v.Data).Value != null)
                        {
                            throw new HL7Exception("OBX-5 is valued, but OBX-2 is not.  A datatype for OBX-5 must be specified using OBX-2.", HL7Exception.REQUIRED_FIELD_MISSING);
                        }
                    }
                }
                else
                {
                    //set class
                    System.Type c = factory.GetTypeClass(obx2.Value, segment.Message.Version);
                    //                Class c = NHapi.Base.Parser.ParserBase.findClass(obx2.getValue(),
                    //                                                segment.getMessage().getVersion(),
                    //                                                "datatype");
                    v.Data = (IType)c.GetConstructor(new System.Type[] { typeof(IMessage) }).Invoke(new System.Object[] { v.Message });
                }
            }
            catch (HL7Exception e)
            {
                throw e;
            }
            catch (System.Exception e)
            {
                throw new HL7Exception(e.GetType().FullName + " trying to set data type of OBX-5", HL7Exception.APPLICATION_INTERNAL_ERROR, e);
            }
        }