Exemplo n.º 1
0
        // Record Target Set up
        protected Patient CreateRecordTarget()
        {
            // Set the Patient we're querying against
            Patient patient = new Patient();

            // Set patient identifier(s)d
            patient.Id.Add(new Identifier("2.16.840.1.113883.3.19.3.163.1", "9880897949"));

            // Set Patient Name
            patient.PatientPerson      = new ActingPerson();
            patient.PatientPerson.Name = PersonName.CreateFirstNameLastName("Cyril", "Lambert");
            EntityNamePart prefix = new EntityNamePart("Mr.", PersonNamePartType.PREFIX);

            patient.PatientPerson.Name.Uses.Add(EntityNameUse.LEGAL);
            patient.PatientPerson.Name.AddNamePart(prefix);

            // Now set the patient's birthdate
            patient.PatientPerson.BirthTime = new PlatformDate(new DateTime(1949, 11, 05)); // client birth date

            // Set Gender
            patient.PatientPerson.AdministrativeGenderCode = AdministrativeGender.MALE;

            // Set the address for this patient
            PostalAddress addr = new PostalAddress();

            addr.Uses.Add(X_BasicPostalAddressUse.HOME);
            addr.Uses.Add(X_BasicPostalAddressUse.PHYSICAL);
            addr.Uses.Add(X_BasicPostalAddressUse.POSTAL);

            PostalAddressPart part = new PostalAddressPart();

            part.Type  = null;
            part.Value = "1234 Main Street";
            addr.AddPostalAddressPart(part);

            part       = new PostalAddressPart();
            part.Type  = PostalAddressPartType.CITY;
            part.Value = "Calgary";
            addr.AddPostalAddressPart(part);

            part       = new PostalAddressPart();
            part.Type  = PostalAddressPartType.STATE;
            part.Value = "Alberta";
            addr.AddPostalAddressPart(part);

            part       = new PostalAddressPart();
            part.Type  = PostalAddressPartType.COUNTRY;
            part.Value = "Canada";
            addr.AddPostalAddressPart(part);

            patient.Addr = addr;

            return(patient);
        }
Exemplo n.º 2
0
        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());
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public virtual void TestFormatValueNonNullMultipleAddressParts()
        {
            AdR2PropertyFormatter formatter     = new AdR2PropertyFormatter();
            PostalAddress         postalAddress = new PostalAddress();

            postalAddress.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "cityname"));
            postalAddress.AddPostalAddressPart(new PostalAddressPart("freeform"));
            postalAddress.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.DELIMITER, ","));
            postalAddress.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "ON"));
            string result = formatter.Format(GetContext("addr", "AD"), new ADImpl(postalAddress));

            Assert.IsTrue(this.result.IsValid());
            AssertXml("something in text node with goofy sub nodes allowed", "<addr><city>cityname</city>freeform<delimiter>,</delimiter><state>ON</state></addr>"
                      , result, true);
        }
Exemplo n.º 5
0
        public virtual void TestFormatValueReservedXmlChars()
        {
            AdR2PropertyFormatter formatter = new AdR2PropertyFormatter();
            PostalAddress         address   = new PostalAddress();

            address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "<cats think they're > humans & dogs 99% of the time/>"
                                                               ));
            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("something in text node", "<addr><city>&lt;cats think they&apos;re &gt; humans &amp; dogs 99% of the time/&gt;</city><state>ON</state><postalCode>H0H0H0</postalCode><country>Canada</country></addr>"
                      , result, true);
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        public virtual void TestFormatValueNonNullMultipleAddressParts()
        {
            AdPropertyFormatter formatter     = new AdPropertyFormatter();
            PostalAddress       postalAddress = new PostalAddress();

            postalAddress.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "cityname"));
            postalAddress.AddPostalAddressPart(new PostalAddressPart("freeform"));
            postalAddress.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.DELIMITER, ","));
            postalAddress.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "ON"));
            string result = formatter.Format(GetContext("addr", "AD.FULL"), new ADImpl(postalAddress));

            Assert.IsFalse(this.result.IsValid());
            Assert.AreEqual(3, this.result.GetHl7Errors().Count);
            // no parts without part type; postal code and country mandatory
            Assert.AreEqual("<addr><city>cityname</city><delimiter>,</delimiter><state>ON</state></addr>", result.Trim(), "something in text node with goofy sub nodes suppressed"
                            );
        }
