/// <summary>
        /// Checks the database to see if the PharmCalcAccept table contains a record indicating that the
        /// calculation factor passed has been accepted..
        /// </summary>
        /// <param name="context"></param>
        protected override void DoWork(CodeActivityContext context)
        {
            int    rxoSetId   = RxoSetId.Get(context);
            double calcFactor = CalcFactor.Get(context);
            bool   result     = false;

            //Lookup all of the PharmCalcAccept records to get the minimum and maximum accepted values.
            EntityList <PharmCalcAccept> acceptRecords = PharmCalcAccept.FindByRxoSetId(PM, QueryStrategy.Normal, rxoSetId);
            PharmOrd pharmOrd = PharmOrd.GetEntityByRxoSetIdAndVersion0(rxoSetId, PM);

            var maxRecords = acceptRecords.Where(e => e.Accepted_High.HasValue);
            var minRecords = acceptRecords.Where(e => e.Accepted_Low.HasValue);

            double?maxAccepted = maxRecords.Count() == 0 ? (double?)null : maxRecords.Max(e => e.Accepted_High.Value);
            double?minAccepted = minRecords.Count() == 0 ? (double?)null : minRecords.Min(e => e.Accepted_Low.Value);

            if (maxAccepted != null && calcFactor <= maxAccepted && calcFactor >= pharmOrd.BSA)
            {
                result = true;
            }

            if (minAccepted != null && calcFactor >= minAccepted && calcFactor <= pharmOrd.BSA)
            {
                result = true;
            }

            Result.Set(context, result);
        }
        /// <summary>
        /// Checks the database to see if the PharmCalcAccept table contains a record indicating that the
        /// calculation factor passed has been accepted..
        /// </summary>
        /// <param name="context"></param>
        protected override void DoWork(CodeActivityContext context)
        {
            ImpacPersistenceManager pm = ImpacPersistenceManagerFactory.CreatePersistenceManager();
            int    rxoSetId            = RxoSetId.Get(context);
            double calcFactor          = CalcFactor.Get(context);

            //Lookup all of the PharmCalcAccept records to get the minimum and maximum accepted values.
            EntityList <PharmCalcAccept> acceptRecords = PharmCalcAccept.FindByRxoSetId(pm, QueryStrategy.Normal, rxoSetId);
            double maxAccepted = acceptRecords.Where(e => e.Accepted_High.HasValue).Max(e => e.Accepted_High.Value);
            double minAccepted = acceptRecords.Where(e => e.Accepted_Low.HasValue).Min(e => e.Accepted_Low.Value);

            Result.Set(context, calcFactor >= minAccepted && calcFactor <= maxAccepted);
        }
        /// <summary>
        /// Writes to the PharmCalcAccept table indicating that the calculation factor passed in has
        /// been accepted.
        /// </summary>
        /// <param name="context"></param>
        protected override void DoWork(CodeActivityContext context)
        {
            ImpacPersistenceManager pm = ImpacPersistenceManagerFactory.CreatePersistenceManager();
            int    rxoSetId            = RxoSetId.Get(context);
            double calcFactor          = AcceptedCalcFactor.Get(context);

            //Get PharmOrd Object
            BOM.Entities.PharmOrd pharmOrd = BOM.Entities.PharmOrd.GetEntityByRxoSetIdAndVersion0(rxoSetId);

            if (pharmOrd.IsNullEntity)
            {
                throw new InvalidOperationException("Cannot find PharmOrd record with Version = 0 and Rxo_Set_Id = " + rxoSetId);
            }

            //Only write to the table if a BSA is found.
            if (pharmOrd.BSA != 0)
            {
                PharmCalcAccept obj = PharmCalcAccept.Create(pm);
                obj.RXO_Set_ID = rxoSetId;

                //If the BSA on the order is equal to the value passed in, reject the change since there's no reason to save the record.
                if (calcFactor == pharmOrd.BSA)
                {
                    pm.RejectChanges();
                    return;
                }

                //Otherwise, if the acepted calc factor is greater than the order BSA, set the high value.  If it's less than the order
                //BSA, set the low value.
                if (calcFactor > pharmOrd.BSA)
                {
                    obj.Accepted_High = calcFactor;
                }
                else
                {
                    obj.Accepted_Low = calcFactor;
                }

                pm.SaveChanges();
            }
        }