Пример #1
0
        public ActionResult SavePharmacist(Pharmacist m, String command)
        {
            // if id's are default, get actual id's for the (new) pharmacist
            // use sql to save pharmacist to db
            if (m.PharmacistId == 0)
            {
                m.Type = Models.User.UserType.Pharmacist;
                var phid = DatabaseUserService.Insert(m);
                m.UserId       = phid;
                m.PharmacistId = DatabasePharmacistService.Insert(m);
                var login = new Login();
                login.LoginToken = "";
                login.UserId     = m.UserId;
                login.SetPassword(Login.GetUniqueKey(32));
                DatabaseLoginService.Insert(login);
                EmailService.SendReset(m);
            }
            else
            {
                DatabaseUserService.Update(m);
                DatabasePharmacistService.Update(m);
            }

            if (DatabaseUserService.GetById((long)Session["user_id"]).Type == Models.User.UserType.PPOkAdmin)
            {
                return(RedirectToAction("AddorEditPharmacy", "PpokAdmin", new { id = m.PharmacyId }));
            }
            return(RedirectToAction("Admin", "Pharmacy"));
        }
        /**
         * Receives a password reset token sent from email in order to redirect to
         * the proper password reset page.
         *
         * @receives - request link from email with embedded one time password
         */
        public ActionResult Reset()
        {
            try {
                var userOtp = DatabaseOtpService.GetByCode(RouteData.Values["otp"].ToString());
                var user    = DatabaseUserService.GetById(userOtp.UserId);

                if (userOtp.IsActive())
                {
                    if (user.Enabled)
                    {
                        return(View("../Login/Reset", new LoginController.ResetData {
                            Email = user.Email, OTP = userOtp.Code
                        }));
                    }
                    else
                    {
                        return(ResetFailure());
                    }
                }
                else
                {
                    return(ExpiredOtp());
                }
            } catch (Exception) {
                return(BadLink());
            }
        }
Пример #3
0
        public ActionResult DeletePharmacist(long id)
        {
            long pharmacyId = DatabasePharmacistService.GetById(id).PharmacyId;

            DatabasePharmacistService.Disable((int)id);
            if (DatabaseUserService.GetById((long)Session["user_id"]).Type == Models.User.UserType.PPOkAdmin)
            {
                return(RedirectToAction("AddorEditPharmacy", "PpokAdmin", new { id = pharmacyId }));
            }
            return(RedirectToAction("Admin", "Pharmacy"));
        }
        public ActionResult ResetRequest(string email)
        {
            var user = DatabaseUserService.GetByEmail(email);

            if (user == null)
            {
                return(Index());
            }

            EmailService.SendReset(user);
            return(ResetRequestSent());
        }
Пример #5
0
        //Sends test emails with working callbacks to the email specified
        public string SendTestEmail()
        {
            var u  = new User();
            var p  = new Patient();
            var n  = new Notification();
            var pr = new Prescription();
            var r  = new Refill();

            u.Email     = "*****@*****.**";     // PUT YOUR EMAIL HERE TO TEST
            u.FirstName = "Test";
            u.LastName  = "User";
            u.Phone     = "+14055555555";
            u.UserId    = DatabaseUserService.Insert(u);

            p.UserId              = u.UserId;
            p.PharmacyId          = 1;
            p.DateOfBirth         = DateTime.Now;
            p.PreferedContactTime = DateTime.Now;
            p.ContactMethod       = Patient.PrimaryContactMethod.Email;
            p.PersonCode          = "0";
            p.SendBirthdayMessage = true;
            p.SendRefillMessage   = true;
            p.PatientId           = DatabasePatientService.Insert(p);

            pr.PatientId = p.PatientId;
            pr.PrescriptionDaysSupply = 30;
            pr.PrescriptionRefills    = 3;
            pr.PrescriptionName       = "Tylenol";
            pr.PrescriptionNumber     = 1;
            pr.PrescriptionUpc        = "ABC123";
            pr.PrescriptionDateFilled = DateTime.Now;
            pr.PrescriptionId         = DatabasePrescriptionService.Insert(pr);

            r.RefillIt       = false;
            r.PrescriptionId = pr.PrescriptionId;
            r.Refilled       = false;
            r.RefillDate     = DateTime.Now;
            r.RefillId       = DatabaseRefillService.Insert(r);

            n.PatientId           = p.PatientId;
            n.Type                = Notification.NotificationType.Refill;
            n.NotificationMessage = "This is a test email for a refill";
            n.ScheduledTime       = DateTime.Now;
            n.SentTime            = null;
            n.Sent                = false;
            n.NotificationId      = DatabaseNotificationService.Insert(n);


            EmailService.SendNotification(n);
            EmailService.SendReset(u);

            return("Sent an notification and reset email to test account");
        }
