示例#1
0
        private void Validate(FormatContext context, BigDecimal bigDecimal)
        {
            ModelToXmlResult modelToXmlResult = context.GetModelToXmlResult();

            if (bigDecimal.CompareTo(BigDecimal.ZERO) < 0 || bigDecimal.CompareTo(BigDecimal.ONE) > 0)
            {
                RecordValueMustBeBetweenZeroAndOneError(context.GetPropertyPath(), modelToXmlResult);
            }
            if (bigDecimal.Scale() > realFormat.GetMaxDecimalPartLength())
            {
                RecordTooManyDigitsToRightOfDecimalError(context.GetPropertyPath(), modelToXmlResult);
            }
        }
示例#2
0
		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);
			}
		}
示例#3
0
        public override string Format(FormatContext context, BareANY hl7Value, int indentLevel)
        {
            string result = base.Format(context, hl7Value, indentLevel);

            if (hl7Value != null)
            {
                string originalText  = ((ANYMetaData)hl7Value).OriginalText;
                bool   hasNullFlavor = hl7Value.HasNullFlavor();
                bool   hasAnyValues  = HasAnyValues(hl7Value);
                this.pqValidationUtils.ValidateOriginalText(context.Type, originalText, hasAnyValues, hasNullFlavor, context.GetVersion()
                                                            , null, context.GetPropertyPath(), context.GetModelToXmlResult());
                // complete hack for BC
                if (SpecificationVersion.IsExactVersion(context.GetVersion(), SpecificationVersion.V02R04_BC))
                {
                    if (hasNullFlavor && HasAnyValues(hl7Value))
                    {
                        // dump the result and rebuild, adding in NF
                        IDictionary <string, string> attributeNameValuePairs = GetAttributeNameValuePairs(context, (PhysicalQuantity)hl7Value.BareValue
                                                                                                          , hl7Value);
                        attributeNameValuePairs.PutAll(CreateNullFlavorAttributes(hl7Value.NullFlavor));
                        result = CreateElement(context, attributeNameValuePairs, indentLevel, true, true);
                    }
                }
                if (StringUtils.IsNotBlank(originalText))
                {
                    string otElement = CreateElement("originalText", null, indentLevel + 1, false, false);
                    otElement += XmlStringEscape.Escape(originalText);
                    otElement += CreateElementClosure("originalText", 0, true);
                    // pulling off the end "/>" is not the most elegant solution, but superclass would need significant refactoring otherwise
                    result = Ca.Infoway.Messagebuilder.StringUtils.Substring(result, 0, result.IndexOf("/>")) + ">" + SystemUtils.LINE_SEPARATOR
                             + otElement + CreateElementClosure(context.GetElementName(), indentLevel, true);
                }
            }
            return(result);
        }
示例#4
0
        protected override string FormatNonNullDataType(FormatContext context, BareANY dataType, int indentLevel)
        {
            EncapsulatedData encapsulatedData = ExtractBareValue(dataType);

            HandleConstraints(encapsulatedData, context.GetConstraints(), context.GetPropertyPath(), context.GetModelToXmlResult());
            IDictionary <string, string> attributes = CreateAttributes(encapsulatedData, context);
            bool hasContent = HasContent(encapsulatedData);
            bool hasReferenceOrThumbnailOrDocument = HasReferenceOrThumbnailOrDocument(encapsulatedData);

            if (!this.isR2)
            {
                AddSpecializationType(encapsulatedData, attributes, context.Type, dataType.DataType, context.GetVersion());
                Validate(context, dataType, encapsulatedData);
            }
            StringBuilder buffer = new StringBuilder();

            buffer.Append(CreateElement(context, attributes, indentLevel, !hasContent, hasReferenceOrThumbnailOrDocument));
            if (hasContent)
            {
                WriteReference(encapsulatedData, buffer, indentLevel + 1, context);
                WriteThumbnail(encapsulatedData, buffer, indentLevel + 1, context);
                this.edContentRenderer.RenderContent(encapsulatedData, buffer, indentLevel + 1, context, hasReferenceOrThumbnailOrDocument
                                                     );
                buffer.Append(CreateElementClosure(context, hasReferenceOrThumbnailOrDocument ? indentLevel : 0, true));
            }
            return(buffer.ToString());
        }
