Пример #1
0
        public static string[] GetAllDateFormats(StandardDataType standardDataType, VersionNumber version)
        {
            if (standardDataType == null || version == null)
            {
                return(new string[0]);
            }
            IDictionary <StandardDataType, IList <string> > exceptionMap = TsDateFormats.versionFormatExceptions.SafeGet(version.GetBaseVersion
                                                                                                                             ());
            IList <string> formats = (exceptionMap == null ? null : exceptionMap.SafeGet(standardDataType));

            if (formats == null)
            {
                formats = TsDateFormats.formats.SafeGet(standardDataType);
            }
            return(CollUtils.IsEmpty(formats) ? new string[0] : formats.ToArray(new string[formats.Count]));
        }
Пример #2
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);
            }
        }
Пример #3
0
 /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
 public override BareANY Parse(ParseContext context, IList <XmlNode> nodes, XmlToModelResult xmlToModelResult)
 {
     xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Data type \"" + context.Type + "\" is not part of the pan-Canadian standard"
                                               , CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[0]));
     return(base.Parse(context, nodes, xmlToModelResult));
 }
Пример #4
0
 private void ValidateNonstructuralFixedValue(Relationship relationship, BareANY value, Hl7Source source, IList <XmlNode> nodes
                                              )
 {
     if (relationship.HasFixedValue())
     {
         bool valueProvided = (value != null && value.BareValue != null);
         bool valid         = valueProvided || (!ConformanceLevelUtil.IsMandatory(relationship) && !ConformanceLevelUtil.IsPopulated(relationship
                                                                                                                                     ));
         // optional and required fixed values do not have to provide a value, but if they do they must conform to specified value
         if (valueProvided)
         {
             if ("BL".Equals(relationship.Type) && value is BL)
             {
                 string valueAsString = ((BL)value).Value.ToString();
                 valid = relationship.FixedValue.EqualsIgnoreCase(valueAsString);
             }
             else
             {
                 if ("ST".Equals(relationship.Type) && value is ST)
                 {
                     string valueAsString = ((ST)value).Value.ToString();
                     valid = relationship.FixedValue.EqualsIgnoreCase(valueAsString);
                 }
                 else
                 {
                     if ("INT.POS".Equals(relationship.Type) && value is INT)
                     {
                         string valueAsString = ((INT)value).Value.ToString();
                         valid = relationship.FixedValue.EqualsIgnoreCase(valueAsString);
                     }
                     else
                     {
                         if (relationship.CodedType)
                         {
                             if (source.IsR2())
                             {
                                 if (GenericClassUtil.IsInstanceOfANY(value))
                                 {
                                     object value2 = GenericClassUtil.GetValueFromANY(value);
                                     Code   code   = value2 == null ? null : CodedTypeR2Helper.GetCode(value2);
                                     valid = (code != null && code.CodeValue != null && StringUtils.Equals(relationship.FixedValue, code.CodeValue));
                                 }
                             }
                             else
                             {
                                 if (value is CD)
                                 {
                                     Code code = ((CD)value).Value;
                                     valid = (code.CodeValue != null && StringUtils.Equals(relationship.FixedValue, code.CodeValue));
                                 }
                             }
                         }
                         else
                         {
                             source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.SYNTAX_ERROR, "Non-structural fixed-value attribute '" + relationship
                                                                         .Name + "' was of unexpected type '" + relationship.Type + "'", CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[0]));
                         }
                     }
                 }
             }
         }
         if (!valid)
         {
             source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.MANDATORY_FIELD_NOT_PROVIDED, "Fixed-value attribute '" + relationship
                                                         .Name + "' must have value '" + relationship.FixedValue + "'", CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[0]));
         }
     }
 }
Пример #5
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        private void WriteAttribute(BeanWrapper bean, Hl7Source source, IList <XmlNode> nodes, Relationship relationship, string traversalName
                                    )
        {
            if (relationship.Structural)
            {
                source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "Data found for relationship as an element but should have been an attribute. "
                                                            + (nodes.IsEmpty() ? ("(" + relationship.Name + ")") : XmlDescriber.DescribePath(nodes[0])), CollUtils.IsEmpty(nodes) ?
                                                            null : (XmlElement)nodes[0]));
            }
            string        type   = DetermineType(nodes, relationship, source, source.GetResult());
            ElementParser parser = (source.IsR2() ? ParserR2Registry.GetInstance().Get(type) : ParserRegistry.GetInstance().Get(type)
                                    );

            if (parser != null)
            {
                try
                {
                    ConstrainedDatatype constraints = source.GetService().GetConstraints(source.GetVersion(), relationship.ConstrainedType);
                    ParseContextImpl    context     = new ParseContextImpl(relationship, constraints, source.GetVersion(), source.GetDateTimeZone(),
                                                                           source.GetDateTimeTimeZone(), CodeTypeRegistry.GetInstance(), source.IsCda());
                    BareANY @object = parser.Parse(context, nodes, source.GetResult());
                    ChangeDatatypeIfNecessary(type, relationship, @object);
                    if (relationship.HasFixedValue())
                    {
                        ValidateNonstructuralFixedValue(relationship, @object, source, nodes);
                    }
                    else
                    {
                        // fixed means nothing to write to bean
                        bean.Write(relationship, @object);
                    }
                }
                catch (InvalidCastException e)
                {
                    source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "Can't parse relationship name=" + relationship.
                                                                Name + ", traversalName=" + traversalName + " [" + e.Message + "]", CollUtils.IsEmpty(nodes) ? null : (XmlElement)nodes[
                                                                    0]));
                }
            }
            else
            {
                source.GetResult().AddHl7Error(new Hl7Error(Hl7ErrorCode.INTERNAL_ERROR, "No parser for type \"" + type + "\". " + (nodes
                                                                                                                                    .IsEmpty() ? ("(" + relationship.Name + ")") : XmlDescriber.DescribePath(nodes[0])), CollUtils.IsEmpty(nodes) ? null : (
                                                                XmlElement)nodes[0]));
            }
        }
Пример #6
0
        private EntityNamePart GetFirstPart(PersonName name, PersonNamePartType type)
        {
            IList <EntityNamePart> parts = FilterParts(name, type);

            return((CollUtils.IsEmpty(parts)) ? null : parts[0]);
        }