Exemplo n.º 10
0
 private void Flush(StringBuilder builder, PostalAddress basicAddress)
 {
     if (builder.Length > 0)
     {
         basicAddress.AddPostalAddressPart(new PostalAddressPart(builder.ToString()));
         builder.Length = 0;
     }
 }
Exemplo n.º 11
0
        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");
        }
Exemplo n.º 12
0
        public virtual void TestFormatValueNonNullMultipleAddressPartsWithUseablePeriods()
        {
            AdR2PropertyFormatter formatter     = new AdR2PropertyFormatter();
            PostalAddress         postalAddress = new PostalAddress();

            postalAddress.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "cityname"));
            postalAddress.AddPostalAddressPart(new PostalAddressPart("freeform"));
            postalAddress.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.DELIMITER, ","));
            postalAddress.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.STATE, "ON"));
            postalAddress.IsNotOrdered = true;
            postalAddress.AddUseablePeriod(new DateWithPattern(DateUtil.GetDate(2007, 2, 23), "yyyyMMdd"), SetOperator.PERIODIC_HULL);
            postalAddress.AddUseablePeriod(new DateWithPattern(DateUtil.GetDate(2009, 9, 17), "yyyyMMdd"), null);
            postalAddress.AddUseablePeriod(new DateWithPattern(DateUtil.GetDate(2014, 6, 8), "yyyyMMdd"), SetOperator.INCLUDE);
            string result = formatter.Format(GetContext("addr", "AD"), new ADImpl(postalAddress));

            Assert.IsTrue(this.result.IsValid());
            AssertXml("addr with useable periods", "<addr isNotOrdered=\"true\"><city>cityname</city>freeform<delimiter>,</delimiter><state>ON</state><useablePeriod operator=\"P\" value=\"20070323\"/><useablePeriod operator=\"I\" value=\"20091017\"/><useablePeriod operator=\"I\" value=\"20140708\"/></addr>"
                      , result, true);
        }
Exemplo n.º 13
0
        public virtual void TestFormatValueNonNull()
        {
            AdR2PropertyFormatter formatter     = new AdR2PropertyFormatter();
            PostalAddress         postalAddress = new PostalAddress();

            postalAddress.AddPostalAddressPart(new PostalAddressPart("something"));
            string result = formatter.Format(GetContext("addr", "AD"), new ADImpl(postalAddress));

            Assert.IsTrue(this.result.IsValid());
            AssertXml("empty address node", "<addr>something</addr>", result, true);
        }
Exemplo n.º 14
0
        public virtual void TestFormatValidSearch()
        {
            AdPropertyFormatter formatter = new AdPropertyFormatter();
            PostalAddress       address   = new PostalAddress();

            address.AddPostalAddressPart(new PostalAddressPart(PostalAddressPartType.CITY, "Toronto"));
            string formattedAddress = formatter.Format(GetContext("addr", "AD.SEARCH"), new ADImpl(address));

            Assert.IsTrue(this.result.IsValid());
            Assert.AreEqual("<addr><city>Toronto</city></addr>", formattedAddress.Trim());
        }
Exemplo n.º 15
0
        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\""));
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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());
        }
Exemplo n.º 18
0
        public virtual void TestFormatValueNonNull()
        {
            AdPropertyFormatter formatter     = new AdPropertyFormatter();
            PostalAddress       postalAddress = new PostalAddress();

            postalAddress.AddPostalAddressPart(new PostalAddressPart("something"));
            string result = formatter.Format(GetContext("addr", "AD.FULL"), new ADImpl(postalAddress));

            Assert.IsFalse(this.result.IsValid());
            Assert.AreEqual(5, this.result.GetHl7Errors().Count);
            // city/state/postalcode/country are mandatory; part without types not allowed
            Assert.AreEqual("<addr></addr>", result.Trim(), "empty address node node");
        }
Exemplo n.º 19
0
        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));
        }