public virtual void ShouldWriteMultipleCardinalityAttribute() { BeanBPrime beanB = new BeanBPrime(); BeanWrapper wrapper = new BeanWrapper(beanB); wrapper.Write(new Relationship("text", "ST", Cardinality.Create("0-10")), "This is my text"); Assert.AreEqual("This is my text", beanB.Text[0], "text"); }
public virtual void ShouldWriteSimpleAttribute() { BeanB beanB = new BeanB(); BeanWrapper wrapper = new BeanWrapper(beanB); wrapper.Write(new Relationship("text", "ST", Cardinality.Create("0-1")), "This is my text"); Assert.AreEqual("This is my text", beanB.Text, "text"); }
public virtual void ShouldWriteSimpleAssociation() { BeanB beanB = new BeanB(); BeanC beanC = new BeanC(); BeanWrapper wrapper = new BeanWrapper(beanC); wrapper.Write(new Relationship("textHolder", "ABCD_IN123456CA.BeanB", Cardinality.Create("0-1")), beanB); Assert.IsNotNull(beanC.BeanB, "bean b"); }
public virtual void ShouldCopyOriginalTextFromCVImplObjectToBean() { BeanD beanD = new BeanD(); BeanWrapper wrapper = new BeanWrapper(beanD); CVImpl cvImpl = new CVImpl(CodeResolverRegistry.Lookup <IntoleranceValue>("CODE")); cvImpl.OriginalText = ORIGINAL_TEXT; wrapper.Write(new Relationship("value", "CV", Cardinality.Create("0-1")), cvImpl); Assert.AreEqual(ORIGINAL_TEXT, ((CV)beanD.GetField("someCode")).OriginalText, "originalText"); }
/// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception> private void WriteAttribute(BeanWrapper bean, Hl7Source source, IList <XmlNode> nodes, Relationship relationship, string traversalName ) { if (relationship.Structural) { source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "Data found for relationship as an element but should have been an attribute. " + (nodes.IsEmpty() ? ("(" + relationship.Name + ")") : XmlDescriber.DescribePath(nodes[0])), CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[0])); } string type = DetermineType(nodes, relationship, source, source.GetResult()); ElementParser parser = (source.IsR2() ? ParserR2Registry.GetInstance().Get(type) : ParserRegistry.GetInstance().Get(type) ); if (parser != null) { try { ConstrainedDatatype constraints = source.GetService().GetConstraints(source.GetVersion(), relationship.ConstrainedType); ParseContextImpl context = new ParseContextImpl(relationship, constraints, source.GetVersion(), source.GetDateTimeZone(), source.GetDateTimeTimeZone(), CodeTypeRegistry.GetInstance(), source.IsCda()); BareANY @object = parser.Parse(context, nodes, source.GetResult()); ChangeDatatypeIfNecessary(type, relationship, @object); if (relationship.HasFixedValue()) { ValidateNonstructuralFixedValue(relationship, @object, source, nodes); } else { // fixed means nothing to write to bean bean.Write(relationship, @object); } } catch (InvalidCastException e) { source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "Can't parse relationship name=" + relationship. Name + ", traversalName=" + traversalName + " [" + e.Message + "]", CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[ 0])); } } else { source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "No parser for type \"" + type + "\". " + (nodes .IsEmpty() ? ("(" + relationship.Name + ")") : XmlDescriber.DescribePath(nodes[0])), CollUtils.IsEmpty(nodes) ? null : ( XmlElement)nodes[0])); } }
/// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception> private void WriteIndicator(BeanWrapper bean, Hl7Source source, IList <XmlNode> nodes, Relationship relationship, string traversalName ) { try { // if "false", as in the indicator element is absent, we will never actually get here :) // can't really parse a boolean here, but we need to check for null flavor NullFlavorHelper nullFlavorHelper = new NullFlavorHelper(relationship.Conformance, nodes.IsEmpty() ? null : nodes[0], new XmlToModelResult(), true); NullFlavor nullFlavor = nullFlavorHelper.ParseNullNode(); object value = (nullFlavor == null ? new BLImpl(!nodes.IsEmpty()) : new BLImpl(nullFlavor)); bean.Write(relationship, value); } catch (InvalidCastException e) { this.log.Info("Can't parse relationship name=" + relationship.Name + ", traversalName=" + traversalName + " [" + e.Message + "]"); } }
private void WriteAssociation(BeanWrapper beanWrapper, Hl7Source source, IList <XmlNode> nodes, Relationship relationship, string traversalName) { this.log.Debug("Writing association: traversalName=" + traversalName + ", relationshipType=" + relationship.Type); // 1. collapsed relationship if (relationship.Cardinality.Single && beanWrapper.IsAssociationMappedToSameBean(relationship)) { this.log.Debug("COLLAPSE RECURSE : " + traversalName + " as collapsed relationship to " + beanWrapper.GetWrappedType()); BeanWrapper childBeanWrapper = beanWrapper.CreateSubWrapper(relationship); WriteSpecialAssociation(childBeanWrapper, source, nodes, relationship); } else { //1b. trivial collapsed relationship with cardinality change (e.g. "RecordId" collapsed into "Location criteria" if (relationship.Cardinality.Multiple && beanWrapper.IsAssociationMappedToSameBean(relationship) && IsTypeWithSingleNonFixedRelationship (relationship, source)) { BeanWrapper childBeanWrapper = beanWrapper.CreateSubWrapper(relationship); foreach (XmlNode node in nodes) { WriteAssociation(childBeanWrapper, source, (XmlElement)node, relationship); } } else { // 2. initialized read-only association if (relationship.Cardinality.Single && beanWrapper.IsPreInitializedDelegate(relationship)) { this.log.Debug("READ-ONLY ASSOCIATION: " + traversalName + " as collapsed relationship to " + beanWrapper.GetWrappedType( )); BeanWrapper childBeanWrapper = new BeanWrapper(beanWrapper.GetInitializedReadOnlyAssociation(relationship)); WriteSpecialAssociation(childBeanWrapper, source, nodes, relationship); } else { // 3a. non-collapsed, multiple-cardinality choice or single-cardinality choice with node name same as choice name if (IsCdaChoice(nodes, relationship, source)) { IList <object> convertedBeans = HandleCdaChoice(nodes, traversalName, relationship, source); if (relationship.Cardinality.Multiple) { this.log.Debug("Special choice handling: WRITING MULTIPLE-CARDINALITY CHOICE: " + beanWrapper.GetWrappedType() + " property with annotation=" + traversalName + " - values=" + convertedBeans); beanWrapper.Write(relationship, convertedBeans); } else { if (relationship.Cardinality.Single && convertedBeans.IsEmpty()) { throw new MarshallingException("Special choice handling: Why is this empty? : " + relationship.Name + " on " + source.Type ); } else { this.log.Debug("Special choice handling: WRITING SINGLE: " + beanWrapper.GetWrappedType() + " property with annotation=" + traversalName + " - value=" + convertedBeans[0]); // may need to ignore values beyond the first; an error will have been logged beanWrapper.Write(relationship, convertedBeans[0]); } } } else { // 3. non-collapsed (including choice, specializationChild, and template type, handling for which is encapsulated in // Source.createChildSource()) if (relationship.TemplateRelationship || relationship.Choice || MessageBeanRegistry.GetInstance().IsMessagePartDefined(source .GetVersion(), relationship.Type)) { IList <object> convertedBeans = new List <object>(); foreach (XmlNode node in nodes) { XmlElement childNode = (XmlElement)node; Hl7PartSource childSource = source.CreatePartSource(relationship, childNode); this.log.Debug("RECURSE for node=" + source.GetCurrentElement().Name + " - relationship=" + relationship.Name + ", tarversalName=" + traversalName + ", of type: " + childSource.Type); object tealChild = MapPartSourceToTeal(childSource, relationship); convertedBeans.Add(tealChild); } if (relationship.Cardinality.Multiple) { this.log.Debug("WRITING MULTIPLE: " + beanWrapper.GetWrappedType() + " property with annotation=" + traversalName + " - values=" + convertedBeans); beanWrapper.Write(relationship, convertedBeans); } else { if (relationship.Cardinality.Single && convertedBeans.IsEmpty()) { throw new MarshallingException("Why is this empty? : " + relationship.Name + " on " + source.Type); } else { this.log.Debug("WRITING SINGLE: " + beanWrapper.GetWrappedType() + " property with annotation=" + traversalName + " - value=" + convertedBeans[0]); // may need to ignore values beyond the first; an error will have been logged beanWrapper.Write(relationship, convertedBeans[0]); } } } else { if (!ConformanceLevelUtil.IsOptional(relationship) && !IsFullyFixedType(relationship, source)) { this.log.Info("IGNORING: HL7 type " + relationship.Type + " with traversalName=" + traversalName + "(" + Describer.Describe (source.GetMessagePartName(), relationship) + ") cannot be mapped to any teal bean"); } } } } } } }