コード例 #1
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));
        }
コード例 #2
0
        /**
         * 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());
            }
        }
コード例 #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
        /**
         * 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());
            }
        }
コード例 #5
0
        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);
            }
        }
コード例 #6
0
        private void SavePatient(Patient patient, string contactMethod, string notificationTime, string birthdayEnabled, string refillsEnabled)
        {
            switch (contactMethod)
            {
            case "text":
                patient.ContactMethod = Patient.PrimaryContactMethod.Text;
                break;

            case "call":
                patient.ContactMethod = Patient.PrimaryContactMethod.Call;
                break;

            case "email":
                patient.ContactMethod = Patient.PrimaryContactMethod.Email;
                break;

            case "optout":
                patient.ContactMethod = Patient.PrimaryContactMethod.OptOut;
                break;
            }

            if (notificationTime.Length == 6)
            {
                notificationTime = "0" + notificationTime;
            }
            patient.PreferedContactTime = DateTime.ParseExact(notificationTime, "hh:mmtt", CultureInfo.InvariantCulture);

            patient.SendBirthdayMessage = birthdayEnabled == "on";
            patient.SendRefillMessage   = refillsEnabled == "on";

            DatabasePatientService.Update(patient);
        }
コード例 #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 PatientListView()
        {
            var patients = DatabasePatientService.GetAllActive((long)Session["pharm_id"]);

            foreach (var p in patients)
            {
                p.LoadUserData();
            }
            return(View("PatientListView", patients));
        }
コード例 #9
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");
        }
コード例 #10
0
        public ActionResult AddorEditPatient(long id = 0)
        {
            Patient patient = new Patient();

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

            return(View(patient));
        }
コード例 #11
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));
        }
コード例 #12
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));
        }
コード例 #13
0
        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));
            }
        }
コード例 #14
0
        public ActionResult Index(string contactMethod, string notificationTime, string birthdayEnabled, string refillsEnabled)
        {
            var userId  = (long)Session[Models.Login.UserIdSession];
            var patient = DatabasePatientService.GetByUserId(userId);

            if (patient == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            patient.LoadUserData();

            SavePatient(patient, contactMethod, notificationTime, birthdayEnabled, refillsEnabled);
            return(View("Index", Tuple.Create(patient, true)));
        }
コード例 #15
0
        public ActionResult Index()
        {
            var userId = (long)Session[Models.Login.UserIdSession];

            var patient = DatabasePatientService.GetByUserId(userId);

            if (patient == null)
            {
                return(RedirectToAction("Index", "Login"));
            }
            patient.LoadUserData();

            return(View("Index", Tuple.Create(patient, true)));
        }
コード例 #16
0
        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);
            }
        }
コード例 #17
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);
        }
コード例 #18
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());
        }
コード例 #19
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");
        }
コード例 #20
0
        public static User GetFullById(long user_id)
        {
            using (var db = DatabaseService.Connection) {
                Dapper.SqlMapper.SetTypeMap(typeof(User), new ColumnAttributeTypeMapper <User>());
                var u = db.Query <User>(ScriptService.Scripts["user_getbyid"], new { user_id = user_id }).FirstOrDefault();

                switch (u.Type)
                {
                case User.UserType.Pharmacist: {
                    var hu = DatabasePharmacistService.GetByUserId(u.UserId);
                    hu.LoadUserData();
                    return(hu);
                }

                case User.UserType.Patient: {
                    var hu = DatabasePatientService.GetByUserId(u.UserId);
                    hu.LoadUserData();
                    return(hu);
                }
                }
                return(u);
            }
        }
コード例 #21
0
        public static bool ParseCsv(HttpPostedFileBase upload, long pharmacyId)
        {
            //Check if valid file was uploaded
            if (upload != null && upload.ContentLength > 0 && upload.FileName.EndsWith(".csv"))
            {
                //Convert binary file received from request into text
                var textdata = string.Empty;
                using (BinaryReader b = new BinaryReader(upload.InputStream)) {
                    var binData = b.ReadBytes(upload.ContentLength);
                    textdata = Encoding.UTF8.GetString(binData);
                }

                //Get list of patients from database for comparison
                var patients    = new Dictionary <string, Patient>();
                var patientlist = DatabasePatientService.GetAll(pharmacyId);
                foreach (var p in patientlist)
                {
                    p.LoadUserData();
                    patients.Add(p.PersonCode, p);
                }

                //Interate over each line of text in the file
                var text = new StringReader(textdata);
                var line = string.Empty;

                //Remove headers from file
                text.ReadLine();

                while ((line = text.ReadLine()) != null)
                {
                    var row = line.Split(',');

                    //Check if patient exists
                    try {
                        var dateNow = DateTime.Now;

                        Patient patient = new Patient()
                        {
                            PersonCode  = row[0],
                            FirstName   = row[1],
                            LastName    = row[2],
                            DateOfBirth = DateTime.ParseExact(row[3], "yyyyMMdd", null),
                            Phone       = row[5],
                            Email       = row[6],
                            PharmacyId  = pharmacyId
                        };
                        if (patients.ContainsKey(row[0]))
                        {
                            //Update patient

                            var oldPatient = patients[row[0]];

                            patient.UserId              = oldPatient.UserId;
                            patient.PatientId           = patients[row[0]].PatientId;
                            patient.Type                = oldPatient.Type;
                            patient.UserLogin           = oldPatient.UserLogin;
                            patient.ContactMethod       = oldPatient.ContactMethod;
                            patient.PreferedContactTime = oldPatient.PreferedContactTime;
                            patient.SendBirthdayMessage = oldPatient.SendBirthdayMessage;
                            patient.SendRefillMessage   = oldPatient.SendRefillMessage;
                            DatabaseUserService.Update(patient);
                            DatabasePatientService.Update(patient);
                            DatabaseUserService.Enable(patient.PatientId);
                            DatabasePatientService.Enable(patient.PatientId);
                        }
                        else
                        {
                            //Create patient
                            patient.PreferedContactTime = new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, 15, 0, 0);
                            patient.UserId    = DatabaseUserService.Insert(patient);
                            patient.PatientId = DatabasePatientService.Insert(patient);
                        }

                        //Check if prescription exists
                        try {
                            var prescriptionId = Convert.ToInt32(row[8]);
                            var prescription   = new Prescription()
                            {
                                PrescriptionDateFilled = DateTime.ParseExact(row[7], "yyyyMMdd", null),
                                PrescriptionNumber     = prescriptionId,
                                PrescriptionId         = prescriptionId,
                                PrescriptionDaysSupply = Convert.ToInt32(row[9]),
                                PrescriptionRefills    = Convert.ToInt32(row[10]),
                                PrescriptionUpc        = row[11],
                                PrescriptionName       = row[12],
                                PatientId = patient.PatientId
                            };

                            DatabasePrescriptionService.InsertOrUpdate(prescription);

                            if (DatabaseRefillService.GetByPrescriptionId(prescription.PrescriptionId) == null)
                            {
                                var refill = new Refill(prescription)
                                {
                                };
                                DatabaseRefillService.Insert(refill);
                            }
                        } catch (Exception e) {
                            //Ignore prescriptions that fail the model building
                        }
                    } catch (Exception e) {
                        //Do not add patients which fail the model building
                    }
                }
                return(true);
            }
            return(false);
        }
コード例 #22
0
 public ActionResult DeletePatient(long id)
 {
     DatabasePatientService.UpdateInactive(DatabasePatientService.GetById((int)id));
     return(PatientListView());
 }
コード例 #23
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);
        }
コード例 #24
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));
        }