Ejemplo n.º 1
0
        private static List <Event> GetOpenSMSEventsFor(string fromNumber)
        {
            List <Event> events;
            //add filter with one week ago when Jon adds date comparisons to CRUDService
            DateTime oneWeekAgo = DateTime.Today.AddDays(-7);

            using (var eventService = new EventService())
                using (var patientService = new PatientService())
                    using (var service = new EventHistoryService())
                    {
                        events = service.GetWhere(
                            (PatientService.PhoneCol.In("Event") == fromNumber) &
                            (PatientService.ContactPreferenceCol.In("Event") == ContactPreference.TEXT &
                             EventService.StatusCol == EventStatus.Sent &
                             EventHistoryService.DateCol >= oneWeekAgo)).Select(hist => hist.Event).ToList();
                    }
            return(events);
        }
Ejemplo n.º 2
0
        public static string Subscribe(Patient p, ContactPreference newPref = ContactPreference.PHONE)
        {
            p.ContactPreference = newPref;

            using (var service = new PatientService())
            {
                try
                {
                    service.Update(p);
                    //this should be persisted in the database
                    return("Congratulations! You have subscribed to communications at " + p.Pharmacy.Name);
                }
                catch (Exception exception)
                {
                    //this should be persisted in the database
                    return("We're sorry, an application error has occurred; please contact your pharmacy to process your request.");
                }
            }
        }
Ejemplo n.º 3
0
        public static string UnsubscribePatient(Patient p)
        {
            p.ContactPreference = ContactPreference.NONE;

            using (var service = new PatientService())
            {
                try
                {
                    service.Update(p);
                    //this should be persisted in the database
                    return("You have unsubscribed from communications at " + p.Pharmacy.Name);
                }
                catch (Exception exception)
                {
                    //this should be persisted in the database
                    return("We're sorry, an application error has occurred; please contact your pharmacy to process your request.");
                }
            }
        }
Ejemplo n.º 4
0
        private void Convert(List <string> lines, Pharmacy pharm)
        {
            using (var patientService = new PatientService())
                using (var drugService = new DrugService())
                    using (var prescriptionService = new PrescriptionService())
                        using (var eventService = new EventService())
                            using (var eventRefillService = new EventRefillService())
                                using (var birthdayeventService = new EventService())
                                    using (var eventScheduleService = new EventScheduleService())
                                    {
                                        //start at 1 to skip columns titles
                                        for (int i = 1; i < lines.Count; i++)
                                        {
                                            string[] values = lines[i].Split(',');
                                            DateTime dob;
                                            if (values[3] == "NULL")
                                            {
                                                dob = DateTime.Now;
                                            }
                                            else
                                            {
                                                dob = new DateTime(System.Convert.ToInt32(values[3].Substring(0, 4)), System.Convert.ToInt32(values[3].Substring(4, 2)), System.Convert.ToInt32(values[3].Substring(6, 2)));
                                            }
                                            Patient patient            = new Patient(System.Convert.ToInt32(values[0]), values[1], values[2], dob, values[4], values[5], values[6], pharm);
                                            Drug    drug               = new Drug(Int64.Parse(values[11]), values[12]);
                                            var     prescriptionCode   = Int32.Parse(values[8]);
                                            var     prescriptionLoaded = prescriptionService.Get(prescriptionCode);

                                            if (prescriptionLoaded == null)
                                            {
                                                Prescription prescription = new Prescription(prescriptionCode, patient, drug, Int32.Parse(values[9]), Int32.Parse(values[10]));
                                                Event        _event       = new Event(patient, "Refill me", EventStatus.ToSend, EventType.REFILL);

                                                EventRefill refillEvent = new EventRefill(prescription, _event);



                                                //for each parsed patient / drug / etc, check if it is already in database
                                                //if so, update it
                                                //if not, create it
                                                var test1 = patientService.Get(patient.Code);
                                                if (test1 != null)
                                                {
                                                    patient.ContactPreference = test1.ContactPreference;
                                                    patientService.Update(patient);
                                                }
                                                else
                                                {
                                                    patientService.Create(patient);
                                                }

                                                if (patient.DOB.Month == DateTime.Today.Month && patient.DOB.Day == DateTime.Today.Day)
                                                {
                                                    var birthdayEvent = new Event(patient, "happy birthday", EventStatus.ToSend, EventType.BIRTHDAY);
                                                    eventService.Create(birthdayEvent);
                                                    var newPatient = patientService.GetWhere(PatientService.EmailCol == patient.Email).FirstOrDefault();
                                                    birthdayeventService.Create(birthdayEvent);
                                                }

                                                var test2 = drugService.Get(drug.Code);
                                                if (test2 != null)
                                                {
                                                    drugService.Update(drug);
                                                }
                                                else
                                                {
                                                    drugService.Create(drug);
                                                }

                                                var test3 = prescriptionService.Get(prescription.Code);
                                                if (test3 != null)
                                                {
                                                    prescriptionService.Update(prescription);
                                                }
                                                else
                                                {
                                                    prescriptionService.Create(prescription);
                                                }

                                                var test4 = eventService.Get(_event.Code);
                                                if (test4 != null)
                                                {
                                                    eventService.Update(_event);
                                                }
                                                else
                                                {
                                                    eventService.Create(_event);
                                                }

                                                var test5 = eventRefillService.Get(refillEvent.Code);
                                                if (test5 != null)
                                                {
                                                    eventRefillService.Update(refillEvent);
                                                }
                                                else
                                                {
                                                    eventRefillService.Create(refillEvent);
                                                }

                                                if (prescription.Refills > 0)
                                                {
                                                    DateTime refill           = new DateTime(System.Convert.ToInt32(values[7].Substring(0, 4)), System.Convert.ToInt32(values[7].Substring(4, 2)), System.Convert.ToInt32(values[7].Substring(6, 2)));
                                                    int      daysBeforeRemind = prescription.Supply - 7;
                                                    if (daysBeforeRemind < 4)
                                                    {
                                                        daysBeforeRemind = 4;
                                                    }

                                                    EventSchedule scheduleEvent = new EventSchedule(_event, refill.AddDays(daysBeforeRemind));

                                                    var test6 = eventScheduleService.Get(scheduleEvent.Code);
                                                    if (test6 != null)
                                                    {
                                                        eventScheduleService.Update(scheduleEvent);
                                                    }
                                                    else
                                                    {
                                                        eventScheduleService.Create(scheduleEvent);
                                                    }
                                                }
                                            }
                                        }
                                    }
        }