Beispiel #1
0
        /// <param name="message">an ER7 or XML encoded message to validate
        /// </param>
        /// <param name="isXML">true if XML, false if ER7
        /// </param>
        /// <param name="version">HL7 version (e.g. "2.2") to which the message belongs
        /// </param>
        /// <returns> true if the message is OK
        /// </returns>
        /// <throws>  HL7Exception if there is at least one error and this validator is set to fail on errors </throws>
        public virtual bool validate(System.String message, bool isXML, System.String version)
        {
            NuGenEncodingRule[]      rules   = myContext.getEncodingRules(version, isXML?"XML":"ER7");
            NuGenValidationException toThrow = null;
            bool result = true;

            for (int i = 0; i < rules.Length; i++)
            {
                NuGenValidationException[] ex = rules[i].test(message);
                for (int j = 0; j < ex.Length; j++)
                {
                    result = false;
                    if (failOnError && toThrow == null)
                    {
                        toThrow = ex[j];
                    }
                }
            }

            if (toThrow != null)
            {
                throw new NuGenHL7Exception("Invalid message", toThrow);
            }

            return(result);
        }
Beispiel #2
0
        /// <param name="message">a parsed message to validate (note that MSH-9-1 and MSH-9-2 must be valued)
        /// </param>
        /// <returns> true if the message is OK
        /// </returns>
        /// <throws>  HL7Exception if there is at least one error and this validator is set to fail on errors </throws>
        public virtual bool validate(Message message)
        {
            Terser t = new Terser(message);

            NuGenMessageRule[] rules = myContext.getMessageRules(message.Version, t.get_Renamed("MSH-9-1"), t.get_Renamed("MSH-9-2"));

            NuGenValidationException toThrow = null;
            bool result = true;

            for (int i = 0; i < rules.Length; i++)
            {
                NuGenValidationException[] ex = rules[i].test(message);
                for (int j = 0; j < ex.Length; j++)
                {
                    result = false;
                    if (failOnError && toThrow == null)
                    {
                        toThrow = ex[j];
                    }
                }
            }

            if (toThrow != null)
            {
                throw new NuGenHL7Exception("Invalid message", toThrow);
            }

            return(result);
        }