示例#1
0
        protected virtual string CreateElement(FormatContext context, string name, QTY <T> value, Boolean?inclusive, bool isSxcm,
                                               int indentLevel)
        {
            string type = Hl7DataTypeName.GetParameterizedType(context.Type);

            if (isSxcm)
            {
                type = "SXCM<" + type + ">";
            }
            PropertyFormatter formatter = FormatterR2Registry.GetInstance().Get(type);

            if (formatter != null)
            {
                bool          isSpecializationType = false;
                FormatContext newContext           = new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(type, isSpecializationType
                                                                                                                               , Ca.Infoway.Messagebuilder.Xml.ConformanceLevel.POPULATED, Cardinality.Create("1"), name, context);
                string result = formatter.Format(newContext, value, indentLevel);
                if (inclusive != null)
                {
                    // TM - small hack to add in the inclusive attribute (low/high) (operator, simple only, is already formatted by using the SXCM type)
                    result = result.ReplaceFirst(" value=", " inclusive=\"" + inclusive.ToString().ToLower() + "\" value=");
                }
                return(result);
            }
            else
            {
                throw new ModelToXmlTransformationException("No formatter found for " + type);
            }
        }
示例#2
0
        // this case shouldn't happen, but is useful when the code is
        // translated
        /// <exception cref="System.Exception"></exception>
        private void AssertFormatterIsRegistered(Type classObj)
        {
            IList <string> keys = FormatterR2Registry.GetInstance().GetRegistrationKey(classObj);

            foreach (string @string in keys)
            {
                Assert.IsNotNull(FormatterR2Registry.GetInstance().Get(@string), "register " + classObj.FullName + " (" + @string + ")");
            }
        }
示例#3
0
        public virtual void TestAllFormattersWithNullValue()
        {
            IDictionary <string, PropertyFormatter> formatters = FormatterR2Registry.GetInstance().GetProtectedRegistryMap();

            foreach (string key in formatters.Keys)
            {
                PropertyFormatter formatter = formatters.SafeGet(key);
                FormatContext     context   = GetContext("name", key);
                try
                {
                    formatter.Format(context, null);
                    formatter.Format(context, null, 0);
                }
                catch (Exception e)
                {
                    Assert.Fail(key + " (" + formatter.GetType().Name + "): formatter failed when given a null value: " + e.Message);
                }
            }
        }
示例#4
0
 protected virtual string CreateWidthElement(FormatContext context, string name, BareDiff diff, int indentLevel)
 {
     if (IsTimestamp(context))
     {
         return(CreateTimestampWidthElement(context, name, diff, indentLevel));
     }
     else
     {
         string            type      = Hl7DataTypeName.GetParameterizedType(context.Type);
         PropertyFormatter formatter = FormatterR2Registry.GetInstance().Get(type);
         if (formatter != null)
         {
             bool isSpecializationType = false;
             return(formatter.Format(new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(type, isSpecializationType
                                                                                                               , Ca.Infoway.Messagebuilder.Xml.ConformanceLevel.MANDATORY, Cardinality.Create("1"), name, context), WrapWithHl7DataType
                                         (type, diff), indentLevel));
         }
         else
         {
             throw new ModelToXmlTransformationException("No formatter found for " + type);
         }
     }
 }
示例#5
0
        protected override string FormatNonNullDataType(FormatContext context, BareANY hl7Value, int indentLevel)
        {
            string           actualType       = hl7Value.DataType.Type;
            StandardDataType actualTypeAsEnum = StandardDataType.GetByTypeName(actualType);
            string           result           = null;

            if (actualTypeAsEnum == null)
            {
                RecordError("Could not determine type for ANY relationship." + (actualType == null ? "'" : actualType + "' not found in StandardDataType enum."
                                                                                ), context);
            }
            else
            {
                if (StandardDataType.ANY.Equals(actualTypeAsEnum.RootDataType))
                {
                    // actual type has been determined to be ANY; this (most likely) means a concrete type has not been specified
                    RecordError("A concrete data type must be specified for a relationship of type ANY.", context);
                }
                else
                {
                    PropertyFormatter formatter = FormatterR2Registry.GetInstance().Get(actualType);
                    if (formatter == null)
                    {
                        string errorText = "Cannot support properties of type " + actualType + " for relationship of type ANY. Please specify a type applicable for ANY in the appropriate message bean.";
                        RecordError(errorText, context);
                    }
                    else
                    {
                        // adjust context and pass processing off to the formatter applicable for the specified type
                        result = formatter.Format(new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(actualType, true, context
                                                                                                                            ), hl7Value, indentLevel);
                    }
                }
            }
            return(result);
        }
示例#6
0
 public BagR2PropertyFormatter(FormatterR2Registry formatterR2Registry) : base(formatterR2Registry, true)
 {
 }