Exemplo n.º 1
0
        /// <summary>
        /// Validates this codable text
        /// </summary>
        /// <param name="path">The path to this object as a string</param>
        /// <param name="messages">the validation messages to date, these may be added to within this method</param>
        public void Validate(string path, List <ValidationMessage> messages)
        {
            var vb = new ValidationBuilder(path, messages);

            if (!HasCodeSystem && !Code.IsNullOrEmptyWhitespace())
            {
                vb.AddValidationMessage(vb.PathName, null, "Code can only be provided if a CodeSystem is specified");
            }

            if (!HasCodeSystem && !DisplayName.IsNullOrEmptyWhitespace())
            {
                vb.AddValidationMessage(vb.PathName, null, "DisplayName can only be provided if a CodeSystem is specified");
            }

            if (DisplayName.IsNullOrEmptyWhitespace() && OriginalText.IsNullOrEmptyWhitespace() && NullFlavour == null)
            {
                vb.AddValidationMessage(vb.PathName, null, "Either OriginalText or DisplayName or a NullFlavour must be provided");
            }

            if (Translations != null)
            {
                foreach (var translation in Translations)
                {
                    translation.Validate(path, messages);
                }
            }

            if (QualifierCodes != null)
            {
                foreach (var qualifierCode in QualifierCodes)
                {
                    qualifierCode.Validate(path, messages);
                }
            }

            if (QualifierCodes != null && OriginalText.IsNullOrEmptyWhitespace())
            {
                vb.AddValidationMessage(vb.PathName + "QualifierCodes & OriginalText", null, "OriginalText must be provided with QualifierCodes");
            }
        }