Пример #6
0
        public User LoadUserData()
        {
            var user = DatabaseUserService.GetById(UserId);

            LastName  = user.LastName;
            FirstName = user.FirstName;
            Phone     = user.Phone;
            Email     = user.Email;
            Type      = user.Type;
            Enabled   = user.Enabled;
            return(this);
        }
Пример #7
0
        public ActionResult UploadRecalls(HttpPostedFileBase upload, string recallMessage)
        {
            var pharm = DatabasePharmacyService.GetById((long)Session["pharm_id"]);

            pharm.GetTemplates();
            if (ModelState.IsValid)
            {
                if (upload != null && upload.ContentLength > 0)
                {
                    if (upload.FileName.EndsWith(".csv"))
                    {
                        var stream   = upload.InputStream;
                        var csvTable = new DataTable();
                        using (var csvReader =
                                   new CsvReader(new StreamReader(stream), true))
                        {
                            csvTable.Load(csvReader);
                        }
                        foreach (DataRow row in csvTable.Rows)
                        {
                            var patient = new Patient {
                                FirstName           = row["PatientFirstName"].ToString(),
                                LastName            = row["PatientLastName"].ToString(),
                                Phone               = row["Phone"].ToString(),
                                PharmacyId          = 1,
                                DateOfBirth         = DateTime.Now,
                                Email               = "*****@*****.**",
                                ContactMethod       = Patient.PrimaryContactMethod.Call,
                                PreferedContactTime = DateTime.Now,
                                PersonCode          = row["PersonCode"].ToString()
                            };
                            var id = DatabaseUserService.Insert(patient);
                            patient.UserId    = id;
                            patient.PatientId = DatabasePatientService.Insert(patient);
                            var notification = new Notification(DateTime.Now, patient.PatientId, Notification.NotificationType.Recall, recallMessage);
                            DatabasePatientService.Disable(patient.PatientId);
                            DatabaseNotificationService.Insert(notification);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("File", "This file format is not supported");
                        return(View(pharm));
                    }
                }
                else
                {
                    ModelState.AddModelError("File", "Please Upload Your file");
                }
            }
            return(View(pharm));
        }
Пример #8
0
        public ActionResult Login(string phonenumber)
        {
            // just a bit of input cleanup
            phonenumber = new Regex("[\\(\\)\\s+\\-]").Replace(phonenumber, "");
            if (!phonenumber.StartsWith("+"))
            {
                if (phonenumber.Length == 10)
                {
                    phonenumber = "+1" + phonenumber;
                }
                else
                {
                    phonenumber = "+" + phonenumber;
                }
            }
            else
            {
                if (phonenumber.Length == 11)
                {
                    phonenumber = "+1" + phonenumber.Substring(1);
                }
            }

            // TODO Tyler - skip this step and get patient directly from phone number?
            var user = DatabaseUserService.GetByPhoneActive(phonenumber);

            if (user == null)
            {
                return(Code(null));
            }

            var patient = DatabasePatientService.GetByUserIdActive(user.UserId);

            if (patient == null)
            {
                return(Code(null));
            }

            var otp = new OTP()
            {
                UserId = patient.UserId,
                Time   = DateTime.Now,
                Code   = new Random().Next(0, 1000000).ToString("000000")
            };

            DatabaseOtpService.Insert(otp);
            NotificationSender.SendNotification(patient, "Your one-time patient login code is " + otp.Code);

            return(Code(patient.UserId));
        }
        private ActionResult RedirectToProperPage(long userId)
        {
            var user = DatabaseUserService.GetById(userId);

            if (user.Type == Models.User.UserType.PPOkAdmin)
            {
                return(Redirect("/PpokAdmin/PharmacyListView"));
            }
            if (user.Type == Models.User.UserType.Pharmacist)
            {
                Session["pharm_id"] = DatabasePharmacistService.GetByUserId(user.UserId).PharmacyId;
                return(Redirect("/Pharmacy/RefillListView"));
            }
            return(null);
        }
Пример #10
0
        public string AddFakeLogin(long pid)
        {
            var pharmAdmin = new Pharmacist {
                FirstName  = "Pharma",
                LastName   = "cist",
                Phone      = "+19999999993",
                Email      = "*****@*****.**",
                PharmacyId = pid,
                UserId     = 1,
                IsAdmin    = true,
                Type       = Models.User.UserType.Pharmacist
            };

            pharmAdmin.UserId = DatabaseUserService.Insert(pharmAdmin);
            var login = new Login {
                LoginId    = 1,
                UserId     = pharmAdmin.UserId,
                LoginToken = ""
            };

            login.SetPassword("harambe");
            DatabaseLoginService.Insert(login);

            DatabasePharmacistService.Insert(pharmAdmin);

            var ppokAdmin = new User {
                LastName  = "dmin",
                FirstName = "PPOk A",
                Type      = Models.User.UserType.PPOkAdmin,
                Phone     = "+19999999998",
                Email     = "*****@*****.**"
            };

            ppokAdmin.UserId = DatabaseUserService.Insert(ppokAdmin);

            var login2 = new Login {
                UserId     = ppokAdmin.UserId,
                LoginToken = ""
            };

            login2.SetPassword("harambe");

            DatabaseLoginService.Insert(login2);

            return("sucess <br/> Pharm: username: [email protected] password: harambe <br/> Admin: username: [email protected] password: harambe");
        }
Пример #11
0
        public ActionResult SavePatient(Patient m, String command)
        {
            // if id's are default, get actual id's for the (new) patient
            // use sql to save patient to db

            if (m.PatientId == 0)
            {
                m.PharmacyId = (long)Session["pharm_id"];
                var pid = DatabaseUserService.Insert((User)m);
                m.UserId = pid;
                DatabasePatientService.Insert(m);
            }
            else
            {
                DatabaseUserService.Update(m);
                DatabasePatientService.Update(m);
            }

            return(PatientListView());
        }
Пример #12
0
        public string AddFakePatient(long pid)
        {
            var pat = new Patient {
                ContactMethod       = Patient.PrimaryContactMethod.Text,
                FirstName           = "John",
                LastName            = "Doe",
                PersonCode          = "1",
                DateOfBirth         = System.DateTime.Now,
                Phone               = "+18065703539",
                PharmacyId          = pid,
                PreferedContactTime = System.DateTime.Now,
                SendRefillMessage   = true,
                SendBirthdayMessage = true
            };
            var id = DatabaseUserService.Insert(pat);

            pat.UserId = id;
            var patId = DatabasePatientService.Insert(pat);

            this.AddFakePresRefillNotif(patId);
            return("success");
        }
Пример #13
0
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (SkipAuthorization(filterContext))
            {
                return;
            }

            var userId = HttpContext.Current.Session[Login.UserIdSession];

            if (userId == null)
            {
                filterContext.Result = new RedirectResult("/Login/Index");
                return;
            }

            var user = DatabaseUserService.GetById((long)userId);

            if (user == null)
            {
                filterContext.Result = new RedirectResult("/Login/Index");
                return;
            }

            switch (user.Type)
            {
            case User.UserType.Pharmacist:
                var pharmacist = DatabasePharmacistService.GetByUserId((long)userId);
                if (pharmacist.IsAdmin)
                {
                    if (!_groups.Contains(Group.PharmacyAdmin))
                    {
                        filterContext.Result = new RedirectResult("/Login/Index");
                        return;
                    }
                }
                else
                {
                    if (!_groups.Contains(Group.Pharmacist))
                    {
                        filterContext.Result = new RedirectResult("/Login/Index");
                        return;
                    }
                }
                break;

            case User.UserType.PPOkAdmin:
                if (!_groups.Contains(Group.PPOkAdmin))
                {
                    filterContext.Result = new RedirectResult("/Login/Index");
                    return;
                }
                break;

            case User.UserType.Patient:
                if (!_groups.Contains(Group.Patient))
                {
                    filterContext.Result = new RedirectResult("/Login/Index");
                    return;
                }
                break;
            }

            base.OnActionExecuting(filterContext);
        }
