public ActionResult CreateNewReport(ReportModel newReport)
        {
            if (Convert.ToString(Session["key"]) != "labIncharge")
            {
                return(RedirectToAction("Login", "Home"));
            }

            LabIncharge_Api inchargeApi = new LabIncharge_Api();

            newReport.labIncharge_ID = (int)Session["UserId"];

            if (newReport.patient_ID != 0 && newReport.reportTime != "-Select" && newReport.date != null && newReport.labResult != null)
            {
                List <ReportModel> reportsModel = new List <ReportModel>();
                newReport.reportTime = Convert.ToString(DateTime.Now.TimeOfDay);
                newReport.date       = DateTime.Now;
                var model = inchargeApi.CreateNewReport(newReport);
                reportsModel.Add(model);

                if (reportsModel.Count != 0)
                {
                    return(View("~/Views/LabIncharge/LabInchargeViewReports.cshtml", reportsModel));
                }
                else
                {
                    return(RedirectToAction("ViewCreateNewReport"));
                }
            }
            else
            {
                return(RedirectToAction("ViewCreateNewReport"));
            }
        }
        public ActionResult Index(int?id)
        {
            if (Convert.ToString(Session["key"]) != "labIncharge")
            {
                return(RedirectToAction("Login", "Home"));
            }

            if (id != null)
            {
                System.Web.HttpContext.Current.Session.Add("key", "labIncharge");
                System.Web.HttpContext.Current.Session.Add("UserId", id);
                Login_Api la   = new Login_Api();
                var       name = la.GetUserName(id);

                System.Web.HttpContext.Current.Session.Add("UserName", name);
            }
            LabIncharge_Api inchargeApi  = new LabIncharge_Api();
            var             reportsModel = inchargeApi.GetAllPatientReports_Api();

            if (reportsModel != null)
            {
                return(View("~/Views/LabIncharge/LabInchargeHome.cshtml", reportsModel));
            }
            return(View("~/Views/Error.cshtml"));
        }
        public ActionResult DeletePatientReport(ReportModel ReportModel)
        {
            LabIncharge_Api inchargeApi = new LabIncharge_Api();

            inchargeApi.DeletePatientReport(ReportModel);

            return(Json("success", JsonRequestBehavior.AllowGet));
        }
        public ActionResult GetAppointments(int id)
        {
            if (Convert.ToString(Session["key"]) != "labIncharge")
            {
                return(RedirectToAction("Login", "Home"));
            }
            Patient_Api patientApi = new Patient_Api();

            IEnumerable <AppointmentModel> patientAppointments = patientApi.GetAppointments(id);
            ReportModel rptmOld = new ReportModel();
            //if (patientAppointments)
            {
                foreach (var a in patientAppointments)
                {
                    try
                    {
                        if (a.requestedReport)
                        {
                            rptmOld.appointmentIntIDs.Add(a.appointment_ID);
                        }
                    }
                    catch (Exception ex)
                    {
                        string test = ex.ToString();
                    }
                }
            }
            LabIncharge_Api inchargeApi  = new LabIncharge_Api();
            var             reportsModel = inchargeApi.GetPatientReports_Api(id);

            ReportModel rptmNew = new ReportModel();

            foreach (var a in reportsModel)
            {
                {
                    rptmNew.appointmentIntIDs.Add(a.appointment_ID);
                }
            }
            foreach (var a in rptmNew.appointmentIntIDs)
            {
                rptmOld.appointmentIntIDs.Remove(a);
            }

            foreach (var a in rptmOld.appointmentIntIDs)
            {
                rptmOld.appointmentIDs.Add(new SelectListItem {
                    Text = a.ToString(), Value = a.ToString()
                });
            }

            return(Json(rptmOld.appointmentIDs, JsonRequestBehavior.AllowGet));
        }
        public ActionResult ReqNewReport(AppointmentModel appModel)
        {
            if (Convert.ToString(Session["key"]) != "doctor")
            {
                return(RedirectToAction("Login", "Home"));
            }

            LabIncharge_Api inchargeApi = new LabIncharge_Api();

            var reportsModel = inchargeApi.ReqNewReport(appModel);

            return(RedirectToAction("GetAppointments"));
        }
        public ActionResult ViewReportsByPatient(AppointmentModel app)
        {
            if (Convert.ToString(Session["key"]) != "doctor")
            {
                return(RedirectToAction("Login", "Home"));
            }


            LabIncharge_Api inchargeApi  = new LabIncharge_Api();
            var             reportsModel = inchargeApi.GetPatientReports_Api(app.paitent_ID);

            return(View("~/Views/Doctor/DoctorManageReports.cshtml", reportsModel));
        }
        public ActionResult GetAppointments()
        {
            if (Convert.ToString(Session["key"]) != "doctor")
            {
                return(RedirectToAction("Login", "Home"));
            }

            int        doctor_id    = (int)Session["UserId"];// 5006;
            Doctor_Api doctorApi    = new Doctor_Api();
            var        appointments = doctorApi.GetDocApntment_Api(doctor_id);

            //var appointments = doctorApi.GetDocApntment_Api(doctor_id);

            appointments.First().filterApps.Add(new SelectListItem {
                Text = "-Select", Value = "0"
            });
            appointments.First().filterApps.Add(new SelectListItem {
                Text = "Today", Value = "1"
            });
            appointments.First().filterApps.Add(new SelectListItem {
                Text = "Tomorrow", Value = "2"
            });
            appointments.First().filterApps.Add(new SelectListItem {
                Text = "All", Value = "3"
            });
            LabIncharge_Api lApi       = new LabIncharge_Api();
            var             allReports = lApi.ViewPatientReports_Api(new ReportModel());

            foreach (var a in appointments)
            {
                if (allReports.Where(r => r.appointment_ID == a.appointment_ID).FirstOrDefault() != null)
                {
                    a.reportAvailable = true;
                }
                else
                {
                    a.reportAvailable = false;
                }
                if (a.appointment_Date > DateTime.Now)
                {
                    a.canCancel = true;
                }
            }


            if (appointments != null)
            {
                return(View("~/Views/Doctor/DoctorViewAppointments.cshtml", appointments.OrderBy(a => a.appointment_Date)));
            }
            return(View("~/Views/Error.cshtml"));
        }
        public ActionResult CreateReport(ReportModel report)
        {
            if (Convert.ToString(Session["key"]) != "doctor")
            {
                return(RedirectToAction("Login", "Home"));
            }

            LabIncharge_Api inchargeApi = new LabIncharge_Api();

            report.labIncharge_ID = (int)Session["UserId"]; //4001;

            var reportsModel = inchargeApi.CreateNewReport(report);

            return(ViewAllReportsByPatient(report.patient_ID));
        }
        public ActionResult ViewAllReportsByDoctor()
        {
            if (Convert.ToString(Session["key"]) != "doctor")
            {
                return(RedirectToAction("Login", "Home"));
            }

            Patient_Api patientApi = new Patient_Api();

            ViewBag.GetPatientsList = new SelectList(patientApi.GetPaitentsList());

            LabIncharge_Api inchargeApi  = new LabIncharge_Api();
            var             reportsModel = inchargeApi.GetAllPatientReports_Api();

            return(View("~/Views/Doctor/DoctorManageReports.cshtml", reportsModel));
        }
        //[HttpPost]
        public ActionResult GetPatientReports(int id)
        {
            if (Convert.ToString(Session["key"]) != "labIncharge")
            {
                return(RedirectToAction("Login", "Home"));
            }

            LabIncharge_Api inchargeApi = new LabIncharge_Api();

            var reportsModel = inchargeApi.GetPatientReports_Api(id);

            if (reportsModel != null)
            {
                return(View("~/Views/LabIncharge/LabInchargeViewReports.cshtml", reportsModel));
            }
            // ErrorModel.ErrorMessage = "Unable to fetch Patient Reports Please try again";
            return(View("~/Views/Error.cshtml"));
        }
        public ActionResult GetAppointmentsByFilter(int filterID)
        {
            if (Convert.ToString(Session["key"]) != "doctor")
            {
                return(RedirectToAction("Login", "Home"));
            }


            int        doctor_id    = (int)Session["UserId"];// 5006;
            Doctor_Api doctorApi    = new Doctor_Api();
            var        appointments = doctorApi.GetDocApntment_Api(doctor_id);

            LabIncharge_Api lApi       = new LabIncharge_Api();
            var             allReports = lApi.ViewPatientReports_Api(new ReportModel());

            foreach (var a in appointments)
            {
                if (allReports.Where(r => r.appointment_ID == a.appointment_ID).FirstOrDefault() != null)
                {
                    a.reportAvailable = true;
                }
                else
                {
                    a.reportAvailable = false;
                }
                int timeNow = Convert.ToInt32(DateTime.Now.Hour);
                int appTime = (Convert.ToInt32((a.timings).Substring(0, 2)));

                if (((a.appointment_Date).ToShortDateString().Equals((DateTime.Now.AddDays(1).ToShortDateString())) && (appTime > timeNow)) || (a.appointment_Date > DateTime.Now))
                {
                    a.canCancel = true;
                }
            }



            if (filterID == 1)
            {
                appointments = appointments.Where(a => ((a.appointment_Date).ToShortDateString().Equals((DateTime.Now).ToShortDateString())));// && a.appointment_Date > DateTime.Now.AddDays(-1) && a.appointment_Date <= DateTime.Now ));


                appointments.First().filterApps.Add(new SelectListItem {
                    Text = "-Select", Value = "0"
                });
                appointments.First().filterApps.Add(new SelectListItem {
                    Text = "Today", Value = "1"
                });
                appointments.First().filterApps.Add(new SelectListItem {
                    Text = "Tomorrow", Value = "2"
                });
                appointments.First().filterApps.Add(new SelectListItem {
                    Text = "All", Value = "3"
                });
            }
            else if (filterID == 2)
            {
                appointments = appointments.Where(a => ((a.appointment_Date).ToShortDateString().Equals(DateTime.Now.AddDays(1).ToShortDateString())));// && a.appointment_Date > DateTime.Now));



                appointments.First().filterApps.Add(new SelectListItem {
                    Text = "-Select", Value = "0"
                });
                appointments.First().filterApps.Add(new SelectListItem {
                    Text = "Today", Value = "1"
                });
                appointments.First().filterApps.Add(new SelectListItem {
                    Text = "Tomorrow", Value = "2"
                });
                appointments.First().filterApps.Add(new SelectListItem {
                    Text = "All", Value = "3"
                });
            }
            //else if (id == 3)
            //{

            //}
            if (filterID == 3 || filterID == 0)
            {
                return(RedirectToAction("GetAppointments"));
            }

            if (appointments != null)
            {
                return(View("~/Views/Doctor/DoctorViewAppointments.cshtml", appointments.OrderBy(a => a.appointment_Date)));
            }
            return(View("~/Views/Error.cshtml"));
        }