Beispiel #1
0
        /// <exception cref="Ca.Infoway.Messagebuilder.Marshalling.HL7.XmlToModelTransformationException"></exception>
        protected override EntityName ParseNonNullNode(ParseContext context, XmlNode node, BareANY parseResult, Type expectedReturnType
                                                       , XmlToModelResult xmlToModelResult)
        {
            EntityName result = null;
            // The incoming xml should specify a specializationType or xsi:type in order to determine how to process the field. (CDA/R1 does allow for EN)
            // However, it should be possible to determine which concrete type to use by applying all known name parsers.
            string specializationType = GetSpecializationType(node);

            if (StringUtils.IsBlank(specializationType))
            {
                specializationType = GetXsiType(node);
            }
            string     upperCaseST = StringUtils.IsBlank(specializationType) ? string.Empty : specializationType.ToUpper();
            NameParser nameParser  = nameParsers.SafeGet(upperCaseST);

            if (nameParser == null && StringUtils.IsNotBlank(specializationType))
            {
                // log error based on bad ST/XT
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, "Could not determine appropriate parser to use for EN specializationType/xsi:type of: "
                                                          + specializationType, (XmlElement)node));
            }
            if (nameParser != null && nameParser.IsParseable(node, context))
            {
                result = (EntityName)nameParser.Parse(context, node, xmlToModelResult).BareValue;
            }
            else
            {
                string actualParserUsed = null;
                // try all known name parsers
                if (tnElementParser.IsParseable(node, context))
                {
                    actualParserUsed = "TN";
                    result           = (EntityName)tnElementParser.Parse(context, node, xmlToModelResult).BareValue;
                }
                else
                {
                    if (pnElementParser.IsParseable(node, context))
                    {
                        actualParserUsed = "PN";
                        result           = (EntityName)pnElementParser.Parse(context, node, xmlToModelResult).BareValue;
                    }
                    else
                    {
                        if (onElementParser.IsParseable(node, context))
                        {
                            actualParserUsed = "ON";
                            result           = (EntityName)onElementParser.Parse(context, node, xmlToModelResult).BareValue;
                        }
                        else
                        {
                            throw new XmlToModelTransformationException("Cannot figure out how to parse EN node " + node.ToString());
                        }
                    }
                }
                // need to log warning - not able to parse name as expected
                xmlToModelResult.AddHl7Error(new Hl7Error(Hl7ErrorCode.DATA_TYPE_ERROR, ErrorLevel.WARNING, "EN field has been handled as type "
                                                          + actualParserUsed, (XmlElement)node));
            }
            return(result);
        }