Exemple #1
0
        public DispatchableDrugStockDTO GetDispatchableDrugStock(int id, string location)
        {
            var drug = _dbHelper.drugs.FirstOrDefault(d => d.DrugId == id);

            if (drug != null)
            {
                DrugLocation available = drug.QuantityByLocation.Find(dl => dl.Location == location);
                if (available != null)
                {
                    DispatchableDrugStockDTO dispatchableDrug = new DispatchableDrugStockDTO()
                    {
                        Id             = drug.DrugId,
                        Name           = drug.DrugName,
                        ExpiryDate     = drug.ExpiryDate,
                        AvailableStock = available.Quantity,
                        CostPerUnit    = drug.CostPerPackage / drug.UnitsInPackage
                    };
                    return(dispatchableDrug);
                }
                return(null);
            }
            return(null);
        }
Exemple #2
0
        public string Subscribe(SubscriptionDTO subscription, string token)
        {
            MemberPrescription prescription = getPrescriptionId(subscription.PrescriptionId);

            if (prescription == null)
            {
                return("Prescription Not Found");
            }

            HttpClient client = new HttpClient();

            client.BaseAddress = new Uri("http://localhost:60177");
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            StringContent       content  = new StringContent(JsonConvert.SerializeObject(""), Encoding.UTF8, "application/json");
            HttpResponseMessage response = client.PostAsync("/api/Drugs/getDispatchableDrugStock/" + prescription.DrugId + "/" + subscription.MemberLocation, content).Result;

            if (response.StatusCode == HttpStatusCode.OK)
            {
                DispatchableDrugStockDTO stock = response.Content.ReadAsAsync <DispatchableDrugStockDTO>().Result;

                int quantityRequired = prescription.DosagePerDay * (7 * prescription.PrescriptionCourseInWeeks);

                if (quantityRequired > stock.AvailableStock)
                {
                    return("Stock Not Available Cannot add subscription");
                }
                else
                {
                    RefillDTO refill = new RefillDTO();
                    refill.SubscriptionId   = SubscriptionNumber;
                    refill.RefillDate       = subscription.SubscriptionDate;
                    refill.DosagePerDay     = prescription.DosagePerDay;
                    refill.CourseInWeeks    = prescription.PrescriptionCourseInWeeks;
                    refill.Location         = subscription.MemberLocation;
                    refill.CostPerUnit      = stock.CostPerUnit;
                    refill.RefillOccurrence = subscription.RefillOccurrence;

                    HttpClient client1 = new HttpClient();
                    client1.BaseAddress = new Uri("http://localhost:2393");
                    client1.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                    StringContent       content1  = new StringContent(JsonConvert.SerializeObject(refill), Encoding.UTF8, "application/json");
                    HttpResponseMessage response1 = client1.PostAsync("/api/Refill/CreateRefill", content1).Result;

                    if (response1.StatusCode == HttpStatusCode.OK)
                    {
                        try
                        {
                            MemberSubscription subscription1 = new MemberSubscription()
                            {
                                SubscriptionId     = SubscriptionNumber,
                                MemberId           = subscription.MemberId,
                                SubscriptionDate   = subscription.SubscriptionDate,
                                MemberLocation     = subscription.MemberLocation,
                                PrescriptionId     = subscription.PrescriptionId,
                                SubscriptionStatus = true
                            };
                            if (subscription.RefillOccurrence == DTO.Occurrence.Weekly)
                            {
                                subscription1.RefillOccurrence = Models.Occurrence.Weekly;
                            }
                            else
                            {
                                subscription1.RefillOccurrence = Models.Occurrence.Monthly;
                            }

                            bool subAdded = _dbHelper.AddSubscription(subscription1);
                            if (subAdded)
                            {
                                SubscriptionNumber++;
                                return("Subscription Created.");
                            }
                            else
                            {
                                return("Could Not Create Subscription");
                            }
                        }
                        catch (Exception)
                        {
                            return("Could Not Create Subscription");
                        }
                    }
                    else
                    {
                        return("Could Not Create RefillOrders");
                    }
                }
            }
            else
            {
                return("Drug Not Found");
            }
        }