示例#5
0
 private void Validate(Int32?integer, FormatContext context, BareANY bareAny)
 {
     if (integer.Value < 0)
     {
         RecordNotNegativeError(integer, context.GetPropertyPath(), context.GetModelToXmlResult());
     }
 }
示例#6
0
 private void Validate(Int32?integer, FormatContext context, BareANY bareAny)
 {
     if (integer.Value <= 0)
     {
         RecordMustBeGreaterThanZeroError(integer, context.GetPropertyPath(), context.GetModelToXmlResult());
     }
 }
示例#7
0
        protected override string FormatNonNullValue(FormatContext context, CodeRole codeRole, int indentLevel)
        {
            bool hasContent = (codeRole.Name != null || codeRole.Value != null);

            // validation here (limited, from schema); must have value or a NF (and if we are here, we don't have a NF)
            if (codeRole.Value == null)
            {
                context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "CR types must have the \"value\" property provided"
                                                                       , context.GetPropertyPath()));
            }
            StringBuilder buffer = new StringBuilder();

            buffer.Append(CreateElement(context, CreateAttributesMap(codeRole, context), indentLevel, !hasContent, true));
            if (hasContent)
            {
                if (codeRole.Name != null)
                {
                    buffer.Append(FormatName(context, codeRole.Name, indentLevel + 1));
                }
                if (codeRole.Value != null)
                {
                    buffer.Append(FormatValue(context, codeRole.Value, indentLevel + 1));
                }
                buffer.Append(CreateElementClosure(context.GetElementName(), indentLevel, true));
            }
            return(buffer.ToString());
        }
示例#8
0
        private void ValidateCardinality(FormatContext context, ICollection <BareANY> collection)
        {
            int size = collection.Count;
            int min  = (int)context.GetCardinality().Min;
            int max  = (int)context.GetCardinality().Max;

            if (size < min)
            {
                context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Number of elements (" + size + ") is less than the specified minimum ("
                                                                       + min + ")", context.GetPropertyPath()));
            }
            if (size > max)
            {
                context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Number of elements (" + size + ") is more than the specified maximum ("
                                                                       + max + ")", context.GetPropertyPath()));
            }
        }
示例#9
0
        private void ValidatePhysicalQuantity(PhysicalQuantity physicalQuantity, BareANY bareANY, FormatContext context)
        {
            string           type   = context.Type;
            ModelToXmlResult errors = context.GetModelToXmlResult();
            // nothing to validate for value, based on R2 schema
            string unitsAsString = (physicalQuantity.Unit == null ? null : physicalQuantity.Unit.CodeValue);

            this.pqValidationUtils.ValidateUnits(type, unitsAsString, null, context.GetPropertyPath(), errors, true);
        }
示例#10
0
        protected override string FormatDenominator(FormatContext context, PhysicalQuantity denominator, int indentLevel)
        {
            if (denominator != null && BigDecimal.ZERO.Equals(denominator.Quantity))
            {
                context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Denominator cannot be zero for RTO types."
                                                                       , context.GetPropertyPath()));
            }
            FormatContext newContext = new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl("PQ", Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                                                                                 .OPTIONAL, Cardinality.Create("0-1"), "denominator", context);

            return(this.pqFormatter.Format(newContext, new PQImpl(denominator), indentLevel));
        }
示例#11
0
 public override string Format(FormatContext context, BareANY hl7Value, int indentLevel)
 {
     // if type is BN then NFs are not allowed
     if (StringUtils.Equals(context.Type, StandardDataType.BN.Type))
     {
         if (hl7Value == null || hl7Value.BareValue == null || hl7Value.HasNullFlavor())
         {
             context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.MANDATORY_FIELD_NOT_PROVIDED, "BN can not be null or have a nullFlavor"
                                                                    , context.GetPropertyPath()));
         }
     }
     return(base.Format(context, hl7Value, indentLevel));
 }
