示例#1
0
 public Vector MoveTo(Element element, XPathNavigator node)
 {
     Vector clone = this.Clone();
     clone.Element = element;
     clone.Node = node;
     return clone;
 }
 private void _linkElementRef(Structure structure, Element element)
 {
     if (element.ElementRef == null && element.ElementRefPath != null)
     {
         element.ElementRef = specification.GetElementByPath(structure, element.ElementRefPath);
     }
 }
        public void ValidateTypeRef(Element element, TypeRef typeref)
        {

            // Test if the Surrect was able to link to the target structure.
            if (typeref.Structure != null)
            {
                Log(Group.Reference, Status.Valid, "Type reference to structure [{0}] is valid", typeref.Code);
                
                // Genest structuren valideren hoeft niet. Want alle structures worden al op hoofdniveau gevalideerd
                //ValidateStructure(typeref.Structure);

            }

            // Test if there is a reference at all
            else if (typeref.Code == null)
            {
                Log(Group.Reference, Status.Failed, "Missing a reference to a structure in element [{0}]", element.Name);
            }

            // Test if code is itself valid? If so, the reference valid but the target is missing.
            else if (Regex.IsMatch(typeref.Code, "[A-Za-z][A-Za-z0-9]*"))
            {
                // Collect first to avoid duplicates
                missingStructureNames.Add(typeref.Code);
            }

            // The code contains invalid characters
            else
            {
                Log(Group.Reference, Status.Failed, "Invalid structure reference '{0}' in {1}", typeref.Code, element.Path);
            }
        }
 public void ReadCardinality(Element element, XPathNavigator node)
 {
     Cardinality cardinality = new Cardinality();
     cardinality.Min = OptionalValue(node, "f:definition/f:min/@value");
     cardinality.Max = OptionalValue(node, "f:definition/f:max/@value");
     element.Cardinality = cardinality;
 }
 public void ValidateConstraints(Element element)
 {
     foreach(Constraint c in element.Constraints)
     {
         ValidateConstraint(element, c);
     }
 }
 private bool _tryLinkToParent(Structure structure, Element element)
 {
     Element parent = specification.ParentOf(structure, element);
     if (parent != null)
     {
         parent.Children.Add(element);
         return true;
     }
     return false;
 }
示例#7
0
 public static void AddExtensionElement(Structure structure, Element parent = null)
 {
     parent = parent  ?? structure.Root;
     string path = string.Format("{0}.extension", parent.Path); 
     Element element = new Element();
     element.Path = new Path(path);
     element.Name = "extension";
     element.Cardinality = new Cardinality { Min = "0", Max = "*" };
     TypeRef typeref = new TypeRef("Extension");
     UriHelper.SetTypeRefIdentification(structure, typeref);
     element.TypeRefs.Add(typeref);
     structure.Elements.Add(element);
 }
 public void ValidateConstraint(Element element, Constraint constraint)
 {
     if (constraint.IsValid)
     {
         
         Log(Group.Constraint, Status.Valid, "Constraint is valid");
     }
     else 
     {
          Log(Group.Constraint, Status.Failed, 
              "Constraint [{0}] ({1}) has an invalid XPath: {2}", 
              constraint.Name, constraint.HumanReadable, constraint.CompilerError.Message);
     }
 }
        public void ReadSliceValue(Element element, XPathNavigator node)
        {
            if (!element.Sliced)
                return;

            if (element.IsExtension) 
            {
                string xpath = string.Format("f:definition/f:type/f:profile/@value");
                string value = OptionalValue(node, xpath);
                element.SliceValue = value;
            }
            else if (element.Multi)
            {
                element.SliceValue = element.FixedValue;
            }
        }
 public void ReadFixedValue(Element element, XPathNavigator node)
 {
     string xpath;
     if (element.Multi)
     {
         xpath = string.Format("f:definition/*[starts-with(name(),'value')]/@value");
         string value = OptionalValue(node, xpath);
         element.FixedValue = value;
     }
     else
     {
         xpath = string.Format("f:definition/f:valueCoding/f:value/@value");
         string value = OptionalValue(node, xpath);
         element.FixedValue = value;
     }
 }
示例#11
0
        public static Structure Primitive(string name, IPrimitiveValidator validator, string nsprefix = FhirNamespaceManager.Fhir)
        {
            Structure structure = new Structure();
            structure.Type = name;
            UriHelper.SetStructureIdentification(structure, UriHelper.BASEPROFILE);

            Element element = new Element();
            element.Path = new Path(name);
            element.Name = name;
            element.IsPrimitive = true;
            element.PrimitiveValidator = validator;
            element.Cardinality = new Cardinality { Min = "1", Max = "1" };
            element.NameSpacePrefix = nsprefix;
            structure.Elements.Add(element);

            AddExtensionElement(structure, element);
            
            return structure;
        }
        public void ValidateCardinality(Element element)
        {
            if (element.Cardinality.Min == null || element.Cardinality.Max == null)
            Log(Group.Element, Status.Incomplete, "Element [{0}] does not define it's cardinality", element.Path);

        }
 public void ValidateElement(Element element)
 {
     ValidateAttribute(element);
     ValidateCardinality(element);
     ValidateConstraints(element);
     ValidateTypeRefs(element);
 }
 public void ValidateAttribute(Element element)
 {
     if (element.Representation == Representation.Attribute)
     {
         if (element.Children != null)
             Log(Group.Attribute, Status.Failed, "Element [{0}] is has an attribute representation and can not have children", element);
     }
 }
        public void InjectSlice(Element element, XPathNavigator node)
        {
            Slicing slicing = GetSlicingForElement(element);
            if (slicing != null)
            {
                if (IsSliceDefinitionNode(node))
                {
                    // todo: SlicingRules op de slicing-element-null implementeren
                }
                else
                {
                    element.Discriminator = slicing.Discriminator;
                    element.Slice = ++slicing.Count;
                }
            }

        }
 public void ReadElementRepresentation(Element element, XPathNavigator node)
 {
     string rep = OptionalValue(node, "f:representation/@value");
     element.Representation = (rep == "xmlAttr") ? Representation.Attribute : Representation.Element;
 }
