/**
         * 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());
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
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());
        }
        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);
        }
Esempio n. 5
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));
        }