Пример #1
0
 public static Drug GetDrug(Int32 pzn)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         return GetDrug(pzn, db);
     }
 }
Пример #2
0
 public static ReplenishmentOrder GetOrder(Int32 id)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         return GetOrder(id, db);
     }
 }
Пример #3
0
 public static ICollection<Position> GetPendingPositionsForDrug(Int32 pzn)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         return PendingPositionsFor(pzn, db).ToList();
     }
 }
Пример #4
0
 public static void InitiateReplenishment(int pzn, int quantity)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         InitiateReplenishment(pzn, quantity, db);
     }
 }
Пример #5
0
 public static void Restock(Int32 pzn, Int32 quantity, DateTime dateOfAction)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         Drug drug = GetDrug(pzn, db);
         drug.Apply(RestockEvent.Create(drug, quantity, dateOfAction));
         db.SaveChanges();
     }
 }
Пример #6
0
 public static bool RequiresReplenishment(Int32 pzn)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         Drug drug = GetDrug(pzn, db);
         Int32 quantityPending = GetQuantityPending(drug, db);
         return drug.RequiresReplenishment(quantityPending);
     }
 }
Пример #7
0
 public static int GetReplenishmentSuggestion(int pzn)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         Drug drug = GetDrug(pzn, db);
         Int32 quantityPending = GetQuantityPending(drug, db);
         return drug.ReplenishmentSuggestion(quantityPending);
     }
 }
Пример #8
0
 public static ICollection<Position> GetPositionsForOrder(Int32 id)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         return (from p in db.PositionSet.Include("Drug")
                     where p.Order.Id == id
                     select p).ToList();
     }
 }
Пример #9
0
 public static void InitiateReplenishment(Int32 pzn, int quantity, PharmacyContainer db)
 {
     Drug drug = DrugService.GetDrug(pzn, db);
     if (HasOpenOrders(drug, db))
     {
         AdjustExistingOrderFor(drug, quantity, db);
     }
     else
     {
         CreatePositionOnOpenOrNewOrder(drug, quantity, db);
     }
     db.SaveChanges();
 }
Пример #10
0
 public static void Cancel(Int32 id)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         ReplenishmentOrder order = GetOrder(id, db);
         order.State = order.State.Cancel();
         foreach (Position p in order.Positions)
         {
             InitiateReplenishment(p.DrugPZN, p.Quantity, db);
         }
         // migrate all positions to new or existing open order
         db.SaveChanges();
     }
 }
Пример #11
0
 public static Boolean HasOpenOrders(Drug drug, PharmacyContainer db)
 {
     return OpenOrdersFor(drug, db).Count() > 0;
 }
Пример #12
0
 internal static IQueryable<Position> PendingPositionsFor(Int32 pzn, PharmacyContainer db)
 {
     return (from p in db.PositionSet.Include("Order")
             where p.DrugPZN == pzn
             && (p.Order.State == OrderState.Open ||
                 p.Order.State == OrderState.Posting ||
                 p.Order.State == OrderState.Ordered)
             select p);
 }
Пример #13
0
 public static ICollection<Drug> GetAllDrugs()
 {
     using (PharmacyContainer db = new PharmacyContainer())
         return db.DrugSet.ToList();
 }
Пример #14
0
 private static Int32 GetQuantityPending(Drug drug, PharmacyContainer db)
 {
     if (OrderService.PendingPositionsFor(drug.PZN, db).Count() > 0)
     {
         // would not work on empty position collections
         return OrderService.PendingPositionsFor(drug.PZN, db).Sum(p => p.Quantity);
     }
     else
     {
         return 0;
     }
 }
Пример #15
0
 public static ICollection<ReplenishmentOrder> GetAllOrders()
 {
     using (PharmacyContainer db = new PharmacyContainer())
         return db.ReplenishmentOrderSet.ToList();
 }
Пример #16
0
 public static void Replenish(Int32 pzn, Int32 quantity, DateTime? dateOfAction, PharmacyContainer db)
 {
     Drug drug = GetDrug(pzn, db);
     drug.Apply(ReplenishEvent.Create(drug, quantity, FailOnNull(dateOfAction)));
     db.SaveChanges();
 }
Пример #17
0
 private static bool OpenOrdersAvailable(PharmacyContainer db)
 {
     return GetOpenOrders(db).Count() > 0;
 }
