Beispiel #1
0
 public void ResendEvent(int eventid, int pharmCode)
 {
     using (var eventService = new EventService())
         using (var service = new EventRefillService())
         {
             var test      = service.GetWhere(EventRefillService.PrescriptionCodeCol == eventid).FirstOrDefault();
             var testEvent = test.Event;
             EventProcessingService.SendEvent(testEvent, pharmCode);
         }
 }
Beispiel #2
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);
                                                    }
                                                }
                                            }
                                        }
                                    }
        }