コード例 #1
0
        public virtual BareANY Adapt(string toDataTypeName, BareANY any)
        {
            BareANY element = null;

            if (any != null)
            {
                PropertyInfo property        = any.GetType().GetProperty("Value");
                object       collectionValue = property.GetValue(any, null);
                if (collectionValue != null)
                {
                    IEnumerable <BareANY> enumerable = (IEnumerable <BareANY>)collectionValue;
                    IEnumerator <BareANY> enumerator = enumerable.GetEnumerator();
                    if (enumerator.MoveNext())
                    {
                        element = enumerator.Current;
                    }
                }
            }
            if (element == null)
            {
                element = new ANYImpl <object>();
            }

            return((BareANY)element);
        }
コード例 #2
0
        public virtual BareANY Adapt(Type toDataType, BareANY any)
        {
            ConstructorInfo constructor       = toDataType.GetConstructor(new Type[] { typeof(Type) });
            object          constructedObject = constructor.Invoke(new object[] { any.GetType() });
            PropertyInfo    property          = toDataType.GetProperty("Value");
            object          collectionValue   = property.GetValue(constructedObject, null);
            Type            collectionType    = collectionValue.GetType();

            collectionType.GetMethod("Add").Invoke(collectionValue, new object[] { any });
            return((BareANY)constructedObject);
        }
コード例 #3
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);
        }
コード例 #4
0
        private void RenderNonStructuralAttribute(AttributeBridge tealBean, Relationship relationship, ConstrainedDatatype constraints
                                                  , TimeZoneInfo dateTimeZone, TimeZoneInfo dateTimeTimeZone)
        {
            string            propertyPath = BuildPropertyPath();
            BareANY           hl7Value     = tealBean.GetHl7Value();
            string            type         = DetermineActualType(relationship, hl7Value, this.result, propertyPath);
            PropertyFormatter formatter    = this.formatterRegistry.Get(type);

            if (formatter == null)
            {
                throw new RenderingException("Cannot support properties of type " + type);
            }
            else
            {
                string xmlFragment = string.Empty;
                try
                {
                    BareANY any = null;
                    bool    isMandatoryOrPopulated = ConformanceLevelUtil.IsMandatory(relationship) || ConformanceLevelUtil.IsPopulated(relationship
                                                                                                                                        );
                    if (relationship.HasFixedValue())
                    {
                        // suppress rendering fixed values for optional or required
                        if (isMandatoryOrPopulated)
                        {
                            any = (BareANY)DataTypeFactory.CreateDataType(relationship.Type, this.isCda && this.isR2);
                            object fixedValue = NonStructuralHl7AttributeRenderer.GetFixedValue(relationship, version, this.isR2, this.result, propertyPath
                                                                                                );
                            ((BareANYImpl)any).BareValue = fixedValue;
                        }
                    }
                    else
                    {
                        any = hl7Value;
                        any = this.adapterProvider.GetAdapter(any != null ? any.GetType() : null, type).Adapt(type, any);
                    }
                    // TODO - CDA - TM - implement default value handling
                    //					boolean valueNotProvided = (any.getBareValue() == null && !any.hasNullFlavor());
                    //					if (valueNotProvided && relationship.hasDefaultValue() && isMandatoryOrPopulated) {
                    //						// FIXME - CDA - TM - this doesn't work - will have a class cast exception (put Object convert(Object/String?) on ANY, implement trivial in ANYImpl, implement where necessary?)
                    //
                    //						any.setBareValue(relationship.getDefaultValue());
                    //					}
                    if (hl7Value != null && Hl7ValueHasContent(hl7Value))
                    {
                        HandleNotAllowedAndIgnored(relationship, propertyPath);
                    }
                    FormatContext context = Ca.Infoway.Messagebuilder.Marshalling.FormatContextImpl.Create(this.result, propertyPath, relationship
                                                                                                           , version, dateTimeZone, dateTimeTimeZone, constraints, this.isCda);
                    if (!StringUtils.Equals(type, relationship.Type))
                    {
                        context = new Ca.Infoway.Messagebuilder.Marshalling.HL7.Formatter.FormatContextImpl(type, true, context);
                    }
                    xmlFragment += formatter.Format(context, any, GetIndent());
                    // if relationship specifies a namespace, need to add it to xml
                    if (StringUtils.IsNotBlank(xmlFragment) & StringUtils.IsNotBlank(relationship.Namespaze))
                    {
                        xmlFragment = System.Text.RegularExpressions.Regex.Replace(xmlFragment, "<" + relationship.Name + " ", "<" + relationship
                                                                                   .Namespaze + ":" + relationship.Name + " ");
                        xmlFragment = System.Text.RegularExpressions.Regex.Replace(xmlFragment, "<" + relationship.Name + ">", "<" + relationship
                                                                                   .Namespaze + ":" + relationship.Name + ">");
                        xmlFragment = System.Text.RegularExpressions.Regex.Replace(xmlFragment, "</" + relationship.Name + ">", "</" + relationship
                                                                                   .Namespaze + ":" + relationship.Name + ">");
                    }
                }
                catch (ModelToXmlTransformationException e)
                {
                    Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, e.Message, propertyPath);
                    this.result.AddHl7Error(hl7Error);
                }
                RenderNewErrorsToXml(CurrentBuffer().GetChildBuilder());
                CurrentBuffer().GetChildBuilder().Append(xmlFragment);
            }
        }