Пример #14
0
        public static Login GetLogin(string email)
        {
            var user = DatabaseUserService.GetByEmail(email);

            return(user == null ? null : DatabaseLoginService.GetByUserId(user.UserId));
        }
Пример #15
0
        public ActionResult SmsResponse()
        {
            var messagingResponse = new MessagingResponse();

            System.Diagnostics.Debug.WriteLine("SMS Response" + " " + Request["from"] + " " + Request["body"]);
            if (Request["body"].ToLower() == "yes")
            {
                var          users  = DatabaseUserService.GetMultipleByPhone(Request["from"]);
                Patient      user   = null;
                Notification newest = null;
                foreach (var u in users)
                {
                    var patT           = DatabasePatientService.GetByUserIdActive(u.UserId);
                    var notificationsT = DatabaseNotificationService.GetByPatientId(patT.PatientId);
                    var newestT        = notificationsT[0];
                    foreach (var n in notificationsT)
                    {
                        if (newestT.SentTime > n.SentTime)
                        {
                            newestT = n;
                        }
                    }
                    if (newestT.Sent && newestT.SentTime > DateTime.Now.AddMinutes(-10))
                    {
                        user   = patT;
                        newest = newestT;
                    }
                }
                user.LoadUserData();
                newest.NotificationResponse = Request["body"];
                DatabaseNotificationService.Update(newest);
                var pres   = DatabasePrescriptionService.GetByPatientId(user.PatientId);
                var refill = DatabaseRefillService.GetByPrescriptionId(pres.PrescriptionId);
                refill.RefillIt = true;
                DatabaseRefillService.Update(refill);
                messagingResponse.Message("Thanks, your prescription will be ready shortly");
            }
            else if (Request["body"].ToLower() == "stop")
            {
                var user          = DatabaseUserService.GetByPhoneActive(Request["from"]);
                var pat           = DatabasePatientService.GetByUserIdActive(user.UserId);
                var notifications = DatabaseNotificationService.GetByPatientId(pat.PatientId);
                var newest        = notifications[0];
                foreach (var n in notifications)
                {
                    if (newest.SentTime < n.SentTime)
                    {
                        newest = n;
                    }
                }
                if (newest.Type == Notification.NotificationType.Refill)
                {
                    pat.SendRefillMessage = false;
                    messagingResponse.Message("You have been unsubscribed from refill notifications");
                }
                else if (newest.Type == Notification.NotificationType.Birthday)
                {
                    pat.SendBirthdayMessage = false;
                    messagingResponse.Message("You have been unsubscribed from birthday notifications");
                }
                else if (newest.Type == Notification.NotificationType.Ready)
                {
                    pat.SendRefillMessage = false;
                    messagingResponse.Message("You have been unsubscribed from refill notifications");
                }
                DatabasePatientService.Update(pat);
            }
            else if (Request["body"].ToLower() == "stop all")
            {
                var user = DatabaseUserService.GetByPhoneActive(Request["from"]);
                var pat  = DatabasePatientService.GetByUserIdActive(user.UserId);
                pat.ContactMethod = Patient.PrimaryContactMethod.OptOut;
            }



            return(new TwiMLResult(messagingResponse));
        }