async void ButtonClicked(object sender, EventArgs e) { script.endDate = RxEnd.Date.ToShortDateString(); using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { if (script.PrescriptionNotificationIDs != null) { foreach (PrescriptionNotificationID notifID in script.PrescriptionNotificationIDs) { CrossLocalNotifications.Current.Cancel(notifID.Id); } //Delete the old notification IDs from the table conn.Execute("DELETE FROM PrescriptionNotificationID WHERE pId = " + script.Id); } //Set the new reminders using the new reminder time. PrescriptionNotifClass.PrescriptionNotifHandler(script); conn.Update(script); } await Navigation.PopAsync(); }
async void ButtonClicked(object sender, EventArgs e) { if (doctor.dName.Equals("12345")) { await DisplayAlert("Oops!", "Your need to choose a doctor", "OK"); } else { //Creates the appointment item to be inserted in the database Appointment appointment = new Appointment() { aptDate = AppointmentDateEntry.Date.Add(AppointmentTimeEntry.Time), reasonForVisit = Reason.Text, diagnosis = Diagnosis.Text, followUpAdvice = FollowUpRecsEntry.Text, uId = user.Id, dName = doctor.dName }; using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { doctor = conn.Query <Doctor>("select * from Doctor where dName=?", doctor.dName)[0]; doctor = conn.GetWithChildren <Doctor>(doctor.Id); } appointment.dId = doctor.Id; //Creates the prescription 0 item to be inserted in the database Prescription p0 = new Prescription() { RxName = Rx0Name.Text, startDate = Rx0StartDate.Date.ToShortDateString(), endDate = Rx0EndDate.Date.ToShortDateString(), reminderTime = Rx0StartDate.Date + Rx0ReminderEntry.Time, dId = doctor.Id, uId = user.Id, aId = appointment.Id }; if (t0) { //Set up notifications for the prescription reminder PrescriptionNotifClass.PrescriptionNotifHandler(p0); } //Creates the prescription 1 item to be inserted in the database Prescription p1 = new Prescription() { RxName = Rx1Name.Text, startDate = Rx1StartDate.Date.ToShortDateString(), endDate = Rx1EndDate.Date.ToShortDateString(), reminderTime = Rx0StartDate.Date + Rx0ReminderEntry.Time, dId = doctor.Id, uId = user.Id, aId = appointment.Id }; if (t1) { //Set up notifications for the prescription reminder PrescriptionNotifClass.PrescriptionNotifHandler(p0); } //Creates the prescription 2 item to be inserted in the database Prescription p2 = new Prescription() { RxName = Rx2Name.Text, startDate = Rx2StartDate.Date.ToShortDateString(), endDate = Rx2EndDate.Date.ToShortDateString(), reminderTime = Rx1StartDate.Date + Rx1ReminderEntry.Time, dId = doctor.Id, uId = user.Id, aId = appointment.Id }; if (t2) { //Set up notifications for the prescription reminder PrescriptionNotifClass.PrescriptionNotifHandler(p2); } //Creates the vaccine 0 item to be inserted in the database Vaccine v0 = new Vaccine() { VaccineName = Vaccine0Name.Text, Date = AppointmentDateEntry.Date.ToShortDateString(), dId = doctor.Id, uId = user.Id, aId = appointment.Id, }; //Creates the vaccine 1 item to be inserted in the database Vaccine v1 = new Vaccine() { VaccineName = Vaccine1Name.Text, Date = AppointmentDateEntry.Date.ToShortDateString(), dId = doctor.Id, uId = user.Id, aId = appointment.Id }; //Creates the vaccine 2 item to be inserted in the database Vaccine v2 = new Vaccine() { VaccineName = Vaccine2Name.Text, Date = AppointmentDateEntry.Date.ToShortDateString(), dId = doctor.Id, uId = user.Id, aId = appointment.Id }; //Creates a future appointment for the user Appointment fa = new Appointment() { aptDate = FollowUpDateEntry.Date.Add(FollowUpTimeEntry.Time), reminderTime = FollowUpDateEntry.Date.Add(FollowUpReminderEntry.Time), dId = doctor.Id, uId = user.Id, dName = doctor.dName }; //Creates a reminder notification for a future appointment and submits it to the Android OS to handle if (needReminder == true) { CrossLocalNotifications.Current.Show("Appointment Reminder", "You have an appointment with Dr. " + doctor.dName + " at " + fa.aptDate.ToShortTimeString(), fa.Id, fa.reminderTime); } //Adds the appointment to the user's appointment list if (user.Appointments == null) { user.Appointments = new List <Appointment> { appointment }; } else { user.Appointments.Add(appointment); } //Adds the appointment to the doctor's appointment list if (doctor.Appointments == null) { doctor.Appointments = new List <Appointment> { appointment }; } else { doctor.Appointments.Add(appointment); } //Checks if the first prescription has a null value if (!(p0.RxName.Equals(""))) { using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { //Ignored if the table already exists conn.CreateTable <Prescription>(); conn.Insert(p0); } //If the prescription has a name, check to see if the user already has a log of said prescription //If they do, then just change the end date if (user.Prescriptions != null) { foreach (Prescription rx in user.Prescriptions) { if (rx.RxName.Equals(p0.RxName)) { p0renew = true; rx.endDate = p0.endDate; } } if (p0renew == false) { user.Prescriptions.Add(p0); } } //Otherwise, add the prescription to the user's list else { user.Prescriptions = new List <Prescription> { p0 }; } //Add the prescription to the doctor's list if (doctor.Prescriptions == null) { doctor.Prescriptions = new List <Prescription> { p0 }; } else { doctor.Prescriptions.Add(p0); } if (appointment.Prescriptions == null) { appointment.Prescriptions = new List <Prescription> { p0 }; } else { appointment.Prescriptions.Add(p0); } } if (!(p1.RxName.Equals(""))) { using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { //Ignored if the table already exists conn.CreateTable <Prescription>(); conn.Insert(p1); } //If the prescription has a name, check to see if the user already has a log of said prescription //If they do, then just change the end date if (user.Prescriptions != null) { foreach (Prescription rx in user.Prescriptions) { if (rx.RxName.Equals(p1.RxName)) { p1renew = true; rx.endDate = p1.endDate; } } if (p1renew == false) { user.Prescriptions.Add(p1); } } //Otherwise, add the prescription to the user's list else { user.Prescriptions = new List <Prescription> { p1 }; } //Add the prescription to the doctor's list if (doctor.Prescriptions == null) { doctor.Prescriptions = new List <Prescription> { p1 }; } else { doctor.Prescriptions.Add(p1); } if (appointment.Prescriptions == null) { appointment.Prescriptions = new List <Prescription> { p1 }; } else { appointment.Prescriptions.Add(p1); } } if (!(p2.RxName.Equals(""))) { using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { //Ignored if the table already exists conn.CreateTable <Prescription>(); conn.Insert(p2); } //If the prescription has a name, check to see if the user already has a log of said prescription //If they do, then just change the end date if (user.Prescriptions != null) { foreach (Prescription rx in user.Prescriptions) { if (rx.RxName.Equals(p2.RxName)) { p2renew = true; rx.endDate = p2.endDate; } } if (p2renew == false) { user.Prescriptions.Add(p2); } } //Otherwise, add the prescription to the user's list else { user.Prescriptions = new List <Prescription> { p2 }; } //Add the prescription to the doctor's list if (doctor.Prescriptions == null) { doctor.Prescriptions = new List <Prescription> { p2 }; } else { doctor.Prescriptions.Add(p2); } if (appointment.Prescriptions == null) { appointment.Prescriptions = new List <Prescription> { p2 }; } else { appointment.Prescriptions.Add(p2); } } if (!(v0.VaccineName.Equals(""))) { using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { //Ignored if the table already exists conn.CreateTable <Vaccine>(); conn.Insert(v0); } if (user.Vaccines != null) { user.Vaccines.Add(v0); } else { user.Vaccines = new List <Vaccine> { v0 }; } if (appointment.Vaccines != null) { appointment.Vaccines.Add(v0); } else { appointment.Vaccines = new List <Vaccine> { v0 }; } if (doctor.Vaccines != null) { doctor.Vaccines.Add(v0); } else { doctor.Vaccines = new List <Vaccine> { v0 }; } } if (!(v1.VaccineName.Equals(""))) { using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { //Ignored if the table already exists conn.CreateTable <Vaccine>(); conn.Insert(v1); } if (user.Vaccines != null) { user.Vaccines.Add(v1); } else { user.Vaccines = new List <Vaccine> { v1 }; } appointment.Vaccines.Add(v1); if (doctor.Vaccines != null) { doctor.Vaccines.Add(v1); } else { doctor.Vaccines = new List <Vaccine> { v1 }; } } if (!(v2.VaccineName.Equals(""))) { using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { //Ignored if the table already exists conn.CreateTable <Vaccine>(); conn.Insert(v2); } if (user.Vaccines != null) { user.Vaccines.Add(v2); } else { user.Vaccines = new List <Vaccine> { v2 }; } appointment.Vaccines.Add(v2); if (doctor.Vaccines != null) { doctor.Vaccines.Add(v2); } else { doctor.Vaccines = new List <Vaccine> { v2 }; } } if (t6) { using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { conn.CreateTable <Appointment>(); conn.InsertWithChildren(fa); } if (user.Appointments != null) { user.Appointments.Add(fa); } else { user.Appointments = new List <Appointment> { fa }; } if (doctor.Appointments != null) { doctor.Appointments.Add(fa); } else { doctor.Appointments = new List <Appointment> { fa }; } } //Adds the appointment to the database //updates the user with its new appointment info //Updates the doctor with its new appointment info using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { //Ignored if the table already exists conn.CreateTable <Appointment>(); conn.CreateTable <Doctor>(); conn.CreateTable <User>(); conn.InsertWithChildren(appointment); conn.UpdateWithChildren(user); conn.UpdateWithChildren(doctor); } await Navigation.PopModalAsync(); } }
public App(string filePath) { Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("MjMyMTM2QDMxMzgyZTMxMmUzMGpzYzNpT1FVcnp4ZDJwdWhQUDhNdnI0MlNxMTlLTEEyZkRIOStpYkpMTlE9"); InitializeComponent(); MainPage = new MainPage(); FilePath = filePath; using (SQLite.SQLiteConnection conn = new SQLite.SQLiteConnection(App.FilePath)) { conn.CreateTable<User>(); var users = conn.Table<User>().ToList(); var doctors = conn.Table<Doctor>(); //Each prescription reminder requires a unique ID which we will track and save to settings. bool hasPrescriptionReminderKey = Preferences.ContainsKey("PrescriptionReminderNotifID"); int PrescriptionReminderID = 1000000; //If the setting does not exist, create it and set it with a starting value. if (!hasPrescriptionReminderKey) { Preferences.Set("PrescriptionReminderNotifID", PrescriptionReminderID); } else { PrescriptionReminderID = Preferences.Get("PrescriptionReminderNotifID", 1000000); //If the ID number gets within 10000 of overflowing, we will reset it. if ((PrescriptionReminderID + 10000) >= int.MaxValue) { PrescriptionReminderID = 1000000; } } if (users?.Any() == true) { //Have to resubmit notifications after device restart because they are not saved. var appts = conn.Table<Appointment>().ToList(); var prescriptions = conn.Table<Prescription>().ToList(); //We need to set up reminders for any prescriptions currently being taken. prescriptions = prescriptions.Where(item => (DateTime.Parse(item.startDate).Date <= DateTime.Now.Date) && (DateTime.Parse(item.endDate).Date >= DateTime.Now.Date)).ToList(); if (prescriptions?.Any() == true) { foreach (var prescript in prescriptions) { //Refresh the reminder notifications for each prescription if it is not entirely past the time that it must be taken. if (DateTime.Parse(prescript.endDate) >= DateTime.Now) { PrescriptionNotifClass.PrescriptionNotifHandler(prescript); } } } if (appts?.Any() == true) { foreach (var x in appts) { if (x.reminderTime > DateTime.Now) { var doctor = conn.GetWithChildren<Doctor>(x.dId); CrossLocalNotifications.Current.Show("Appointment Reminder", "You have an appointment with Dr. " + doctor.dName + " at " + x.aptDate.ToShortTimeString(), x.Id, x.reminderTime); } } } } conn.Close(); } }