private void RenderRealmCodes(PartBridge tealBean) { if (tealBean.GetRealmCode() != null) { string type = "CS"; PropertyFormatter formatter = this.formatterRegistry.Get(type); Relationship placeholderRelationship = new Relationship("realmCode", type, Cardinality.Create("0-*")); placeholderRelationship.DomainType = "Realm"; FormatContext context = Ca.Infoway.Messagebuilder.Marshalling.FormatContextImpl.Create(this.result, null, placeholderRelationship , version, null, null, null, this.isCda); foreach (Realm realm in tealBean.GetRealmCode()) { BareANY any = (BareANY)DataTypeFactory.CreateDataType(type, this.isCda && this.isR2); if (this.isR2) { ((BareANYImpl)any).BareValue = new CodedTypeR2 <Realm>(realm); } else { ((BareANYImpl)any).BareValue = realm; } string xmlFragment = formatter.Format(context, any, GetIndent()); CurrentBuffer().GetChildBuilder().Append(xmlFragment); } } }
private BareANY WrapWithHl7DataType(string hl7DataType, BareDiff diff) { try { BareANY hl7Value = (BareANY)DataTypeFactory.CreateDataType(hl7DataType, false); if (diff != null) { if (diff.BareValue != null) { ((BareANYImpl)hl7Value).BareValue = diff.BareValue; } else { hl7Value.NullFlavor = diff.NullFlavor; } } return(hl7Value); } catch (Exception e) { throw new ModelToXmlTransformationException("Unable to instantiate HL7 data type: " + hl7DataType, e); } }
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); } }