public async Task <IActionResult> DrugList(int id)
        {
            var pharmacySystem = await _pharmacySystemService.Get(id);

            if (_adapterContext.SetPharmacySystemAdapter(pharmacySystem) == null)
            {
                return(View(new List <DrugListDTO>()));
            }
            ViewBag.PharmacyId = id;
            var drugList = _adapterContext.PharmacySystemAdapter.GetAllDrugs();

            _adapterContext.RemoveAdapter();

            return(View(drugList));
        }
        public async Task <IActionResult> Order(DrugProcurementDTO drugProcurementDto)
        {
            var pharmacySystem = await _pharmacySystemService.Get(drugProcurementDto.PharmacySystemId);

            if (_adapterContext.SetPharmacySystemAdapter(pharmacySystem) == null)
            {
                throw new ArgumentNullException("There is no pharmacy with id=" + drugProcurementDto.PharmacySystemId);
            }

            if (_adapterContext.PharmacySystemAdapter.OrderDrugs(drugProcurementDto.PharmacyId,
                                                                 drugProcurementDto.DrugId,
                                                                 drugProcurementDto.Quantity))
            {
                if (await _drugService.AddQuantity(drugProcurementDto.Code, drugProcurementDto.Quantity))
                {
                    TempData["Success"] = "Order successful!";
                }
                else
                {
                    TempData["Failure"] = "Drug procured but does not exsist in our database, contact administrator!";
                }
            }
            else
            {
                TempData["Failure"] = "Order unsuccessful!";
            }

            return(RedirectToAction("Index", drugProcurementDto));
        }
Beispiel #3
0
        public async Task <ActionResult <List <DrugListDTO> > > GetDrugsFromPharmacy(int id)
        {
            List <DrugListDTO> ret            = new List <DrugListDTO>();
            PharmacySystem     pharmacySystem = await _pharmacySystemService.Get(id);

            if (_adapterContext.SetPharmacySystemAdapter(pharmacySystem) != null)
            {
                ret.AddRange(_adapterContext.PharmacySystemAdapter.GetAllDrugs());
            }

            return(Ok(ret));
        }
Beispiel #4
0
        public async Task <IActionResult> SendPrescription(PrescriptionForm form)
        {
            PushSubscription pushSubscription = new PushSubscription()
            {
                Endpoint = Request.Form["PushEndpoint"], P256DH = Request.Form["PushP256DH"], Auth = Request.Form["PushAuth"]
            };
            PushPayload pushPayload = new PushPayload();

            if (!FormValid(form))
            {
                pushPayload.Title   = "Unsuccess";
                pushPayload.Message = "Invalid prescription data!";
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);

                return(RedirectToAction("Index"));
            }

            var    reportFilePath = "Resources";
            string reportFileName = Guid.NewGuid().ToString() + ".json";
            var    prescription   = new { drugId = form.Drug, jmbg = form.Patient };
            string json           = JsonConvert.SerializeObject(prescription, Formatting.Indented);

            try
            {
                System.IO.File.WriteAllText(reportFilePath + "/" + reportFileName, json);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);

                pushPayload.Title   = "Unsuccess";
                pushPayload.Message = "Error occured while creating prescription file!";
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);
            }
            var pharmacy = await _pharmacySystemService.Get(form.PharmacySystem);

            if (_adapterContext.SetPharmacySystemAdapter(pharmacy) != null)
            {
                if (_adapterContext.PharmacySystemAdapter.SendDrugConsumptionReport(reportFilePath, reportFileName))
                {
                    pushPayload.Title   = "Success";
                    pushPayload.Message = "Prescription successfully created and uploaded!";
                }
                else
                {
                    pushPayload.Title   = "Unsuccess";
                    pushPayload.Message = "Prescription upload to " + pharmacy.Name + @" unsuccessfull!";
                }
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);
            }
            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Edit(int id)
        {
            var pharmacy = await _pharmacySystemService.Get(id);

            if (pharmacy == null)
            {
                return(NotFound("Pharmacy does not exist."));
            }

            PharmacySystemDTO dto = new PharmacySystemDTO()
            {
                Id     = pharmacy.Id,
                Name   = pharmacy.Name,
                Url    = pharmacy.Url,
                ApiKey = pharmacy.ApiKey,
                Email  = pharmacy.Email,
                ActionsBenefitsExchangeName = pharmacy.ActionsBenefitsExchangeName,
                ActionsBenefitsSubscribed   = pharmacy.ActionsBenefitsSubscribed,
                GrpcHost = pharmacy.GrpcAdress.GrpcHost,
                GrpcPort = pharmacy.GrpcAdress.GrpcPort
            };

            return(View(dto));
        }