示例#12
0
        private void ValidatePhysicalQuantity(FormatContext context, PhysicalQuantity physicalQuantity, BareANY bareANY)
        {
            // does not validate originalText here as this section is bypassed when value is a NullFlavor
            string           type             = context.Type;
            ModelToXmlResult errors           = context.GetModelToXmlResult();
            bool             hasNullFlavor    = (bareANY == null || bareANY.NullFlavor != null);
            string           quantityAsString = physicalQuantity.Quantity == null ? null : physicalQuantity.Quantity.ToPlainString();

            this.pqValidationUtils.ValidateValue(quantityAsString, context.GetVersion(), type, hasNullFlavor, null, context.GetPropertyPath
                                                     (), errors);
            string unitsAsString = (physicalQuantity.Unit == null ? null : physicalQuantity.Unit.CodeValue);

            this.pqValidationUtils.ValidateUnits(type, unitsAsString, null, context.GetPropertyPath(), errors, false);
        }
示例#13
0
 private void HandleConstraints(string type, ConstrainedDatatype constraints, BareANY hl7Value, ICollection <BareANY> bareAnyCollection
                                , FormatContext context)
 {
     IiCollectionConstraintHandler.ConstraintResult constraintResult = this.constraintHandler.CheckConstraints(type, constraints
                                                                                                               , bareAnyCollection);
     if (constraintResult != null && !constraintResult.IsFoundMatch())
     {
         // there should be a match, but if not we need to create an II with the appropriate values and add to collection
         Identifier identifier = constraintResult.GetIdentifer();
         //In Java these are really the same collection due to type erasure. In .NET we need two different collections.
         ICollection <II> iiCollection = (ICollection <II>)hl7Value.BareValue;
         iiCollection.Add(new IIImpl(identifier));
         context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.CDA_FIXED_CONSTRAINT_PROVIDED, ErrorLevel.INFO, "A fixed constraint was added for compliance: "
                                                                + identifier, context.GetPropertyPath()));
     }
 }
示例#14
0
        private void Validate(Money money, FormatContext context)
        {
            // nothing much to validate for R2 version of datatype
            ModelToXmlResult modelToXmlResult = context.GetModelToXmlResult();
            string           propertyPath     = context.GetPropertyPath();
            BigDecimal       amount           = money.Amount;

            if (amount != null)
            {
                string value       = amount.ToString();
                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, propertyPath, modelToXmlResult);
                }
            }
        }
示例#15
0
        protected override string FormatNonNullValue(FormatContext context, BareRatio value, int indentLevel)
        {
            StringBuilder buffer = new StringBuilder();

            buffer.Append(CreateElement(context, null, indentLevel, false, true));
            T bareNumerator   = (T)value.BareNumerator;
            U bareDenominator = (U)value.BareDenominator;

            if (bareNumerator == null || bareDenominator == null)
            {
                context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Numerator and denominator must be non-null; both are mandatory for Ratio types."
                                                                       , context.GetPropertyPath()));
            }
            buffer.Append(FormatNumerator(context, bareNumerator, indentLevel + 1));
            buffer.Append(FormatDenominator(context, bareDenominator, indentLevel + 1));
            buffer.Append(CreateElementClosure(context.GetElementName(), indentLevel, true));
            return(buffer.ToString());
        }
示例#16
0
        public virtual void HandleOperator(IDictionary <string, string> attributes, FormatContext context, ANYMetaData wrapper)
        {
            string type        = context == null ? null : context.Type;
            bool   isSxcm      = (type != null && type.StartsWith("SXCM<"));
            bool   hasOperator = wrapper != null && wrapper.Operator != null;

            if (hasOperator)
            {
                if (isSxcm)
                {
                    attributes["operator"] = wrapper.Operator.CodeValue;
                }
                else
                {
                    context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Operator property not applicable for type: "
                                                                           + type, context.GetPropertyPath()));
                }
            }
        }
