Esempio n. 1
0
 public Outcome(string type, Kind kind, Vector vector, string message, int nesting = 0)
 {
     this.Type = type;
     this.Kind = kind;
     this.Vector = vector;
     this.Message = message;
     this.Nesting = nesting;
 }
Esempio n. 2
0
 public void Add(string type, Kind kind, Vector vector, string message, params object[] args)
 {
     Outcome outcome;
     outcome.Type = type;
     outcome.Vector = vector;
     outcome.Message = string.Format(message, args);
     outcome.Kind = kind;
     outcome.Nesting = this.nesting;
     Outcomes.Add(outcome);
 }
Esempio n. 3
0
 public Vector Clone()
 {
     Vector clone = new Vector();
     clone.Structure = this.Structure;
     clone.Element = this.Element;
     clone.Node = this.Node.CreateNavigator();
     clone.NSM = this.NSM;
     clone.Origin = this.Origin;
     return clone;
 }
Esempio n. 4
0
 public static Vector Create(Structure structure, XPathNavigator node, XmlNamespaceManager nsm)
 {
     Vector vector = new Vector();
     vector.Structure = structure;
     vector.Element = (structure != null) ? structure.Root : null;
     vector.Node = node;
     vector.NSM = nsm;
     vector.Origin = vector; 
     return vector;
 }
 public void ValidateConstraint(Vector vector, Constraint constraint)
 {
     if (constraint.IsValid)
     {
         try
         {
             bool valid = vector.Evaluate(constraint);
             if (valid)
                 report.Add("Constraint", Kind.Valid, vector, "Node [{0}] conforms to constraint [{1}]", vector.Node.Name, constraint.Name);
             else
                 report.Add("Constraint", Kind.Failed, vector, "Node [{0}] does not conform to constraint [{1}]: {2} ", vector.Node.Name, constraint.Name, constraint.HumanReadable);
         }
         catch (XPathException e)
         {
             report.Add("Constraint", Kind.Failed, vector, "Evaluation of constraint [{0}] evaluation failed: {1}", constraint.Name, e.Message);
         }
     }
 }
        public void ValidateCode(Vector vector)
        {
            if (vector.Element.Binding == null)
                return;

            string value = vector.GetValue("@value");
            bool exists = vector.Element.Binding.Contains(value);
            
            if (exists)
            {
                report.Add("Coding", Kind.Valid, vector, "Code [{0}] ({1}) is valid [{2}]",
                    vector.Element.Name, vector.Element.Binding.System, value);
            }
            else
            {
                report.Add("Coding", Kind.Failed, vector, "Code [{0}] ({1}) contains a nonexisting value [{2}]",
                    vector.Element.Name, vector.Element.Binding.System, value);
            }
            
        }
 public void ValidateCardinality(Vector vector)
 {   
     int count = vector.Count(); 
     if (vector.Element.Cardinality.InRange(count))
     {
         report.Add("Cardinality", Kind.Valid, vector, "Cardinality ({1}) of element [{0}] is valid", vector.Element.Name, count);
     }
     else 
     {
         if (count == 0)
         {
             report.Add("Cardinality", Kind.Failed, vector,
              "Node [{0}] has missing child node [{1}] ",
              vector.NodePath(), vector.Element.Name);
         }
         else
         {
             report.Add("Cardinality", Kind.Failed, vector,
                 "The occurence {0} of node [{1}] under [{2}] is out of range ({3})",
                 count, vector.NodePath(), vector.Element.Name, vector.Element.Cardinality);
         }
     }
 }
 public void ValidateElementRef(Vector vector)
 {
     if (vector.Element.ElementRef != null)
     {
         Vector clone = vector.Clone();
         clone.Element = vector.Element.ElementRef;
         ValidateElement(clone);
     }
 }
 public void ValidateStructure(Vector vector)
 {
     if (vector.Structure == null)
     {
         report.Add("Structure", Kind.Unknown, vector, "Node [{0}] does not match a known structure. Further evaluation is impossible.", vector.Node.Name);
     }
     else
     {
         report.Start("structure", vector);
         ValidateElement(vector);
         report.End();
     }
 }
 public void ValidateElement(Vector vector)
 {
     report.Start("element", vector);
     ValidateCode(vector);
     ValidateConstraints(vector);
     ValidateStructures(vector);
     ValidatePrimitive(vector);
     ValidateForMissingStructures(vector);
     ValidateNodeChildren(vector);
     ValidateElementChildren(vector);
     ValidateElementRef(vector);
     ValidateSlices(vector);
     report.End();
 }
        public void ValidatePrimitive(Vector vector)
        {
            // fail. validation of primites should be done at the root element
            // this should be the root element of a structure
            if (!vector.Element.IsPrimitive)
                return;

            if (vector.Element.NameSpacePrefix != FhirNamespaceManager.Fhir)
                return;

            try
            {
                string value = vector.GetContent();
                string pattern = vector.Element.PrimitivePattern;
                if (Regex.IsMatch(value, pattern))
                {   
                    report.Add("Primitive", Kind.Valid, vector, "The value format ({0}) of primitive [{1}] is valid. ", vector.Element.Name, vector.Node.Name);
                }
                else
                {
                    report.Add("Primitive", Kind.Failed, vector, "The value format ({0}) of primitive [{1}] not valid: '{2}'", vector.Element.Name, vector.Node.Name, value);
                }
            }
            catch
            {
                report.Add("Primitive", Kind.Failed, vector, "The value of primitive [{0}] was not present.", vector.Node.Name);
            }
        }
        public void ValidateNodeChildren(Vector vector)
        {
            if (vector.Element.HasTypeRef) //element has a reference, so there are no Element children to validate to. 
                return;

            if (vector.Element.NameSpacePrefix != FhirNamespaceManager.Fhir)
            {
                report.Add("Element", Kind.Info, "Element [{0}] was skipped because it was not in the FHIR namespace.", vector.Element.Name);
                return;
            }

            foreach(Vector v in vector.NodeChildren)
            {
                ValidateNodeChild(v);
            }
        }
 public void ValidateSlices(Vector vector)
 {
      
 }
