public virtual void TestFormatPostalAddressUses() { AdR2PropertyFormatter formatter = new AdR2PropertyFormatter(); PostalAddress address = new PostalAddress(); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.HOME); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.PHYSICAL); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "Toronto")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "ON")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.POSTAL_CODE, "H0H0H0")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.COUNTRY, "Canada")); // since the uses as a set, order is not guaranteed string result = formatter.Format(GetContext("addr", "AD"), new ADImpl(address)); Assert.IsTrue(this.result.IsValid()); Assert.IsTrue(result.StartsWith("<addr use=\""), "open tag"); Assert.IsTrue(result.Contains("\"H PHYS\"") || result.Contains("\"H PHYS\""), "H PHYS"); }
public virtual void TestFormatTooManyPostalAddressUses() { AdPropertyFormatter formatter = new AdPropertyFormatter(); PostalAddress address = new PostalAddress(); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.HOME); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.PHYSICAL); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.DIRECT); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.CONFIDENTIAL); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "Toronto")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "ON")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.POSTAL_CODE, "H0H0H0")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.COUNTRY, "Canada")); string result = formatter.Format(GetContext("addr", "AD.FULL"), new ADImpl(address)); Assert.IsFalse(this.result.IsValid()); Assert.AreEqual(1, this.result.GetHl7Errors().Count); Assert.IsTrue(result.StartsWith("<addr use=\""), "open tag"); Assert.IsTrue(result.Contains("\"H PHYS DIR CONF\"")); }
/// <exception cref="System.Exception"></exception> private void AssertValidAddressUse(x_BasicPostalAddressUse use) { PostalAddress postalAddress = new PostalAddress(); postalAddress.AddUse(use); string result = new AdBasicPropertyFormatter().Format(GetContext("address", "AD.BASIC"), new ADImpl(postalAddress)); Assert.IsTrue(this.result.IsValid()); string expected = "<address use=\"" + use.CodeValue + "\">" + SystemUtils.LINE_SEPARATOR + "</address>" + SystemUtils.LINE_SEPARATOR; AssertXmlEquals("use formatted properly", expected, result); }
public virtual void TestFormatManyPostalAddressUses() { AdR2PropertyFormatter formatter = new AdR2PropertyFormatter(); PostalAddress address = new PostalAddress(); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.HOME); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.PHYSICAL); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.DIRECT); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.CONFIDENTIAL); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "Toronto")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "ON")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.POSTAL_CODE, "H0H0H0")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.COUNTRY, "Canada")); string result = formatter.Format(GetContext("addr", "AD"), new ADImpl(address)); Assert.IsTrue(this.result.IsValid()); Assert.IsTrue(result.StartsWith("<addr use=\""), "open tag"); Assert.IsTrue(result.Contains("\"H PHYS DIR CONF\"")); AssertXml("xml as expected", "<addr use=\"H PHYS DIR CONF\"><city>Toronto</city><state>ON</state><postalCode>H0H0H0</postalCode><country>Canada</country></addr>" , result, true); }
public virtual void TestFormatSearchCannotHaveUses() { AdPropertyFormatter formatter = new AdPropertyFormatter(); PostalAddress address = new PostalAddress(); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.HOME); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "Toronto")); string formattedAddress = formatter.Format(GetContext("addr", "AD.SEARCH"), new ADImpl(address)); Assert.IsFalse(this.result.IsValid()); Assert.AreEqual(1, this.result.GetHl7Errors().Count); Assert.AreEqual("<addr><city>Toronto</city></addr>", formattedAddress.Trim()); }
public virtual void TestFormatDuplicatePartTypesAllowed() { // confirmed via Sam that all part types can occur multiple times AdR2PropertyFormatter formatter = new AdR2PropertyFormatter(); PostalAddress address = new PostalAddress(); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.HOME); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "Toronto")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "ON")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.POSTAL_CODE, "H0H0H0")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.COUNTRY, "Canada")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.COUNTRY, "US")); formatter.Format(GetContext("addr", "AD"), new ADImpl(address)); Assert.IsTrue(this.result.IsValid()); }
public virtual void TestFormatInvalidUseOfCodeAndCodeSystem() { AdPropertyFormatter formatter = new AdPropertyFormatter(); PostalAddress address = new PostalAddress(); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.HOME); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, CodeUtil.ConvertToCode("Toronto", "1.2.3.4.5" ))); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "ON")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.POSTAL_CODE, "H0H0H0")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.COUNTRY, "Canada")); formatter.Format(GetContext("addr", "AD.FULL"), new ADImpl(address)); Assert.IsFalse(this.result.IsValid()); Assert.AreEqual(1, this.result.GetHl7Errors().Count); }
public virtual void TestFormatWeirdUseOfCodeAndCodeSystem() { AdR2PropertyFormatter formatter = new AdR2PropertyFormatter(); PostalAddress address = new PostalAddress(); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.HOME); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "Toronto")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "ON")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.POSTAL_CODE, "H0H0H0")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.COUNTRY, "Canada")); string result = formatter.Format(GetContext("addr", "AD"), new ADImpl(address)); Assert.IsTrue(this.result.IsValid()); AssertXml("xml as expected", "<addr use=\"H\"><city>Toronto</city><state>ON</state><postalCode>H0H0H0</postalCode><country>Canada</country></addr>" , result, true); }
public virtual void TestFormatInvalidPartTypeForFull() { AdPropertyFormatter formatter = new AdPropertyFormatter(); PostalAddress address = new PostalAddress(); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.HOME); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.DELIVERY_INSTALLATION_TYPE, "this isn't allowed" )); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "Toronto")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "ON")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.POSTAL_CODE, "H0H0H0")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.COUNTRY, "Canada")); formatter.Format(GetContext("addr", "AD.FULL"), new ADImpl(address)); Assert.IsFalse(this.result.IsValid()); Assert.AreEqual(1, this.result.GetHl7Errors().Count); }
public virtual void TestFormatValueTooLong() { AdPropertyFormatter formatter = new AdPropertyFormatter(); PostalAddress address = new PostalAddress(); address.AddUse(Ca.Infoway.Messagebuilder.Domainvalue.Basic.X_BasicPostalAddressUse.HOME); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "12345678901234567890123456789012345678901234567890123456789012345678901234567890" )); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "123456789012345678901234567890123456789012345678901234567890123456789012345678901" )); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.POSTAL_CODE, "H0H0H0")); address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.COUNTRY, "Canada")); formatter.Format(GetContext("addr", "AD.FULL"), new ADImpl(address)); Assert.IsFalse(this.result.IsValid()); Assert.AreEqual(1, this.result.GetHl7Errors().Count); }
protected sealed override string FormatNonNullValue(FormatContext context, PostalAddress postalAddress, int indentLevel) { Hl7BaseVersion baseVersion = context.GetVersion().GetBaseVersion(); string dataType = context.Type; AbstractAdPropertyFormatter.AD_VALIDATION_UTILS.ValidatePostalAddress(postalAddress, dataType, context.GetVersion(), null , context.GetPropertyPath(), context.GetModelToXmlResult()); PostalAddress basicAddress = new PostalAddress(); StringBuilder builder = new StringBuilder(); // remove any non-basic address parts foreach (PostalAddressPart part in EmptyIterable <object> .NullSafeIterable(postalAddress.Parts)) { if (part.Type == PostalAddressPartType.CITY || part.Type == PostalAddressPartType.STATE || part.Type == PostalAddressPartType .COUNTRY || part.Type == PostalAddressPartType.POSTAL_CODE || part.Type == PostalAddressPartType.DELIMITER) { Flush(builder, basicAddress); basicAddress.AddPostalAddressPart(part); } else { if (StringUtils.IsNotBlank(part.Value)) { if (builder.Length > 0) { builder.Append(" "); } builder.Append(part.Value); } } } Flush(builder, basicAddress); foreach (Ca.Infoway.Messagebuilder.Domainvalue.PostalAddressUse use in postalAddress.Uses) { if (AbstractAdPropertyFormatter.AD_VALIDATION_UTILS.IsAllowableUse(dataType, use, baseVersion)) { basicAddress.AddUse(use); } } return(base.FormatNonNullValue(context, basicAddress, indentLevel)); }