Exemplo n.º 1
0
        private OpenEhr.RM.DataTypes.Quantity.DateTime.DvDateTime ToDvDateTime(object value)
        {
            DesignByContract.Check.Require(value != null, string.Format(CommonStrings.XMustNotBeNull, "value"));
            OpenEhr.RM.DataTypes.Quantity.DateTime.DvDateTime dateTime = null;

            if (AssumedTypes.Iso8601DateTime.ValidIso8601DateTime(value.ToString()))
            {
                dateTime = new OpenEhr.RM.DataTypes.Quantity.DateTime.DvDateTime(value.ToString());
            }
            else
            {
                throw new ApplicationException(string.Format(
                                                   AmValidationStrings.XIsNotTypeYValue, value.ToString(), "Iso8601DateTime"));
            }

            return(dateTime);
        }
Exemplo n.º 2
0
        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);
            }
        }
Exemplo n.º 3
0
        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"));
            }
        }