Esempio n. 14
0
 public void Start(string type, Vector vector)
 {
     Add(type, Kind.Start, vector);
     nesting++;
 }
 public void ValidateNodeChild(Vector vector)
 {
     string name = vector.Node.Name;
     if (!vector.Element.HasChild(name))
         report.Add("Element", Kind.Unknown, vector, "Element [{0}] contains undefined element [{1}]", vector.Element.Name, name);
 }
        public void ValidateElementChildren(Vector vector)
        {
            foreach (Vector v in vector.ElementChildren)
            {
                ValidateCardinality(v);

                foreach(Vector u in v.Matches)
                {
                    ValidateElement(u);
                }
            }
        }
 public void ValidateStructures(Vector vector)
 {
     foreach(Vector v in vector.ElementStructures)
     {
         ValidateStructure(v);
     }
 }
 public void ValidateForMissingStructures(Vector vector)
 {
     IEnumerable<string> missing = vector.Element.TypeRefs.Where(t => t.Structure == null).Select(t => t.Code);
     foreach (string s in missing)
     {
         report.Add("Structure", Kind.Skipped, vector, "Profile misses structure [{0}]. Evaluation is skipped.", s);
     }
 }
 public void ValidateConstraints(Vector vector)
 {
     foreach (Constraint constraint in vector.Element.Constraints)
     {
         ValidateConstraint(vector, constraint);
     }
 }
Esempio n. 20
0
 private void Add(string type, Kind kind, Vector vector)
 {
     Outcome outcome = new Outcome(type, kind, vector, null, this.nesting);
     
     Outcomes.Add(outcome);
 }