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); }
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); } }