Exemple #1
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);
        }
Exemple #2
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
                                                                       ()));
        }
Exemple #3
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());
        }
Exemple #4
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());
        }
Exemple #5
0
        protected override string FormatNonNullDataType(FormatContext context, BareANY bareAny, int indentLevel)
        {
            Interval <T> value = ExtractBareValue(bareAny);

            context = ValidateInterval(value, bareAny, context);
            StringBuilder buffer = new StringBuilder();

            if (value.Representation == Representation.SIMPLE)
            {
                buffer.Append(CreateElement(context, context.GetElementName(), new QTYImpl <T>(value.Value), indentLevel));
            }
            else
            {
                buffer.Append(CreateElement(context, null, indentLevel, false, true));
                AppendIntervalBounds(context, value, buffer, indentLevel + 1);
                buffer.Append(CreateElementClosure(context, indentLevel, true));
            }
            return(buffer.ToString());
        }
Exemple #6
0
 protected virtual string CreateElement(FormatContext context, IDictionary <string, string> attributes, int indentLevel, bool
                                        close, bool lineBreak)
 {
     // RM18070 - include (if required) ST/XT attributes for PQ.LAB as well (which can contain meta data even with a NF)
     if (!IsNullFlavor(attributes) || IsCodedType(context) || IsPqLab(context))
     {
         if (attributes == null)
         {
             attributes = new Dictionary <string, string>();
         }
         IDictionary <string, string> extraAttributes = CreateSpecializationTypeAttibutesIfNecessary(context);
         // bug 13884 - csharp throws exception if put duplicate key in map; this was occurring when using putAll() instead of below code
         foreach (string key in extraAttributes.Keys)
         {
             // TM - decided to not overwrite already existing attributes (as these would have been explicitly set)
             if (!attributes.ContainsKey(key) || StringUtils.IsBlank(attributes.SafeGet(key)))
             {
                 //attributes.remove(key);
                 attributes[key] = extraAttributes.SafeGet(key);
             }
         }
     }
     return(CreateElement(context.GetElementName(), attributes, indentLevel, close, lineBreak));
 }
Exemple #7
0
 public FormatContextImpl(string newType, bool isSpecializationType, FormatContext context) : this(newType, isSpecializationType
                                                                                                   , context.GetConformanceLevel(), context.GetCardinality(), context.GetElementName(), context)
 {
 }
Exemple #8
0
 public FormatContextImpl(string newType, FormatContext context) : this(newType, false, context.GetConformanceLevel(), context
                                                                        .GetCardinality(), context.GetElementName(), context)
 {
 }
Exemple #9
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());
        }
Exemple #10
0
 protected virtual string CreateElementClosure(FormatContext context, int indentLevel, bool lineBreak)
 {
     return(CreateElementClosure(context.GetElementName(), indentLevel, lineBreak));
 }
Exemple #11
0
        public override string Format(FormatContext formatContext, BareANY hl7Value, int indentLevel)
        {
            if (hl7Value == null)
            {
                return(string.Empty);
            }
            string           specializationType       = hl7Value.DataType.Type;
            StandardDataType specializationTypeAsEnum = StandardDataType.GetByTypeName(specializationType);

            if (specializationTypeAsEnum != null && StandardDataType.ANY.Equals(specializationTypeAsEnum.RootDataType))
            {
                // specializationType has been determined to be an ANY variant; this (most likely) means specializationType has not been specified, so don't do any special processing
                return(base.Format(formatContext, hl7Value, indentLevel));
            }
            else
            {
                string            mappedSpecializationType = this.polymorphismHandler.MapCdaR1Type(hl7Value.DataType, formatContext.IsCda());
                PropertyFormatter formatter  = FormatterRegistry.GetInstance().Get(mappedSpecializationType);
                string            parentType = formatContext.Type;
                if (formatter == null || !AnyHelper.IsValidTypeForAny(parentType, specializationType))
                {
                    string errorText = "Cannot support properties of type " + specializationType + " for " + parentType + ". Please specify a specializationType applicable for "
                                       + parentType + " in the appropriate message bean.";
                    throw new ModelToXmlTransformationException(errorText);
                }
                else
                {
                    // pass processing off to the formatter applicable for the given specializationType
                    StandardDataType type = hl7Value.DataType;
                    return(formatter.Format(new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(formatContext.GetModelToXmlResult
                                                                                                                          (), formatContext.GetPropertyPath(), formatContext.GetElementName(), mappedSpecializationType, type.Coded ? "Code" : formatContext
                                                                                                                      .GetDomainType(), formatContext.GetConformanceLevel(), formatContext.GetCardinality(), true, formatContext.GetVersion(),
                                                                                                                      formatContext.GetDateTimeZone(), formatContext.GetDateTimeTimeZone(), null, formatContext.GetConstraints(), formatContext
                                                                                                                      .IsCda()), hl7Value, indentLevel));
                }
            }
        }
Exemple #12
0
 // only checking II constraints for now
 protected virtual FormatContext CreateSubContext(FormatContext context)
 {
     return(new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(context.GetModelToXmlResult(), context.GetPropertyPath
                                                                                          (), context.GetElementName(), GetSubType(context), context.GetDomainType(), context.GetConformanceLevel(), context.GetCardinality
                                                                                          (), context.IsSpecializationType(), context.GetVersion(), context.GetDateTimeZone(), context.GetDateTimeTimeZone(), null
                                                                                      , null, context.IsCda()));
 }
Exemple #13
0
 protected virtual void CreateMissingMandatoryWarning(FormatContext context)
 {
     context.GetModelToXmlResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, context.GetElementName() + " is a mandatory field, but no value is specified"
                                                            , context.GetPropertyPath()));
 }