private void butMovePats_Click(object sender, EventArgs e) { if (gridMain.SelectedIndices.Length < 1) { MsgBox.Show(this, "You must select at least one clinic to move patients from."); return; } if (_clinicNumTo == -1) { MsgBox.Show(this, "You must pick a 'To' clinic in the box above to move patients to."); return; } Dictionary <long, Clinic> dictClinicsFrom = gridMain.SelectedTags <Clinic>().ToDictionary(x => x.ClinicNum); Clinic clinicTo = gridMain.GetTags <Clinic>().FirstOrDefault(x => x.ClinicNum == _clinicNumTo); if (clinicTo == null) { MsgBox.Show(this, "The clinic could not be found."); return; } if (dictClinicsFrom.ContainsKey(clinicTo.ClinicNum)) { MsgBox.Show(this, "The 'To' clinic should not also be one of the 'From' clinics."); return; } Dictionary <long, int> dictClinFromCounts = Clinics.GetClinicalPatientCount(true) .Where(x => dictClinicsFrom.ContainsKey(x.Key)).ToDictionary(x => x.Key, x => x.Value); if (dictClinFromCounts.Sum(x => x.Value) == 0) { MsgBox.Show(this, "There are no patients assigned to the selected clinics."); return; } string msg = Lan.g(this, "This will move all patients to") + " " + clinicTo.Abbr + " " + Lan.g(this, "from the following clinics") + ":\r\n" + string.Join("\r\n", dictClinFromCounts.Select(x => dictClinicsFrom[x.Key].Abbr)) + "\r\n" + Lan.g(this, "Continue?"); if (MessageBox.Show(msg, "", MessageBoxButtons.YesNo) != DialogResult.Yes) { return; } ODProgress.ShowAction(() => { int patsMoved = 0; List <Action> listActions = dictClinFromCounts.Select(x => new Action(() => { Patients.ChangeClinicsForAll(x.Key, clinicTo.ClinicNum); //update all clinicNums to new clinic Clinic clinicCur; SecurityLogs.MakeLogEntry(Permissions.PatientEdit, 0, "Clinic changed for " + x.Value + " patients from " + (dictClinicsFrom.TryGetValue(x.Key, out clinicCur)?clinicCur.Abbr:"") + " to " + clinicTo.Abbr + "."); patsMoved += x.Value; ClinicEvent.Fire(ODEventType.Clinic, Lan.g(this, "Moved patients") + ": " + patsMoved + " " + Lan.g(this, "out of") + " " + dictClinFromCounts.Sum(y => y.Value)); })).ToList(); ODThread.RunParallel(listActions, TimeSpan.FromMinutes(2)); }, startingMessage: Lan.g(this, "Moving patients") + "...", eventType: typeof(ClinicEvent), odEventType: ODEventType.Clinic); _dictClinicalCounts = Clinics.GetClinicalPatientCount(); FillGrid(); MsgBox.Show(this, "Done"); }
private void butMovePats_Click(object sender, EventArgs e) { if (gridMain.SelectedIndices.Length < 1) { MsgBox.Show(this, "You must select at least one clinic to move patients from."); return; } List <Clinic> listClinicsFrom = gridMain.SelectedIndices.OfType <int>().Select(x => (Clinic)gridMain.Rows[x].Tag).ToList(); List <Clinic> listClinicsTo = gridMain.Rows.Select(x => x.Tag as Clinic).ToList(); if (_clinicNumTo == -1) { MsgBox.Show(this, "You must pick a 'To' clinic in the box above to move patients to."); return; } Clinic clinicTo = listClinicsTo.FirstOrDefault(x => x.ClinicNum == _clinicNumTo); if (clinicTo == null) { MsgBox.Show(this, "The clinic could not be found."); return; } Action actionCloseProgress = ODProgressOld.ShowProgressStatus("ClinicReassign", this, Lan.g(this, "Gathering patient data") + "..."); Dictionary <long, List <long> > dictClinicPats = Patients.GetPatNumsByClinic(listClinicsFrom.Select(x => x.ClinicNum).ToList()).Select() .GroupBy(x => PIn.Long(x["ClinicNum"].ToString()), x => PIn.Long(x["PatNum"].ToString())) .ToDictionary(x => x.Key, x => x.ToList()); actionCloseProgress?.Invoke(); int totalPatCount = dictClinicPats.Sum(x => x.Value.Count); if (totalPatCount == 0) { MsgBox.Show(this, "The selected clinics are not clinics for any patients."); return; } string strClinicFromDesc = string.Join(", ", listClinicsFrom.FindAll(x => dictClinicPats.ContainsKey(x.ClinicNum)).Select(x => (x.ClinicNum == 0?"HQ":x.Abbr))); string strClinicToDesc = clinicTo.Abbr; string msg = Lan.g(this, "Move all patients to") + " " + strClinicToDesc + " " + Lan.g(this, "from the following clinics") + ": " + strClinicFromDesc + "?"; if (MessageBox.Show(msg, "", MessageBoxButtons.OKCancel) != DialogResult.OK) { return; } actionCloseProgress = ODProgressOld.ShowProgressStatus("ClinicReassign", this, Lan.g(this, "Moving patients") + "..."); int patsMoved = 0; List <Action> listActions = dictClinicPats.Select(x => new Action(() => { patsMoved += x.Value.Count; ODEvent.Fire(new ODEventArgs("ClinicReassign", Lan.g(this, "Moving patients") + ": " + patsMoved + " out of " + totalPatCount)); Patients.ChangeClinicsForAll(x.Key, clinicTo.ClinicNum); //update all clinicNums to new clinic SecurityLogs.MakeLogEntry(Permissions.PatientEdit, 0, "Clinic changed for " + x.Value.Count + " patients from " + (x.Key == 0 ? "HQ" : Clinics.GetAbbr(x.Key)) + " to " + clinicTo.Abbr + "."); })).ToList(); ODThread.RunParallel(listActions, TimeSpan.FromMinutes(2)); actionCloseProgress?.Invoke(); _dictClinicalCounts = Clinics.GetClinicalPatientCount(); FillGrid(); MsgBox.Show(this, "Done"); }
private void FormClinics_Load(object sender, System.EventArgs e) { if (ListClinics == null) { ListClinics = Clinics.GetAllForUserod(Security.CurUser); } if (_listClinicDefLinksAll == null) { _listClinicDefLinksAll = DefLinks.GetDefLinksByType(DefLinkType.Clinic); } ListClinicsOld = ListClinics.Select(x => x.Copy()).ToList(); _listClinicDefLinksAllOld = _listClinicDefLinksAll.Select(x => x.Copy()).ToList(); _listDefLinkClinicSpecialties = GetDefLinkClinicList(); _listClinicSpecialtyDefs = Defs.GetDefsForCategory(DefCat.ClinicSpecialty); checkOrderAlphabetical.Checked = PrefC.GetBool(PrefName.ClinicListIsAlphabetical); _dictClinicalCounts = Clinics.GetClinicalPatientCount(); if (IsSelectionMode) { butAdd.Visible = false; butOK.Visible = true; groupClinicOrder.Visible = false; groupMovePats.Visible = false; int widthDiff = (groupClinicOrder.Width - butOK.Width); this.MinimumSize = new Size(this.MinimumSize.Width - widthDiff, this.MinimumSize.Height); this.Width -= widthDiff; gridMain.Width += widthDiff; checkShowHidden.Visible = false; checkShowHidden.Checked = false; } else { if (checkOrderAlphabetical.Checked) { butUp.Enabled = false; butDown.Enabled = false; } else { butUp.Enabled = true; butDown.Enabled = true; } } if (IsMultiSelect) { butSelectAll.Visible = true; butSelectNone.Visible = true; gridMain.SelectionMode = GridSelectionMode.MultiExtended; } FillGrid(); for (int i = 0; i < gridMain.Rows.Count; i++) { if (ListSelectedClinicNums.Contains(((Clinic)gridMain.Rows[i].Tag).ClinicNum)) { gridMain.SetSelected(i, true); } } }
private void FormClinics_Load(object sender, System.EventArgs e) { checkOrderAlphabetical.Checked = PrefC.GetBool(PrefName.ClinicListIsAlphabetical); if (ListClinics == null) { ListClinics = Clinics.GetAllForUserod(Security.CurUser); if (IncludeHQInList) { ListClinics.Insert(0, new Clinic() { ClinicNum = 0, Description = Lan.g(this, "Headquarters"), Abbr = Lan.g(this, "HQ") }); } //if alphabetical checkbox is checked/unchecked it triggers a pref cache refresh, but does not refill the clinic cache, so we need to sort here //in case the pref was changed since last time this was opened. ListClinics.Sort(ClinicSort); } _listClinicsOld = ListClinics.Select(x => x.Copy()).ToList(); _listClinicDefLinksAllOld = DefLinks.GetDefLinksByType(DefLinkType.Clinic); _dictClinicalCounts = new SerializableDictionary <long, int>(); if (IsSelectionMode) { butAdd.Visible = false; butOK.Visible = true; groupClinicOrder.Visible = false; groupMovePats.Visible = false; int widthDiff = (groupClinicOrder.Width - butOK.Width); MinimumSize = new Size(MinimumSize.Width - widthDiff, MinimumSize.Height); Width -= widthDiff; gridMain.Width += widthDiff; butSelectAll.Location = new Point(butSelectAll.Location.X + widthDiff, butSelectAll.Location.Y); butSelectNone.Location = new Point(butSelectNone.Location.X + widthDiff, butSelectNone.Location.Y); checkShowHidden.Visible = false; checkShowHidden.Checked = false; } else { if (checkOrderAlphabetical.Checked) { butUp.Enabled = false; butDown.Enabled = false; } _dictClinicalCounts = Clinics.GetClinicalPatientCount(); } if (IsMultiSelect) { butSelectAll.Visible = true; butSelectNone.Visible = true; gridMain.SelectionMode = GridSelectionMode.MultiExtended; } FillGrid(false); if (!ListSelectedClinicNums.IsNullOrEmpty()) { for (int i = 0; i < gridMain.ListGridRows.Count; i++) { if (ListSelectedClinicNums.Contains(((Clinic)gridMain.ListGridRows[i].Tag).ClinicNum)) { gridMain.SetSelected(i, true); } } } }