Exemplo n.º 1
0
        // Send message from one user to other user
        public void SendMessage(string Text, int PatientId, int DoctorId, bool FromPatient, string ConnectionId)
        {
            HospitalManagementContext db = new HospitalManagementContext();

            db.Messages.Add(new Message()
            {
                DoctorId = DoctorId, FromPatient = FromPatient, PatientId = PatientId, Text = Text
            });

            db.SaveChanges();

            User user;

            if (FromPatient)
            {
                user = db.Users.Include(u => u.Patient).Where(u => u.Patient.Id == PatientId).FirstOrDefault();
            }
            else
            {
                user = db.Users.Include(u => u.Doctor).Where(u => u.Doctor.Id == DoctorId).FirstOrDefault();
            }

            Clients.Client(ConnectionId).NewMessageRecieved(Context.ConnectionId, Text, JsonConvert.SerializeObject(user, Formatting.None,
                                                                                                                    new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            }));
        }
        public ActionResult GetUpdatedCountsAndList()
        {
            User user = (User)HttpContext.Session["LoggedInUser"];

            if (user != null && user.Role.Name == "Admin")
            {
                HospitalManagementContext db = new HospitalManagementContext();

                HttpContext.Session["TotalPatientList"]          = db.Users.Include(u => u.Patient).Where(u => u.Patient != null).Where(u => u.Patient.Status == "Admitted").ToList();
                HttpContext.Session["TotalPatients"]             = db.Users.Count(u => u.Patient != null && u.Patient.Status == "Admitted");
                HttpContext.Session["TotalCaregiverList"]        = db.Users.Include(u => u.Caregiver).Where(u => u.Caregiver != null).ToList();
                HttpContext.Session["TotalCareGivers"]           = db.Users.Count(u => u.Caregiver != null);
                HttpContext.Session["TotalDoctorList"]           = db.Users.Include(u => u.Doctor).Where(u => u.Doctor != null).ToList();
                HttpContext.Session["TotalDoctors"]              = db.Users.Count(u => u.Doctor != null);
                HttpContext.Session["RecetlyRegisteredUserList"] = db.Users.OrderByDescending(u => u.Id).Take(10).ToList();
                HttpContext.Session["TotalLoginUsers"]           = db.Users.Count(u => u.IsLogin != null && u.IsLogin == true);
                HttpContext.Session["TotalLogoutUsers"]          = db.Users.Count(u => u.IsLogin == null || u.IsLogin == false);
                HttpContext.Session["TotalInactive"]             = db.Users.Count(u => (u.IsLogin == null || u.IsLogin == false) && u.LastLogin != null && DbFunctions.DiffDays(u.LastLogin.Value, DateTime.Now) > 1);
                HttpContext.Session["InactiveUserList"]          = db.Users.Where(u => (u.IsLogin == null || u.IsLogin == false) && u.LastLogin != null && DbFunctions.DiffDays(u.LastLogin.Value, DateTime.Now) > 1).ToList();
                HttpContext.Session["FailLoginAttemptList"]      = db.LoginAttempts.Where(l => l.IsPassed == false).ToList();
            }

            return(Json(new
            {
                Status = "updated"
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 3
0
        public ActionResult Login(LoginModel loginModel)
        {
            if (ModelState.IsValid)
            {
                HospitalManagementContext dataContext = new HospitalManagementContext();
                // Check credentials
                User user = dataContext.Users.FirstOrDefault(u => u.Email == loginModel.Email && u.Password == loginModel.Password);

                if (user != null)
                {
                    HttpContext.Session["LoggedInUser"] = user;
                    // Check if admin
                    if (user.Role.Name == "Admin")
                    {
                        HttpContext.Session["Role"]               = "Admin";
                        HttpContext.Session["TotalPatientList"]   = dataContext.Users.Where(u => u.Patient != null).Where(u => u.Patient.Status == "Admitted").ToList();
                        HttpContext.Session["TotalPatients"]      = dataContext.Users.Count(u => u.Patient != null && u.Patient.Status == "Admitted");
                        HttpContext.Session["TotalCaregiverList"] = dataContext.Users.Where(u => u.Caregiver != null).ToList();
                        HttpContext.Session["TotalCareGivers"]    = dataContext.Users.Count(u => u.Caregiver != null);
                        HttpContext.Session["TotalDoctorList"]    = dataContext.Users.Where(u => u.Doctor != null).ToList();
                        HttpContext.Session["TotalDoctors"]       = dataContext.Users.Count(u => u.Doctor != null);

                        return(RedirectToAction("Index", "Home"));
                    }

                    else if (user.Role.Name == "Patient")
                    {
                        HttpContext.Session["Patient"]   = user.Patient;
                        HttpContext.Session["PatientId"] = user.Patient.Id;
                        HttpContext.Session["Doctor"]    = null;
                        HttpContext.Session["DoctorId"]  = -1;
                        HttpContext.Session["Role"]      = "Patient";
                        return(RedirectToAction("Index", "Patient"));
                    }

                    else if (user.Role.Name == "Caregiver")
                    {
                        HttpContext.Session["Role"] = "Caregiver";
                        return(RedirectToAction("Index", "CareGiver"));
                    }

                    else if (user.Role.Name == "Doctor")
                    {
                        HttpContext.Session["Patient"]   = null;
                        HttpContext.Session["PatientId"] = -1;
                        HttpContext.Session["Doctor"]    = user.Doctor;
                        HttpContext.Session["DoctorId"]  = user.Doctor.Id;
                        HttpContext.Session["Role"]      = "Doctor";
                        return(RedirectToAction("Index", "Doctor"));
                    }
                }
                // Invalid credentials
                else
                {
                    ModelState.AddModelError("", "Invalid username or password");
                }
            }

            return(View());
        }
Exemplo n.º 4
0
 public void assignPrescription()
 {
     using (var context = new HospitalManagementContext())
     {
         Console.WriteLine("Enter Patient Name:");
         string pname     = Console.ReadLine();
         var    p         = context.Patients.Single(b => b.PatientName == pname);
         int    patientid = p.PatientId;
         Console.WriteLine("Enter DoctorName:");
         string dname    = Console.ReadLine();
         var    d        = context.Doctors.Single(b => b.DoctorName == dname);
         int    doctorid = d.DoctorId;
         Console.WriteLine("Enter Prescription Disease");
         var dis                = Console.ReadLine();
         var pres               = context.Prescription.Single(b => b.PrescriptionDisease == dis);
         int Presid             = pres.PrescriptionId;
         var assignPrescription = new AssignPrescription()
         {
             PatientId      = patientid,
             DoctorId       = doctorid,
             PrescriptionId = Presid,
         };
         context.AssignPrescription.Add(assignPrescription);
         context.SaveChanges();
     }
 }
        public ActionResult LogOut(bool ajax)
        {
            HospitalManagementContext dataContext = new HospitalManagementContext();

            User loginUser = (User)HttpContext.Session["LoggedInUser"];

            User user = dataContext.Users.FirstOrDefault(u => u.Id == loginUser.Id);

            user.IsLogin = false;

            dataContext.SaveChanges();

            HttpContext.Session["LoggedInUser"]              = null;
            HttpContext.Session["Role"]                      = null;
            HttpContext.Session["TotalCareGivers"]           = null;
            HttpContext.Session["TotalPatients"]             = null;
            HttpContext.Session["TotalDoctors"]              = null;
            HttpContext.Session["TotalPatientList"]          = null;
            HttpContext.Session["TotalDoctorList"]           = null;
            HttpContext.Session["TotalCaregiverList"]        = null;
            HttpContext.Session["RecetlyRegisteredUserList"] = null;

            if (!ajax)
            {
                return(RedirectToAction("Login", "Home"));
            }
            else
            {
                return(Json(new
                {
                    Status = "logout"
                }, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult EnableAccount(string email, string token)
        {
            // Check token validity
            HospitalManagementContext dataContext = new HospitalManagementContext();

            User user = dataContext.Users.FirstOrDefault(u => u.Email == email && u.EnableToken == token && u.IsEnabled == false);

            if (user != null)
            {
                user.EnableToken       = null;
                user.IsEnabled         = true;
                user.LoginAttemptCount = 0;

                dataContext.SaveChanges();

                HttpContext.Session["email"] = email;
            }
            else
            {
                // Invalid token
                return(RedirectToAction("InvalidToken", "Home"));
            }

            return(RedirectToAction("Login", "Home"));
        }
        public ActionResult ResetPassword(SignupModel signupModel)
        {
            if (ModelState.IsValid)
            {
                // Password strength
                string regix = "^(?=.*[A-Z].*[A-Z])(?=.*[!@#$&*])(?=.*[0-9].*[0-9])(?=.*[a-z].*[a-z].*[a-z]).{8}$";

                if (!Regex.IsMatch(signupModel.Password, regix))
                {
                    ModelState.AddModelError("Password", "Password should contain 2 uppercases, 1 special case, 2 digits and 3 lowercases.");
                    return(View());
                }

                // Check if user already exists
                HospitalManagementContext dataContext = new HospitalManagementContext();
                // Check credentials

                string email = (string)HttpContext.Session["email"];

                User user = dataContext.Users.FirstOrDefault(u => u.Email == email);

                if (user != null)
                {
                    if (signupModel.OTP != user.OTP)
                    {
                        ModelState.AddModelError("OTP", "OTP not matched");
                        return(View());
                    }

                    if ((DateTime.Now - user.OTPExpiration.Value).TotalSeconds > this.verificationCodedExpirationSeconds)
                    {
                        ModelState.AddModelError("OTP", "OTP is expired");
                        return(View());
                    }

                    // Save token in database
                    user.Token = null;
                    user.OTP   = null;

                    user.Salt     = GenerateRandomString(10);
                    user.Password = Crypto.SHA256(signupModel.Password + user.Salt);

                    dataContext.SaveChanges();

                    HttpContext.Session["email"] = null;

                    return(RedirectToAction("Login", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Email does not exists");
                }
            }

            return(View());
        }
        public ActionResult DeleteUser(long id)
        {
            HospitalManagementContext db = new HospitalManagementContext();

            User user = db.Users.Where(u => u.Id == id).FirstOrDefault();

            if (user != null)
            {
                if (user.Role.Name == "Caregiver")
                {
                    user.Caregiver.Patient = null;
                    db.Caregivers.Remove(user.Caregiver);
                }
                else if (user.Role.Name == "Doctor")
                {
                    var doctor = db.Doctors.Include(d => d.Messages).SingleOrDefault(d => d.Id == user.Doctor.Id);

                    foreach (var message in doctor.Messages.ToList())
                    {
                        db.Messages.Remove(message);
                    }

                    db.Doctors.Remove(user.Doctor);
                }
                else if (user.Role.Name == "Patient")
                {
                    try
                    {
                        if (user.Patient.Caregiver != null)
                        {
                            Caregiver caregiver = db.Caregivers.ToList().Where(u => u.Patient.Id == user.Patient.Id).First();
                            caregiver.Patient = null;
                        }
                    }
                    catch (Exception e)
                    {
                    }

                    var patient = db.Patients.Include(p => p.Messages).SingleOrDefault(p => p.Id == user.Patient.Id);

                    foreach (var message in patient.Messages.ToList())
                    {
                        db.Messages.Remove(message);
                    }

                    db.Patients.Remove(user.Patient);
                }

                db.Users.Remove(user);
                db.SaveChanges();
            }

            return(RedirectToAction("Security", "Home"));
        }
Exemplo n.º 9
0
        // Get chat history of patient and doctor
        public ActionResult ChatHistory(int PatientId, int DoctorId)
        {
            HospitalManagementContext db = new HospitalManagementContext();

            List <Message> Messages = db.Messages.Include(u => u.Patient).Include(u => u.Doctor).Where(u => u.DoctorId == DoctorId).Where(u => u.PatientId == PatientId).ToList();

            return(Content(JsonConvert.SerializeObject(Messages, Formatting.None,
                                                       new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
            }), "application/json"));
        }
 public void Dispose(bool disposing)
 {
     if (!disposing)
     {
         return;
     }
     if (_context == null)
     {
         return;
     }
     _context.Dispose();
     _context = null;
 }
Exemplo n.º 11
0
        public void getAppointments()
        {
            using (var context = new HospitalManagementContext())
            {
                Console.WriteLine("Enter Doctor Name:");
                string dname = Console.ReadLine();

                var doctor = context.Doctors.Single(b => b.DoctorName == dname);
                //Console.WriteLine(doctor.DoctorId);
                int doctorid     = doctor.DoctorId;
                var appointments = context.Appointments.Count(b => b.DoctorId == doctorid);
                Console.WriteLine("Appointments:" + appointments);
            }
        }
        public ActionResult ForgotPassword(LoginModel loginModel)
        {
            if (ModelState.IsValid)
            {
                // Check if user already exists
                HospitalManagementContext dataContext = new HospitalManagementContext();

                // Check credentials
                string email = loginModel.Email;

                User user = dataContext.Users.FirstOrDefault(u => u.Email == email);

                if (user != null)
                {
                    var token = Guid.NewGuid().ToString();

                    string sRandomOTP = GenerateRandomString(8);

                    var resetLink = "<a href='" + Url.Action("ResetPassword", "Home", new { email = email, token = token }, "http") + "'>Reset Password</a>";

                    // Send email
                    string subject = "Password Reset";
                    string body    = "<b>Please find the Password Reset Token</b><br/>" + resetLink + "<br/><br/>OTP:<br/>" + sRandomOTP; //edit it
                    try
                    {
                        SendEMail(email, subject, body);
                    }
                    catch (Exception ex)
                    {
                        ModelState.AddModelError("Fail", "Unable to send email");
                        return(View());
                    }

                    // Save otp token in database
                    user.Token         = token;
                    user.OTP           = sRandomOTP;
                    user.OTPExpiration = DateTime.Now;

                    dataContext.SaveChanges();

                    ModelState.AddModelError("Success", "Email Sent");
                }
                else
                {
                    ModelState.AddModelError("Fail", "Email does not exists");
                }
            }

            return(View());
        }
Exemplo n.º 13
0
        public ActionResult AllEvents()
        {
            User user = (User)HttpContext.Session["LoggedInUser"];

            List <Event> allEvents = new List <Event>();

            if (user != null)
            {
                HospitalManagementContext db = new HospitalManagementContext();

                allEvents = db.Database.SqlQuery <Event>("select * from [dbo].Events e where e.UserId = " + user.Id).ToList();

                //allEvents = (List<Event>) db.Events.ToList().Where(e => e.UserId == user.Id);
            }

            return(Content(JsonConvert.SerializeObject(allEvents), "application/json"));
        }
Exemplo n.º 14
0
        // Fetch data for pie chart to show atmost top 5 patients w.r.t disease percentage
        public ActionResult PatientDiseasePercentage()
        {
            HospitalManagementContext DataContext = new HospitalManagementContext();

            List <DiseasePercentage> DiseasePercentages = DataContext.Database.SqlQuery <DiseasePercentage>("select top 5 count(p.Disease) Count, p.Disease Label from[HospitalManagement].[dbo].Patients p where p.Status = 'Admitted' group by p.Disease order by count(p.Disease) desc").ToList();

            // Set color of each percecnage section

            int TotalPatients = DataContext.Patients.Where(p => p.Status == "Admitted").ToList().Count;

            if (DiseasePercentages.Count > 0)
            {
                DiseasePercentages[0].Value     = Math.Round(((double)(DiseasePercentages[0].Count) / TotalPatients) * 100, 2);
                DiseasePercentages[0].Color     = "#13dafe";
                DiseasePercentages[0].Highlight = "#13dafe";
            }
            if (DiseasePercentages.Count > 1)
            {
                DiseasePercentages[1].Value     = Math.Round(((double)(DiseasePercentages[1].Count) / TotalPatients) * 100, 2);
                DiseasePercentages[1].Color     = "#6164c1";
                DiseasePercentages[1].Highlight = "#6164c1";
            }
            if (DiseasePercentages.Count > 2)
            {
                DiseasePercentages[2].Value     = Math.Round(((double)(DiseasePercentages[2].Count) / TotalPatients) * 100, 2);
                DiseasePercentages[2].Color     = "#99d683";
                DiseasePercentages[2].Highlight = "#99d683";
            }

            if (DiseasePercentages.Count > 3)
            {
                DiseasePercentages[3].Value     = Math.Round(((double)(DiseasePercentages[3].Count) / TotalPatients) * 100, 2);
                DiseasePercentages[3].Color     = "#ffca4a";
                DiseasePercentages[3].Highlight = "#ffca4a";
            }
            if (DiseasePercentages.Count > 4)
            {
                DiseasePercentages[4].Value     = Math.Round(((double)(DiseasePercentages[4].Count) / TotalPatients) * 100, 2);
                DiseasePercentages[4].Color     = "#4c5667";
                DiseasePercentages[4].Highlight = "#4c5667";
            }

            return(Content(JsonConvert.SerializeObject(DiseasePercentages), "application/json"));
        }
Exemplo n.º 15
0
        // Register new user connection
        public void RegisterUser(int UserId, bool IsPatient)
        {
            // Get User from database
            HospitalManagementContext db = new HospitalManagementContext();

            User User;

            if (IsPatient)
            {
                User = db.Users.Include(u => u.Patient).Where(u => u.Id == UserId).FirstOrDefault();
            }
            else
            {
                User = db.Users.Include(u => u.Doctor).Where(u => u.Id == UserId).FirstOrDefault();
            }

            if (User != null)
            {
                UserConnection UserConnection = new UserConnection()
                {
                    ConnectionId = Context.ConnectionId, IsPatient = IsPatient, User = User
                };

                Clients.Client(Context.ConnectionId).Init(
                    JsonConvert.SerializeObject(UserConnections.ToList(), Formatting.None,
                                                new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                }));

                lock (UserConnections)
                {
                    Clients.Clients(UserConnections.Keys.ToList()).NewClientRegistered(
                        JsonConvert.SerializeObject(UserConnection, Formatting.None,
                                                    new JsonSerializerSettings()
                    {
                        ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                    }));

                    UserConnections.AddOrUpdate(Context.ConnectionId, UserConnection, (key, oldValue) => UserConnection);
                }
            }
        }
        public ActionResult ResetPassword(string email, string token)
        {
            // Check token validity
            HospitalManagementContext dataContext = new HospitalManagementContext();

            User user = dataContext.Users.FirstOrDefault(u => u.Email == email && u.Token == token);

            if (user != null)
            {
                HttpContext.Session["email"] = email;
            }
            else
            {
                // Invalid token
                return(RedirectToAction("InvalidToken", "Home"));
            }

            return(View());
        }
Exemplo n.º 17
0
        public void AddPatients()
        {
            using (var context = new HospitalManagementContext())
            {
                Console.WriteLine("Enter Patient Name:");
                string pname = Console.ReadLine();
                Console.WriteLine("Enter Address:");
                string address = Console.ReadLine();
                Console.WriteLine("Enter ContactNo:");
                string contact = Console.ReadLine();
                Console.WriteLine("Enter Gender:");
                string gender = Console.ReadLine();
                Console.WriteLine("Enter Age:");
                int age = Convert.ToInt32(Console.ReadLine());
                try
                {
                    var appoint = context.Appointments.Single(b => b.PatientName == pname);
                    //Console.WriteLine(doctor.DoctorId);
                    int aid = appoint.AppointmentId;



                    var Patient = new Patients()
                    {
                        PatientName   = pname,
                        Address       = address,
                        ContactNo     = contact,
                        Gender        = gender,
                        Age           = age,
                        AppointmentId = aid,
                    };


                    context.Patients.Add(Patient);
                } catch (Exception e)
                {
                    Console.WriteLine("Patient DontTake any Appointment");
                    throw new ArgumentException("Patient DontTake any Appointment");
                }
                context.SaveChanges();
            }
        }
        // Show dashboard of admin
        public ActionResult Index()
        {
            if (HttpContext.Session["LoggedInUser"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            else
            {
                HospitalManagementContext db = new HospitalManagementContext();

                HttpContext.Session["TotalPatientList"]   = db.Users.Include(u => u.Patient).Where(u => u.Patient != null).Where(u => u.Patient.Status == "Admitted").ToList();
                HttpContext.Session["TotalPatients"]      = db.Users.Count(u => u.Patient != null && u.Patient.Status == "Admitted");
                HttpContext.Session["TotalCaregiverList"] = db.Users.Include(u => u.Caregiver).Where(u => u.Caregiver != null).ToList();
                HttpContext.Session["TotalCareGivers"]    = db.Users.Count(u => u.Caregiver != null);
                HttpContext.Session["TotalDoctorList"]    = db.Users.Include(u => u.Doctor).Where(u => u.Doctor != null).ToList();
                HttpContext.Session["TotalDoctors"]       = db.Users.Count(u => u.Doctor != null);

                return(View());
            }
        }
Exemplo n.º 19
0
        public ActionResult CountGenderPerMonthFilledLine()
        {
            HospitalManagementContext dataContext = new HospitalManagementContext();

            List <CountGendersPerMonth> GenderMonth = dataContext.Database.SqlQuery <CountGendersPerMonth>("Select u.Gender, p.EntryDate ActualDate, datename(month, DATEPART(MONTH, p.EntryDate)) month, DATEPART(MONTH, p.EntryDate) monthnumber, COUNT(p.User_Id) count from [HospitalManagement].[dbo].[Patients] p,[HospitalManagement].[dbo].[Users] u where u.Id = p.User_Id and p.Status = 'Admitted' group by DATEPART(MONTH, p.EntryDate), p.EntryDate, u.Gender").ToList();

            // Create months list
            var labels = new List <string>()
            {
                "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"
            };

            var MaleCount = new List <int>()
            {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };

            var FemaleCount = new List <int>()
            {
                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
            };

            for (int i = 0; i < GenderMonth.Count; i++)
            {
                if (GenderMonth[i].Gender == "Male")
                {
                    MaleCount[GenderMonth[i].MonthNumber - 1] = GenderMonth[i].Count;
                }
                else
                {
                    FemaleCount[GenderMonth[i].MonthNumber - 1] = GenderMonth[i].Count;
                }
            }

            return(Json(new
            {
                labels = labels,
                MaleCount = MaleCount,
                FemaleCount = FemaleCount
            }, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 20
0
        public ActionResult CountGenderPerMonthHollow()
        {
            HospitalManagementContext dataContext = new HospitalManagementContext();

            List <CountGendersPerMonth> GenderMonthFinal = new List <CountGendersPerMonth>()
            {
                new CountGendersPerMonth(0, 0, "January"),
                new CountGendersPerMonth(0, 0, "February"),
                new CountGendersPerMonth(0, 0, "March"),
                new CountGendersPerMonth(0, 0, "April"),
                new CountGendersPerMonth(0, 0, "May"),
                new CountGendersPerMonth(0, 0, "June"),
                new CountGendersPerMonth(0, 0, "July"),
                new CountGendersPerMonth(0, 0, "August"),
                new CountGendersPerMonth(0, 0, "September"),
                new CountGendersPerMonth(0, 0, "October"),
                new CountGendersPerMonth(0, 0, "November"),
                new CountGendersPerMonth(0, 0, "December")
            };

            List <CountGendersPerMonth> GenderMonth = dataContext.Database.SqlQuery <
                CountGendersPerMonth>("select datename(month, p.EntryDate) " +
                                      "Month, count(case when u.Gender = 'Female' then 1 end)" +
                                      " FemaleCount, count(case when u.Gender = 'Male' then 1 end)" +
                                      " MaleCount from [dbo].[Patients] p left join [dbo].[Users] " +
                                      "u on p.User_Id = u.Id where p.Status = 'Admitted' group by datename(month, p.EntryDate);").ToList();

            for (int i = 0; i < GenderMonthFinal.Count; i++)
            {
                for (int j = 0; j < GenderMonth.Count; j++)
                {
                    if (GenderMonth[j].Month == GenderMonthFinal[i].Month)
                    {
                        GenderMonthFinal[i].MaleCount   = GenderMonth[j].MaleCount;
                        GenderMonthFinal[i].FemaleCount = GenderMonth[j].FemaleCount;
                    }
                }
            }

            return(Content(JsonConvert.SerializeObject(GenderMonthFinal), "application/json"));
        }
Exemplo n.º 21
0
 public void assignAssistant()
 {
     using (var context = new HospitalManagementContext())
     {
         Console.WriteLine("Enter Patient Name:");
         string pname     = Console.ReadLine();
         var    appoint   = context.Appointments.Single(b => b.PatientName == pname);
         int    appointid = appoint.AppointmentId;
         Console.WriteLine("Enter AssistantName:");
         string assist           = Console.ReadLine();
         var    assistant        = context.HealthAssistants.Single(b => b.AssistantName == assist);
         int    assistid         = assistant.AssistantId;
         var    assignAssistants = new AssignAssistants()
         {
             AssistantId   = assistid,
             AppointmentId = appointid,
         };
         context.AssignAssistants.Add(assignAssistants);
         context.SaveChanges();
     }
 }
Exemplo n.º 22
0
        public ActionResult GetUpdatedCountsAndList()
        {
            User user = (User)HttpContext.Session["LoggedInUser"];

            if (user != null && user.Role.Name == "Admin")
            {
                HospitalManagementContext db = new HospitalManagementContext();

                HttpContext.Session["TotalPatientList"]   = db.Users.Include(u => u.Patient).Where(u => u.Patient != null).Where(u => u.Patient.Status == "Admitted").ToList();
                HttpContext.Session["TotalPatients"]      = db.Users.Count(u => u.Patient != null && u.Patient.Status == "Admitted");
                HttpContext.Session["TotalCaregiverList"] = db.Users.Include(u => u.Caregiver).Where(u => u.Caregiver != null).ToList();
                HttpContext.Session["TotalCareGivers"]    = db.Users.Count(u => u.Caregiver != null);
                HttpContext.Session["TotalDoctorList"]    = db.Users.Include(u => u.Doctor).Where(u => u.Doctor != null).ToList();
                HttpContext.Session["TotalDoctors"]       = db.Users.Count(u => u.Doctor != null);
            }

            return(Json(new
            {
                Status = "updated"
            }, JsonRequestBehavior.AllowGet));
        }
        // Show security dashboard of admin
        public ActionResult Security()
        {
            if (HttpContext.Session["LoggedInUser"] == null)
            {
                return(RedirectToAction("Login", "Home"));
            }
            else
            {
                HospitalManagementContext db = new HospitalManagementContext();

                HttpContext.Session["RecetlyRegisteredUserList"] = db.Users.OrderByDescending(u => u.Id).Take(10).ToList();
                HttpContext.Session["TotalLoginUsers"]           = db.Users.Count(u => u.IsLogin != null && u.IsLogin == true);
                HttpContext.Session["TotalLogoutUsers"]          = db.Users.Count(u => u.IsLogin == null || u.IsLogin == false);
                HttpContext.Session["TotalInactive"]             = db.Users.Count(u => (u.IsLogin == null || u.IsLogin == false) && u.LastLogin != null && DbFunctions.DiffDays(u.LastLogin.Value, DateTime.Now) > 1);
                HttpContext.Session["InactiveUserList"]          = db.Users.Where(u => (u.IsLogin == null || u.IsLogin == false) && u.LastLogin != null && DbFunctions.DiffDays(u.LastLogin.Value, DateTime.Now) > 1).ToList();
                HttpContext.Session["FailLoginAttemptList"]      = db.LoginAttempts.Where(l => l.IsPassed == false).ToList();
                HttpContext.Session["AllUserList"] = db.Users.ToList();

                return(View());
            }
        }
Exemplo n.º 24
0
 public void AddAppointments()
 {
     using (var context = new HospitalManagementContext())
     {
         Console.WriteLine("Enter Patient Name:");
         string pname = Console.ReadLine();
         Console.WriteLine("Enter Doctor Name:");
         string dname = Console.ReadLine();
         Console.WriteLine("Enter Appointment Time:");
         string time   = Console.ReadLine();
         var    doctor = context.Doctors.Single(b => b.DoctorName == dname);
         //Console.WriteLine(doctor.DoctorId);
         int doctorid = doctor.DoctorId;
         var appoint  = new Appointments()
         {
             PatientName     = pname,
             DoctorId        = doctorid,
             AppointmentTime = System.DateTime.Parse(time),
         };
         context.Appointments.Add(appoint);
         context.SaveChanges();
     }
 }
        public ActionResult CountLoginAttemptsPerMonthHollow()
        {
            HospitalManagementContext dataContext = new HospitalManagementContext();

            List <CountLoginAttemptPerMonth> countLoginAttemptPerMonthFinal = new List <CountLoginAttemptPerMonth>()
            {
                new CountLoginAttemptPerMonth(0, 0, "January"),
                new CountLoginAttemptPerMonth(0, 0, "February"),
                new CountLoginAttemptPerMonth(0, 0, "March"),
                new CountLoginAttemptPerMonth(0, 0, "April"),
                new CountLoginAttemptPerMonth(0, 0, "May"),
                new CountLoginAttemptPerMonth(0, 0, "June"),
                new CountLoginAttemptPerMonth(0, 0, "July"),
                new CountLoginAttemptPerMonth(0, 0, "August"),
                new CountLoginAttemptPerMonth(0, 0, "September"),
                new CountLoginAttemptPerMonth(0, 0, "October"),
                new CountLoginAttemptPerMonth(0, 0, "November"),
                new CountLoginAttemptPerMonth(0, 0, "December")
            };

            List <CountLoginAttemptPerMonth> countLoginAttemptPerMonth = dataContext.Database.SqlQuery <CountLoginAttemptPerMonth>("select DATENAME(month, DateAdd( month , Month(l.AttemptDateTime) , 0 ) - 1) Month, count(case when l.IsPassed = 0 then 1 end) FailAttempts, count(case when l.IsPassed = 1 then 1 end) SuccessAttempts from [HospitalManagement].[dbo].[LoginAttempts] l where YEAR(l.AttemptDateTime) = ' " + DateTime.Now.Year + " ' GROUP BY MONTH(l.AttemptDateTime);").ToList();

            for (int i = 0; i < countLoginAttemptPerMonthFinal.Count; i++)
            {
                for (int j = 0; j < countLoginAttemptPerMonth.Count; j++)
                {
                    if (countLoginAttemptPerMonth[j].Month == countLoginAttemptPerMonthFinal[i].Month)
                    {
                        countLoginAttemptPerMonthFinal[i].FailAttempts    = countLoginAttemptPerMonth[j].FailAttempts;
                        countLoginAttemptPerMonthFinal[i].SuccessAttempts = countLoginAttemptPerMonth[j].SuccessAttempts;
                    }
                }
            }

            return(Content(JsonConvert.SerializeObject(countLoginAttemptPerMonthFinal), "application/json"));
        }
        public ActionResult Login(LoginModel loginModel)
        {
            if (ModelState.IsValid)
            {
                HospitalManagementContext dataContext = new HospitalManagementContext();

                User user = dataContext.Users.FirstOrDefault(u => u.Email == loginModel.Email);

                if (user != null)
                {
                    if (user.IsEnabled != null && user.IsEnabled.Value == false)
                    {
                        ModelState.AddModelError("", "Your account is disabled");
                        return(View());
                    }

                    string salt = "";

                    if (user.Salt != null)
                    {
                        salt = user.Salt;
                    }

                    string sha256 = Crypto.SHA256(loginModel.Password + salt);

                    // Check credentials
                    user = dataContext.Users.FirstOrDefault(u => u.Email == loginModel.Email && u.Password == sha256);

                    if (user != null)
                    {
                        // Perform 2 factor authentication
                        //if (user.ContactNo != null || user.ContactNo != "")
                        //{
                        //    string messageId = this.SendSms(user.ContactNo);

                        //    if (messageId != null)
                        //    {
                        //        loginModel.VerificationCode = this.verificationCode;
                        //        HttpContext.Session["LoginModel"] = loginModel;
                        //        HttpContext.Session["VerificationCodeExpiration"] = DateTime.Now;
                        //        return RedirectToAction("Verify", "Home");
                        //    }
                        //}

                        user.IsLogin   = true;
                        user.LastLogin = DateTime.Now;

                        dataContext.SaveChanges();

                        LoginAttempt loginAttempt = new LoginAttempt();

                        loginAttempt.AttemptDateTime = DateTime.Now;
                        loginAttempt.Email           = loginModel.Email;
                        loginAttempt.IsPassed        = true;
                        loginAttempt.IpAddress       = Request.UserHostAddress;

                        dataContext.LoginAttempts.Add(loginAttempt);

                        dataContext.SaveChanges();

                        HttpContext.Session["LoggedInUser"] = user;
                        // Check if admin
                        if (user.Role.Name == "Admin")
                        {
                            HttpContext.Session["Role"]                      = "Admin";
                            HttpContext.Session["TotalPatientList"]          = dataContext.Users.Where(u => u.Patient != null).Where(u => u.Patient.Status == "Admitted").ToList();
                            HttpContext.Session["TotalPatients"]             = dataContext.Users.Count(u => u.Patient != null && u.Patient.Status == "Admitted");
                            HttpContext.Session["TotalCaregiverList"]        = dataContext.Users.Where(u => u.Caregiver != null).ToList();
                            HttpContext.Session["TotalCareGivers"]           = dataContext.Users.Count(u => u.Caregiver != null);
                            HttpContext.Session["TotalDoctorList"]           = dataContext.Users.Where(u => u.Doctor != null).ToList();
                            HttpContext.Session["TotalDoctors"]              = dataContext.Users.Count(u => u.Doctor != null);
                            HttpContext.Session["RecetlyRegisteredUserList"] = dataContext.Users.OrderByDescending(u => u.Id).Take(10).ToList();
                            HttpContext.Session["TotalLoginUsers"]           = dataContext.Users.Count(u => u.IsLogin != null && u.IsLogin == true);
                            HttpContext.Session["TotalLogoutUsers"]          = dataContext.Users.Count(u => u.IsLogin == null || u.IsLogin == false);
                            HttpContext.Session["TotalInactive"]             = dataContext.Users.Count(u => (u.IsLogin == null || u.IsLogin == false) && u.LastLogin != null && DbFunctions.DiffDays(u.LastLogin.Value, DateTime.Now) > 1);

                            return(RedirectToAction("Index", "Home"));
                        }

                        else if (user.Role.Name == "Patient")
                        {
                            HttpContext.Session["Patient"]   = user.Patient;
                            HttpContext.Session["PatientId"] = user.Patient.Id;
                            HttpContext.Session["Doctor"]    = null;
                            HttpContext.Session["DoctorId"]  = -1;
                            HttpContext.Session["Role"]      = "Patient";
                            return(RedirectToAction("Index", "Patient"));
                        }

                        else if (user.Role.Name == "Caregiver")
                        {
                            HttpContext.Session["Role"] = "Caregiver";
                            return(RedirectToAction("Index", "CareGiver"));
                        }

                        else if (user.Role.Name == "Doctor")
                        {
                            HttpContext.Session["Patient"]   = null;
                            HttpContext.Session["PatientId"] = -1;
                            HttpContext.Session["Doctor"]    = user.Doctor;
                            HttpContext.Session["DoctorId"]  = user.Doctor.Id;
                            HttpContext.Session["Role"]      = "Doctor";
                            return(RedirectToAction("Index", "Doctor"));
                        }
                    }
                    // Invalid credentials
                    else
                    {
                        user = dataContext.Users.FirstOrDefault(u => u.Email == loginModel.Email);
                        // Log login attempt
                        int loginAttemptCount = user.LoginAttemptCount == null ? 0 : user.LoginAttemptCount.Value;

                        if (loginAttemptCount >= maxLoginAttempt)
                        {
                            // Disable the account

                            user.IsEnabled   = false;
                            user.EnableToken = GenerateRandomString(8);

                            var    resetLink = "<a href='" + Url.Action("EnableAccount", "Home", new { email = user.Email, token = user.EnableToken }, "http") + "'>Enable Account Now</a>";
                            string body      = "Someone try to login to your account. We disabled your account.<br/><br/><b>You can enable your account by clicking below link</b><br/>" + resetLink;

                            try
                            {
                                SendEMail(user.Email, "Invalid Login Attempt", body);
                            }
                            catch (Exception e)
                            {
                                // Do what you want
                            }
                        }

                        user.LoginAttemptCount = loginAttemptCount + 1;

                        dataContext.SaveChanges();

                        // Add database entry
                        LoginAttempt loginAttempt = new LoginAttempt();

                        loginAttempt.AttemptDateTime = DateTime.Now;
                        loginAttempt.Email           = loginModel.Email;
                        loginAttempt.Password        = loginModel.Password;
                        loginAttempt.IsPassed        = false;
                        loginAttempt.IpAddress       = Request.UserHostAddress;

                        dataContext.LoginAttempts.Add(loginAttempt);

                        dataContext.SaveChanges();

                        ModelState.AddModelError("", "Invalid username or password");
                    }
                }
                // Invalid credentials
                else
                {
                    // Add database entry
                    LoginAttempt loginAttempt = new LoginAttempt();

                    loginAttempt.AttemptDateTime = DateTime.Now;
                    loginAttempt.Email           = loginModel.Email;
                    loginAttempt.Password        = loginModel.Password;
                    loginAttempt.IsPassed        = false;
                    loginAttempt.IpAddress       = Request.UserHostAddress;

                    dataContext.LoginAttempts.Add(loginAttempt);

                    dataContext.SaveChanges();

                    ModelState.AddModelError("", "Invalid username or password");
                }
            }

            return(View());
        }
Exemplo n.º 27
0
 public PatientsController(HospitalManagementContext context)
 {
     _context = context;
 }
Exemplo n.º 28
0
        // In this method we will create default User roles and Admin user for login
        private void createRolesandUsers()
        {
            ApplicationDbContext context = new ApplicationDbContext();

            var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
            var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));


            // In Startup iam creating first Admin Role and creating a default Admin User
            if (!roleManager.RoleExists("SuperAdmin"))
            {
                HospitalManagementContext _context = new HospitalManagementContext();
                // first we create Admin rool
                var role = new IdentityRole();
                role.Name = "SuperAdmin";
                roleManager.Create(role);

                //Here we create a Admin super user who will maintain the website

                var user = new ApplicationUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";

                string    userPWD = "abc123";
                AdminRole Admins  = new AdminRole();
                Admins.Name       = "Super";
                Admins.Role       = "SuperAdmin";
                Admins.Updated    = DateTime.Today;
                Admins.UpdatedBy  = "Origin Super Admin";
                Admins.IsBlocked  = "Active";
                Admins.IsAssigned = "Control Room";
                Admins.BuildingId = 0;
                Admins.PostId     = 0;
                _context.Admins.Add(Admins); _context.SaveChanges();

                var chkUser = UserManager.Create(user, userPWD);

                //Add default User to Role Admin
                if (chkUser.Succeeded)
                {
                    var result1 = UserManager.AddToRole(user.Id, "SuperAdmin");
                }
            }

            // creating Creating Manager role
            if (!roleManager.RoleExists("FloorAdmin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "FloorAdmin";
                roleManager.Create(role);
            }

            // creating Creating Employee role
            if (!roleManager.RoleExists("LabAdmin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "LabAdmin";
                roleManager.Create(role);
            }

            // creating Creating Employee role
            if (!roleManager.RoleExists("TicketAdmin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "TicketAdmin";
                roleManager.Create(role);
            }

            // creating Creating Employee role
            if (!roleManager.RoleExists("BillAdmin"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "BillAdmin";
                roleManager.Create(role);
            }
        }
        public ActionResult Register(SignupModel signupModel, bool captchaValid)
        {
            if (ModelState.IsValid)
            {
                // Do signup
                // 2 uppercases, 1 special case, 2 digits, 3 lower case and length 8
                string regex = "^(?=.*?[A-Z].*?[A-Z])(?=.*[!@#$&*])(?=.*?[0-9].*?[0-9])(?=.*?[a-z].*?[a-z].*?[a-z]).{8,}$";
                //string regex = "^(?=.*?[0-9].*?[0-9])(?=.*[!@#$%])[0-9a-zA-Z!@#$%0-9]{8,}$";

                if (!Regex.IsMatch(signupModel.Password, regex))
                {
                    ModelState.AddModelError("Password", "Password should contain 2 uppercases, 1 special case, 2 digits and 3 lowercases.");
                    return(View());
                }

                HospitalManagementContext dataContext = new HospitalManagementContext();
                // Check credentials
                User user = dataContext.Users.FirstOrDefault(u => u.Email == signupModel.Email);

                if (user != null)
                {
                    ModelState.AddModelError("Email", "User already exists");
                    return(View());
                }

                user = new User();

                user.ContactNo         = signupModel.ContactNo;
                user.Salt              = GenerateRandomString(10);
                user.Password          = Crypto.SHA256(signupModel.Password + user.Salt);
                user.Email             = signupModel.Email;
                user.IsEnabled         = true;
                user.LoginAttemptCount = 0;

                // add role as patient
                if (signupModel.signupAs == SignupAs.Patient)
                {
                    user.Role = dataContext.Roles.ToList().Where(u => u.Name == "Patient").FirstOrDefault();
                    // Entry date and time
                    user.Patient = new Patient();

                    user.Patient.EntryDate = DateTime.Now;
                    user.Patient.EntryTime = DateTime.Now.TimeOfDay;
                    user.Patient.Status    = "Admitted";
                }
                else if (signupModel.signupAs == SignupAs.Doctor)
                {
                    user.Doctor = new Doctor();
                    user.Role   = dataContext.Roles.ToList().Where(u => u.Name == "Doctor").FirstOrDefault();
                }
                else
                {
                    user.Caregiver = new Caregiver();
                    user.Role      = dataContext.Roles.ToList().Where(u => u.Name == "Caregiver").FirstOrDefault();
                }

                dataContext.Users.Add(user);

                dataContext.SaveChanges();

                return(RedirectToAction("Success", "Home"));
            }
            if (!captchaValid)
            {
                Console.WriteLine("Invalid recaptcha");
            }
            return(View());
        }
Exemplo n.º 30
0
 public GenericRepository(HospitalManagementContext context)
 {
     _context = context;
     DbSet    = _context.Set <T>();
 }