public async Task SaveTaskAsync(MedicineHistory item, bool isNew) { try{ if (isNew == true) { await medicineTable.InsertAsync(item); } else { await medicineTable.UpdateAsync(item); } } catch (Exception ex) { Debug.WriteLine(@"Exception: {0}", ex.Message); } }
public async void end(Medicine currentMedicine) { var temp = await reminderManager.GetReminderAsync(); foreach (var t in temp) { if (t.MedicineId == currentMedicine.Id) { await reminderManager.DeleteTaskAsync(t); DeleteNotification(t); } } //delete thie medicine currentMedicine.IsTaking = false; await medicineManager.DeleteTaskAsync(currentMedicine); App.contentChanged = true; //set a new medicine history MedicineHistory medicineHistory = new MedicineHistory { Id = Guid.NewGuid().ToString(), UserId = App.email, MedicineName = currentMedicine.MedicineName, Directions = currentMedicine.Directions, TimeToDisplay = currentMedicine.StartTime.ToString("dd/MMM/yyyy ddd") + " - " + DateTime.Now.ToString("dd/MMM/yyyy ddd"), Description = currentMedicine.Description, Duration = currentMedicine.Duration, TimesPerDay = currentMedicine.TimesPerDay, Unit = currentMedicine.Unit, StartTime = currentMedicine.StartTime, DirectionsToDisplay = currentMedicine.TimesPerDay + " times a day, " + currentMedicine.Unit + " each time", IsDone = true, IsUnDone = false }; if (currentMedicine.TimesPerDay == 1) { medicineHistory.DirectionsToDisplay = "Once a day, " + currentMedicine.Unit + " each time"; } //medicineHistoryManager = MedicineHistoryManager.DefaultManager; await medicineHistoryManager.SaveTaskAsync(medicineHistory, true); await DisplayAlert("Notice:", "You have ended this medicine!", "OK"); }
/// <summary> /// Retrieves the medicines the patient has been prescribed from the database and stores them /// in the medicineHistory arraylist /// </summary> public void retrieveMedicineHistory() { DataTable table = new DataTable(); string connStr = "server=csdatabase.eku.edu;user=stu_csc340;database=csc340_db;port=3306;password=Colonels18;SSLMode=None"; MySqlConnection conn = new MySqlConnection(connStr); try { Console.WriteLine("Connecting to MySQL..."); conn.Open(); string sql = "SELECT m.name, DATE_FORMAT(pr.dateFilled, \"%m-%d-%Y\") AS dateFilled, m.quantity, m.dosage, m.route, " + "m.instructions, m.prescriptionID " + "FROM DixonPatient pa JOIN DixonPrescription pr ON pr.patientID = pa.patientID " + "JOIN DixonMedicine m ON m.prescriptionID = pr.id WHERE pa.patientID = @id;"; MySqlCommand cmd = new MySqlCommand(sql, conn); cmd.Parameters.AddWithValue("@id", Id); MySqlDataAdapter myAdapter = new MySqlDataAdapter(cmd); myAdapter.Fill(table); Console.WriteLine("Table is ready."); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } conn.Close(); MedicineHistory.Clear(); foreach (DataRow row in table.Rows) { Medicine medicine = new Medicine(); medicine.Name = row["name"].ToString(); medicine.Date = row["dateFilled"].ToString(); medicine.Quantity = (int)row["quantity"]; medicine.Dosage = row["dosage"].ToString(); medicine.Route = row["route"].ToString(); medicine.Instructions = row["instructions"].ToString(); medicine.PrescriptionID = (int)row["prescriptionID"]; medicineHistory.Add(medicine); } }
public MedicineHistoryPage(MedicineHistory medicineHistory) { InitializeComponent(); BindingContext = medicineHistory; }
public async Task DeleteTaskAsync(MedicineHistory item) { await medicineTable.DeleteAsync(item); }
async void EndClicked(object sender, EventArgs e) { var startday = new DateTime(currentMedicine.StartTime.Year, currentMedicine.StartTime.Month, currentMedicine.StartTime.Day); var diff = DateTime.Now - startday; var difff = diff.Days + 1; if (difff < int.Parse(currentMedicine.Duration)) { var res = await DisplayAlert("Notice!", "You haven't finished this medication. Are you sure to terminate it early? ", "Yes", "No"); if (res) { //delete related reminders ReminderManager reminderManager = ReminderManager.DefaultManager; var temp = await reminderManager.GetReminderAsync(); foreach (var t in temp) { if (t.MedicineId == currentMedicine.Id) { await reminderManager.DeleteTaskAsync(t); DeleteNotification(t); } } //delete thie medicine MedicineManager medicineManager = MedicineManager.DefaultManager; await medicineManager.DeleteTaskAsync(currentMedicine); App.contentChanged = true; //set a new medicine history MedicineHistory medicineHistory = new MedicineHistory { Id = Guid.NewGuid().ToString(), UserId = App.email, MedicineName = currentMedicine.MedicineName, Directions = currentMedicine.Directions, TimeToDisplay = currentMedicine.StartTime.ToString("dd/MMM/yyyy ddd") + " - " + DateTime.Now.ToString("dd/MMM/yyyy ddd"), Description = currentMedicine.Description, Duration = currentMedicine.Duration, TimesPerDay = currentMedicine.TimesPerDay, Unit = currentMedicine.Unit, StartTime = currentMedicine.StartTime, DirectionsToDisplay = currentMedicine.TimesPerDay + " times a day, " + currentMedicine.Unit + " each time", IsDone = false, IsUnDone = true }; if (currentMedicine.TimesPerDay == 1) { medicineHistory.DirectionsToDisplay = "Once a day, " + currentMedicine.Unit + " each time"; } medicineHistory.Duration = difff.ToString(); MedicineHistoryManager medicineHistoryManager = MedicineHistoryManager.DefaultManager; await medicineHistoryManager.SaveTaskAsync(medicineHistory, true); await DisplayAlert("Notice:", "You have ended this medicine!", "OK"); } } else { //delete related reminders ReminderManager reminderManager = ReminderManager.DefaultManager; var temp = await reminderManager.GetReminderAsync(); foreach (var t in temp) { if (t.MedicineId == currentMedicine.Id) { await reminderManager.DeleteTaskAsync(t); DeleteNotification(t); } } //delete thie medicine MedicineManager medicineManager = MedicineManager.DefaultManager; await medicineManager.DeleteTaskAsync(currentMedicine); App.contentChanged = true; //set a new medicine history MedicineHistory medicineHistory = new MedicineHistory { Id = Guid.NewGuid().ToString(), UserId = App.email, MedicineName = currentMedicine.MedicineName, Directions = currentMedicine.Directions, TimeToDisplay = currentMedicine.StartTime.ToString("dd/MMM/yyyy ddd") + " - " + DateTime.Now.ToString("dd/MMM/yyyy ddd"), Description = currentMedicine.Description, Duration = currentMedicine.Duration, TimesPerDay = currentMedicine.TimesPerDay, Unit = currentMedicine.Unit, StartTime = currentMedicine.StartTime, DirectionsToDisplay = currentMedicine.TimesPerDay + " times a day, " + currentMedicine.Unit + " each time", IsDone = true, IsUnDone = false }; if (currentMedicine.TimesPerDay == 1) { medicineHistory.DirectionsToDisplay = "Once a day, " + currentMedicine.Unit + " each time"; } medicineHistory.Duration = difff.ToString(); MedicineHistoryManager medicineHistoryManager = MedicineHistoryManager.DefaultManager; await medicineHistoryManager.SaveTaskAsync(medicineHistory, true); await DisplayAlert("Notice:", "You have ended this medicine!", "OK"); } await Navigation.PopAsync(); }