/// <summary>
        /// Creates a new instance of the <see cref="WeightValue"/> class by subtracting
        /// the operand from this weight value.
        /// </summary>
        ///
        /// <param name="value1">
        /// The weight value from which <paramref name="value2"/> is to
        /// be subtracted.
        /// </param>
        ///
        /// <param name="value2">
        /// The weight value to subtract from <paramref name="value1"/>.
        /// </param>
        ///
        /// <remarks>
        /// This constructor creates a <see cref="WeightValue"/> that is
        /// the difference between this weight value and the operand. The value is
        /// always subtracted. If both operands have a
        /// <see cref="DisplayValue"/> set and they have the same
        /// <see cref="DisplayValue.UnitsCode"/>,
        /// then the result sets DisplayValue with the same units code and the
        /// value is the difference between the operands.
        /// </remarks>
        ///
        /// <exception cref="InvalidOperationException">
        /// The <paramref name="value2"/> parameter is larger than the <paramref name="value1"/> parameter.
        /// </exception>
        ///
        public static WeightValue operator -(
            WeightValue value1,
            WeightValue value2)
        {
            WeightValue newValue = new WeightValue();

            if (value2.Value > value1.Value)
            {
                throw new InvalidOperationException(Resources.WeightResultNotPositive);
            }

            newValue.Value = value1.Value - value2.Value;

            if (value1.DisplayValue != null && value2.DisplayValue != null)
            {
                if (value1.DisplayValue.UnitsCode == value2.DisplayValue.UnitsCode ||
                    value1.DisplayValue.Units == value2.DisplayValue.Units)
                {
                    newValue.DisplayValue           = new DisplayValue();
                    newValue.DisplayValue.UnitsCode = value1.DisplayValue.UnitsCode;
                    newValue.DisplayValue.Value     =
                        value1.DisplayValue.Value - value2.DisplayValue.Value;
                    newValue.DisplayValue.Units = value1.DisplayValue.Units;
                }
            }

            return(newValue);
        }
        /// <summary>
        /// Populates this <see cref="Weight"/> instance from the data in the XML.
        /// </summary>
        ///
        /// <param name="typeSpecificXml">
        /// The XML to get the weight data from.
        /// </param>
        ///
        /// <exception cref="InvalidOperationException">
        /// The first node in <paramref name="typeSpecificXml"/> is not
        /// a weight node.
        /// </exception>
        ///
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            XPathNavigator weightNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode("weight");

            Validator.ThrowInvalidIfNull(weightNav, Resources.WeightUnexpectedNode);

            _when = new HealthServiceDateTime();
            _when.ParseXml(weightNav.SelectSingleNode("when"));

            _value = new WeightValue();
            _value.ParseXml(weightNav.SelectSingleNode("value"));
        }
