コード例 #1
0
        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));
        }
コード例 #2
0
        public async Task <IActionResult> Search(string name)
        {
            var pharmacySystems = await _pharmacySystemService.GetAll();

            List <SearchResultDto> result = new List <SearchResultDto>();

            foreach (PharmacySystem pharmacySystem in pharmacySystems)
            {
                if (_adapterContext.SetPharmacySystemAdapter(pharmacySystem) == null)
                {
                    continue;
                }

                List <DrugDto> search = new List <DrugDto>();
                search.AddRange(_adapterContext.PharmacySystemAdapter.DrugAvailibility(name));

                if (search.Count > 0)
                {
                    result.Add(new SearchResultDto()
                    {
                        pharmacySystem = pharmacySystem, drugs = new List <DrugDto>(search)
                    });
                }
            }
            _adapterContext.RemoveAdapter();
            ViewBag.SearchBox = name;
            return(View(result));
        }
コード例 #3
0
        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));
        }
コード例 #4
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));
        }
コード例 #5
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"));
        }
コード例 #6
0
        public async Task <IActionResult> Index(DateRangeDTO dateRangeDto)
        {
            DateRange        dateRange        = new DateRange(dateRangeDto.From, dateRangeDto.To);
            PushSubscription pushSubscription = new PushSubscription()
            {
                Endpoint = Request.Form["PushEndpoint"], P256DH = Request.Form["PushP256DH"], Auth = Request.Form["PushAuth"]
            };
            PushPayload pushPayload = new PushPayload();

            var reports = await _drugService.GetDrugConsuption(dateRange);

            if (reports == null)
            {
                pushPayload.Title   = "Unsuccess";
                pushPayload.Message = "Comunication error!";
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);

                return(RedirectToAction("Index"));
            }
            if (reports.Count == 0)
            {
                pushPayload.Title   = "Unsuccess";
                pushPayload.Message = "Nothing found in given data range!";
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);

                return(RedirectToAction("Index"));
            }
            var json           = JsonConvert.SerializeObject(reports, Formatting.Indented);
            var reportFileName = $"{dateRange.From:yyyy-MM-dd}-to-{dateRange.To:yyyy-MM-dd}-report.json";
            var reportFilePath = "Resources";

            try
            {
                System.IO.File.WriteAllText(Path.Combine(reportFilePath, reportFileName), json);
            }
            catch (Exception dnfe)
            {
                Console.WriteLine(dnfe);

                pushPayload.Title   = "Unsuccess";
                pushPayload.Message = "Error occured while creating report file!";
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);

                return(RedirectToAction("Index"));
            }
            var pharmacySystems = await _pharmacySystemService.GetAll();

            foreach (var ps in pharmacySystems)
            {
                if (_adapterContext.SetPharmacySystemAdapter(ps) == null)
                {
                    continue;
                }

                if (_adapterContext.PharmacySystemAdapter.SendDrugConsumptionReport(reportFilePath, reportFileName))
                {
                    pushPayload.Title   = "Success";
                    pushPayload.Message = "Report successfully created and uploaded to " + ps.Name + "!";
                }
                else
                {
                    pushPayload.Title   = "Unsuccess";
                    pushPayload.Message = "Report upload to " + ps.Name + " unsuccessfull!";
                }
                _pushNotificationService.SendNotification(pushSubscription, pushPayload);
            }

            return(RedirectToAction("Index"));
        }