Esempio n. 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);
        }
Esempio n. 2
0
        private void WriteDataType(BeanProperty property, BareANY value, string dataTypeName)
        {
            BareANY field = new DataTypeFieldHelper(property.Bean, property.Name).Get <BareANY>();

            if (field == null)
            {
                //this is required for the case sure when we collapse an association with cardinality > 1
                //into a List of data types. See DevicePrescriptionSummaryQueryCriteriaBean#getRxDispenseIndicator
                if (property.Collection)
                {
                    ListElementUtil.AddElement(property.Get(), value.BareValue);
                }
            }
            else
            {
                value = this.adapterProvider.GetAdapter(dataTypeName, field.GetType()).Adapt(field.GetType(), value);
                if (value.HasNullFlavor())
                {
                    new DataTypeFieldHelper(property.Bean, property.Name).SetNullFlavor(value.NullFlavor);
                }
                if (field is ANYMetaData && value is ANYMetaData)
                {
                    // preserve any meta data (yes, this is not ideal)
                    ((ANYMetaData)field).Language     = ((ANYMetaData)value).Language;
                    ((ANYMetaData)field).DisplayName  = ((ANYMetaData)value).DisplayName;
                    ((ANYMetaData)field).OriginalText = ((ANYMetaData)value).OriginalText;
                    ((ANYMetaData)field).Translations.AddAll(((ANYMetaData)value).Translations);
                }
                ((BareANYImpl)field).BareValue = value.BareValue;
                field.DataType = value.DataType;
            }
        }
Esempio n. 3
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);
            }
        }
Esempio n. 4
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        public virtual BareANY Parse(ParseContext context, IList <XmlNode> nodes, XmlToModelResult xmlToModelResult)
        {
            ParseContext newContext  = ConvertContext(context);
            BareANY      parseResult = this.r1Parser.Parse(newContext, nodes, xmlToModelResult);

            if (parseResult.BareValue == null && !parseResult.HasNullFlavor())
            {
                parseResult = this.r1ParserFrequency.Parse(newContext, nodes, xmlToModelResult);
            }
            return(ConvertDataType(parseResult));
        }
Esempio n. 5
0
        public override string Format(FormatContext context, BareANY hl7Value, int indentLevel)
        {
            string result = base.Format(context, hl7Value, indentLevel);

            // also calls formatNonNullDataType, but only if no NullFlavor present
            // if the supplied value had a null flavor we still need to handle other properties (if present)
            if (hl7Value != null && hl7Value.HasNullFlavor())
            {
                result = FormatNonNullDataType(context, hl7Value, indentLevel);
            }
            return(result);
        }
Esempio n. 6
0
 internal virtual BareANY CopyAndReturnAdapted(BareANY any, BareANY adaptedAny, object newValue)
 {
     if (any.HasNullFlavor())
     {
         NullFlavor nullFlavor = any.NullFlavor;
         adaptedAny.NullFlavor = nullFlavor;
     }
     else
     {
         ((BareANYImpl)adaptedAny).BareValue = newValue;
     }
     return(adaptedAny);
 }
Esempio n. 7
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));
 }
Esempio n. 8
0
        public virtual BareANY Adapt(string toDataTypeName, BareANY any)
        {
            MethodInfo                    rawCollectionMethod = any.GetType().GetMethod("RawCollection");
            ICollection <object>          collection          = (ICollection <object>)rawCollectionMethod.Invoke(any, new object[] { });
            SETImpl <TNImpl, TrivialName> adaptedSet          = new SETImpl <TNImpl, TrivialName>(typeof(TNImpl));

            if (any.HasNullFlavor())
            {
                NullFlavor nullFlavor = any.NullFlavor;
                adaptedSet.NullFlavor = nullFlavor;
            }
            else
            {
                adaptedSet.RawSet().AddAll(ToSetOfTrivialName(collection));
            }
            return(adaptedSet);
        }
