Пример #1
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);
            }
        }