Exemplo n.º 1
0
 /// <summary>
 /// Constructs a postal address part with the supplied parameters.
 /// </summary>
 ///
 /// <param name="type_0">the part type</param>
 /// <param name="code_1">the c for the part type</param>
 /// <param name="originalValue">the value of the part type</param>
 public PostalAddressPart(PostalAddressPartType type_0, Code code_1,
                          String originalValue)
 {
     this.type      = type_0;
     this.code      = code_1;
     this.value_ren = originalValue;
 }
Exemplo n.º 2
0
 /// <summary>
 /// Constructs a postal address part with the supplied parameters.
 /// </summary>
 ///
 /// <param name="type_0">the part type</param>
 /// <param name="codedString">a cd string containing the c and value for this postal address part type</param>
 public PostalAddressPart(PostalAddressPartType type_0,
                          CodedString <Code> codedString)
 {
     this.type      = type_0;
     this.code      = (codedString == null) ? null : codedString.Code;
     this.value_ren = (codedString == null) ? null : codedString.Value;
 }
Exemplo n.º 3
0
        private PostalAddressPartType GetPostalAddressPartType(string type, XmlElement element, XmlToModelResult xmlToModelResult
                                                               )
        {
            PostalAddressPartType postalAddressPartType = null;

            try
            {
                postalAddressPartType = GetNamePartType <PostalAddressPartType>(type);
                if (postalAddressPartType != null && element.HasAttribute("partType"))
                {
                    string partTypeCode        = element.GetAttribute("partType");
                    string correctPartTypeCode = postalAddressPartType.CodeValue;
                    if (!StringUtils.Equals(correctPartTypeCode, partTypeCode))
                    {
                        string message = System.String.Format("Address partType attribute for element {0} must have a fixed value of {1}", type,
                                                              correctPartTypeCode);
                        RecordError(message, element, xmlToModelResult);
                    }
                }
            }
            catch (XmlToModelTransformationException)
            {
            }
            // don't re-throw exception (seems like overkill)!
            if (postalAddressPartType == null)
            {
                // error if part type not found
                RecordError("Address part type not valid: " + type, element, xmlToModelResult);
            }
            return(postalAddressPartType);
        }
