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; }
public void ValidateConstraints(Element element) { foreach(Constraint c in element.Constraints) { ValidateConstraint(element, c); } }
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; }
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); } }
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); }
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 Vector MoveTo(Element element, XPathNavigator node) { Vector clone = this.Clone(); clone.Element = element; clone.Node = node; return clone; }
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); } }
private bool _tryLinkToParent(Structure structure, Element element) { Element parent = profile.ParentOf(structure, element); if (parent != null) { parent.Children.Add(element); return true; } return false; }
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); }
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); } }
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); } }
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; }
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); }
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; }
public Structure StructureOf(Element element) { foreach (Structure structure in Structures) { if (structure.Elements.Contains(element)) return structure; } return null; }
public void ValidateElement(Element element) { ValidateAttribute(element); ValidateCardinality(element); ValidateConstraints(element); ValidateTypeRefs(element); }
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); } }
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"); }
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; }
public void ReadReference(Element element, XPathNavigator node) { element.BindingUri = OptionalValue(node, "f:definition/f:binding/f:referenceResource/f:reference/@value"); }
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++; } }
public Vector MoveTo(Element element) { Vector clone = this.Clone(); clone.Element = element; return clone; }
public Element ParentOf(Element element) { Structure structure = StructureOf(element); return ParentOf(structure, element); }
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; }
public Element ParentOf(Structure structure, Element element) { Path path = element.Path.Parent(); Element parent = structure.Elements.Find(e => e.Path.Equals(path)); return parent; }