示例#17
0
        private void Validate(Money money, FormatContext context)
        {
            ModelToXmlResult modelToXmlResult = context.GetModelToXmlResult();
            string           propertyPath     = context.GetPropertyPath();
            BigDecimal       amount           = money.Amount;

            if (amount == null)
            {
                RecordMissingValueError(propertyPath, modelToXmlResult);
            }
            else
            {
                string value       = amount.ToString();
                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, propertyPath, modelToXmlResult);
                }
                if (StringUtils.Length(decimalPart) > MAX_DIGITS_AFTER_DECIMAL)
                {
                    RecordTooManyDigitsAfterDecimalError(value, propertyPath, modelToXmlResult);
                }
                if (!StringUtils.IsNumeric(integerPart) || !StringUtils.IsNumeric(decimalPart))
                {
                    RecordMustContainDigitsOnlyError(value, propertyPath, modelToXmlResult);
                }
            }
            Ca.Infoway.Messagebuilder.Domainvalue.Basic.Currency currency = money.Currency;
            if (currency == null)
            {
                RecordMissingCurrencyError(propertyPath, modelToXmlResult);
            }
            else
            {
                if (!Ca.Infoway.Messagebuilder.Domainvalue.Basic.Currency.CANADIAN_DOLLAR.CodeValue.Equals(currency.CodeValue))
                {
                    RecordCurrencyMustBeCadError(propertyPath, modelToXmlResult);
                }
            }
        }
示例#18
0
        protected sealed override string FormatNonNullValue(FormatContext context, PostalAddress postalAddress, int indentLevel)
        {
            Hl7BaseVersion baseVersion = context.GetVersion().GetBaseVersion();
            string         dataType    = context.Type;

            AbstractAdPropertyFormatter.AD_VALIDATION_UTILS.ValidatePostalAddress(postalAddress, dataType, context.GetVersion(), null
                                                                                  , context.GetPropertyPath(), context.GetModelToXmlResult());
            PostalAddress basicAddress = new PostalAddress();
            StringBuilder builder      = new StringBuilder();

            // remove any non-basic address parts
            foreach (PostalAddressPart part in EmptyIterable <object> .NullSafeIterable(postalAddress.Parts))
            {
                if (part.Type == PostalAddressPartType.CITY || part.Type == PostalAddressPartType.STATE || part.Type == PostalAddressPartType
                    .COUNTRY || part.Type == PostalAddressPartType.POSTAL_CODE || part.Type == PostalAddressPartType.DELIMITER)
                {
                    Flush(builder, basicAddress);
                    basicAddress.AddPostalAddressPart(part);
                }
                else
                {
                    if (StringUtils.IsNotBlank(part.Value))
                    {
                        if (builder.Length > 0)
                        {
                            builder.Append(" ");
                        }
                        builder.Append(part.Value);
                    }
                }
            }
            Flush(builder, basicAddress);
            foreach (Ca.Infoway.Messagebuilder.Domainvalue.PostalAddressUse use in postalAddress.Uses)
            {
                if (AbstractAdPropertyFormatter.AD_VALIDATION_UTILS.IsAllowableUse(dataType, use, baseVersion))
                {
                    basicAddress.AddUse(use);
                }
            }
            return(base.FormatNonNullValue(context, basicAddress, indentLevel));
        }
