Example #1
0
        public async Task <IActionResult> Dashboard()
        {
            if (hospitalId != null && roleName == "Hospital")
            {
                try
                {
                    var bedResource = await _hospitalService.GetAllBedsForHospital(hospitalId);

                    if (bedResource == null)
                    {
                        bedResource = new BedResource();
                    }

                    var patients = await _patientService.GetPatientsForHospital(hospitalId);

                    if (patients == null)
                    {
                        patients = new List <PatientFullData>();
                    }

                    var recieptionist = await _recieptionistService.GetRecieptionistFullData(userId);

                    List <PatientFullData> notitficationList = new List <PatientFullData>();

                    if (recieptionist != null || recieptionist.NotificationData != null)
                    {
                        foreach (var notification in recieptionist.NotificationData)
                        {
                            notitficationList.Add(JsonConvert.DeserializeObject <PatientFullData>(notification.NotificationText));
                        }
                    }

                    HospitalStatisticsViewModel hospitalStatistics = new HospitalStatisticsViewModel()
                    {
                        Notifications        = notitficationList,
                        AvailableBedsCount   = bedResource.AvailableBeds.Count,
                        UmAvailableBedsCount = bedResource.UnAvailableBeds.Count,
                        PatientsCount        = patients.Count()
                    };
                    return(View(hospitalStatistics));
                }
                catch
                {
                    ViewBag.ErrorLoadingPatients = true;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(RedirectToAction("Login", "Account"));
        }