예제 #1
0
 private void ValidateDecimal(string value, string type, XmlToModelResult result, XmlElement element)
 {
     if (NumberUtil.IsNumber(value))
     {
         if (!StandardDataType.REAL.Type.Equals(type))
         {
             string     integerPart = value.Contains(".") ? StringUtils.SubstringBefore(value, ".") : value;
             string     decimalPart = value.Contains(".") ? StringUtils.SubstringAfter(value, ".") : string.Empty;
             RealFormat format      = GetFormat(type);
             if (StandardDataType.REAL_CONF.Type.Equals(type) && !ValueIsBetweenZeroAndOneInclusive(integerPart, decimalPart))
             {
                 RecordValueMustBeBetweenZeroAndOneError(value, type, result, element);
             }
             // TM - decided to remove check on overall length; we check before and after decimal lengths, which should be sufficient
             if (StringUtils.Length(integerPart) > format.GetMaxIntegerPartLength())
             {
                 RecordTooManyCharactersBeforeDecimalError(value, type, result, element, format);
             }
             if (StringUtils.Length(decimalPart) > format.GetMaxDecimalPartLength())
             {
                 RecordTooManyDigitsAfterDecimalError(value, type, result, element, format);
             }
         }
     }
     else
     {
         if (StringUtils.IsBlank(value))
         {
             RecordValueMustBeSpecifiedError(result, element);
         }
     }
 }
예제 #2
0
        private BigDecimal ValidateValue(string value, string type, XmlToModelResult xmlToModelResult, XmlElement element)
        {
            if (StringUtils.IsBlank(value))
            {
                return(null);
            }
            if (NumberUtil.IsNumber(value))
            {
                string integerPart = value.Contains(".") ? StringUtils.SubstringBefore(value, ".") : value;
                string decimalPart = value.Contains(".") ? StringUtils.SubstringAfter(value, ".") : string.Empty;
                if (StringUtils.Length(integerPart) > MAX_DIGITS_BEFORE_DECIMAL)
                {
                    RecordTooManyDigitsBeforeDecimalError(value, type, xmlToModelResult, element);
                }
                if (StringUtils.Length(decimalPart) > MAX_DIGITS_AFTER_DECIMAL)
                {
                    RecordTooManyDigitsAfterDecimalError(value, type, xmlToModelResult, element);
                }
                if (!StringUtils.IsNumeric(integerPart) || !StringUtils.IsNumeric(decimalPart))
                {
                    RecordMustContainDigitsOnlyError(value, xmlToModelResult, element);
                }
            }
            BigDecimal result = null;

            try
            {
                result = new BigDecimal(value);
            }
            catch (FormatException)
            {
                RecordInvalidNumberError(value, type, element, xmlToModelResult);
            }
            return(result);
        }
예제 #3
0
        private BigDecimal ValidateValue(string value, string type, XmlToModelResult xmlToModelResult, XmlElement element)
        {
            if (StringUtils.IsBlank(value))
            {
                if (element.HasAttribute("value"))
                {
                    RecordInvalidNumberError(value, type, element, xmlToModelResult);
                }
                return(null);
            }
            if (NumberUtil.IsNumber(value))
            {
                string integerPart = value.Contains(".") ? StringUtils.SubstringBefore(value, ".") : value;
                string decimalPart = value.Contains(".") ? StringUtils.SubstringAfter(value, ".") : string.Empty;
                if (!StringUtils.IsNumeric(integerPart) || !StringUtils.IsNumeric(decimalPart))
                {
                    RecordMustContainDigitsOnlyError(value, xmlToModelResult, element);
                }
            }
            BigDecimal result = null;

            try
            {
                result = new BigDecimal(value);
            }
            catch (FormatException)
            {
                RecordInvalidNumberError(value, type, element, xmlToModelResult);
            }
            return(result);
        }
