private bool Or(OpenEhr.Paths.AssertionContext contextObj) { DesignByContract.Check.Require(!string.IsNullOrEmpty(this.Type), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "Type")); OpenEhr.Paths.AssertionContext leftObjContext = this.leftOperand.Evaluate(contextObj); if (leftObjContext == null || leftObjContext.Data == null) { return(false); } object leftObj = leftObjContext.Data; bool leftBoolValue = ToBoolean(leftObj); if (leftBoolValue) { return(true); } OpenEhr.Paths.AssertionContext rightObjContext = this.rightOperand.Evaluate(contextObj); if (rightObjContext == null) { throw new ApplicationException(string.Format(CommonStrings.XIsNull, "rightObjContext")); } if (rightObjContext.Data == null) { throw new ApplicationException(string.Format(CommonStrings.XIsNull, "rightObjContext.Data")); } object rightObj = rightObjContext.Data; bool rightBoolValue = ToBoolean(rightObj); return(rightBoolValue); }
/// <summary> /// An abstract function evaluating the obj against the ExprItem. /// </summary> /// <param name="obj">The object to be evaluated</param> /// <returns>Can be an object, a list of object or boolean</returns> internal object Evaluate(object obj) { OpenEhr.Paths.AssertionContext contextObj = new OpenEhr.Paths.AssertionContext(obj, null); OpenEhr.Paths.AssertionContext returnedObject = Evaluate(contextObj); if (returnedObject == null) return null; object result = returnedObject.Data; AssumedTypes.IList iList = result as AssumedTypes.IList; if (iList != null && iList.Count == 1) return iList[0]; return result; }
/// <summary> /// An abstract function evaluating the obj against the ExprItem. /// </summary> /// <param name="obj">The object to be evaluated</param> /// <returns>Can be an object, a list of object or boolean</returns> internal object Evaluate(object obj) { OpenEhr.Paths.AssertionContext contextObj = new OpenEhr.Paths.AssertionContext(obj, null); OpenEhr.Paths.AssertionContext returnedObject = Evaluate(contextObj); if (returnedObject == null) { return(null); } object result = returnedObject.Data; AssumedTypes.IList iList = result as AssumedTypes.IList; if (iList != null && iList.Count == 1) { return(iList[0]); } return(result); }
private bool Matches(OpenEhr.Paths.AssertionContext contextObj) { DesignByContract.Check.Require(!string.IsNullOrEmpty(this.Type), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "Type")); OpenEhr.Paths.AssertionContext leftObjContext = this.leftOperand.Evaluate(contextObj); if (leftObjContext == null || leftObjContext.Data == null) { return(false); } OpenEhr.Paths.AssertionContext rightObjContext = this.rightOperand.Evaluate(contextObj); if (rightObjContext == null) { throw new ApplicationException(string.Format(CommonStrings.XIsNull, "rightObjContext")); } if (rightObjContext.Data == null) { throw new ApplicationException(string.Format(CommonStrings.XIsNull, "rightObjContext.Data")); } object rightObj = rightObjContext.Data; object leftObj = leftObjContext.Data; string referenceTypeFromRightExpr = ((ExprLeaf)(this.RightOperand)).ReferenceType; referenceTypeFromRightExpr = referenceTypeFromRightExpr.ToLower(System.Globalization.CultureInfo.InvariantCulture); switch (referenceTypeFromRightExpr) { case "pattern": { return(Regex.Match(leftObj.ToString(), rightObj.ToString(), RegexOptions.Compiled | RegexOptions.Singleline).Success); } // TODO: LIST, INTERVAL ETC. default: throw new ApplicationException(string.Format( AmValidationStrings.TypeXNotSupportedByYOperator, referenceTypeFromRightExpr + " (referenceTypeFromRightExpr)", "Matches")); } }
internal override OpenEhr.Paths.AssertionContext Evaluate(OpenEhr.Paths.AssertionContext contextObj) { DesignByContract.Check.Require(contextObj != null, string.Format(CommonStrings.XMustNotBeNull, "contextObj")); switch (this.Operator.Value) { case OperatorKind.op_eq: return(new OpenEhr.Paths.AssertionContext(Equals(contextObj), contextObj)); case OperatorKind.op_matches: return(new OpenEhr.Paths.AssertionContext(Matches(contextObj), contextObj)); case OperatorKind.op_lt: return(new OpenEhr.Paths.AssertionContext(Less(contextObj), contextObj)); case OperatorKind.op_le: return(new OpenEhr.Paths.AssertionContext(LessEquals(contextObj), contextObj)); case OperatorKind.op_gt: return(new OpenEhr.Paths.AssertionContext(Greater(contextObj), contextObj)); case OperatorKind.op_ge: return(new OpenEhr.Paths.AssertionContext(GreaterEquals(contextObj), contextObj)); case OperatorKind.op_and: return(new OpenEhr.Paths.AssertionContext(And(contextObj), contextObj)); case OperatorKind.op_or: return(new OpenEhr.Paths.AssertionContext(Or(contextObj), contextObj)); case OperatorKind.op_ne: return(new OpenEhr.Paths.AssertionContext(NotEquals(contextObj), contextObj)); default: throw new NotSupportedException(this.Operator.ToString() + "operator not supported"); } }
internal abstract OpenEhr.Paths.AssertionContext Evaluate(OpenEhr.Paths.AssertionContext contextObj);
internal override OpenEhr.Paths.AssertionContext Evaluate(OpenEhr.Paths.AssertionContext contextObj) { throw new Exception("The method or operation is not implemented."); }
private bool Less(OpenEhr.Paths.AssertionContext contextObj) { DesignByContract.Check.Require(!string.IsNullOrEmpty(this.Type), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "Type")); OpenEhr.Paths.AssertionContext leftObjContext = this.leftOperand.Evaluate(contextObj); if (leftObjContext == null || leftObjContext.Data == null) { return(false); } OpenEhr.Paths.AssertionContext rightObjContext = this.rightOperand.Evaluate(contextObj); if (rightObjContext == null) { throw new ApplicationException(string.Format(CommonStrings.XIsNull, "rightObjContext")); } if (rightObjContext.Data == null) { throw new ApplicationException(string.Format(CommonStrings.XIsNull, "rightObjContext.Data")); } object rightObj = rightObjContext.Data; object leftObj = leftObjContext.Data; this.Type = this.Type.ToLower(System.Globalization.CultureInfo.InvariantCulture); switch (this.Type) { case "date_time": case "dv_date_time": case "date": case "dv_date": case "iso8601datetime": { OpenEhr.RM.DataTypes.Quantity.DateTime.DvDateTime leftDateTime = ToDvDateTime(leftObj); OpenEhr.RM.DataTypes.Quantity.DateTime.DvDateTime rightDateTime = ToDvDateTime(rightObj); return(leftDateTime < rightDateTime); } case "integer": { int leftInt = ToInt(leftObj); int rightInt = ToInt(rightObj); return(leftInt < rightInt); } case "double": case "float": { double leftDouble = ToDouble(leftObj); double rightDouble = ToDouble(rightObj); return(leftDouble < rightDouble); } case "duration": case "dv_duration": case "iso8601duration": OpenEhr.RM.DataTypes.Quantity.DateTime.DvDuration leftDuration = ToDvDuration(leftObj); OpenEhr.RM.DataTypes.Quantity.DateTime.DvDuration rightDuration = ToDvDuration(rightObj); return(leftDuration < rightDuration); case "time": case "dv_time": case "iso8601time": OpenEhr.RM.DataTypes.Quantity.DateTime.DvTime leftTime = ToDvTime(leftObj); OpenEhr.RM.DataTypes.Quantity.DateTime.DvTime rightTime = ToDvTime(rightObj); return(leftTime < rightTime); case "string": if (AssumedTypes.Iso8601DateTime.ValidIso8601DateTime(rightObj.ToString())) { this.Type = "DV_DATE_TIME"; } else if (AssumedTypes.Iso8601Time.ValidIso8601Time(rightObj.ToString())) { this.Type = "DV_TIME"; } else if (AssumedTypes.Iso8601Duration.ValidIso8601Duration(rightObj.ToString())) { this.Type = "DV_DURATION"; } else { throw new ApplicationException(string.Format( AmValidationStrings.OperatorXInvalidForTypeY, "<", "string")); } return(Less(contextObj)); default: throw new ApplicationException("Type is not supported in equal operator: " + this.Type); } }
private bool NotEquals(OpenEhr.Paths.AssertionContext contextObj) { DesignByContract.Check.Require(!string.IsNullOrEmpty(this.Type), string.Format(CommonStrings.XMustNotBeNullOrEmpty, "Type")); OpenEhr.Paths.AssertionContext leftObjContext = this.leftOperand.Evaluate(contextObj); OpenEhr.Paths.AssertionContext rightObjContext = this.rightOperand.Evaluate(contextObj); object rightObj = rightObjContext.Data; object leftObj = leftObjContext.Data; this.Type = this.Type.ToLower(System.Globalization.CultureInfo.InvariantCulture); switch (this.Type) { case "string": return(leftObj.ToString() != rightObj.ToString()); case "integer": { int leftInt = ToInt(leftObj); int rightInt = ToInt(rightObj); return(leftInt != rightInt); } case "double": case "float": { double leftDouble = ToDouble(leftObj); double rightDouble = ToDouble(rightObj); return(leftDouble != rightDouble); } case "boolean": case "bool": { bool leftBool = ToBoolean(leftObj); bool rightBool = ToBoolean(rightObj); return(leftBool != rightBool); } case "date_time": case "dv_date_time": case "date": case "dv_date": case "iso8601datetime": { OpenEhr.RM.DataTypes.Quantity.DateTime.DvDateTime leftDateTime = ToDvDateTime(leftObj); OpenEhr.RM.DataTypes.Quantity.DateTime.DvDateTime rightDateTime = ToDvDateTime(rightObj); return(leftDateTime != rightDateTime); } case "duration": case "dv_duration": case "iso8601duration": OpenEhr.RM.DataTypes.Quantity.DateTime.DvDuration leftDuration = ToDvDuration(leftObj); OpenEhr.RM.DataTypes.Quantity.DateTime.DvDuration rightDuration = ToDvDuration(rightObj); return(leftDuration != rightDuration); case "time": case "dv_time": case "iso8601time": OpenEhr.RM.DataTypes.Quantity.DateTime.DvTime leftTime = ToDvTime(leftObj); OpenEhr.RM.DataTypes.Quantity.DateTime.DvTime rightTime = ToDvTime(rightObj); return(leftTime != rightTime); default: throw new ApplicationException(string.Format( AmValidationStrings.TypeXNotSupportedByYOperator, this.Type, "NotEquals")); } }