private void Validate(FormatContext context, BigDecimal bigDecimal) { ModelToXmlResult modelToXmlResult = context.GetModelToXmlResult(); string value = bigDecimal.ToString(); string integerPart = value.Contains(".") ? StringUtils.SubstringBefore(value, ".") : value; string decimalPart = value.Contains(".") ? StringUtils.SubstringAfter(value, ".") : string.Empty; if (integerPart.Length > realFormat.GetMaxIntegerPartLength()) { RecordTooManyCharactersToLeftOfDecimalError(context.GetPropertyPath(), modelToXmlResult); } if (decimalPart.Length > realFormat.GetMaxDecimalPartLength()) { RecordTooManyDigitsToRightOfDecimalError(context.GetPropertyPath(), modelToXmlResult); } }
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); } } }
private void RecordTooManyCharactersBeforeDecimalError(string value, string type, XmlToModelResult result, XmlElement element , RealFormat format) { result.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Value " + value + " of type " + type + " should have no more than " + format.GetMaxIntegerPartLength() + " characters before the decimal", element)); }