Пример #1
0
        public ActionResult SendNotification(long id)
        {
            var n = DatabaseNotificationService.GetById(id);

            NotificationSending.NotificationSender.SendNotification(n);
            return(Redirect("/Notification/NotificationList"));
        }
Пример #2
0
 public static Notification MarkSent(Notification notification, DateTime time)
 {
     notification.Sent     = true;
     notification.SentTime = time;
     DatabaseNotificationService.Update(notification);
     return(notification);
 }
Пример #3
0
        public ActionResult RecallResponse(long id)
        {
            var    notification = DatabaseNotificationService.GetById(id);
            var    user         = DatabasePatientService.GetById(notification.PatientId);
            string digits       = Request["Digits"];

            System.Diagnostics.Debug.WriteLine(digits);
            if (digits.Contains("9"))
            {
                var xml = new XDocument(
                    new XElement("Response",
                                 new XElement("Say",
                                              "Connecting you to a pharmacist."),
                                 new XElement("Dial",
                                              DatabasePharmacyService.GetById(user.PharmacyId).PharmacyPhone)
                                 )
                    );
                return(new XmlActionResult(xml));
            }
            else
            {
                var xml = new XDocument(
                    new XElement("Response",
                                 new XElement("Say",
                                              "Unrecognized Input, Goodbye")
                                 )
                    );
                return(new XmlActionResult(xml));
            }
        }
Пример #4
0
        public ActionResult Refill(long id)
        {
            var      n   = DatabaseNotificationService.GetById(id);
            var      pat = DatabasePatientService.GetById(n.PatientId);
            Pharmacy p   = DatabasePharmacyService.GetById(pat.PharmacyId);

            p.GetTemplates();
            string message = p.GetRefillTemplate().TemplatePhone;
            var    xml     = new XDocument(
                new XElement("Response",
                             new XElement("Gather",
                                          new XAttribute("timeout", "10"),
                                          new XAttribute("numDigits", "1"),
                                          new XAttribute("action", "https://ocharambe.localtunnel.me/twilioresponse/refillresponse/" + id),
                                          new XElement("Say",
                                                       message
                                                       )
                                          ),
                             new XElement("Say",
                                          "We didn't recieve any input, Goodbye!")
                             )
                );

            return(new XmlActionResult(xml));
        }
        /**
         * Modifies a patients contact preferences to request not to be
         * contacted again.
         *
         * @receives - unsubscribe request from the bottom of notification based emails
         */
        public ActionResult Unsubscribe()
        {
            try {
                var otp          = DatabaseEmailOtpService.GetByCode(RouteData.Values["otp"].ToString());
                var notification = DatabaseNotificationService.GetById(otp.NotificationId);
                var patient      = DatabasePatientService.GetById(notification.PatientId);

                if (otp.IsActive())
                {
                    if (patient.object_active)
                    {
                        patient.ContactMethod = Patient.PrimaryContactMethod.OptOut;
                        DatabasePatientService.Update(patient);

                        notification.NotificationResponse = "Unsubscribe";
                        DatabaseNotificationService.Update(notification);

                        DatabaseEmailOtpService.Disable(otp.Id);

                        return(UnsubscribeSuccess());
                    }
                    else
                    {
                        return(UnsubscribeFailure());
                    }
                }
                else
                {
                    return(ExpiredOtp());
                }
            } catch (Exception) {
                return(BadLink());
            }
        }
        /**
         * Sets a notification as responded to. Since the only response requried
         * by an email, other than ignoring it, is YES it simply starts a refill
         *
         * @receives - refill response link from sent emails
         */
        public ActionResult Respond()
        {
            try {
                var otp          = DatabaseEmailOtpService.GetByCode(RouteData.Values["otp"].ToString());
                var notification = DatabaseNotificationService.GetById(otp.NotificationId);
                var patient      = DatabasePatientService.GetById(notification.PatientId);

                if (otp.IsActive())
                {
                    if (patient.object_active)
                    {
                        notification.NotificationResponse = "Refill";
                        DatabaseNotificationService.Update(notification);

                        var refill = DatabaseRefillService.GetByPrescriptionId(DatabasePrescriptionService.GetByPatientId(patient.PatientId).PrescriptionId);
                        refill.RefillIt = true;
                        DatabaseRefillService.Update(refill);

                        DatabaseEmailOtpService.Disable(otp.Id);

                        return(RefillSuccess());
                    }
                    else
                    {
                        return(RefillFailure());
                    }
                }
                else
                {
                    return(ExpiredOtp());
                }
            } catch (Exception) {
                return(BadLink());
            }
        }
