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); } }
private void HarvestConstraints(Hl7.Fhir.Model.Profile.ElementDefinitionComponent source, Element target) { if (source.Constraint == null) return; foreach (Hl7.Fhir.Model.Profile.ElementDefinitionConstraintComponent c in source.Constraint) { Constraint constraint = new Constraint(); constraint.Name = c.Name ?? c.Key; constraint.XPath = c.Xpath; constraint.HumanReadable = c.Human; target.Constraints.Add(constraint); } }
public void ValidateConstraint(Vector vector, Constraint constraint) { if (constraint.IsValid) { try { bool valid = vector.Evaluate(constraint); if (valid) Log(Group.Constraint, Status.Valid, vector, "Node [{0}] conforms to constraint [{1}]", vector.Node.Name, constraint.Name); else Log(Group.Constraint, Status.Failed, vector, "Node [{0}] does not conform to constraint [{1}]: \"{2}\" ", vector.Node.Name, constraint.Name, constraint.HumanReadable); } catch (XPathException e) { Log(Group.Constraint, Status.Failed, vector, "Evaluation of constraint [{0}] evaluation failed: {1}", constraint.Name, e.Message); } } }
public bool Evaluate(Constraint constraint) { bool valid = (bool)Node.Evaluate(constraint.Expression); return valid; }