예제 #4
0
        public virtual BigDecimal ValidateValue(string value, VersionNumber version, string type, bool hasNullFlavor, XmlElement
                                                element, string propertyPath, Hl7Errors errors)
        {
            int        maxIntDigits            = this.GetMaxIntDigits(version, type);
            int        maxFractionDigits       = this.GetMaxFractionDigits(version, type);
            bool       alreadyWarnedAboutValue = false;
            BigDecimal result = null;

            if (StringUtils.IsBlank(value))
            {
                if (!hasNullFlavor)
                {
                    CreateWarning("No value provided for physical quantity", element, propertyPath, errors);
                }
            }
            else
            {
                if (NumberUtil.IsNumber(value))
                {
                    string integerPart  = value.Contains(".") ? StringUtils.SubstringBefore(value, ".") : value;
                    string decimalPart  = value.Contains(".") ? StringUtils.SubstringAfter(value, ".") : string.Empty;
                    string errorMessage = "PhysicalQuantity for {0}/{1} can contain a maximum of {2} {3} places";
                    if (StringUtils.Length(decimalPart) > maxFractionDigits)
                    {
                        CreateWarning(System.String.Format(errorMessage, version.GetBaseVersion(), type, maxFractionDigits, "decimal"), element,
                                      propertyPath, errors);
                    }
                    if (StringUtils.Length(integerPart) > maxIntDigits)
                    {
                        CreateWarning(System.String.Format(errorMessage, version.GetBaseVersion(), type, maxIntDigits, "integer"), element, propertyPath
                                      , errors);
                    }
                    if (!StringUtils.IsNumeric(integerPart) || !StringUtils.IsNumeric(decimalPart))
                    {
                        alreadyWarnedAboutValue = true;
                        CreateWarning(System.String.Format("value \"{0}\" must contain digits only", value), element, propertyPath, errors);
                    }
                }
                try
                {
                    result = new BigDecimal(value);
                }
                catch (FormatException)
                {
                    if (!alreadyWarnedAboutValue)
                    {
                        CreateWarning(System.String.Format("value \"{0}\" is not a valid decimal value", value), element, propertyPath, errors);
                    }
                }
            }
            return(result);
        }
예제 #5
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        private Int32?ParseNonNullNode(ParseContext context, XmlElement element, XmlToModelResult xmlToModelResult)
        {
            Int32? result          = null;
            string unparsedInteger = GetAttributeValue(element, "value");

            if (StringUtils.IsNotBlank(unparsedInteger))
            {
                if (!NumberUtil.IsNumber(unparsedInteger))
                {
                    RecordNotAValidNumberError(element, xmlToModelResult);
                }
                else
                {
                    result = NumberUtil.ParseAsInteger(unparsedInteger);
                    // using the isNumeric check to catch silly things such as passing in a hexadecimal number (0x1a, for example)
                    bool mustBePositive = StandardDataType.INT_POS.Type.Equals(context.Type);
                    if (StandardDataType.INT.Type.Equals(context.Type) && unparsedInteger.StartsWith("-"))
                    {
                        // remove negative sign to not confuse isNumeric() check
                        unparsedInteger = Ca.Infoway.Messagebuilder.StringUtils.Substring(unparsedInteger, 1);
                    }
                    if (!NumberUtil.IsInteger(unparsedInteger) || !StringUtils.IsNumeric(unparsedInteger))
                    {
                        RecordInvalidIntegerError(result, element, mustBePositive, xmlToModelResult);
                    }
                    else
                    {
                        if (mustBePositive && result.Value == 0)
                        {
                            RecordMustBeGreaterThanZeroError(element, xmlToModelResult);
                        }
                    }
                }
            }
            else
            {
                if (element.HasAttribute("value"))
                {
                    RecordEmptyValueError(element, xmlToModelResult);
                }
                else
                {
                    RecordMissingValueError(element, xmlToModelResult);
                }
            }
            return(result);
        }
예제 #6
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        private Int32?ParseNonNullNode(ParseContext context, XmlElement element, BareANY bareAny, XmlToModelResult xmlToModelResult
                                       )
        {
            Int32? result          = null;
            string unparsedInteger = GetAttributeValue(element, "value");

            if (StringUtils.IsNotBlank(unparsedInteger))
            {
                if (!NumberUtil.IsNumber(unparsedInteger))
                {
                    RecordNotAValidNumberError(element, xmlToModelResult);
                }
                else
                {
                    result = NumberUtil.ParseAsInteger(unparsedInteger);
                    if (unparsedInteger.StartsWith("-"))
                    {
                        // remove negative sign to not confuse isNumeric() check
                        unparsedInteger = Ca.Infoway.Messagebuilder.StringUtils.Substring(unparsedInteger, 1);
                    }
                    // using the isNumeric check to catch silly things such as passing in a hexadecimal number (0x1a, for example)
                    if (!NumberUtil.IsInteger(unparsedInteger) || !StringUtils.IsNumeric(unparsedInteger))
                    {
                        RecordInvalidIntegerError(result, element, xmlToModelResult);
                    }
                }
            }
            else
            {
                if (element.HasAttribute("value"))
                {
                    RecordEmptyValueError(element, xmlToModelResult);
                }
                else
                {
                    RecordMissingValueError(element, xmlToModelResult);
                }
            }
            this.sxcmHelper.HandleOperator(element, context, xmlToModelResult, (ANYMetaData)bareAny);
            if (element.HasAttribute("unsorted"))
            {
                bool unsorted = Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(element.GetAttribute("unsorted"));
                ((ANYMetaData)bareAny).Unsorted = unsorted;
            }
            return(result);
        }