/**
         * 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());
            }
        }
        public void MakePhoneCall(Notification notification)
        {
            var p = DatabasePatientService.GetById(notification.PatientId);

            p.LoadUserData();
            if (testTwilio)
            {
                var to           = new PhoneNumber(p.Phone);
                var from         = new PhoneNumber("+14052469892");
                Uri callback_url = null;
                switch (notification.Type)
                {
                case Notification.NotificationType.Refill:
                    callback_url = new Uri("http://ocharambe.localtunnel.me/twilioresponse/refill/" + notification.NotificationId);
                    break;

                case Notification.NotificationType.Ready:
                    callback_url = new Uri("http://ocharambe.localtunnel.me/twilioresponse/ready/" + notification.NotificationId);
                    break;

                case Notification.NotificationType.Birthday:
                    callback_url = new Uri("http://ocharambe.localtunnel.me/twilioresponse/birthday" + notification.NotificationId);
                    break;
                }
                var call = CallResource.Create(to,
                                               from,
                                               url: callback_url);
            }
        }
        /**
         * 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());
            }
        }
예제 #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));
        }
예제 #5
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));
            }
        }
예제 #6
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));
            }
        }
예제 #7
0
        public ActionResult AddorEditPatient(long id = 0)
        {
            Patient patient = new Patient();

            if (id != 0)
            {
                patient = DatabasePatientService.GetById((int)id);
                patient.LoadUserData();
            }

            return(View(patient));
        }
        public void MakeRecallPhoneCall(Notification notification)
        {
            Patient p = DatabasePatientService.GetById(notification.PatientId);

            p.LoadUserData();
            if (testTwilio)
            {
                var to   = new PhoneNumber(p.Phone);
                var from = new PhoneNumber("+14052469892");
                var call = CallResource.Create(to,
                                               from,
                                               url: new Uri("http://ocharambe.localtunnel.me/twilioresponse/recall/" + notification.NotificationId));
            }
        }
        public void SendTextMessage(Notification notification)
        {
            var p = DatabasePatientService.GetById(notification.PatientId);

            p.LoadUserData();
            var temp = GetTempFromPharmacy(notification.Type);

            if (testTwilio)
            {
                var message = MessageResource.Create(
                    to: new PhoneNumber(p.Phone),
                    from: new PhoneNumber("+14052469892 "),
                    body: temp.TemplateText);
            }
        }
예제 #10
0
        private Patient GetPatient(string patientId)
        {
            long patientIdLong;

            if (!long.TryParse(patientId, out patientIdLong))
            {
                return(null);
            }

            var patient = DatabasePatientService.GetById(patientIdLong);

            if (patient == null)
            {
                return(null);
            }
            patient.LoadUserData();
            return(patient);
        }
예제 #11
0
        /**
         * Compiles a notification into an email. Fills template placeholders
         * with actual data, sets proper email parameters, and renders the body
         * of the email based on notification type.
         *
         * @param - Notifiation - the notification to compile
         * @returns - MailMessage - the compiled email with rendered body
         */
        public static MailMessage Build(Notification notification)
        {
            //Get necessary data to build and format the email
            var patient  = DatabasePatientService.GetById(notification.PatientId);
            var user     = DatabaseUserService.GetById(patient.UserId);
            var pharmacy = DatabasePharmacyService.GetById(patient.PharmacyId);

            var message = new MailMessage();

            message.To.Add(new MailAddress(user.Email));
            message.From = new MailAddress(ConfigurationManager.AppSettings["SendEmailAddress"]);

            //Emails always get style sheet and header
            var body       = EmailHtmlLoader.TemplateHtml;
            var content    = "";
            var emailtitle = "";

            //Set email subject and body based on type of email
            switch (notification.Type)
            {
            case Notification.NotificationType.Birthday:
                message.Subject = "Happy Birthday, from " + pharmacy.PharmacyName + "!";
                content        += EmailHtmlLoader.BirthdayHtml;
                emailtitle      = "Happy Birthday!";
                break;

            case Notification.NotificationType.Ready:
                message.Subject = "Your Refill is ready to be picked up";
                content        += EmailHtmlLoader.ReadyHtml;
                emailtitle      = "You have a refill ready to be picked up";
                break;

            case Notification.NotificationType.Recall:
                message.Subject  = "A Prescription you received has been recalled!";
                message.Priority = MailPriority.High;
                content         += EmailHtmlLoader.RecallHtml;
                emailtitle       = "There has been a recall on a prescription you received";
                break;

            case Notification.NotificationType.Refill:
                message.Subject = "Your medication is up for refill";
                content        += EmailHtmlLoader.RefillHtml;
                emailtitle      = "Would you like to refill your medication with us?";
                break;

            case Notification.NotificationType.Reset:
                break;

            default:
                message.Subject = "Unknown Notification Type";
                break;
            }

            //Set contact reason message
            var reason = "You are receiving this email because ";

            if (notification.Type == Notification.NotificationType.Recall)
            {
                reason += "this is a mandatory email from your pharmacy. " +
                          "If you have any questions please call" + pharmacy.PharmacyPhone +
                          " to speak with your pharmacist.";
            }
            else
            {
                reason += "of your personal contact preferences. If you wish to unsubscribe" +
                          " from all future emails, please click the button below or contact" +
                          " your pharmacist at " + pharmacy.PharmacyPhone + ".";
            }
            body = body.Replace("{{ContactReason}}", reason);

            //Replace html template placeholder with renderbody
            body = body.Replace("{{EmailBody}}", content);
            body = body.Replace("{{EmailTitle}}", emailtitle);
            body = body.Replace("{{MessageText}}", notification.NotificationMessage);

            //Replace sentinels in email with personalized data
            body = body.Replace("{{PharmacyName}}", pharmacy.PharmacyName);
            body = body.Replace("{{PharmacyPhone}}", pharmacy.PharmacyPhone);
            body = body.Replace("{{PharmacyAddress}}", pharmacy.PharmacyAddress);
            body = body.Replace("{{Name}}", patient.GetFullName());
            body = body.Replace("{{FirstName}}", patient.FirstName);
            body = body.Replace("{{LastName}}", patient.LastName);
            body = body.Replace("{{Phone}}", patient.Phone);
            body = body.Replace("{{Email}}", patient.Email);
            body = body.Replace("{{DOBShort}}", patient.DateOfBirth.ToShortDateString());
            body = body.Replace("{{DOBLong}}", patient.DateOfBirth.ToLongDateString());
            body = body.Replace("{{ContactTimeShort}}", patient.PreferedContactTime.ToShortTimeString());
            body = body.Replace("{{ContactTimeLong}}", patient.PreferedContactTime.ToLongTimeString());

            //Set up links
            body = body.Replace("{{OtpCode}}", OTPService.GenerateEmailOtp(notification).Code);
            body = body.Replace("{{PatientId}}", patient.PatientId.ToString());
            body = body.Replace("{{RespondLink}}", "http://localhost:50082/email/respond");
            body = body.Replace("{{UnsubscribeLink}}", "http://localhost:50082/email/unsubscribe");

            message.Body       = body;
            message.IsBodyHtml = true;

            return(message);
        }
예제 #12
0
 public ActionResult DeletePatient(long id)
 {
     DatabasePatientService.UpdateInactive(DatabasePatientService.GetById((int)id));
     return(PatientListView());
 }