Пример #1
0
        /// <exception cref="System.Exception"></exception>
        public virtual void AssertToStringAsExpected(Ca.Infoway.Messagebuilder.Domainvalue.URLScheme urlScheme, string address, string
                                                     expectedValue)
        {
            TelecommunicationAddress telecommunicationAddress = new TelecommunicationAddress();

            telecommunicationAddress.UrlScheme = urlScheme;
            telecommunicationAddress.Address   = address;
            Assert.AreEqual(expectedValue, telecommunicationAddress.ToString(), "value");
        }
Пример #2
0
        public virtual string DetermineActualType(TelecommunicationAddress telecomAddress, string type, string specializationType
                                                  , VersionNumber version, XmlElement element, string propertyPath, Hl7Errors errors, bool logErrors)
        {
            string actualType     = type;
            bool   isTelAll       = StandardDataType.TEL_ALL.Type.Equals(type);
            bool   isTelPhonemail = StandardDataType.TEL_PHONEMAIL.Type.Equals(type);

            if (isTelAll || isTelPhonemail)
            {
                if (IsCeRxOrNewfoundland(version))
                {
                    Ca.Infoway.Messagebuilder.Domainvalue.URLScheme urlScheme = telecomAddress.UrlScheme;
                    if ("mailto".Equals(urlScheme == null ? null : urlScheme.CodeValue))
                    {
                        actualType = "TEL.EMAIL";
                    }
                    else
                    {
                        actualType = "TEL.PHONE";
                    }
                }
                else
                {
                    if (StringUtils.IsBlank(specializationType))
                    {
                        if (logErrors)
                        {
                            string errorMessage = System.String.Format("No specialization type provided. Specialization type of TEL.PHONE/TEL.EMAIL{0} must be specified for abstract data type {1}. Assuming TEL.PHONE"
                                                                       , isTelAll ? "/TEL.URI" : string.Empty, type);
                            CreateError(errorMessage, element, propertyPath, errors);
                        }
                        actualType = "TEL.PHONE";
                    }
                    else
                    {
                        if (!StandardDataType.TEL_PHONE.Type.Equals(specializationType) && !StandardDataType.TEL_EMAIL.Type.Equals(specializationType
                                                                                                                                   ) && !(StandardDataType.TEL_URI.Type.Equals(specializationType) && isTelAll))
                        {
                            if (logErrors)
                            {
                                string errorMessage = System.String.Format("Invalid specialization type provided. Specialization type of TEL.PHONE/TEL.EMAIL{0} must be specified for abstract data type {1}. Assuming TEL.PHONE"
                                                                           , isTelAll ? "/TEL.URI" : string.Empty, type);
                                CreateError(errorMessage, element, propertyPath, errors);
                            }
                            actualType = "TEL.PHONE";
                        }
                        else
                        {
                            actualType = specializationType;
                        }
                    }
                }
            }
            return(actualType);
        }
Пример #3
0
        internal static void AssertInvalidUrlScheme(TestableAbstractValueNullFlavorPropertyFormatter <TelecommunicationAddress> formatter
                                                    , Ca.Infoway.Messagebuilder.Domainvalue.URLScheme urlScheme, FormatContext context)
        {
            TelecommunicationAddress address = new TelecommunicationAddress();

            address.UrlScheme = urlScheme;
            address.Address   = "sometext";
            formatter.GetAttributeNameValuePairsForTest(context, address, new TELImpl());
            Assert.IsFalse(context.GetModelToXmlResult().IsValid());
            Assert.AreEqual(1, context.GetModelToXmlResult().GetHl7Errors().Count);
            Assert.IsTrue(context.GetModelToXmlResult().GetHl7Errors()[0].GetMessage().Contains("Scheme " + urlScheme.CodeValue + " is not valid"
                                                                                                ), "expected message");
        }
Пример #4
0
        /// <exception cref="System.Exception"></exception>
        internal static void AssertValidUrlScheme(TestableAbstractValueNullFlavorPropertyFormatter <TelecommunicationAddress> formatter
                                                  , Ca.Infoway.Messagebuilder.Domainvalue.URLScheme urlScheme, FormatContext context, string expected)
        {
            TelecommunicationAddress address = new TelecommunicationAddress();

            address.UrlScheme = urlScheme;
            address.Address   = "someAddress";
            IDictionary <string, string> result = formatter.GetAttributeNameValuePairsForTest(context, address, new TELImpl());

            Assert.IsTrue(context.GetModelToXmlResult().IsValid());
            Assert.AreEqual(1, result.Count, "map size");
            Assert.IsTrue(result.ContainsKey("value"), "key as expected");
            Assert.AreEqual(expected + address.Address, result.SafeGet("value"), "value as expected");
        }
