示例#1
0
 /// <summary> Checks a segment against a list of allowed fields
 /// (ie those mentioned in the profile with usage other than X).  Returns
 /// a list of exceptions representing field that appear
 /// but are not supposed to.
 /// </summary>
 /// <param name="allowedFields">an array of Integers containing field #s of allowed fields
 /// </param>
 private NuGenHL7Exception[] checkForExtraFields(Segment segment, System.Collections.ArrayList allowedFields)
 {
     System.Collections.ArrayList exList = new System.Collections.ArrayList();
     for (int i = 1; i <= segment.numFields(); i++)
     {
         if (!allowedFields.Contains((System.Int32)i))
         {
             try
             {
                 Genetibase.NuGenHL7.model.Type[] reps = segment.getField(i);
                 for (int j = 0; j < reps.Length; j++)
                 {
                     if (hasContent(reps[j]))
                     {
                         NuGenHL7Exception e = new NuGenXElementPresentException("Field " + i + " in " + segment.getName() + " appears in the message but not in the profile");
                         exList.Add(e);
                     }
                 }
             }
             catch (NuGenHL7Exception he)
             {
                 throw new NuGenProfileException("Problem testing against profile", he);
             }
         }
     }
     return(this.toArray(exList));
 }
示例#2
0
 /// <summary> Checks a group's children against a list of allowed structures for the group
 /// (ie those mentioned in the profile with usage other than X).  Returns
 /// a list of exceptions representing structures that appear in the message
 /// but are not supposed to.
 /// </summary>
 private NuGenHL7Exception[] checkForExtraStructures(Group group, System.Collections.ArrayList allowedStructures)
 {
     System.Collections.ArrayList exList = new System.Collections.ArrayList();
     System.String[] childNames          = group.Names;
     for (int i = 0; i < childNames.Length; i++)
     {
         if (!allowedStructures.Contains(childNames[i]))
         {
             try
             {
                 Structure[] reps = group.getAll(childNames[i]);
                 for (int j = 0; j < reps.Length; j++)
                 {
                     if (hasContent(reps[j]))
                     {
                         NuGenHL7Exception e = new NuGenXElementPresentException("The structure " + childNames[i] + " appears in the message but not in the profile");
                         exList.Add(e);
                     }
                 }
             }
             catch (NuGenHL7Exception he)
             {
                 throw new NuGenProfileException("Problem checking profile", he);
             }
         }
     }
     return(toArray(exList));
 }