Exemplo n.º 4
0
        private PostalAddress ParseAddressPartTypes(XmlNode node, XmlToModelResult xmlToModelResult)
        {
            PostalAddress result     = new PostalAddress();
            XmlNodeList   childNodes = node.ChildNodes;

            foreach (XmlNode childNode in new XmlNodeListIterable(childNodes))
            {
                if (IsNonBlankTextNode(childNode))
                {
                    string value = childNode.Value;
                    result.AddPostalAddressPart(new PostalAddressPart(value));
                }
                else
                {
                    if (childNode is XmlElement)
                    {
                        XmlElement element = (XmlElement)childNode;
                        string     name    = NodeUtil.GetLocalOrTagName(element);
                        if (!"useablePeriod".Equals(name))
                        {
                            PostalAddressPartType postalAddressPartType = GetPostalAddressPartType(name, element, xmlToModelResult);
                            string value = GetTextValue(name, element, xmlToModelResult);
                            if (postalAddressPartType != null)
                            {
                                result.AddPostalAddressPart(new PostalAddressPart(postalAddressPartType, value));
                            }
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 5
0
        private void ValidatePartTypeProvided(PostalAddressPartType partType, IList <PostalAddressPart> parts, XmlElement element,
                                              string propertyPath, Hl7Errors errors)
        {
            bool found = false;

            foreach (PostalAddressPart postalAddressPart in parts)
            {
                if (postalAddressPart.Type == partType)
                {
                    found = true;
                    break;
                }
            }
            if (!found)
            {
                CreateError("Part type '" + partType + "' is mandatory for AD.FULL", element, propertyPath, errors);
            }
        }
Exemplo n.º 6
0
        public virtual bool IsAllowableAddressPart(PostalAddressPartType partType, string type)
        {
            bool isBasic  = StandardDataType.AD_BASIC.Type.Equals(type);
            bool isFull   = StandardDataType.AD_FULL.Type.Equals(type);
            bool isSearch = StandardDataType.AD_SEARCH.Type.Equals(type);
            bool result   = true;

            if (partType == null)
            {
                // no part type : only allowed for BASIC (max 4, plus max 4 delimiter)
                if (!isBasic)
                {
                    result = false;
                }
            }
            else
            {
                if (partType == PostalAddressPartType.DELIMITER)
                {
                    if (isSearch)
                    {
                        result = false;
                    }
                }
                else
                {
                    if (isFull)
                    {
                        if (!PostalAddressPartType.IsFullAddressPartType(partType))
                        {
                            result = false;
                        }
                    }
                    else
                    {
                        if (!PostalAddressPartType.IsBasicAddressPartType(partType))
                        {
                            result = false;
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 7
0
        private PostalAddress ParseNode(XmlNode node, XmlToModelResult xmlToModelResult)
        {
            PostalAddress result     = new PostalAddress();
            XmlNodeList   childNodes = node.ChildNodes;

            foreach (XmlNode childNode in new XmlNodeListIterable(childNodes))
            {
                if (IsNonBlankTextNode(childNode))
                {
                    string value = childNode.Value;
                    result.AddPostalAddressPart(new PostalAddressPart(value));
                }
                else
                {
                    if (childNode is XmlElement)
                    {
                        XmlElement            element = (XmlElement)childNode;
                        string                name    = NodeUtil.GetLocalOrTagName(element);
                        PostalAddressPartType postalAddressPartType = GetPostalAddressPartType(name);
                        string                value        = GetTextValue(name, element, xmlToModelResult);
                        string                codeAsString = GetAttributeValue(childNode, "code");
                        // only for state/country
                        string codeSystem = GetAttributeValue(childNode, "codeSystem");
                        // only for state/country
                        Code code = CodeUtil.ConvertToCode(codeAsString, codeSystem);
                        if (postalAddressPartType == null)
                        {
                            // error if part type not found
                            RecordError("Address part type not valid: " + name, element, xmlToModelResult);
                        }
                        else
                        {
                            result.AddPostalAddressPart(new PostalAddressPart(postalAddressPartType, code, value));
                        }
                    }
                }
            }
            return(result);
        }
Exemplo n.º 8
0
        private void ValidatePostalAddressParts(PostalAddress postalAddress, string type, VersionNumber version, XmlElement element
                                                , string propertyPath, Hl7Errors errors)
        {
            int  countBlankParts = 0;
            bool isBasic         = StandardDataType.AD_BASIC.Type.Equals(type);
            bool isSearch        = StandardDataType.AD_SEARCH.Type.Equals(type);
            bool isFull          = StandardDataType.AD_FULL.Type.Equals(type);
            bool isAd            = StandardDataType.AD.Type.Equals(type);

            foreach (PostalAddressPart postalAddressPart in postalAddress.Parts)
            {
                int partLength = StringUtils.Length(postalAddressPart.Value);
                if (partLength > MAX_PART_LENGTH)
                {
                    // value max length of 80
                    CreateError("Address part types have a maximum allowed length of " + MAX_PART_LENGTH + " (length found: " + partLength +
                                ")", element, propertyPath, errors);
                }
                // error if part type not allowed
                PostalAddressPartType partType = postalAddressPart.Type;
                if (partType == null)
                {
                    countBlankParts++;
                    // no part type : only allowed for BASIC (max 4, plus max 4 delimiter)
                    if (!isBasic)
                    {
                        CreateError("Text without an address part only allowed for AD.BASIC", element, propertyPath, errors);
                    }
                }
                else
                {
                    if (partType == PostalAddressPartType.DELIMITER)
                    {
                        if (isSearch)
                        {
                            CreateError("Part type " + partType.Value + " is not allowed for AD.SEARCH", element, propertyPath, errors);
                        }
                    }
                    else
                    {
                        if (isFull || isAd)
                        {
                            if (!PostalAddressPartType.IsFullAddressPartType(partType))
                            {
                                CreateError("Part type " + partType.Value + " is not allowed for AD or AD.FULL", element, propertyPath, errors);
                            }
                        }
                        else
                        {
                            if (!PostalAddressPartType.IsBasicAddressPartType(partType))
                            {
                                CreateError("Part type " + partType.Value + " is not allowed for AD.BASIC or AD.SEARCH", element, propertyPath, errors);
                            }
                        }
                    }
                }
                // code/codesystem are only for state/country
                if (postalAddressPart.Code != null)
                {
                    if (partType != PostalAddressPartType.STATE && partType != PostalAddressPartType.COUNTRY)
                    {
                        CreateError("Part type " + partType.Value + " is not allowed to specify code or codeSystem", element, propertyPath, errors
                                    );
                    }
                }
            }
            if (isBasic && countBlankParts > MAX_DELIMITED_LINES)
            {
                CreateError("AD.BASIC is only allowed a maximum of " + MAX_DELIMITED_LINES + " delimiter-separated address lines (address lines without an address part type)"
                            , element, propertyPath, errors);
            }
            if (isSearch && CollUtils.IsEmpty(postalAddress.Parts))
            {
                CreateError("AD.SEARCH must specify at least one part type", element, propertyPath, errors);
            }
            // city/state/postalCode/country mandatory for AD.FULL
            // new change for R02.05 (pre-adopted by R02.04.03 AB) onwards - these fields are now only *required*, not mandatory
            if (isFull && !SpecificationVersion.IsExactVersion(SpecificationVersion.R02_04_03_AB, version))
            {
                ValidatePartTypeProvided(PostalAddressPartType.CITY, postalAddress.Parts, element, propertyPath, errors);
                ValidatePartTypeProvided(PostalAddressPartType.STATE, postalAddress.Parts, element, propertyPath, errors);
                ValidatePartTypeProvided(PostalAddressPartType.POSTAL_CODE, postalAddress.Parts, element, propertyPath, errors);
                ValidatePartTypeProvided(PostalAddressPartType.COUNTRY, postalAddress.Parts, element, propertyPath, errors);
            }
        }
Exemplo n.º 9
0
 /// <summary>
 /// Constructs a part with the given type and value.
 /// </summary>
 ///
 /// <param name="value">the value of the part type</param>
 /// <param name="type_0">the part type</param>
 public PostalAddressPart(String value_ren, PostalAddressPartType type_0)
 {
     this.type      = type_0;
     this.value_ren = value_ren;
 }
Exemplo n.º 10
0
 /// <summary>
 /// Constructs a postal address part with the supplied parameters.
 /// </summary>
 ///
 /// <param name="type_0">the part type</param>
 /// <param name="code_1">the c for the part type</param>
 public PostalAddressPart(PostalAddressPartType type_0, Code code_1)
 {
     this.type = type_0;
     this.code = code_1;
 }
Exemplo n.º 11
0
 private void AssertPostalAddressPartAsExpected(string message, PostalAddressPart postalAddressPart, PostalAddressPartType
                                                expectedType, string expectedValue)
 {
     Assert.AreEqual(expectedType, postalAddressPart.Type, message + " type");
     Assert.AreEqual(expectedValue, postalAddressPart.Value, message + " value");
 }