コード例 #1
0
ファイル: Varies.cs プロジェクト: erdemsarigh/nhapi
        /// <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);
            }
        }
コード例 #2
0
ファイル: Varies.cs プロジェクト: tristanwilson111/nHapi
        /// <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);
            }
        }
コード例 #3
0
ファイル: OBX.cs プロジェクト: snosrap/nhapi
 ///<summary>
 /// Returns all repetitions of Observation Value (OBX-5).
 ///</summary>
 public Varies[] GetObservationValue()
 {
     Varies[] ret = null;
     try {
     IType[] t = this.GetField(5);
     ret = new Varies[t.Length];
     for (int i = 0; i < ret.Length; i++) {
     ret[i] = (Varies)t[i];
     }
     } catch (HL7Exception he) {
     HapiLogFactory.GetHapiLog(this.GetType()).Error("Unexpected problem obtaining field value.  This is a bug.", he);
     throw new System.Exception("An unexpected error ocurred", he);
     } catch (System.Exception cce) {
     HapiLogFactory.GetHapiLog(GetType()).Error("Unexpected problem obtaining field value.  This is a bug.", cce);
     throw new System.Exception("An unexpected error ocurred", cce);
       }
      return ret;
 }
コード例 #4
0
ファイル: Varies.cs プロジェクト: erichwu/nHapi
        /// <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);
            }
        }
コード例 #5
0
ファイル: XMLParser.cs プロジェクト: liddictm/nHapi
		/// <summary> Encodes a Varies type by extracting it's data field and encoding that.  Returns true 
		/// if the data field (or one of its components) contains a value.  
		/// </summary>
		private bool EncodeVaries(Varies datatypeObject, XmlElement datatypeElement)
		{
			bool hasData = false;
			if (datatypeObject.Data != null)
			{
				hasData = Encode(datatypeObject.Data, datatypeElement);
			}
			return hasData;
		}
コード例 #6
0
ファイル: XMLParser.cs プロジェクト: liddictm/nHapi
		/// <summary> Parses an XML element into a Varies by determining whether the element is primitive or 
		/// composite, calling setData() on the Varies with a new generic primitive or composite as appropriate, 
		/// and then calling parse again with the new Type object.  
		/// </summary>
		private void ParseVaries(Varies datatypeObject, XmlElement datatypeElement)
		{
			//figure out what data type it holds 
			//short nodeType = datatypeElement.getFirstChild().getNodeType();        
			if (!HasChildElement(datatypeElement))
			{
				//it's a primitive 
				datatypeObject.Data = new GenericPrimitive(datatypeObject.Message);
			}
			else
			{
				//it's a composite ... almost know what type, except that we don't have the version here 
				datatypeObject.Data = new GenericComposite(datatypeObject.Message);
			}
			Parse(datatypeObject.Data, datatypeElement);
		}
コード例 #7
0
ファイル: MainForm.cs プロジェクト: dgrinberg/HL7-Snoop
 /// <summary>
 /// Processes the varies.
 /// "Varies" are the data in the OBX segment, the sending application can set the type hence generically the OBX 
 /// value field is a variant type. 
 /// The "Varies" data parameter contains the data in type IType (hence being passed back to process field).
 /// </summary>
 /// <param name="varies">The varies.</param>
 /// <param name="fieldDescription">The field description.</param>
 /// <param name="fieldCount">The field count.</param>
 /// <param name="parentNode">The parent node.</param>
 private void ProcessVaries(Varies varies, string fieldDescription, string fieldCount, FieldGroup parentNode)
 {
     this.ProcessField(varies.Data, fieldDescription, fieldCount, parentNode);
 }