示例#19
0
        public virtual string Format(FormatContext context, BareANY value, int indentLevel)
        {
            if (value == null)
            {
                return(string.Empty);
            }
            object bareValue = value.BareValue;
            Interval <PlatformDate> innerDateInterval   = null;
            Interval <MbDate>       innerMbDateInterval = null;

            if (bareValue != null && bareValue is DateInterval)
            {
                DateInterval dateInterval = (DateInterval)bareValue;
                HandleConstraints(context, context.GetModelToXmlResult(), context.GetPropertyPath(), dateInterval);
                innerDateInterval   = dateInterval.Interval;
                innerMbDateInterval = IntervalFactory.CreateMbDateInterval(innerDateInterval);
            }
            BareANY newValue = new IVLImpl <TS, Interval <MbDate> >(typeof(Interval <object>), innerMbDateInterval, value.NullFlavor, value
                                                                    .DataType);

            return(actualFormatter.Format(context, newValue, indentLevel));
        }
示例#20
0
        protected override string FormatNonNullDataType(FormatContext context, BareANY hl7Value, int indentLevel)
        {
            CodedTypeR2 <Code> codedType = ExtractBareValue(hl7Value);

            HandleConstraints(codedType, context.GetConstraints(), context.GetPropertyPath(), context.GetModelToXmlResult());
            StringBuilder result = new StringBuilder();
            IDictionary <string, string> attributes = GetAttributeNameValuePairs(context, codedType, hl7Value);

            ValidateChildContent(codedType, context);
            bool hasChildContent = HasChildContent(codedType, context);
            bool hasSimpleValue  = (SimpleValueAllowed() && HasSimpleValue(codedType));

            if (hasChildContent || hasSimpleValue || !attributes.IsEmpty())
            {
                result.Append(CreateElement(context, attributes, indentLevel, !(hasChildContent || hasSimpleValue), !hasSimpleValue || hasChildContent
                                            ));
                if (hasChildContent || hasSimpleValue)
                {
                    CreateChildContent(codedType, context, indentLevel + 1, result);
                    result.Append(CreateElementClosure(context, indentLevel, true));
                }
            }
            return(result.ToString());
        }
示例#21
0
 private void RecordError(string message, FormatContext context)
 {
     context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, message, context.GetPropertyPath()));
 }
示例#22
0
        private void Validate(StringBuilder buffer, int indentLevel, FormatContext context, bool hasLang, BareANY dataType)
        {
            // ST has min length of 1 according to schema, and cannot have both a NF and text
            // no details on what language strings are allowed
            ModelToXmlResult result = context.GetModelToXmlResult();

            if (dataType.HasNullFlavor())
            {
                if (dataType.BareValue != null)
                {
                    Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "ST cannot have both a nullFlavour and a text value.", context
                                                     .GetPropertyPath());
                    result.AddHl7Error(hl7Error);
                }
            }
            else
            {
                if (StringUtils.IsBlank(GetStringValue(dataType)))
                {
                    Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "ST text value must be provided.", context.GetPropertyPath
                                                         ());
                    result.AddHl7Error(hl7Error);
                }
            }
            if (hasLang && StringUtils.IsBlank(GetLanguage(dataType)))
            {
                Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "ST language attribute, if provided, can not be blank.", context
                                                 .GetPropertyPath());
                result.AddHl7Error(hl7Error);
            }
        }
示例#23
0
        private void Validate(FormatContext context, BareANY dataType, EncapsulatedData encapsulatedData)
        {
            string         type = context.Type;
            string         specializationType = dataType.DataType == null ? null : dataType.DataType.Type;
            Hl7BaseVersion baseVersion        = context.GetVersion().GetBaseVersion();
            Hl7Errors      errors             = context.GetModelToXmlResult();

            this.edValidationUtils.DoValidate(encapsulatedData, specializationType, baseVersion, type, context.GetPropertyPath(), errors
                                              );
        }
