Esempio n. 1
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));
        }
Esempio n. 2
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));
        }