public async void HistoryListViewClick() { if (SelectedItem == null) { return; } // Populate edit history from database var history = await db.GetReferralHistoryDetails(SelectedItem.ID.ToString()); foreach (var entry in history) { HistoryData historyDataItem = new HistoryData { EditTime = entry["editTime"], Name = entry["name"], CAD = entry["cad"], Status = entry["status"], DOD = entry["dod"], ReqTime = entry["reqTime"], Nature = entry["nature"], Provider = entry["provider"] }; ReferralHistory.Add(historyDataItem); } EditReferralItem = SelectedItem; ViewReferralHistoryDialog viewHistoryDialog = new ViewReferralHistoryDialog() { Owner = Application.Current.MainWindow, DataContext = this }; if (viewHistoryDialog.ShowDialog() == false && viewHistoryDialog.duplicateReferral == true) { // dupe var DupeReferralItem = new ReferralData { ID = "0", PatientName = ReferralHistory.Last().Name, CAD = ReferralHistory.Last().CAD, CallStatus = "Active", DateOfDischarge = ReferralHistory.Last().DOD, RequestedTime = ReferralHistory.Last().ReqTime, CallTaker = Environment.UserName.ToLower(), Nature = "[DUPE] " + ReferralHistory.Last().Nature, Provider = ReferralHistory.Last().Provider, CreatedDate = DateTime.Now.ToString("M-d-yyyy"), CreatedTime = DateTime.Now.ToString("HH:mm:ss") }; // Cleanup the referral object DupeReferralItem.PatientName = DupeReferralItem.PatientName.Trim(); DupeReferralItem.CAD = DupeReferralItem.CAD.Trim(); DupeReferralItem.RequestedTime = DupeReferralItem.RequestedTime.Trim(); DupeReferralItem.Nature = DupeReferralItem.Nature.Trim(); await Task.Run(async() => { var result = await db.InsertIntoCollection(DupeReferralItem); StatusMessageAPIStatus = result; }); StatusMessageAPIStatus = "Item duplicated and will be available on next refresh cycle"; } SelectedItem = null; ReferralHistory.Clear(); }
public async void ViewItemClick() { if (SelectedItem == null) { return; } // Populate edit history from database var history = await db.GetReferralHistoryDetails(SelectedItem.ID); foreach (var entry in history) { HistoryData historyDataItem = new HistoryData { EditTime = entry["editTime"], Name = entry["name"], CAD = entry["cad"], Status = entry["status"], DOD = entry["dod"], ReqTime = entry["reqTime"], Nature = entry["nature"], Provider = entry["provider"] }; ReferralHistory.Add(historyDataItem); } EditReferralItem = SelectedItem; string oldProvider = EditReferralItem.Provider; NewReferralDialog newReferralDialog = new NewReferralDialog() { Owner = Application.Current.MainWindow, Title = "Edit Referral Item Data", DataContext = this }; if (EditReferralItem.Provider == "MAS") { newReferralDialog.RadioButton_MAS.IsChecked = true; } else { newReferralDialog.RadioButton_Logisticare.IsChecked = true; } if (newReferralDialog.ShowDialog() == true) { // Cleanup the referral object EditReferralItem.PatientName = EditReferralItem.PatientName.Trim(); EditReferralItem.CAD = EditReferralItem.CAD.Trim(); EditReferralItem.RequestedTime = EditReferralItem.RequestedTime.Trim(); EditReferralItem.Nature = EditReferralItem.Nature.Trim(); if (newReferralDialog.RadioButton_MAS.IsChecked == true) { EditReferralItem.Provider = "MAS"; } else { EditReferralItem.Provider = "Logisticare"; } await Task.Run(async() => { // Moved referral? Drop event and reset CallStatus to an active state if (oldProvider != EditReferralItem.Provider) { EditReferralItem.CallStatus = "Active"; } var result = await db.UpdateReferral(EditReferralItem); StatusMessageAPIStatus = $"UpdateReferral: ID = {EditReferralItem.ID}, {result.Trim()}"; if (result.Trim() == "false") { MessageBox.Show("Referenced object is no longer flagged as active. Edits cancelled", "Informational", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }); // pop referral from observable collection if provider has changed if (oldProvider != EditReferralItem.Provider) { ObservableCollection <ReferralData> obsCol; if (EditReferralItem.Provider == "MAS") { obsCol = ReferralCollectionLogisticare; } else { obsCol = ReferralCollectionMAS; } var obj = obsCol.SingleOrDefault(a => a.ID == EditReferralItem.ID); if (obj != null) { obsCol.Remove(obj); } } } SelectedItem = null; ReferralHistory.Clear(); }