Esempio n. 1
0
        private void ProcessUnknownStructuralAttributes(ICollection <string> knownItems, XmlElement element, MessageVisitor visitor
                                                        )
        {
            XmlAttributeCollection attrs = element.Attributes;

            if (attrs != null)
            {
                foreach (XmlNode node in new XmlNamedNodeMapIterable(attrs))
                {
                    XmlAttribute item = (XmlAttribute)node;
                    if (IsIgnorable(item))
                    {
                    }
                    else
                    {
                        // skip it
                        if (!NamespaceUtil.IsHl7Node(item))
                        {
                        }
                        else
                        {
                            // skip it
                            if (!knownItems.Contains(item.Name))
                            {
                                knownItems.Add(item.Name);
                                // this call will intentionally fail fast with an error (since relationship is null)
                                visitor.VisitStructuralAttribute(element, item, null);
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        private void MapToTeal(Hl7Source source, BeanWrapper wrapper, Relationship relationship)
        {
            bool hasNullFlavor          = MapNodeAttributesToTeal(source, wrapper, relationship);
            IList <XmlElement> elements = NodeUtil.ToElementList(source.GetCurrentElement());

            if (hasNullFlavor && elements.IsEmpty())
            {
                // don't bother processing/validating any further
                // however, if there are elements and the association has a nullFlavor, something weird is going on so keep processing
                return;
            }
            // 1) "elements" contains the xml-order of the current part's relationships - note that this can have duplicates at this point
            // 2) "source" contains the message part being processed - this is not exposed
            // 3) "source" contains the result bean where errors can be stored - this *is* exposed
            // 4) need to watch choice/template cases (including choices with supertypes)
            // relationship.getType() is
            //		- choice type (if choice)
            //		- null (if template)
            //		- or the actual type
            // source.getMessagePartName() is
            //      - the choice option (if above was a choice)
            //      - the actual template type (if above was null)
            //      - or the actual type (which it is in all cases, really)
            IList <string>               xmlElementNamesInProvidedOrder = new List <string>();
            List <Relationship>          sortedRelationshipsMatchingUpToXmlElementNames = new List <Relationship>();
            IDictionary <string, string> resolvedRelationshipNames = new Dictionary <string, string>();
            int length = elements.Count;

            for (int j = 0; j < length; j++)
            {
                XmlElement      element  = elements[j];
                string          nodeName = NodeUtil.GetLocalOrTagName(element);
                IList <XmlNode> nodes    = new List <XmlNode>();
                nodes.Add(element);
                while (j + 1 < length && IsSameElementName(element, elements[j + 1]))
                {
                    nodes.Add(elements[++j]);
                }
                if (NamespaceUtil.IsHl7Node(element))
                {
                    Relationship xmlRelationship = source.GetRelationship(nodeName);
                    if (xmlRelationship != null)
                    {
                        ValidateNamespace(element, xmlRelationship, source);
                        // since we have a match we know that the xml name is correct; all we need the xmlRelationship for is sorting purposes
                        // however, for choice and template relationships, there will be an apparent mismatch between relationship names
                        xmlElementNamesInProvidedOrder.Add(nodeName);
                        sortedRelationshipsMatchingUpToXmlElementNames.Add(xmlRelationship);
                        resolvedRelationshipNames[GenerateRelationshipKey(xmlRelationship)] = nodeName;
                    }
                    Process(wrapper, source, nodes, nodeName);
                }
            }
            ValidateElementOrder(source, xmlElementNamesInProvidedOrder, sortedRelationshipsMatchingUpToXmlElementNames, resolvedRelationshipNames
                                 );
            // only do this if relationship not null and relationship not a null flavor???
            ValidateMissingMandatoryNonStructuralRelationships(source, resolvedRelationshipNames);
        }
Esempio n. 3
0
 private void ValidateNamespace(XmlNode node, Relationship xmlRelationship, Hl7Source source)
 {
     if (!NamespaceUtil.IsNamespaceCorrect(node, xmlRelationship))
     {
         string message = System.String.Format("Expected relationship {0}.{1} to have namespace {2} but was {3}", xmlRelationship.
                                               ParentType, xmlRelationship.Name, NamespaceUtil.GetExpectedNamespace(xmlRelationship), NamespaceUtil.GetActualNamespace(
                                                   node));
         Hl7Error hl7Error = new Hl7Error(Hl7ErrorCode.UNEXPECTED_NAMESPACE, ErrorLevel.ERROR, message, node);
         source.GetResult().AddHl7Error(hl7Error);
     }
 }
Esempio n. 4
0
        public ModelType(string typeName)
        {
            if (typeName == null)
            {
                throw new ArgumentNullException("typeName");
            }

            CodeType      = null;
            TypeName      = typeName;
            DisplayName   = typeName;
            ShortTypeName = NamespaceUtil.GetFullTypeNameShortTypeName(typeName);
        }
Esempio n. 5
0
        private bool MapNodeAttributesToTeal(Hl7Source source, BeanWrapper wrapper, Relationship relationship)
        {
            XmlElement       currentElement   = source.GetCurrentElement();
            NullFlavorHelper nullFlavorHelper = new NullFlavorHelper(relationship != null ? relationship.Conformance : Ca.Infoway.Messagebuilder.Xml.ConformanceLevel
                                                                     .OPTIONAL, currentElement, source.GetResult(), true);
            bool hasValidNullFlavorAttribute = nullFlavorHelper.HasValidNullFlavorAttribute();

            if (hasValidNullFlavorAttribute)
            {
                wrapper.WriteNullFlavor(source, relationship, nullFlavorHelper.ParseNullNode());
            }
            else
            {
                XmlAttributeCollection map = currentElement.Attributes;
                foreach (XmlNode attributeNode in new XmlNamedNodeMapIterable(map))
                {
                    Relationship attributeRelationship = source.GetRelationship(NodeUtil.GetLocalOrTagName(attributeNode));
                    if (!NamespaceUtil.IsHl7Node(attributeNode))
                    {
                    }
                    else
                    {
                        // quietly ignore it
                        if (attributeRelationship == null)
                        {
                            this.log.Info("Can't find NodeAttribute relationship named: " + attributeNode.Name);
                        }
                        else
                        {
                            ValidateNamespace(attributeNode, attributeRelationship, source);
                            if (attributeRelationship.HasFixedValue())
                            {
                                ValidateFixedValue(source, currentElement, (XmlAttribute)attributeNode, attributeRelationship);
                            }
                            wrapper.WriteNodeAttribute(attributeRelationship, attributeNode.Value, source.GetVersion(), source.IsR2());
                        }
                    }
                    ValidateMandatoryAttributesExist(source, currentElement);
                }
            }
            return(hasValidNullFlavorAttribute);
        }
Esempio n. 6
0
        private void ProcessUnknownChildElements(ICollection <string> knownItems, XmlElement element, MessageVisitor visitor)
        {
            IList <XmlElement> children = NodeUtil.ToElementList(element);

            foreach (XmlElement child in children)
            {
                if (!NamespaceUtil.IsHl7Node(child))
                {
                }
                else
                {
                    // ignore it
                    string localOrTagName = NodeUtil.GetLocalOrTagName(child);
                    if (!knownItems.Contains(localOrTagName))
                    {
                        knownItems.Add(localOrTagName);
                        // this call will intentionally fail fast with an error (since relationship is null)
                        visitor.VisitNonStructuralAttribute(element, Arrays.AsList(child), null);
                    }
                }
            }
        }