Пример #1
0
        public void ReadPath(Element element, XPathNavigator node)
        {
            string s = node.SelectSingleNode("f:path/@value", ns).Value;

            element.Path = new Path(s);
            element.Name = element.Path.ElementName;
        }
Пример #2
0
 public void ValidateConstraints(Element element)
 {
     foreach(Constraint c in element.Constraints)
     {
         ValidateConstraint(element, c);
     }
 }
Пример #3
0
 public TypeRef ReadTypeRef(Element element, XPathNavigator node)
 {
     TypeRef typeref = new TypeRef();
     typeref.Code = Value(node, "f:code/@value");
     typeref.ProfileName = OptionalValue(node, "f:profile/@value");
     return typeref;
 }
Пример #4
0
        public void ValidateTypeRef(Element element, TypeRef typeref)
        {

            // Test if the Surrect was able to link to the target structure.
            if (typeref.Structure != null)
            {
                report.Add("Reference", Kind.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)
            {
                report.Add("Reference", Kind.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
            {
                report.Add("Reference", Kind.Failed, "Invalid structure reference '{0}' in {1}", typeref.Code, element.Path);
            }
        }
Пример #5
0
        public void ValidateCardinality(Element element)
        {
            if (element.Cardinality.Min == null || element.Cardinality.Max == null)
            report.Add("Element", Kind.Incomplete,
                "Element [{0}] does not define it's cardinality", element.Path);

        }
Пример #6
0
 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;
 }
Пример #7
0
 public Vector MoveTo(Element element, XPathNavigator node)
 {
     Vector clone = this.Clone();
     clone.Element = element;
     clone.Node = node;
     return clone;
 }
Пример #8
0
 public void ReadTypeRefs(Element element, XPathNavigator node)
 {
     var iterator = node.Select("f:definition/f:type", ns);
     foreach(XPathNavigator n in iterator)
     {
         TypeRef typeref = ReadTypeRef(element, n);
         element.TypeRefs.Add(typeref);
     }
 }
Пример #9
0
 private bool _tryLinkToParent(Structure structure, Element element)
 {
     Element parent = profile.ParentOf(structure, element);
     if (parent != null)
     {
         parent.Children.Add(element);
         return true;
     }
     return false;
 }
Пример #10
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 = "*" };
     element.TypeRefs.Add(new TypeRef { Code = "Extension" });
     structure.Elements.Add(element);
 }
Пример #11
0
 public void ValidateConstraint(Element element, Constraint constraint)
 {
     if (constraint.IsValid)
     {
         report.Add("Constraint", Kind.Valid, "Constraint is valid");
     }
     else 
     {
          report.Add("Constraint", Kind.Failed, 
              "Constraint [{0}] ({1}) has an invalid XPath: {2}", 
              constraint.Name, constraint.HumanReadable, constraint.CompilerError.Message);
     }
 }
Пример #12
0
        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);
            }   
        }
Пример #13
0
        public static Structure Primitive(string name, string pattern, string nsprefix = FhirNamespaceManager.Fhir)
        {
            Structure structure = new Structure();
            structure.Name = name;

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

            AddExtensionElement(structure, element);
            return structure;
        }
Пример #14
0
 public void ReadElementDefinition(Element element, XPathNavigator node)
 {
     ReadPath(element, node);
     ReadReference(element, node);
     ReadTypeRefs(element, node);
     ReadElementRef(element, node);
     ReadCardinality(element, node);
     ReadConstraints(element, node);
 }
Пример #15
0
        public 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;
            
        }
Пример #16
0
 public Structure StructureOf(Element element)
 {
     foreach (Structure structure in Structures)
     {
         if (structure.Elements.Contains(element))
             return structure;
     }
     return null;
 }
Пример #17
0
 public void ValidateElement(Element element)
 {
     ValidateAttribute(element);
     ValidateCardinality(element);
     ValidateConstraints(element);
     ValidateTypeRefs(element);
 }
Пример #18
0
 public void ValidateAttribute(Element element)
 {
     if (element.IsAttribute)
     {
         if (element.Children != null)
             report.Add("Attribute", Kind.Failed, "Element [{0}] is has an attribute representation and can not have children", element);
     }
 }
Пример #19
0
 public void ValidateTypeRefs(Element element)
 {
     foreach (TypeRef t in element.TypeRefs)
     {
         ValidateTypeRef(element, t);
     }
 }
Пример #20
0
 public void ReadElementRef(Element element, XPathNavigator node)
 {
     element.ElementRefPath = OptionalValue(node, "f:definition/f:nameReference/@value");
 }
Пример #21
0
 private Slicing readSlicing(Element element, XPathNavigator node)
 {
     Slicing slicing = new Slicing();
     slicing.Discriminator = new Path(Value(node, "f:slicing/f:discriminator/@value"));
     slicing.Path = element.Path;
     //slicing.Rule = (SlicingRules)Enum.Parse(typeof(SlicingRules), Value(node, "f:slicing/f:rules/@value"));
     //slicing.Ordered = (Value(node, "f:slicing/f:ordered/@value").ToLower() == "true");
     return slicing;
 }
Пример #22
0
 public void ReadReference(Element element, XPathNavigator node)
 {
     element.BindingUri = OptionalValue(node, "f:definition/f:binding/f:referenceResource/f:reference/@value");
 }
Пример #23
0
 public void PatchSliceInfo(Element element)
 {
     Slicing slicing = Slicings.FirstOrDefault(s => s.Path.Equals(element.Path));
     if (slicing != null)
     {
         element.Discriminator = slicing.Discriminator;
         element.Slice = slicing.Count++;
     }
 }
Пример #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);
 }
Пример #26
0
 public Element ReadElement(XPathNavigator node)
 {
     Element element = new Element();
     if (IsSliced(node))
     {
         Slicing s = readSlicing(element, node);
         Slicings.Add(s);
     }
     ReadElementDefinition(element, node);
     
     return element;
 }
Пример #27
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;
 }