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")); }
public async Task <IActionResult> GetHospitalStatistics([FromRoute] Guid hospitalId) { if (hospitalId == Guid.Empty) { return(BadRequest()); } 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) { 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(Ok(hospitalStatistics)); } catch (Exception e) { return(BadRequest(e.Message)); } }