示例#3
0
        /// <summary> Tests an element against the corresponding usage code.  The element
        /// is required in its encoded form.
        /// </summary>
        /// <param name="encoded">the pipe-encoded message element
        /// </param>
        /// <param name="usage">the usage code (e.g. "CE")
        /// </param>
        /// <param name="name">the name of the element (for use in exception messages)
        /// </param>
        /// <returns>s null if there is no problem, an HL7Exception otherwise
        /// </returns>
        private NuGenHL7Exception testUsage(System.String encoded, System.String usage, System.String name)
        {
            NuGenHL7Exception e = null;

            if (usage.ToUpper().Equals("R".ToUpper()))
            {
                if (encoded.Length == 0)
                {
                    e = new NuGenProfileNotFollowedException("Required element " + name + " is missing");
                }
            }
            else if (usage.ToUpper().Equals("RE".ToUpper()))
            {
                //can't test anything
            }
            else if (usage.ToUpper().Equals("O".ToUpper()))
            {
                //can't test anything
            }
            else if (usage.ToUpper().Equals("C".ToUpper()))
            {
                //can't test anything yet -- wait for condition syntax in v2.6
            }
            else if (usage.ToUpper().Equals("CE".ToUpper()))
            {
                //can't test anything
            }
            else if (usage.ToUpper().Equals("X".ToUpper()))
            {
                if (encoded.Length > 0)
                {
                    e = new NuGenXElementPresentException("Element " + name + " is present but specified as not used (X)");
                }
            }
            else if (usage.ToUpper().Equals("B".ToUpper()))
            {
                //can't test anything
            }
            return(e);
        }
		/// <summary> Tests an element against the corresponding usage code.  The element 
		/// is required in its encoded form.  
		/// </summary>
		/// <param name="encoded">the pipe-encoded message element 
		/// </param>
		/// <param name="usage">the usage code (e.g. "CE")
		/// </param>
		/// <param name="name">the name of the element (for use in exception messages)
		/// </param>
		/// <returns>s null if there is no problem, an HL7Exception otherwise 
		/// </returns>
		private NuGenHL7Exception testUsage(System.String encoded, System.String usage, System.String name)
		{
			NuGenHL7Exception e = null;
			if (usage.ToUpper().Equals("R".ToUpper()))
			{
				if (encoded.Length == 0)
					e = new NuGenProfileNotFollowedException("Required element " + name + " is missing");
			}
			else if (usage.ToUpper().Equals("RE".ToUpper()))
			{
				//can't test anything 
			}
			else if (usage.ToUpper().Equals("O".ToUpper()))
			{
				//can't test anything
			}
			else if (usage.ToUpper().Equals("C".ToUpper()))
			{
				//can't test anything yet -- wait for condition syntax in v2.6 
			}
			else if (usage.ToUpper().Equals("CE".ToUpper()))
			{
				//can't test anything
			}
			else if (usage.ToUpper().Equals("X".ToUpper()))
			{
				if (encoded.Length > 0)
					e = new NuGenXElementPresentException("Element " + name + " is present but specified as not used (X)");
			}
			else if (usage.ToUpper().Equals("B".ToUpper()))
			{
				//can't test anything 
			}
			return e;
		}
		/// <summary> Checks a segment against a list of allowed fields 
		/// (ie those mentioned in the profile with usage other than X).  Returns 
		/// a list of exceptions representing field that appear 
		/// but are not supposed to.  
		/// </summary>
		/// <param name="allowedFields">an array of Integers containing field #s of allowed fields
		/// </param>
		private NuGenHL7Exception[] checkForExtraFields(Segment segment, System.Collections.ArrayList allowedFields)
		{
			System.Collections.ArrayList exList = new System.Collections.ArrayList();
			for (int i = 1; i <= segment.numFields(); i++)
			{
				if (!allowedFields.Contains((System.Int32) i))
				{
					try
					{
						Genetibase.NuGenHL7.model.Type[] reps = segment.getField(i);
						for (int j = 0; j < reps.Length; j++)
						{
							if (hasContent(reps[j]))
							{
								NuGenHL7Exception e = new NuGenXElementPresentException("Field " + i + " in " + segment.getName() + " appears in the message but not in the profile");
								exList.Add(e);
							}
						}
					}
					catch (NuGenHL7Exception he)
					{
						throw new NuGenProfileException("Problem testing against profile", he);
					}
				}
			}
			return this.toArray(exList);
		}
		/// <summary> Checks a group's children against a list of allowed structures for the group 
		/// (ie those mentioned in the profile with usage other than X).  Returns 
		/// a list of exceptions representing structures that appear in the message  
		/// but are not supposed to.  
		/// </summary>
		private NuGenHL7Exception[] checkForExtraStructures(Group group, System.Collections.ArrayList allowedStructures)
		{
			System.Collections.ArrayList exList = new System.Collections.ArrayList();
			System.String[] childNames = group.Names;
			for (int i = 0; i < childNames.Length; i++)
			{
				if (!allowedStructures.Contains(childNames[i]))
				{
					try
					{
						Structure[] reps = group.getAll(childNames[i]);
						for (int j = 0; j < reps.Length; j++)
						{
							if (hasContent(reps[j]))
							{
								NuGenHL7Exception e = new NuGenXElementPresentException("The structure " + childNames[i] + " appears in the message but not in the profile");
								exList.Add(e);
							}
						}
					}
					catch (NuGenHL7Exception he)
					{
						throw new NuGenProfileException("Problem checking profile", he);
					}
				}
			}
			return toArray(exList);
		}