示例#24
0
        protected override string FormatNonNullValue(FormatContext context, UncertainRange <PlatformDate> value, int indentLevel)
        {
            // convert URG to an IVL and use IVL formatter
            Interval <PlatformDate> convertedInterval = IntervalFactory.CreateFromUncertainRange(value);
            IVLImpl <TS, Interval <PlatformDate> > convertedHl7Interval = new IVLImpl <TS, Interval <PlatformDate> >(convertedInterval);
            FormatContext ivlContext = new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(context.Type.Replace
                                                                                                                     ("URG", "IVL"), context.IsSpecializationType(), context);
            string xml = this.formatter.Format(ivlContext, convertedHl7Interval, indentLevel);

            xml = ChangeAnyIvlRemnants(xml);
            // inclusive attributes not allowed for URG<TS>
            if (value.LowInclusive != null || value.HighInclusive != null)
            {
                context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "High/Low inclusive fields should not be set; these attributes are not allowed for "
                                                                       + context.Type + " types", context.GetPropertyPath()));
            }
            return(xml);
        }
示例#25
0
 private void ValidateSpecializationType(StandardDataType specializationType, bool valueOmitted, FormatContext context)
 {
     if (specializationType == StandardDataType.TS || specializationType == null)
     {
         if (Ca.Infoway.Messagebuilder.BooleanUtils.ValueOf(Runtime.GetProperty(TsDateFormats.ABSTRACT_TS_IGNORE_SPECIALIZATION_TYPE_ERROR_PROPERTY_NAME
                                                                                )))
         {
         }
         else
         {
             // user has specified that this validation error should be suppressed
             if (valueOmitted)
             {
             }
             else
             {
                 // RM16399 - there are some cases where it is valid to omit a specialization type (such as when not providing a TS value)
                 // do nothing; other potential errors will be caught by the default concrete TS formatter
                 context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("No specializationType provided. Value should be one of TS.FULLDATE / TS.FULLDATETIME / TS.FULLDATEPARTTIME. TS.FULLDATETIME will be assumed."
                                                                                                                           , specializationType.Type), context.GetPropertyPath()));
             }
         }
     }
     else
     {
         if (specializationType != StandardDataType.TS_FULLDATE && specializationType != StandardDataType.TS_FULLDATETIME && specializationType
             != StandardDataType.TS_FULLDATEPARTTIME)
         {
             context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("Invalid specializationType: {0}. Value should be one of TS.FULLDATE / TS.FULLDATETIME / TS.FULLDATEPARTTIME. TS.FULLDATETIME will be assumed."
                                                                                                                       , specializationType.Type), context.GetPropertyPath()));
         }
     }
 }
示例#26
0
        private void Validate(StringBuilder buffer, int indentLevel, FormatContext context, bool isStLang, BareANY dataType)
        {
            // ST.LANG not allowed for CeRx; not checking as this should be controlled by the message set
            // is ST allowed to be 0 length or only whitespace???
            ModelToXmlResult result   = context.GetModelToXmlResult();
            string           language = GetLanguage(dataType);

            if (isStLang)
            {
                if (!STImpl.ALLOWED_LANGUAGES.Contains(language))
                {
                    Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The language attribute content ({0}) is not an allowed value. Using en-CA instead."
                                                                                                        , language), context.GetPropertyPath());
                    result.AddHl7Error(hl7Error);
                }
            }
            else
            {
                if (language != null)
                {
                    Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, System.String.Format("The language attribute ({0}) is not allowed for ST element types"
                                                                                                        , language), context.GetPropertyPath());
                    result.AddHl7Error(hl7Error);
                }
            }
        }
示例#27
0
 public FormatContextImpl(string newType, bool isSpecializationType, Ca.Infoway.Messagebuilder.Xml.ConformanceLevel newConformanceLevel
                          , Cardinality newCardinality, string elementName, FormatContext context) : this(context.GetModelToXmlResult(), context.GetPropertyPath
                                                                                                              (), elementName, newType, context.GetDomainType(), newConformanceLevel, newCardinality, isSpecializationType, context.GetVersion
                                                                                                              (), context.GetDateTimeZone(), context.GetDateTimeTimeZone(), context.GetCodingStrength(), null, context.IsCda())
 {
 }
