async void Handle_DeleteClicked(object sender, EventArgs e) { if (!isClinicianAccessing) { await DisplayAlert("Unauthorized", "Only a clinician can update a user's medications", "OK"); return; } var mi = ((MenuItem)sender); Medication selectedMedication = mi.CommandParameter as Medication; bool answer = await DisplayAlert("Are you sure?", "Do you want to remove " + selectedMedication.name + " from " + UserController.Instance.LoggedInUser.FullName + "?", "Yes", "No"); if (answer == true) { if (SegControl.SelectedSegment == 0) { UserController.Instance.LoggedInUser.currentMedications.Remove(selectedMedication); observableMedicationList.Clear(); observableMedicationList.AddRange(UserController.Instance.LoggedInUser.currentMedications); } else { UserController.Instance.LoggedInUser.historicMedications.Remove(selectedMedication); observableMedicationList.Clear(); observableMedicationList.AddRange(UserController.Instance.LoggedInUser.historicMedications); } UserAPI userAPI = new UserAPI(); HttpStatusCode userUpdated = await userAPI.UpdateUser(true); switch (userUpdated) { case HttpStatusCode.Created: await DisplayAlert("", "User medications successfully updated", "OK"); await Navigation.PopAsync(); break; case HttpStatusCode.BadRequest: await DisplayAlert("", "User medications update failed (400)", "OK"); break; case HttpStatusCode.ServiceUnavailable: await DisplayAlert("", "Server unavailable, check connection", "OK"); break; case HttpStatusCode.Unauthorized: await DisplayAlert("", "Unauthorised to modify profile", "OK"); break; case HttpStatusCode.InternalServerError: await DisplayAlert("", "Server error, please try again (500)", "OK"); break; } } }
async void Handle_MedicationTapped(object sender, ItemTappedEventArgs e) { if (e == null) { return; //ItemSelected is called on deselection, which results in SelectedItem being set to null } bool answer = await DisplayAlert("Are you sure?", "Do you want to assign " + MedicationsList.SelectedItem + " to " + UserController.Instance.LoggedInUser.FullName + "?", "Yes", "No"); if (answer == true) { //Do active ingredients call MedicationResponseObject medicationsReturned = await drugAutoFillActiveIngredientsAPI.activeIngredients(MedicationsList.SelectedItem.ToString()); //Create new medication object Medication newMedication = new Medication(); newMedication.name = MedicationsList.SelectedItem.ToString(); newMedication.activeIngredients = medicationsReturned.activeIngredients; newMedication.history = new List <string>(); newMedication.history.Add("Started taking on " + DateTime.Now.ToShortDateString() + ", " + DateTime.Now.ToString("HH:mm:ss")); newMedication.DetailString = newMedication.history[0]; //Add it to the user's current medications UserController.Instance.LoggedInUser.currentMedications.Add(newMedication); //Update list view parentmedicationsPage.refreshMedicationsListView(); //Save user object UserAPI userAPI = new UserAPI(); HttpStatusCode userUpdated = await userAPI.UpdateUser(true); switch (userUpdated) { case HttpStatusCode.Created: await DisplayAlert("", "User medications successfully updated", "OK"); await Navigation.PopAsync(); break; case HttpStatusCode.BadRequest: await DisplayAlert("", "User medications update failed (400)", "OK"); break; case HttpStatusCode.ServiceUnavailable: await DisplayAlert("", "Server unavailable, check connection", "OK"); break; case HttpStatusCode.Unauthorized: await DisplayAlert("", "Unauthorised to modify profile", "OK"); break; case HttpStatusCode.InternalServerError: await DisplayAlert("", "Server error, please try again (500)", "OK"); break; } } }
async void Handle_MoveToClicked(object sender, EventArgs e) { if (!isClinicianAccessing) { await DisplayAlert("Unauthorized", "Only a clinician can update a user's medications", "OK"); return; } var mi = ((MenuItem)sender); Medication selectedMedication = mi.CommandParameter as Medication; String status = SegControl.SelectedSegment == 0 ? "historic" : "current"; bool answer = await DisplayAlert("Are you sure?", "Do you want to move " + selectedMedication.name + " to " + UserController.Instance.LoggedInUser.FullName + "'s " + status + " medications?", "Yes", "No"); if (answer == true) { if (SegControl.SelectedSegment == 0) { UserController.Instance.LoggedInUser.currentMedications.Remove(selectedMedication); selectedMedication.history.Add("Stopped taking on " + DateTime.Now.ToShortDateString() + ", " + DateTime.Now.ToString("HH:mm:ss")); selectedMedication.DetailString = selectedMedication.history[selectedMedication.history.Count - 1]; UserController.Instance.LoggedInUser.historicMedications.Add(selectedMedication); observableMedicationList.Clear(); observableMedicationList.AddRange(UserController.Instance.LoggedInUser.currentMedications); } else { UserController.Instance.LoggedInUser.historicMedications.Remove(selectedMedication); selectedMedication.history.Add("Started taking on " + DateTime.Now.ToShortDateString() + ", " + DateTime.Now.ToString("HH:mm:ss")); selectedMedication.DetailString = selectedMedication.history[selectedMedication.history.Count - 1]; UserController.Instance.LoggedInUser.currentMedications.Add(selectedMedication); observableMedicationList.Clear(); observableMedicationList.AddRange(UserController.Instance.LoggedInUser.historicMedications); } //update the User UserAPI userAPI = new UserAPI(); HttpStatusCode userUpdated = await userAPI.UpdateUser(true); switch (userUpdated) { case HttpStatusCode.Created: await DisplayAlert("", "User medications successfully updated", "OK"); await Navigation.PopAsync(); break; case HttpStatusCode.BadRequest: await DisplayAlert("", "User medications update failed (400)", "OK"); break; case HttpStatusCode.ServiceUnavailable: await DisplayAlert("", "Server unavailable, check connection", "OK"); break; case HttpStatusCode.Unauthorized: await DisplayAlert("", "Unauthorised to modify profile", "OK"); break; case HttpStatusCode.InternalServerError: await DisplayAlert("", "Server error, please try again (500)", "OK"); break; } } }