示例#17
0
 public Structure StructureOf(Element element)
 {
     foreach (Structure structure in Structures)
     {
         if (structure.Elements.Contains(element))
             return structure;
     }
     return null;
 }
示例#18
0
        // todo: test resource boundary path following
        /// <summary>
        /// Follows the path into child elements and into other structures. The latter hasn't been tested yet
        /// </summary>
        /// <param name="origin">The element where the follow starts </param>
        /// <param name="path">The path to follow</param>
        /// <returns>The element (if found) at the end of the path, otherwise returns null</returns>
        public Element FollowPath(Element origin, Path path)
        {
            Segment segment = path.Segments.FirstOrDefault();

            if (segment == null)
            {
                // we have arrived at the matching path tail.
                return origin;
            }
            else
            {
                Element child = null;

                if (origin.Children.Count > 0)
                {
                    child = origin.Children.FirstOrDefault(e => segment.Match(e.Name));
                }
                else 
                {
                    TypeRef t = origin.TypeRefs.FirstOrDefault();
                    Structure structure = (t != null) ? t.Structure : null;
                    Element parent = (structure != null) ? structure.Root : null;

                    if (parent != null)
                    {
                        child = parent.Children.FirstOrDefault(e => segment.Match(e.Name));
                    }

                }
                
                if (child != null)
                {
                    Element target = FollowPath(child, path.ForChild());
                    return target;
                }

                return null;
            }
        }
        public void ReadElementDefinition(Element element, XPathNavigator node)
        {

            element.Path = ReadElementPath(node);
            element.Name = element.Path.ElementName;
            ReadElementRepresentation(element, node);
            ReadReference(element, node);
            ReadTypeRefs(element, node);
            ReadElementRef(element, node);
            ReadCardinality(element, node);
            ReadConstraints(element, node);
            ReadFixedValue(element, node);
            InjectSlice(element, node);
            ReadSliceValue(element, node);
        }
 public TypeRef ReadTypeRef(Element element, XPathNavigator node)
 {
     
     string code = Value(node, "f:code/@value");
     string profileUri = OptionalValue(node, "f:profile/@value");
     
     return new TypeRef(code, profileUri);
 }
 public void ReadReference(Element element, XPathNavigator node)
 {
     element.BindingUri = OptionalValue(node, "f:definition/f:binding/f:referenceResource/f:reference/@value");
 }
 public Element ReadElement(Structure structure, XPathNavigator node)
 {
     Element element = new Element();
     element.ID = id++;
     
     ReadElementDefinition(element, node);
     return element;
 }
示例#23
0
 public Element ParentOf(Structure structure, Element element)
 {
     Path path = element.Path.Parent();
     Element parent = structure.Elements.Find(e => e.Path.Equals(path));
     return parent;
 }
示例#24
0
 public Vector MoveTo(Element element)
 {
     Vector clone = this.Clone();
     clone.Element = element;
     return clone;
 }
示例#25
0
 public Element ParentOf(Element element)
 {
     Structure structure = StructureOf(element);
     return ParentOf(structure, element);
 }
        public void ReadConstraints(Element element, XPathNavigator node)
        {
            foreach (XPathNavigator nav in node.Select("f:definition/f:constraint", ns))
            {
                Constraint constraint = new Constraint();
                
                XPathNavigator xName = nav.SelectSingleNode("f:name/@value", ns);
                string key = OptionalValue(nav, "f:key/@value");
                constraint.Name = (xName != null) ? xName.Value : element.Path+", Key:"+key;

                constraint.XPath = nav.SelectSingleNode("f:xpath/@value", ns).Value;
                constraint.HumanReadable = OptionalValue(nav, "f:human/@value");
                element.Constraints.Add(constraint);
            }   
        }
        private void _addNameSpace(Element element)
        {
            if (element.HasTypeRef)
            {
                TypeRef typeref = element.TypeRefs.FirstOrDefault(t => t.Structure != null);
                if (typeref != null)
                {
                    element.NameSpacePrefix = typeref.Structure.NameSpacePrefix;
                }
            }

            if (element.NameSpacePrefix == null)
                element.NameSpacePrefix = FhirNamespaceManager.Fhir;
        }
 public void ValidateTypeRefs(Element element)
 {
     foreach (TypeRef t in element.TypeRefs)
     {
         ValidateTypeRef(element, t);
     }
 }
 public void ReadElementRef(Element element, XPathNavigator node)
 {
     element.ElementRefPath = OptionalValue(node, "f:definition/f:nameReference/@value");
 }
 internal Slicing GetSlicingForElement(Element element)
 {
     Slicing slicing = Slicings.FirstOrDefault(s => s.Path.Equals(element.Path));
     return slicing;
 }