Пример #7
0
        public ActionResult RefillResponse(long id)
        {
            string digits = Request["Digits"];

            System.Diagnostics.Debug.WriteLine(Request["To"]);
            var notification = DatabaseNotificationService.GetById(id);
            var user         = DatabasePatientService.GetById(notification.PatientId);

            if (digits.Contains("1"))
            {
                XDocument xml = null;
                if (user != null)
                {
                    notification.NotificationResponse = Request["digits"];
                    DatabaseNotificationService.Update(notification);
                    var refill = DatabaseRefillService.GetByPrescriptionId(DatabasePrescriptionService.GetByPatientId(user.PatientId).PrescriptionId);
                    refill.RefillIt = true;
                    DatabaseRefillService.Update(refill);
                    xml = new XDocument(
                        new XElement("Response",
                                     new XElement("Say",
                                                  "Your refill will be ready shortly.")
                                     )
                        );
                }
                else
                {
                    xml = new XDocument(
                        new XElement("Response",
                                     new XElement("Say",
                                                  "couldn't find refill")
                                     )
                        );
                }
                return(new XmlActionResult(xml));
            }
            else if (digits.Contains("9"))
            {
                var xml = new XDocument(
                    new XElement("Response",
                                 new XElement("Say",
                                              "Connecting you to a pharmacist."),
                                 new XElement("Dial",
                                              DatabasePharmacyService.GetById(user.PharmacyId).PharmacyPhone)
                                 )
                    );
                return(new XmlActionResult(xml));
            }
            else
            {
                var xml = new XDocument(
                    new XElement("Response",
                                 new XElement("Say",
                                              "Unrecognized Input, Goodbye")
                                 )
                    );
                return(new XmlActionResult(xml));
            }
        }
Пример #8
0
        public ActionResult GetNotifications()
        {
            List <Notification> notifications = DatabaseNotificationService.GetDateRange((long)Session["pharm_id"], DateTime.Now, @DateTime.Now.AddDays(7));

            ViewBag.date1 = @DateTime.Now.ToShortDateString();
            ViewBag.date2 = @DateTime.Now.AddDays(7).ToShortDateString();
            return(View(notifications));
        }
Пример #9
0
        public Refill(Prescription prescription)
        {
            PrescriptionId = prescription.PrescriptionId;
            Refilled       = false;
            RefillIt       = false;
            var notification = Notification.CreateNotification(prescription.PrescriptionDateFilled.AddDays(prescription.PrescriptionDaysSupply - 2), prescription.PatientId, Notification.NotificationType.Refill);

            DatabaseNotificationService.Insert(notification);
        }
Пример #10
0
        public ActionResult GetNotifications(string datePicker1, string datePicker2)
        {
            var date1 = DateTime.Parse(datePicker1);
            var date2 = DateTime.Parse(datePicker2);

            ViewBag.date1 = date1.ToShortDateString();
            ViewBag.date2 = date2.ToShortDateString();
            List <Notification> notifications = DatabaseNotificationService.GetDateRange((long)Session["pharm_id"], date1, date2);

            return(View("NotificationList", notifications));
        }
Пример #11
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");
        }
Пример #12
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));
        }
Пример #13
0
        public static bool SendFilledNotification(Refill refill)
        {
            var n = new Notification(refill, Notification.NotificationType.Ready);
            var p = DatabasePrescriptionService.GetById(refill.PrescriptionId);

            n.PatientId = p.PatientId;
            System.Diagnostics.Debug.WriteLine(n.PatientId);
            n.NotificationId = DatabaseNotificationService.Insert(n);
            var pat    = Patient.PatientDict[n.PatientId];
            var twilio = new TwilioApi(pat.getPharmacy());

            SendNotification(n, twilio);
            return(true);
        }
Пример #14
0
        private List <Notification> getNotifications()
        {
            var tempList             = DatabaseNotificationService.GetDateRange(DateTime.Now.AddYears(-100), DateTime.Now);
            List <Notification> list = new List <Notification>();

            if (tempList == null)
            {
                tempList = new List <Notification>();
            }
            foreach (var n in tempList)
            {
                if (!n.Sent && n.ScheduledTime.Date <= DateTime.Now.Date && Patient.PatientDict[n.PatientId].PreferedContactTime.TimeOfDay <= DateTime.Now.TimeOfDay && Patient.PatientDict[n.PatientId].PharmacyId == 1)
                {
                    list.Add(n);
                }
            }
            // TODO add birthdays and get not sent but before current datetime
            return(list);
        }
Пример #15
0
        public ActionResult Recall(long id)
        {
            var n   = DatabaseNotificationService.GetById(id);
            var xml = new XDocument(
                new XElement("Response",
                             new XElement("Gather",
                                          new XAttribute("timeout", "10"),
                                          new XAttribute("numDigits", "1"),
                                          new XAttribute("action", "https://ocharambe.localtunnel.me/twilioresponse/recallresponse/" + id),
                                          new XElement("Say",
                                                       n.NotificationMessage
                                                       )
                                          ),
                             new XElement("Say",
                                          "Goodbye!")
                             )
                );

            return(new XmlActionResult(xml));
        }
Пример #16
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));
        }
Пример #17
0
 public ActionResult DeleteNotification(long id)
 {
     DatabaseNotificationService.Disable(id);
     return(Redirect("/Notification/NotificationList"));
 }