Пример #5
0
        private TelecommunicationAddress ParseTelecommunicationAddress(XmlNode node, XmlToModelResult xmlToModelResult)
        {
            string value = GetAttributeValue(node, "value");

            if (StringUtils.IsBlank(value) && this.allowReference)
            {
                value = GetAttributeValue(node, "reference");
            }
            // remove the // that appear after the colon if necessary
            // e.g. file://monkey
            value = value == null ? null : System.Text.RegularExpressions.Regex.Replace(value, "://", ":");
            // anything before the FIRST colon is the URL scheme. Anything after it is the address.
            int    colonIndex = value == null ? -1 : value.IndexOf(':');
            string address    = null;

            Ca.Infoway.Messagebuilder.Domainvalue.URLScheme urlScheme = null;
            if (colonIndex == -1)
            {
                address = value;
            }
            else
            {
                address = Ca.Infoway.Messagebuilder.StringUtils.Substring(value, colonIndex + 1);
                string urlSchemeString = Ca.Infoway.Messagebuilder.StringUtils.Substring(value, 0, colonIndex);
                urlScheme = CodeResolverRegistry.Lookup <Ca.Infoway.Messagebuilder.Domainvalue.URLScheme>(urlSchemeString);
                if (urlScheme == null)
                {
                    string message = "Unrecognized URL scheme '" + urlSchemeString + "' in element " + XmlDescriber.DescribePath(node);
                    xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, message, (XmlElement)node));
                }
            }
            TelecommunicationAddress result = new TelecommunicationAddress();

            result.Address   = address;
            result.UrlScheme = urlScheme;
            // handle address uses
            string addressUses = GetAttributeValue(node, "use");

            if (addressUses != null)
            {
                StringTokenizer tokenizer = new StringTokenizer(addressUses);
                while (tokenizer.HasMoreElements())
                {
                    result.AddAddressUse(CodeResolverRegistry.Lookup <Ca.Infoway.Messagebuilder.Domainvalue.TelecommunicationAddressUse>(tokenizer
                                                                                                                                         .NextToken()));
                }
            }
            return(result);
        }
Пример #6
0
        private TelecommunicationAddress ParseValue(XmlNode node, XmlToModelResult xmlToModelResult)
        {
            string value = GetAttributeValue(node, "value");

            if (StringUtils.IsBlank(value))
            {
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "TEL elements must have a value or a nullFlavor."
                                                          , (XmlElement)node));
            }
            // remove the // that appear after the colon if necessary
            // e.g. file://monkey
            value = value == null ? null : System.Text.RegularExpressions.Regex.Replace(value, "://", ":");
            // anything before the FIRST colon is the URL scheme. Anything after it is the address.
            int    colonIndex = value == null ? -1 : value.IndexOf(':');
            string address    = null;

            Ca.Infoway.Messagebuilder.Domainvalue.URLScheme urlScheme = null;
            if (colonIndex == -1)
            {
                address = value;
            }
            else
            {
                address = Ca.Infoway.Messagebuilder.StringUtils.Substring(value, colonIndex + 1);
                string urlSchemeString = Ca.Infoway.Messagebuilder.StringUtils.Substring(value, 0, colonIndex);
                urlScheme = CodeResolverRegistry.Lookup <Ca.Infoway.Messagebuilder.Domainvalue.URLScheme>(urlSchemeString);
                if (urlScheme == null)
                {
                    urlScheme = CodeResolverRegistry.Lookup <Ca.Infoway.Messagebuilder.Domainvalue.URLScheme>(urlSchemeString.ToLower());
                    if (urlScheme == null)
                    {
                        string message = "Unrecognized URL scheme '" + urlSchemeString + "' in element " + XmlDescriber.DescribePath(node);
                        xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, message, (XmlElement)node));
                    }
                }
            }
            TelecommunicationAddress result = new TelecommunicationAddress();

            result.Address   = address;
            result.UrlScheme = urlScheme;
            return(result);
        }
Пример #7
0
        private void ValidateTelecomAddressScheme(TelecommunicationAddress telecomAddress, string type, Hl7BaseVersion baseVersion
                                                  , XmlElement element, string propertyPath, Hl7Errors errors)
        {
            Ca.Infoway.Messagebuilder.Domainvalue.URLScheme urlScheme = telecomAddress.UrlScheme;
            string urlSchemeValue = (urlScheme == null ? null : urlScheme.CodeValue.ToLower());

            if (urlScheme == null)
            {
                CreateError("TelecomAddress must have a valid URL scheme (e.g. 'http://')", element, propertyPath, errors);
            }
            else
            {
                if (StandardDataType.TEL.Type.Equals(type))
                {
                    // any known scheme should be ok here
                    ICollection <ICollection <string> > values = ALLOWABLE_SCHEMES_BY_TYPE.Values;
                    foreach (ICollection <string> set in values)
                    {
                        if (set.Contains(urlSchemeValue))
                        {
                            return;
                        }
                    }
                    // we're good here
                    CreateError("TelecomAddressScheme " + urlScheme.CodeValue + " is not valid for " + type, element, propertyPath, errors);
                }
                else
                {
                    ICollection <string> allowableSchemes = ALLOWABLE_SCHEMES_BY_TYPE.SafeGet(type);
                    if (allowableSchemes == null || !allowableSchemes.Contains(urlSchemeValue))
                    {
                        CreateError("TelecomAddressScheme " + urlScheme.CodeValue + " is not valid for " + type, element, propertyPath, errors);
                    }
                }
            }
        }
Пример #8
0
        /// <exception cref="System.Exception"></exception>
        private void AssertValidValueAttribute(string type, string value, string address, Ca.Infoway.Messagebuilder.Domainvalue.URLScheme
                                               urlScheme)
        {
            XmlNode node = CreateNode("<something value=\"" + value + "\" />");
            TelecommunicationAddress telecommunicationAddress = (TelecommunicationAddress) new TelR2ElementParser().Parse(CreateContext
                                                                                                                              (type, SpecificationVersion.V02R02), node, this.xmlResult).BareValue;

            Assert.IsTrue(this.xmlResult.IsValid());
            Assert.AreEqual(address, telecommunicationAddress.Address, "correct address returned");
            Assert.AreEqual(urlScheme.CodeValue, telecommunicationAddress.UrlScheme.CodeValue, "correct urlscheme returned");
        }