Esempio n. 9
0
 internal virtual BareDiff CreateDiffType(ParseContext context, XmlElement width, XmlToModelResult xmlToModelResult)
 {
     if (IsTimestampType(context))
     {
         return(CreateDateDiff(context, width, xmlToModelResult));
     }
     else
     {
         BareANY bareAny = CreateType(context, width, xmlToModelResult);
         if (bareAny.HasNullFlavor())
         {
             return(new Diff <T>(bareAny.NullFlavor));
         }
         else
         {
             return(new Diff <T>((T)bareAny.BareValue));
         }
     }
 }
Esempio n. 10
0
        public override string Format(FormatContext context, BareANY hl7Value, int indentLevel)
        {
            string result = string.Empty;

            if (hl7Value != null)
            {
                V value = ExtractBareValue(hl7Value);
                Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformanceLevel = context.GetConformanceLevel();
                Cardinality cardinality = context.GetCardinality();
                if (hl7Value.HasNullFlavor())
                {
                    result = CreateElement(context, CreateNullFlavorAttributes(hl7Value.NullFlavor), indentLevel, true, true);
                    if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality))
                    {
                        CreateMissingMandatoryWarning(context);
                    }
                }
                else
                {
                    if (value == null || IsEmptyCollection(value))
                    {
                        if (conformanceLevel == null || IsMandatoryOrPopulated(context))
                        {
                            if (ConformanceLevelUtil.IsMandatory(conformanceLevel, cardinality))
                            {
                                result = CreateElement(context, AbstractPropertyFormatter.EMPTY_ATTRIBUTE_MAP, indentLevel, true, true);
                                CreateMissingMandatoryWarning(context);
                            }
                            else
                            {
                                result = CreateElement(context, AbstractPropertyFormatter.NULL_FLAVOR_ATTRIBUTES, indentLevel, true, true);
                            }
                        }
                    }
                    else
                    {
                        result = FormatNonNullDataType(context, hl7Value, indentLevel);
                    }
                }
            }
            return(result);
        }
Esempio n. 11
0
 private void HandleNullFlavor(CodedTypeR2 <Code> codedType, IDictionary <string, string> result, BareANY bareAny, FormatContext
                               context)
 {
     if (bareAny != null && bareAny.HasNullFlavor())
     {
         result.PutAll(CreateNullFlavorAttributes(bareAny.NullFlavor));
     }
     else
     {
         if (codedType == null)
         {
             Ca.Infoway.Messagebuilder.Xml.ConformanceLevel conformanceLevel = context.GetConformanceLevel();
             Cardinality cardinality = context.GetCardinality();
             if (conformanceLevel == null || ConformanceLevelUtil.IsPopulated(conformanceLevel, cardinality))
             {
                 result.PutAll(AbstractPropertyFormatter.NULL_FLAVOR_ATTRIBUTES);
             }
         }
     }
 }
Esempio n. 12
0
 private bool Hl7ValueHasContent(BareANY hl7Value)
 {
     if (hl7Value.BareValue != null)
     {
         // there's a value; if it's a list, check if it is empty
         if (ListElementUtil.IsCollection(hl7Value.BareValue))
         {
             return(!ListElementUtil.IsEmpty(hl7Value.BareValue));
         }
         else
         {
             return(true);
         }
     }
     else
     {
         // contains no value, but perhaps has a null flavor
         return(hl7Value.HasNullFlavor());
     }
 }
Esempio n. 13
0
        public override string Format(FormatContext context, BareANY hl7Value, int indentLevel)
        {
            if (hl7Value == null)
            {
                return(string.Empty);
            }
            StandardDataType specializationType = hl7Value.DataType;
            bool             valueOmitted       = hl7Value.HasNullFlavor() && hl7Value.BareValue == null;

            ValidateSpecializationType(specializationType, valueOmitted, context);
            PropertyFormatter formatter = fullDateTimeFormatter;
            string            formatterSpecializationType = StandardDataType.TS_FULLDATETIME.Type;

            if (StandardDataType.TS_FULLDATE == specializationType)
            {
                formatter = fullDateFormatter;
                formatterSpecializationType = StandardDataType.TS_FULLDATE.Type;
            }
            return(formatter.Format(new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(formatterSpecializationType
                                                                                                              , true, context), hl7Value, indentLevel));
        }