Пример #18
0
 private static IQueryable<ReplenishmentOrder> OpenOrdersFor(Drug drug, PharmacyContainer db)
 {
     return (from o in db.ReplenishmentOrderSet
             where o.Positions.Where(p => p.DrugPZN == drug.PZN).Count() > 0
             && o.State == OrderState.Open select o);
 }
Пример #19
0
 private static void CreatePositionOnOpenOrNewOrder(Drug drug, int quantity, PharmacyContainer db)
 {
     if (OpenOrdersAvailable(db))
     {
         ReplenishmentOrder openOrder = GetOpenOrders(db).First();
         openOrder.Positions.Add(new Position
         {
             Drug = drug,
             Order = openOrder,
             Quantity = quantity
         });
     }
     else
     {
         ReplenishmentOrder newOrder = new ReplenishmentOrder();
         newOrder.Positions.Add(new Position
         {
             Drug = drug,
             Order = newOrder,
             Quantity = quantity
         });
         db.ReplenishmentOrderSet.Add(newOrder);
     }
 }
Пример #20
0
 private static IEnumerable<ReplenishmentOrder> GetOpenOrders(PharmacyContainer db)
 {
     return (from o in db.ReplenishmentOrderSet where o.State == OrderState.Open select o);
 }
Пример #21
0
 private static void AdjustExistingOrderFor(Drug drug, int quantity, PharmacyContainer db)
 {
     foreach (Position p in GetPendingPositionsForDrug(drug.PZN))
     {
         if (p.Order.State == OrderState.Open)
         {
             p.Quantity = p.Quantity + quantity;
             db.Entry(p).State = System.Data.EntityState.Modified;
         }
     }
 }
Пример #22
0
 private static Drug CreateDrug(Drug newDrug)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         var count = (from d in db.DrugSet where d.PZN == newDrug.PZN select d).Count();
         if (count > 0)
             throw new ArgumentException(String.Format("Drug with PZN {0} already exists!", newDrug.PZN));
         db.DrugSet.Add(newDrug);
         db.SaveChanges();
         return newDrug;
     }
 }
Пример #23
0
        public static Drug UpdateDrug(Drug drug, String name, String description, int minimumInventoryLevel, int optimalInventoryLevel)
        {
            Util.ConvertEmptyToNull(ref description);

            using (PharmacyContainer db = new PharmacyContainer())
            {
                Drug attachedDrug = GetDrug(drug.PZN, db);
                attachedDrug.Name = name;
                attachedDrug.Description = description;
                attachedDrug.MinimumInventoryLevel = minimumInventoryLevel;
                attachedDrug.OptimalInventoryLevel = optimalInventoryLevel;
                db.SaveChanges();
                return attachedDrug;
            }
        }
Пример #24
0
        internal static ReplenishmentOrder GetOrder(Int32 id, PharmacyContainer db)
        {
            ReplenishmentOrder result = (from o in db.ReplenishmentOrderSet where o.Id == id select o).FirstOrDefault();

            if (result == default(ReplenishmentOrder))
                throw new ArgumentException(String.Format("Order with ID {0} not found", id.ToString()));

            return result;
        }
Пример #25
0
 public static void UpdateExpectedDeliveryDate(Int32 id, DateTime expectedDelivery)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         ReplenishmentOrder order = GetOrder(id, db);
         order.ExpectedDelivery = expectedDelivery;
         db.SaveChanges();
     }
 }
Пример #26
0
 public static void ProceedToNextState(Int32 id)
 {
     using (PharmacyContainer db = new PharmacyContainer())
     {
         ReplenishmentOrder order = GetOrder(id, db);
         order.State = order.State.Next();
         if (order.State == OrderState.Finished)
         {
             foreach (Position p in order.Positions)
             {
                 DrugService.Replenish(p.Drug.PZN, p.Quantity, order.ActualDelivery, db);
             }
         }
         db.SaveChanges();
     }
 }
Пример #27
0
        internal static Drug GetDrug(Int32 pzn, PharmacyContainer db)
        {
            Drug result = (from d in db.DrugSet where d.PZN == pzn select d).FirstOrDefault();

            if (result == default(Drug))
                throw new ArgumentException(String.Format("Drug with PZN {0} not found", pzn.ToString()));

            return result;
        }