public virtual void VisitAttribute(AttributeBridge tealBean, Relationship relationship, ConstrainedDatatype constraints, TimeZoneInfo dateTimeZone, TimeZoneInfo dateTimeTimeZone) { PushPropertyPathName(DeterminePropertyName(tealBean.GetPropertyName(), relationship), false); if (relationship.Structural) { string propertyPath = BuildPropertyPath(); if (tealBean.GetValue() != null) { HandleNotAllowedAndIgnored(relationship, propertyPath); } // TODO - CDA - TM - may need to handle constraints for structural attributes new VisitorStructuralAttributeRenderer(relationship, tealBean.GetValue()).Render(CurrentBuffer().GetStructuralBuilder(), propertyPath, this.result); AddNewErrorsToList(CurrentBuffer().GetWarnings()); } else { bool hasProperty = !StringUtils.IsEmpty(tealBean.GetPropertyName()); if (hasProperty) { RenderNonStructuralAttribute(tealBean, relationship, constraints, dateTimeZone, dateTimeTimeZone); } else { if (ConformanceLevelUtil.IsMandatoryOrPopulated(relationship)) { IDictionary <string, string> attributes = null; if (ConformanceLevelUtil.IsPopulated(relationship)) { attributes = new Dictionary <string, string>(); attributes["nullFlavor"] = "NI"; } string placeholderXml = XmlRenderingUtils.CreateStartElement(relationship.Name, attributes, GetIndent(), true, true); CurrentBuffer().GetChildBuilder().Append(placeholderXml); } } } this.propertyPathNames.Pop(); }
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); } }
public FixedValueIfNotProvidedAttributeBeanBridge(TopLevelBeanBridgeWrapper _enclosing, AttributeBridge relationshipBridge , BareANY any) : base(relationshipBridge.GetRelationship(), any) { this._enclosing = _enclosing; this.relationshipBridge = relationshipBridge; }
public virtual void VisitAttribute(AttributeBridge tealBean, Relationship relationship, ConstrainedDatatype constraints, TimeZoneInfo dateTimeZone, TimeZoneInfo dateTimeTimeZone) { this.attributeVisited = true; }