Example #3
0
        /// <summary>
        /// Populates this <see cref="WeightGoal"/> instance from the data in the XML.
        /// </summary>
        ///
        /// <param name="typeSpecificXml">
        /// The XML to get the weight goal data from.
        /// </param>
        ///
        /// <exception cref="InvalidOperationException">
        /// The first node in <paramref name="typeSpecificXml"/> is not
        /// a weight-goal node.
        /// </exception>
        ///
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            XPathNavigator weightGoalNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode("weight-goal");

            Validator.ThrowInvalidIfNull(weightGoalNav, Resources.WeightGoalUnexpectedNode);

            XPathNavigator initialNav =
                weightGoalNav.SelectSingleNode("initial");

            if (initialNav != null)
            {
                _initialWeight = new WeightValue();
                _initialWeight.ParseXml(initialNav);
            }

            XPathNavigator minNav =
                weightGoalNav.SelectSingleNode("minimum");

            if (minNav != null)
            {
                _minWeight = new WeightValue();
                _minWeight.ParseXml(minNav);
            }

            XPathNavigator maxNav =
                weightGoalNav.SelectSingleNode("maximum");

            if (maxNav != null)
            {
                _maxWeight = new WeightValue();
                _maxWeight.ParseXml(maxNav);
            }

            XPathNavigator goalNav =
                weightGoalNav.SelectSingleNode("goal-info");

            if (goalNav != null)
            {
                _goal = new Goal();
                _goal.ParseXml(goalNav);
            }
        }
        private static void AppendWeightValue(StringBuilder result, WeightValue value, string labelFormat)
        {
            string unitsString = string.Empty;
            string valueString;

            if (value.DisplayValue != null)
            {
                valueString = value.DisplayValue.ToString();
            }
            else
            {
                valueString = (value.Value * 1000).ToString(CultureInfo.InvariantCulture);
                unitsString = Resources.DietaryDailyIntakeToStringUnitGrams;
            }

            result.AppendFormat(
                labelFormat,
                valueString,
                unitsString);
        }
 /// <summary>
 /// Creates a new instance of the <see cref="Weight"/> class with the
 /// specified date/time and weight.
 /// </summary>
 ///
 /// <param name="when">
 /// The date/time when the weight measurement occurred.
 /// </param>
 ///
 /// <param name="weight">
 /// The person's weight.
 /// </param>
 ///
 /// <exception cref="ArgumentNullException">
 /// The <paramref name="when"/> or <paramref name="weight"/> parameter is <b>null</b>.
 /// </exception>
 ///
 public Weight(HealthServiceDateTime when, WeightValue weight)
     : base(TypeId)
 {
     When  = when;
     Value = weight;
 }
        /// <summary>
        /// Populates this <see cref="DietaryDailyIntake"/> instance from the
        /// data in the XML.
        /// </summary>
        ///
        /// <param name="typeSpecificXml">
        /// The XML to get the dietary intake data from.
        /// </param>
        ///
        /// <exception cref="InvalidOperationException">
        /// The first node in <paramref name="typeSpecificXml"/> is not
        /// a <see cref="DietaryDailyIntake"/> node.
        /// </exception>
        ///
        protected override void ParseXml(IXPathNavigable typeSpecificXml)
        {
            XPathNavigator intakeNav =
                typeSpecificXml.CreateNavigator().SelectSingleNode(
                    "dietary-intake-daily");

            Validator.ThrowInvalidIfNull(intakeNav, Resources.DietaryDailyIntakeUnexpectedNode);

            _when = new HealthServiceDate();
            _when.ParseXml(intakeNav.SelectSingleNode("when"));

            XPathNavigator caloriesNav =
                intakeNav.SelectSingleNode("calories");

            if (caloriesNav != null)
            {
                _calories = caloriesNav.ValueAsInt;
            }

            XPathNavigator totalFatNav =
                intakeNav.SelectSingleNode("total-fat");

            if (totalFatNav != null)
            {
                _totalFat = new WeightValue();
                _totalFat.ParseXml(totalFatNav);
            }

            XPathNavigator satFatNav =
                intakeNav.SelectSingleNode("saturated-fat");

            if (satFatNav != null)
            {
                _saturatedFat = new WeightValue();
                _saturatedFat.ParseXml(satFatNav);
            }

            XPathNavigator transFatNav =
                intakeNav.SelectSingleNode("trans-fat");

            if (transFatNav != null)
            {
                _transFat = new WeightValue();
                _transFat.ParseXml(transFatNav);
            }

            XPathNavigator proteinNav =
                intakeNav.SelectSingleNode("protein");

            if (proteinNav != null)
            {
                _protein = new WeightValue();
                _protein.ParseXml(proteinNav);
            }

            XPathNavigator totalCarbsNav =
                intakeNav.SelectSingleNode("total-carbohydrates");

            if (totalCarbsNav != null)
            {
                _totalCarbs = new WeightValue();
                _totalCarbs.ParseXml(totalCarbsNav);
            }

            XPathNavigator fiberNav =
                intakeNav.SelectSingleNode("dietary-fiber");

            if (fiberNav != null)
            {
                _fiber = new WeightValue();
                _fiber.ParseXml(fiberNav);
            }

            XPathNavigator sugarsNav =
                intakeNav.SelectSingleNode("sugars");

            if (sugarsNav != null)
            {
                _sugars = new WeightValue();
                _sugars.ParseXml(sugarsNav);
            }

            XPathNavigator sodiumNav =
                intakeNav.SelectSingleNode("sodium");

            if (sodiumNav != null)
            {
                _sodium = new WeightValue();
                _sodium.ParseXml(sodiumNav);
            }

            XPathNavigator cholesterolNav =
                intakeNav.SelectSingleNode("cholesterol");

            if (cholesterolNav != null)
            {
                _cholesterol = new WeightValue();
                _cholesterol.ParseXml(cholesterolNav);
            }
        }