Esempio n. 1
0
        public MemberPrescription getPrescriptionId(int prescriptionId)
        {
            MemberPrescription prescription = _dbHelper.getPrescriptionId(prescriptionId);

            if (prescription != null)
            {
                return(prescription);
            }
            return(null);
        }
        public ActionResult CreatePrescription([FromBody] MemberPrescription prescription)
        {
            bool added = _subscriptionService.CreatePrescription(prescription);

            if (added)
            {
                return(Ok(prescription));
            }
            return(BadRequest("Could not add Prescription"));
        }
Esempio n. 3
0
        //public List<MemberSubscription> memberSubscriptions = new List<MemberSubscription>() {  new MemberSubscription()
        //    {
        //        SubscriptionId = 101,
        //        MemberId = 1,
        //        SubscriptionDate = Convert.ToDateTime("02/02/2020"),
        //        PrescriptionId = 1,
        //        RefillOccurrence = Occurrence.Monthly,
        //        MemberLocation = "Pune",
        //        SubscriptionStatus = true
        //    },
        // new MemberSubscription()
        //{
        //    SubscriptionId = 102,
        //    MemberId = 2,
        //    SubscriptionDate = Convert.ToDateTime("09/02/2020"),
        //    PrescriptionId = 2,
        //    RefillOccurrence = Occurrence.Weekly,
        //    MemberLocation = "Mumbai",
        //    SubscriptionStatus = true
        //}
        //};

        public bool AddPrescription(MemberPrescription prescription)
        {
            try
            {
                memberPrescriptions.Add(prescription);
                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
Esempio n. 4
0
        public bool CreatePrescription(MemberPrescription prescription)
        {
            prescription.PrescriptionId = PrescriptionNumber;
            bool PrescriptionCreated = _dbHelper.AddPrescription(prescription);

            if (PrescriptionCreated == true)
            {
                PrescriptionNumber++;
                return(true);
            }
            return(false);
        }
 public ActionResult CreatePrescription([FromBody] MemberPrescription prescription)
 {
     _log4net.Info("Subscription MicroService : " + nameof(CreatePrescription));
     try
     {
         bool added = _subscriptionService.CreatePrescription(prescription);
         if (added)
         {
             return(Ok(prescription));
         }
         return(BadRequest("Could not add Prescription"));
     }
     catch (Exception e)
     {
         _log4net.Error("Exception Occured : " + e.Message + " from " + nameof(CreatePrescription));
         return(null);
     }
 }
Esempio n. 6
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");
            }
        }