示例#28
0
        public override string Format(FormatContext context, BareANY hl7Value, int indentLevel)
        {
            bool isAny = false;
            CD   cd    = null;

            if (hl7Value is CD)
            {
                cd = (CD)hl7Value;
            }
            else
            {
                isAny = true;
                // bypass some validations
                cd = ConvertAnyToCd(hl7Value);
            }
            StringBuilder result = new StringBuilder();

            if (cd != null)
            {
                HandleConstraints(cd.Value, context.GetConstraints(), context.GetPropertyPath(), context.GetModelToXmlResult());
                // don't bother validating if we don't have anything to validate
                if (cd.HasNullFlavor() || HasValue(cd, context))
                {
                    Hl7Errors     errors  = context.GetModelToXmlResult();
                    VersionNumber version = context.GetVersion();
                    string        type    = context.Type;
                    bool          isCne   = context.GetCodingStrength() == CodingStrength.CNE;
                    bool          isCwe   = context.GetCodingStrength() == CodingStrength.CWE;
                    // we can't lookup a code supplied in an ANY datatype as we don't know the domain
                    // a "reverse" lookup of domain type by code/codesystem could be possible, but difficult to implement to be 100% correct (MB does not track code systems)
                    if (!isAny)
                    {
                        if (cd.Value != null && cd.Value.CodeValue != null)
                        {
                            ValidateCodeExists(cd.Value, context.GetDomainType(), version, context.IsCda(), context.GetPropertyPath(), errors);
                        }
                    }
                    string codeAsString = (cd.Value != null ? cd.Value.CodeValue : null);
                    CD_VALIDATION_UTILS.ValidateCodedType(cd, codeAsString, isCwe, isCne, false, context.IsFixed(), type, version, null, context
                                                          .GetPropertyPath(), errors);
                }
                IDictionary <string, string> attributes = new Dictionary <string, string>();
                Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformanceLevel = context.GetConformanceLevel();
                Cardinality cardinality = context.GetCardinality();
                if (cd.HasNullFlavor())
                {
                    if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality))
                    {
                        LogMandatoryError(context);
                    }
                    else
                    {
                        attributes.PutAll(CreateNullFlavorAttributes(hl7Value.NullFlavor));
                    }
                }
                else
                {
                    if (!HasValue(cd, context))
                    {
                        if (conformanceLevel == null || IsMandatoryOrPopulated(context))
                        {
                            if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality))
                            {
                                LogMandatoryError(context);
                            }
                            else
                            {
                                attributes.PutAll(AbstractPropertyFormatter.NULL_FLAVOR_ATTRIBUTES);
                            }
                        }
                    }
                }
                // Codes can have other attributes in map even if has NullFlavor
                attributes.PutAll(GetAttributeNameValuePairs(context, cd.Value, hl7Value));
                bool hasChildContent = HasChildContent(cd, context);
                if (hasChildContent || (!attributes.IsEmpty() || ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality)))
                {
                    result.Append(CreateElement(context, attributes, indentLevel, !hasChildContent, !hasChildContent));
                    if (hasChildContent)
                    {
                        CreateChildContent(cd, result);
                        result.Append("</").Append(context.GetElementName()).Append(">");
                        result.Append(SystemUtils.LINE_SEPARATOR);
                    }
                }
            }
            return(result.ToString());
        }
示例#29
0
        private void LogMandatoryError(FormatContext context)
        {
            string errorMessage = context.GetElementName() + " is a mandatory field, but no value is specified";

            context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, errorMessage, context.GetPropertyPath
                                                                       ()));
        }
示例#30
0
 protected sealed override string FormatNonNullValue(FormatContext context, PostalAddress postalAddress, int indentLevel)
 {
     AbstractAdPropertyFormatter.AD_VALIDATION_UTILS.ValidatePostalAddress(postalAddress, context.Type, context.GetVersion(),
                                                                           null, context.GetPropertyPath(), context.GetModelToXmlResult());
     return(base.FormatNonNullValue(context, postalAddress, indentLevel));
 }