private void FormTreatPlanCurEdit_Load(object sender, EventArgs e) { if (TreatPlanCur == null || (TreatPlanCur.TPStatus != TreatPlanStatus.Active && TreatPlanCur.TPStatus != TreatPlanStatus.Inactive)) { throw new Exception("No treatment plan loaded."); } _treatPlanUnassigned = TreatPlans.GetUnassigned(TreatPlanCur.PatNum); this.Text = TreatPlanCur.Heading + " - {" + Lans.g(this, TreatPlanCur.TPStatus.ToString()) + "}"; _listTpAttachesAll = TreatPlanAttaches.GetAllForPatNum(TreatPlanCur.PatNum); _listTpAttachesCur = _listTpAttachesAll.FindAll(x => x.TreatPlanNum == TreatPlanCur.TreatPlanNum); _listTpProcsAll = Procedures.GetProcsByStatusForPat(TreatPlanCur.PatNum, new[] { ProcStat.TP, ProcStat.TPi }); ProcedureLogic.SortProcedures(ref _listTpProcsAll); _listTpProcsCur = _listTpProcsAll.FindAll(x => _listTpAttachesCur.Any(y => x.ProcNum == y.ProcNum) || (TreatPlanCur.TPStatus == TreatPlanStatus.Active && (x.AptNum > 0 || x.PlannedAptNum > 0))); _listAppointments = Appointments.GetMultApts(_listTpProcsAll.SelectMany(x => new[] { x.AptNum, x.PlannedAptNum }).Distinct().Where(x => x > 0).ToList()); textHeading.Text = TreatPlanCur.Heading; textNote.Text = TreatPlanCur.Note; FillGrids(); if (TreatPlanCur.TPStatus == TreatPlanStatus.Inactive && TreatPlanCur.Heading == Lan.g("TreatPlan", "Unassigned")) { gridTP.Title = Lan.g("TreatPlan", "Unassigned Procedures"); labelHeading.Visible = false; textHeading.Visible = false; labelNote.Visible = false; textNote.Visible = false; gridAll.Visible = false; butLeft.Visible = false; butRight.Visible = false; butOK.Enabled = false; butDelete.Visible = false; } if (TreatPlanCur.TPStatus == TreatPlanStatus.Active) { butMakeActive.Enabled = false; butDelete.Enabled = false; } comboPlanType.Items.AddRange(Enum.GetNames(typeof(TreatPlanType))); comboPlanType.SelectedIndex = (int)TreatPlanCur.TPType; }
private void butOK_Click(object sender, EventArgs e) { TreatPlanCur.Heading = textHeading.Text; TreatPlanCur.Note = textNote.Text; TreatPlanCur.UserNumPresenter = 0; TreatPlanCur.TPType = (TreatPlanType)comboPlanType.SelectedIndex; if (TreatPlanCur.TreatPlanNum == 0) { TreatPlanCur.TreatPlanNum = TreatPlans.Insert(TreatPlanCur); } else { TreatPlans.Update(TreatPlanCur); } //get all TPAttaches for this TP where there is either a procedure with a TPAttach linking it to this TP //or, if this TP is active, a procedure linked to an appt by AptNum or PlannedAptNun List <TreatPlanAttach> listNew = _listTpAttachesCur.FindAll(x => _listTpProcsCur.Any(y => x.ProcNum == y.ProcNum)); _listTpProcsCur.FindAll(x => !listNew.Any(y => x.ProcNum == y.ProcNum)) .ForEach(x => listNew.Add(new TreatPlanAttach() { TreatPlanNum = TreatPlanCur.TreatPlanNum, ProcNum = x.ProcNum, Priority = 0 })); TreatPlanAttaches.Sync(listNew, TreatPlanCur.TreatPlanNum); if (_makeActive) { TreatPlans.SetOtherActiveTPsToInactive(TreatPlanCur); } if (TreatPlanCur.TPStatus == TreatPlanStatus.Active) { //we have to this whether we just made this the active or it was already active, otherwise any procs we move off of the active plan will //retain the TP status and AuditPlans will throw them back on this TP. //Changing the status to TPi of any procs that are not on this plan prevents that from happening. Procedures.SetTPActive(TreatPlanCur.PatNum, listNew.Select(x => x.ProcNum).ToList()); } DialogResult = DialogResult.OK; }