public AsyncPlan(AsyncESAPI ACurrent, PlanSum psIn, Patient ptIn, AsyncCourse cIn) { A = ACurrent; pt = ptIn; Course = cIn; ps = psIn; Id = ps.Id; var dates = ps.PlanSetups.Select(x => x.HistoryDateTime).OrderByDescending(x => x); HistoryDateTime = ps.PlanSetups.Select(x => x.HistoryDateTime).OrderByDescending(x => x).FirstOrDefault(); PlanType = ComponentTypes.Sum; NumFractions = 0; Dose = 0; if (ps.StructureSet == null) { Valid = false; } else { StructureSetId = ps.StructureSet.Id; StructureSetUID = ps.StructureSet.UID; foreach (Structure s in ps.StructureSet.Structures) { StructureIds.Add(s.Id); _Structures.Add(s.Id, s); Structures.Add(s.Id, new AsyncStructure(ACurrent, s, ps.StructureSet.Id, ps.StructureSet.UID)); } } foreach (PlanSetup p in ps.PlanSetups) { ConstituentPlans.Add(new AsyncPlan(A, p, ptIn, cIn)); } HashId = Convert.ToInt32(ps.Id.GetHashCode() + ps.Course.Id.GetHashCode() + string.Concat(ConstituentPlans.Select(x => x.UID)).GetHashCode()); UID = String.Join("+", ConstituentPlans.Select(x => x.UID)); }
public PlanningItemViewModel(PlanningItem planningItem) { if (planningItem is PlanSetup) { PlanSetup planSetup = (PlanSetup)planningItem; PlanningItemId = planSetup.Id; PlanningItemCourse = planSetup.Course.Id; PlanningItemIdWithCourse = PlanningItemCourse + "/" + PlanningItemId; PlanningItemType = "Plan"; PlanningItemIdWithCourseAndType = PlanningItemCourse + "/" + PlanningItemId + " (" + PlanningItemType + ")"; PlanningItemObject = planSetup; PlanningItemStructureSet = planSetup.StructureSet; PlanningItemImage = planSetup.StructureSet.Image; Creation = (DateTime)planSetup.CreationDateTime; } if (planningItem is PlanSum) { PlanSum planSum = (PlanSum)planningItem; PlanningItemId = planSum.Id; PlanningItemCourse = planSum.Course.Id; PlanningItemIdWithCourse = PlanningItemCourse + "/" + PlanningItemId; PlanningItemType = "PlanSum"; PlanningItemIdWithCourseAndType = PlanningItemCourse + "/" + PlanningItemId + " (" + PlanningItemType + ")"; PlanningItemObject = planSum; PlanningItemStructureSet = planSum.StructureSet; PlanningItemImage = planSum.StructureSet.Image; Creation = (DateTime)planSum.HistoryDateTime; } }
public void BuildList() { PlanSumList.Clear(); planT.Clear(); if (!isPsum) { PS = (PlanSetup)plan; planT.Add(PS.TargetVolumeID); } else { SumPlan = (PlanSum)plan; foreach (var pss in SumPlan.PlanSetups) { PlanSumList.Add(new PlanSumClass { PlanName = pss.Id, PlanDose = pss.TotalDose }); planT.Add(pss.TargetVolumeID); Double.TryParse(pss.TotalDose.ToString().Split(' ').First(), out checkedDose); sumDose = sumDose + checkedDose; } tbRxdose.Text = sumDose.ToString(); listBoxZone.DataContext = PlanSumList; listBoxZone.Items.Refresh(); } }
//--------------------------------------------------------------------------------------------- public void Execute(ScriptContext context, Window window) { PlanSetup plan = context.PlanSetup; PlanSum psum = context.PlanSumsInScope.FirstOrDefault(); if (plan == null && psum == null) { return; } window.Closing += new System.ComponentModel.CancelEventHandler(OnWindowClosing); window.Background = System.Windows.Media.Brushes.Cornsilk; window.Height = 120; window.Width = 1024; SelectedPlanningItem = plan != null ? (PlanningItem)plan : (PlanningItem)psum; // Plans in plansum can have different structuresets but here we only use structureset to allow chosing one structure SelectedStructureSet = plan != null ? plan.StructureSet : psum.PlanSetups.First().StructureSet; window.Title = "DVH Lookups for " + SelectedPlanningItem.Id + " / " + SelectedStructureSet.Id; if (SelectedPlanningItem.Dose == null) { return; } InitializeUI(window); }
public List <ErrorViewModel> Calculate(PlanningItem planningItem) { var errorGrid = new List <ErrorViewModel>(); var planErrors = new List <ErrorViewModel>(); var planSumErrors = new List <ErrorViewModel>(); var planSumDoseErrors = new List <ErrorViewModel>(); if (planningItem is PlanSetup) { PlanSetup planSetup = (PlanSetup)planningItem; planErrors = GetPlanSetupErrors(planSetup); errorGrid.AddRange(planErrors); } if (planningItem is PlanSum) { PlanSum planSum = (PlanSum)planningItem; foreach (PlanSetup planSetup in planSum.PlanSetups) { planErrors = GetPlanSetupErrors(planSetup); errorGrid.AddRange(planErrors); } planSumDoseErrors = GetPlanSumRxErrors(planSum); errorGrid.AddRange(planSumDoseErrors); } return(errorGrid); }
public ObservableCollection <PQMSummaryViewModel> AddPQMSummary(ObservableCollection <PQMSummaryViewModel> PqmSummaries, ConstraintViewModel constraintPath, PlanningItemViewModel planningItem, Patient patient) { StructureSet structureSet = planningItem.PlanningItemStructureSet; Structure evalStructure; var calculator = new PQMSummaryCalculator(); if (planningItem.PlanningItemObject is PlanSum) { var waitWindowPQM = new WaitWindowPQM(); PlanSum plansum = (PlanSum)planningItem.PlanningItemObject; if (plansum.IsDoseValid() == true) { waitWindowPQM.Show(); foreach (PQMSummaryViewModel pqm in PqmSummaries) { evalStructure = calculator.FindStructureFromAlias(structureSet, pqm.TemplateId, pqm.TemplateAliases, pqm.TemplateCodes); if (evalStructure != null) { var pqmSummary = calculator.GetObjectiveProperties(pqm, planningItem, structureSet, new StructureViewModel(evalStructure)); pqm.Achieved_Comparison = pqmSummary.Achieved; pqm.AchievedColor_Comparison = pqmSummary.AchievedColor; pqm.AchievedPercentageOfGoal_Comparison = pqmSummary.AchievedPercentageOfGoal; pqm.Met_Comparison = pqmSummary.Met; } } waitWindowPQM.Close(); } } else //is plansetup { var waitWindowPQM = new WaitWindowPQM(); PlanSetup planSetup = (PlanSetup)planningItem.PlanningItemObject; if (planSetup.IsDoseValid() == true) { waitWindowPQM.Show(); foreach (PQMSummaryViewModel pqm in PqmSummaries) { evalStructure = calculator.FindStructureFromAlias(structureSet, pqm.TemplateId, pqm.TemplateAliases, pqm.TemplateCodes); if (evalStructure != null) { if (evalStructure.Id.Contains("PTV") == true) { foreach (Structure s in structureSet.Structures) { if (s.Id == planSetup.TargetVolumeID) { evalStructure = s; } } } var pqmSummary = calculator.GetObjectiveProperties(pqm, planningItem, structureSet, new StructureViewModel(evalStructure)); pqm.Achieved_Comparison = pqmSummary.Achieved; } } waitWindowPQM.Close(); } } return(PqmSummaries); }
public static Course Course(this PlanSum ps) { #if VMS110 return(ps.PlanSetups.FirstOrDefault()?.Course); #else return(ps.Course); #endif }
//--------------------------------------------------------------------------------------------- /// <summary> /// This method creates a Plan Quality Metric report for the specified plansum. /// </summary> /// <param name="patient">loaded patient</param> /// <param name="ss">structure set to use while generating Plan Quality Metrics</param> /// <param name="psum">Plansum for which the report is going to be generated.</param> /// <param name="rootPath">root directory for the report. This method creates a subdirectory /// 'patientid' under the root, then creates the xml and html reports in the subdirectory.</param> /// <param name="userId">User whose id will be stamped on the report.</param> //--------------------------------------------------------------------------------------------- override protected void dumpReportXML(Patient patient, StructureSet ss, PlanningItem plan_, string sXMLPath) { if (!(plan_ is PlanSum)) { throw new ApplicationException("PlanSumReporter should be used only for PlanSum types!"); } PlanSum psum = (PlanSum)plan_; XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = ("\t"); System.IO.MemoryStream mStream = new System.IO.MemoryStream(); XmlWriter writer = XmlWriter.Create(mStream, settings); writer.WriteStartDocument(true); writer.WriteStartElement("PlanQualityReport"); writer.WriteAttributeString("created", DateTime.Now.ToString()); writer.WriteAttributeString("userid", currentuser); writer.WriteAttributeString("eclipseVersion", eclipseVersion); writer.WriteAttributeString("scriptVersion", scriptVersion); writer.WriteStartElement("Patient"); WritePatientXML(patient, writer); writer.WriteStartElement("PlanSum"); psum.WriteXml(writer); foreach (PlanSetup plan in psum.PlanSetups) { WritePlanXML(plan, writer, CtrlPtSelector.IncludeControlPoints); } writer.WriteEndElement(); // </PlanSum> writer.WriteEndElement(); // </Patient> writer.WriteStartElement("DoseStatistics"); WriteDoseStatisticsXML_Target(patient, ss, psum, writer); WriteDoseStatisticsXML_Prostate2GyOrLess(patient, ss, psum, writer); WriteDoseStatisticsXML_HeadAndNeck2GyOrLess(patient, ss, psum, writer); writer.WriteEndElement(); // </DoseStatistics> writer.WriteEndElement(); // </PlanQualityReport> writer.WriteEndDocument(); writer.Flush(); mStream.Flush(); // write the XML file report. using (System.IO.FileStream file = new System.IO.FileStream(sXMLPath, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { // Have to rewind the MemoryStream in order to read its contents. mStream.Position = 0; mStream.CopyTo(file); file.Flush(); file.Close(); } writer.Close(); mStream.Close(); }
public void Execute(ScriptContext context /*, System.Windows.Window window*/) { string html = GrabDx(context); PlanSetup ps = context.PlanSetup; PlanSum psum = context.PlanSumsInScope.FirstOrDefault(); PlanningItem pi = ps != null ? (PlanningItem)ps : (PlanningItem)psum; string temp = System.Environment.GetEnvironmentVariable("TEMP"); string htmlPath = string.Format("{0}\\{1}({2}){3}.html", temp, context.Patient.LastName, context.Patient.Id, pi.Id); using (System.IO.FileStream file = new System.IO.FileStream (htmlPath, System.IO.FileMode.Create, System.IO.FileAccess.Write)) { } //MessageBox.Show(htmlPath); //htmlPath = @"\\varnwcdcpap001.nyumc.org\va_data$\filedata\ProgramData\Vision\PublishedScripts\dx.html"; //System.IO.File.WriteAllText(htmlPath, html); //XmlWriterSettings settings = new XmlWriterSettings(); //settings.Indent = true; //settings.IndentChars = ("\t"); //System.IO.MemoryStream mStream = new System.IO.MemoryStream(); //using (XmlWriter writer = XmlWriter.Create(mStream, settings)) //{ // // generate DVHs in an HTML report for selected structures // ExportDVHs(context, writer); // // done writing // writer.Flush(); // mStream.Flush(); // // write the XML file. // string temp = System.Environment.GetEnvironmentVariable("TEMP"); // string htmlPath = string.Format("{0}\\{1}({2})-plan-{3}.html", temp, // context.Patient.LastName, context.Patient.Id, context.PlanSetup.Id); // using (System.IO.FileStream file = new System.IO.FileStream // (htmlPath, System.IO.FileMode.Create, System.IO.FileAccess.Write)) // { // // Have to rewind the MemoryStream in order to read its contents. // mStream.Position = 0; // mStream.CopyTo(file); // file.Flush(); // file.Close(); // } WriteHtml(html); // 'Start' generated HTML file to launch browser window //System.Diagnostics.Process.Start(htmlPath); System.Diagnostics.Process.Start(fileinfo.FullName); // Sleep for a few seconds to let internet browser window to start System.Threading.Thread.Sleep(TimeSpan.FromSeconds(1)); }
/// <summary> /// This method exists to guess the prescription of a plan sum by summing all plan setup prescribed doses and /// generating a /// relative dvh curve. Can't technically do relative dose with plan sum...but let's try to do it anyway /// </summary> /// <param name="ps">the plan sum where relative dose dvh curve is desired</param> /// <param name="s">the structure to sample</param> /// <param name="vPres">the volume presentation to create the curve</param> /// <param name="binWidth">the bin width to create the curve</param> /// <returns></returns> public static DVHPoint[] GetRelativeDVHCumulativeData(this PlanSum ps, Structure s, VolumePresentation vPres, double binWidth) { var guessedRxGy = ps.TotalPrescribedDoseGy(); var psDVH = ps.GetDVHCumulativeData(s, DoseValuePresentation.Absolute, vPres, binWidth); var scalingPoint = new DoseValue(guessedRxGy, DoseValue.DoseUnit.Gy); var dvhCurve = psDVH.CurveData.ConvertToRelativeDose(scalingPoint); return(dvhCurve); }
public void Execute(ScriptContext context, Window window) { PlanSetup planSetup = context.PlanSetup; PlanSum psum = context.PlanSumsInScope.FirstOrDefault(); bool first = true; SelectedPlanningItem = planSetup != null ? (PlanningItem)planSetup : (PlanningItem)psum; SelectedStructureSet = planSetup != null ? planSetup.StructureSet : psum.PlanSetups.First().StructureSet; // MessageBox.Show(String.Format("3 Planning Iten Sum = {0}", SelectedPlanningItem.Id)); if (SelectedStructureSet == null) { throw new ApplicationException("The selected plan does not reference a StructureSet."); } // For this example we will retrieve first available structure of PTV type // Add existing WPF control to the script window. var mainControl = new PlanMetrics.MainControl(); window.Content = mainControl; window.Width = 850; window.Height = 750; window.Title = "Plan : " + SelectedPlanningItem.Id;// + ", Structure : " + target.Id; mainControl.tbPatName.Text = context.Patient.Name.Split('(').First(); mainControl.tbPatID.Text = context.Patient.Id; mainControl.tbPlanId.Text = SelectedPlanningItem.Id; mainControl.tbDate.Text = DateTime.Today.ToString("MMMM d, yyyy"); mainControl.plan = SelectedPlanningItem; //pass planSetup from here to Maincontrol mainControl.set = SelectedStructureSet; mainControl.isPsum = planSetup != null ? false : true; if (!mainControl.isPsum) { mainControl.tbRxdose.Text = planSetup.TotalDose.ToString().Split(' ').First(); mainControl.BuildList(); mainControl.ComputeTargets(); } else { mainControl.BuildList(); mainControl.ComputeTargets(); } }
/// <summary> /// Starts execution of script. This method can be called directly from PluginTester or indirectly from Eclipse /// through the Execute method. /// </summary> /// <param name="patient">Opened patient</param> /// <param name="PItemsInScope">Planning Items in scope</param> /// <param name="pItem">Opened Planning Item</param> /// <param name="currentUser">Current user</param> /// <param name="window">WPF window</param> public static void Start(Patient pat, List <PlanningItem> PItemsInScope, PlanningItem pItem, Course course, StructureSet ss, User currentUser, Window window) { if (pat == null || pItem == null) { throw new ApplicationException("Please open a plan or a plan sum before running the script"); } window.Title = "Radiobiological Effect Window"; var uc = new RBEReport.UserControl1(); window.Content = uc; uc.VM.PatientId = pat.Id; uc.VM.PatientName = pat.FirstName + " " + pat.LastName; if (pat.DateOfBirth != null) { uc.VM.DOB = pat.DateOfBirth.GetValueOrDefault().Date.ToShortDateString(); } if (course != null) { uc.VM.CourseId = course.Id; } else { uc.VM.CourseId = GetPlanSumCourse(pat, pItem as PlanSum); } uc.VM.PlanId = pItem.Id; if (pItem is PlanSetup) { uc.VM.Approval = (pItem as PlanSetup).ApprovalStatus.ToString(); } else { uc.VM.Approval = string.Empty; //if nothing is set (Approval == null), MigraDoc crashes. } uc.VM.Modification = pItem.HistoryUserName; uc.VM.Date = pItem.HistoryDateTime.ToString(); if (pItem is PlanSetup) { uc.VM.AddPlanningItem(pItem as PlanSetup); } else { PlanSum sum = pItem as PlanSum; foreach (PlanSetup ps in sum.PlanSetups) { uc.VM.AddPlanningItem(ps); } } }
public string NTCPreturn(string strnum, string gradename, StructureSet list, PlanSum plan, double n, double m, double td50) { Structure retstructure = null; int bit = 0; double EUD = 0; double Ntcp = 0; string NTCPstring = ""; foreach (Structure scan in list.Structures) { if (scan.Id == strnum) { retstructure = scan; bit = 1; if (retstructure.IsEmpty == true) { bit = 2; break; } DVHData dvh = plan.GetDVHCumulativeData(retstructure, DoseValuePresentation.Absolute, VolumePresentation.Relative, 1); var dvhdata = dvh.CurveData.ToList(); string volume = dvh.Volume.ToString(); string dvhstr = volume; double fEUD = 0; string dvhnums = dvhdata.Count.ToString(); for (int i = 0; i < dvhdata.Count - 1; i++) { fEUD += (dvhdata[i].Volume - dvhdata[i + 1].Volume) / 100 * Math.Pow(dvhdata[i].DoseValue.Dose / 100, 1 / n); } EUD = Math.Pow(fEUD, n); double t = treturn(EUD, m, td50); Ntcp = NTCP(t); NTCPstring += string.Format("NTCP of {0}, {1} is {2}%\n", strnum, gradename, (Ntcp * 100).ToString("F2")); } } if (bit == 0) { NTCPstring += ""; return(NTCPstring); } else if (bit == 2) { NTCPstring += ""; return(NTCPstring); } else { return(NTCPstring); } }
public static string comparaIsosPlanSuma(PlanSum planSuma) { string texto = ""; foreach (PlanSetup etapaA in planSuma.PlanSetups) { foreach (PlanSetup etapaB in planSuma.PlanSetups) { if (isosDiferentes(etapaA, etapaB)) { texto += "\nLos planes " + etapaA.Id + " y " + etapaB.Id + " tienen isos similares.\nEvaluar la utilización de un mismo iso"; } } } return(texto); }
static string GetPlanSumCourse(Patient pat, PlanningItem item) { PlanSum sum = item as PlanSum; foreach (Course cour in pat.Courses) { foreach (PlanSum ps in cour.PlanSums) { if (ps == sum) { return(cour.Id); } } } return(""); }
// Determines if dose is valid in a plan. public static bool IsDoseValid(this PlanningItem pitem) { if (pitem is PlanSetup) { return(((PlanSetup)pitem).IsDoseValid); } else if (pitem is PlanSum) { PlanSum psum = (PlanSum)pitem; var plans = (from p in psum.PlanSetups where p.IsDoseValid == false select p); return(plans.Count() <= 0); } else { throw new ApplicationException("Unknown PlanningItem type " + pitem.ToString()); } }
public static bool IsDoseValid(this PlanningItem pitem) { if (pitem is PlanSetup) { return(((PlanSetup)pitem).IsDoseValid); } else if (pitem is PlanSum) { // scan for plans with invalid dose, if there are none then we can assume plansum dose is valid. PlanSum psum = (PlanSum)pitem; var plans = (from p in psum.PlanSetups where p.IsDoseValid == false select p); return(plans.Count() <= 0); } else { throw new ApplicationException("Unknown PlanningItem type " + pitem.ToString()); } }
public static string GetConformationNumber(StructureSet structureSet, PlanningItemViewModel planningItem, StructureViewModel evalStructure, MatchCollection testMatch, Group evalunit) { try { var structure = structureSet.Structures.FirstOrDefault(x => x.Id == evalStructure.StructureName); DVHData dvh = planningItem.PlanningItemObject.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, VolumePresentation.Relative, 0.1); DoseValue prescribedDose; double planDoseDouble = 0; if ((dvh.SamplingCoverage < 0.9) || (dvh.Coverage < 0.9)) { return("Unable to calculate - insufficient dose or sampling coverage"); } if (planningItem.PlanningItemObject is PlanSum) { PlanSum planSum = (PlanSum)planningItem.PlanningItemObject; foreach (PlanSetup planSetup in planSum.PlanSetups) { planDoseDouble += planSetup.TotalDose.Dose; } } if (planningItem.PlanningItemObject is PlanSetup) { PlanSetup planSetup = (PlanSetup)planningItem.PlanningItemObject; planDoseDouble = planSetup.TotalDose.Dose; } prescribedDose = new DoseValue(planDoseDouble, DoseValue.DoseUnit.cGy); Group eval = testMatch[0].Groups["evalpt"]; Group unit = testMatch[0].Groups["unit"]; DoseValue.DoseUnit du = (unit.Value.CompareTo("%") == 0) ? DoseValue.DoseUnit.Percent : (unit.Value.CompareTo("cGy") == 0) ? DoseValue.DoseUnit.cGy : DoseValue.DoseUnit.Unknown; var body = structureSet.Structures.Where(x => x.Id.Contains("BODY")).First(); //VolumePresentation vpFinal = (evalunit.Value.CompareTo("%") == 0) ? VolumePresentation.Relative : VolumePresentation.AbsoluteCm3; VolumePresentation vpFinal = VolumePresentation.AbsoluteCm3; DoseValuePresentation dvpFinal = (evalunit.Value.CompareTo("%") == 0) ? DoseValuePresentation.Relative : DoseValuePresentation.Absolute; DoseValue dv = new DoseValue(double.Parse(eval.Value) / 100 * prescribedDose.Dose, DoseValue.DoseUnit.cGy); double bodyWithPrescribedDoseVolume = planningItem.PlanningItemObject.GetVolumeAtDose(body, prescribedDose, vpFinal); double targetWithPrescribedDoseVolume = planningItem.PlanningItemObject.GetVolumeAtDose(structure, dv, vpFinal); double targetVolume = Convert.ToDouble(evalStructure.VolumeValue); var cn = (targetWithPrescribedDoseVolume / targetVolume) * (targetWithPrescribedDoseVolume / bodyWithPrescribedDoseVolume); return(string.Format("{0:0.0}", cn)); } catch (NullReferenceException) { return("Unable to calculate - DVH is not valid"); } }
public static string planesEnDiferenteEquipo(PlanSum planSum) { string texto = ""; string IdEquipo = planSum.PlanSetups.First().Beams.First().TreatmentUnit.Id; foreach (PlanSetup plan in planSum.PlanSetups) { foreach (Beam campo in plan.Beams) { if (!campo.TreatmentUnit.Id.Equals(IdEquipo)) { texto += "\nEl plan suma contiene campos en diferentes equipos de tratamiento"; return(texto); } } } return(texto); }
public void Execute(ScriptContext context /*,System.Windows.Window window*/) { PlanSum plan = context.PlanSumsInScope.First(); //PlanSetup plan = sumplan.PlanSetups.ElementAt(0); //StructureSet ss = plan.StructureSet; StructureSet ss = plan.StructureSet; string plansummary = string.Format("Sum plan {0}\n", plan.Id.ToString()); string msgfmt = plansummary; msgfmt += "Structure\t\tIntended Dose Index\tPlan\tJudge\n"; msgfmt += Absmax("BRAIN_PRV", 7000, 1, ss, plan); msgfmt += Absmax("SPINAL_CORD_PRV", 5000, 1, ss, plan); msgfmt += Absmax("Spinal Canal", 5000, 1, ss, plan); msgfmt += Absmax("BRAIN_STEM_PRV", 5400, 1, ss, plan); msgfmt += Absmax("Brainstem", 5400, 1, ss, plan); msgfmt += Absmean("PAROTID_L", 2600, 1, ss, plan); msgfmt += Absmean("PAROTID_R", 2600, 1, ss, plan); msgfmt += "\n"; msgfmt += Absmax("Chiasm", 5000, 1, ss, plan); msgfmt += Absmax("OPTIC_NRV_PRV", 5000, 1, ss, plan); msgfmt += Absmean("EAR_INN_L_PRV", 4500, 1, ss, plan); msgfmt += Absmean("EAR_INN_R_PRV", 4500, 1, ss, plan); msgfmt += Absmax("EYE", 4000, 1, ss, plan); msgfmt += Absmean("LENS_L", 600, 1, ss, plan); msgfmt += Absmean("LENS_R", 600, 1, ss, plan); msgfmt += Absmean("MUSCLE_CONST", 5400, 1, ss, plan); msgfmt += Absmean("LARYNX", 4500, 1, ss, plan); msgfmt += "\n"; msgfmt += NTCPreturn("Brain", "Burman 1991, necrosis/infarct", ss, plan, 0.25, 0.15, 60); msgfmt += NTCPreturn("Brainstem", "Burman 1991, necrosis/infarct", ss, plan, 0.16, 0.14, 65); msgfmt += NTCPreturn("Spinal Canal", "Burman 1991, Myelitis/necrosis", ss, plan, 0.05, 0.175, 66.5); msgfmt += NTCPreturn("PAROTID_L", "Dijkema 2011, saliva flow < 25%", ss, plan, 1.13, 0.42, 39.4); msgfmt += NTCPreturn("PAROTID_R", "Dijkema 2011, saliva flow < 25%", ss, plan, 1.13, 0.42, 39.4); msgfmt += NTCPreturn("Chiasm", "Burman 1991, Blindness", ss, plan, 0.25, 0.14, 65); msgfmt += NTCPreturn("OPTIC_NRV_PRV", "Burman 1991, Blindness", ss, plan, 0.25, 0.14, 65); msgfmt += NTCPreturn("LENS_L", "Burman 1991, Cataract requiring intervention", ss, plan, 0.30, 0.27, 18); msgfmt += NTCPreturn("LENS_R", "Burman 1991, Cataract requiring intervention", ss, plan, 0.30, 0.27, 18); msgfmt += NTCPreturn("THYROID", "Bakhshandeh 2012, Hypothyroidism", ss, plan, 0.49, 0.24, 60); msgfmt += NTCPreturn("Tongue", "Musha, RTOG Grade over2", ss, plan, 0.03, 0.15, 72); msgfmt += NTCPreturn("Tongue", "Musha, RTOG Grade over1", ss, plan, 0.05, 0.23, 42.5); MessageBox.Show(msgfmt, "Head and Neck Dose Index"); }
public static string GetVolumeAtDose(StructureSet structureSet, PlanningItemViewModel planningItem, Structure evalStructure, MatchCollection testMatch, Group evalunit) { //check for sufficient sampling and dose coverage DVHData dvh = planningItem.PlanningItemObject.GetDVHCumulativeData(evalStructure, DoseValuePresentation.Absolute, VolumePresentation.Relative, 0.1); //MessageBox.Show(evalStructure.Id + "- Eval unit: " + evalunit.Value.ToString() + "Achieved unit: " + dvAchieved.UnitAsString + " - Sampling coverage: " + dvh.SamplingCoverage.ToString() + " Coverage: " + dvh.Coverage.ToString()); if ((dvh.SamplingCoverage < 0.9) || (dvh.Coverage < 0.9)) { return("Unable to calculate - insufficient dose or sampling coverage"); } Group eval = testMatch[0].Groups["evalpt"]; Group unit = testMatch[0].Groups["unit"]; DoseValue.DoseUnit du = (unit.Value.CompareTo("%") == 0) ? DoseValue.DoseUnit.Percent : (unit.Value.CompareTo("cGy") == 0) ? DoseValue.DoseUnit.cGy : DoseValue.DoseUnit.Unknown; VolumePresentation vp = (unit.Value.CompareTo("%") == 0) ? VolumePresentation.Relative : VolumePresentation.AbsoluteCm3; DoseValue dv = new DoseValue(double.Parse(eval.Value), du); double volume = double.Parse(eval.Value); VolumePresentation vpFinal = (evalunit.Value.CompareTo("%") == 0) ? VolumePresentation.Relative : VolumePresentation.AbsoluteCm3; DoseValuePresentation dvpFinal = (evalunit.Value.CompareTo("%") == 0) ? DoseValuePresentation.Relative : DoseValuePresentation.Absolute; if (planningItem.PlanningItemObject is PlanSum) { double planDoseDouble = 0; PlanSum planSum = (PlanSum)planningItem.PlanningItemObject; foreach (PlanSetup planSetup in planSum.PlanSetups) { planDoseDouble += planSetup.TotalDose.Dose; } dv = new DoseValue(planDoseDouble, DoseValue.DoseUnit.cGy); } double volumeAchieved = planningItem.PlanningItemObject.GetVolumeAtDose(evalStructure, dv, vpFinal); return(string.Format("{0:0.00} {1}", volumeAchieved, evalunit.Value)); // todo: better formatting based on VolumePresentation //#if false // string message = string.Format("{0} - Dose unit = {1}, Volume Presentation = {2}, vpFinal = {3}, dvpFinal ={4}", // objective.DVHObjective, du.ToString(), vp.ToString(), vpFinal.ToString(), dvpFinal.ToString()); // MessageBox.Show(message); //#endif }
public static string GetGradientIndex(StructureSet structureSet, PlanningItemViewModel planningItem, Structure evalStructure, MatchCollection testMatch, Group evalunit) { // we have Gradient Index pattern DVHData dvh = planningItem.PlanningItemObject.GetDVHCumulativeData(evalStructure, DoseValuePresentation.Absolute, VolumePresentation.Relative, 0.1); if ((dvh.SamplingCoverage < 0.9) || (dvh.Coverage < 0.9)) { return("Unable to calculate - insufficient dose or sampling coverage"); } Group eval = testMatch[0].Groups["evalpt"]; Group unit = testMatch[0].Groups["unit"]; DoseValue prescribedDose; double planDoseDouble = 0; DoseValue.DoseUnit du = (unit.Value.CompareTo("%") == 0) ? DoseValue.DoseUnit.Percent : (unit.Value.CompareTo("cGy") == 0) ? DoseValue.DoseUnit.cGy : DoseValue.DoseUnit.Unknown; if (planningItem.PlanningItemObject is PlanSum) { PlanSum planSum = (PlanSum)planningItem.PlanningItemObject; foreach (PlanSetup planSetup in planSum.PlanSetups) { planDoseDouble += planSetup.TotalDose.Dose; } } if (planningItem.PlanningItemObject is PlanSetup) { PlanSetup planSetup = (PlanSetup)planningItem.PlanningItemObject; planDoseDouble = planSetup.TotalDose.Dose; } prescribedDose = new DoseValue(planDoseDouble, DoseValue.DoseUnit.cGy); //var body = structureSet.Structures.Where(x => x.Id.Contains("BODY")).First(); VolumePresentation vpFinal = VolumePresentation.AbsoluteCm3; DoseValuePresentation dvpFinal = (evalunit.Value.CompareTo("%") == 0) ? DoseValuePresentation.Relative : DoseValuePresentation.Absolute; DoseValue dv = new DoseValue(double.Parse(eval.Value) / 100 * prescribedDose.Dose, DoseValue.DoseUnit.cGy); double bodyWithPrescribedDoseVolume = planningItem.PlanningItemObject.GetVolumeAtDose(evalStructure, prescribedDose, vpFinal); double bodyWithEvalDoseVolume = planningItem.PlanningItemObject.GetVolumeAtDose(evalStructure, dv, vpFinal); var gi = bodyWithEvalDoseVolume / bodyWithPrescribedDoseVolume; return(string.Format("{0:0.0}", gi)); }
public ObservableCollection <PlanSelectDetailViewModel> Calculate(ObservableCollection <PlanningItemViewModel> planningItemList) { var PlanningItemSummaries = new ObservableCollection <PlanSelectDetailViewModel>(); var PlanSummary = new ObservableCollection <PlanSelectDetailViewModel>(); foreach (PlanningItemViewModel planningItem in planningItemList) { if (planningItem.PlanningItemObject is PlanSum) { PlanSum planSum = (PlanSum)planningItem.PlanningItemObject; int sumOfFractions = 0; double sumOfPlanSetupDoses = 0; foreach (PlanSetup planSetup in planSum.PlanSetups.OrderBy(x => x.CreationDateTime)) { sumOfFractions += planSetup.NumberOfFractions.Value; sumOfPlanSetupDoses += planSetup.TotalDose.Dose; } var PlanningItemSummary = new PlanSelectDetailViewModel { ActivePlanningItem = new PlanningItemViewModel(planSum), PlanningItemIdWithCourse = planSum.Course + "/" + planSum.Id, ApprovalStatus = "PlanSum", PlanName = planSum.Course + "/" + planSum.Id, PlanStructureSet = planSum.StructureSet.Id, IsPlanSum = true, PlanCreated = planSum.CreationDateTime.ToString(), PlanFractions = sumOfFractions.ToString(), PlanTotalDose = sumOfPlanSetupDoses.ToString(), IsDoseValid = planSum.IsDoseValid() }; PlanningItemSummaries.Add(PlanningItemSummary); } else { PlanSetup planSetup = (PlanSetup)planningItem.PlanningItemObject; string planTarget; if (planSetup.TargetVolumeID != null) { planTarget = planSetup.TargetVolumeID; } else { planTarget = "No target selected"; } var PlanningItemSummary = new PlanSelectDetailViewModel { ActivePlanningItem = new PlanningItemViewModel(planSetup), PlanningItemIdWithCourse = planSetup.Course + "/" + planSetup.Id, ApprovalStatus = planSetup.ApprovalStatus.ToString(), PlanName = planSetup.Course + "/" + planSetup.Id, IsPlanSum = false, PlanStructureSet = planSetup.StructureSet.Id, PlanNumFields = planSetup.Beams.Count().ToString(), PlanningItemObject = planningItem.PlanningItemObject, PlanCreated = planSetup.CreationDateTime.ToString(), PlanFxDose = planSetup.DosePerFraction.Dose.ToString(), PlanFractions = planSetup.NumberOfFractions.ToString(), PlanTotalDose = planSetup.TotalDose.Dose.ToString(), PlanTarget = planTarget, IsDoseValid = planSetup.IsDoseValid() }; PlanningItemSummaries.Add(PlanningItemSummary); } } return(PlanningItemSummaries); }
public static string GetMinMaxMean(StructureSet structureSet, PlanningItemViewModel planningItem, StructureViewModel evalStructure, MatchCollection testMatch, Group evalunit, Group type) { try { var structure = structureSet.Structures.FirstOrDefault(x => x.Id == evalStructure.StructureName); if (type.Value.CompareTo("Volume") == 0) { return(string.Format("{0:0.00} {1}", evalStructure.VolumeValue, evalunit.Value)); } else { double planSumRxDose = 0; DVHData dvh; DoseValuePresentation dvp = (evalunit.Value.CompareTo("%") == 0) ? DoseValuePresentation.Relative : DoseValuePresentation.Absolute; if (dvp == DoseValuePresentation.Relative && planningItem.PlanningItemObject is PlanSum) { PlanSum planSum = (PlanSum)planningItem.PlanningItemObject; foreach (PlanSetup planSetup in planSum.PlanSetups) { double planSetupRxDose = planSetup.TotalDose.Dose; planSumRxDose += planSetupRxDose; } dvh = planningItem.PlanningItemObject.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, VolumePresentation.Relative, 0.1); } else { dvh = planningItem.PlanningItemObject.GetDVHCumulativeData(structure, dvp, VolumePresentation.Relative, 0.1); } if (type.Value.CompareTo("Max") == 0) { //checking dose output unit and adapting to template //Gy to cGy if ((evalunit.Value.CompareTo("Gy") == 0) && (dvh.MaxDose.Unit.CompareTo(DoseValue.DoseUnit.cGy) == 0)) { return(new DoseValue(dvh.MaxDose.Dose / 100, DoseValue.DoseUnit.Gy).ToString()); } //Gy to Gy or % to % else { if (dvp == DoseValuePresentation.Relative && planningItem.PlanningItemObject is PlanSum) { double maxDoseDouble = double.Parse(dvh.MaxDose.ValueAsString); //double return((maxDoseDouble / planSumRxDose * 100).ToString("0.0") + " " + evalunit.Value); } else { return(dvh.MaxDose.ToString()); } } } else if (type.Value.CompareTo("Min") == 0) { //checking dose output unit and adapting to template //Gy to cGy if ((evalunit.Value.CompareTo("Gy") == 0) && (dvh.MinDose.Unit.CompareTo(DoseValue.DoseUnit.cGy) == 0)) { return(new DoseValue(dvh.MinDose.Dose / 100, DoseValue.DoseUnit.Gy).ToString()); } //Gy to Gy or % to % else { return(dvh.MinDose.ToString()); } } else { //checking dose output unit and adapting to template //Gy to cGy if ((evalunit.Value.CompareTo("Gy") == 0) && (dvh.MeanDose.Unit.CompareTo(DoseValue.DoseUnit.cGy) == 0)) { return(new DoseValue(dvh.MeanDose.Dose / 100, DoseValue.DoseUnit.Gy).ToString()); } //Gy to Gy or % to % else { return(dvh.MeanDose.ToString()); } } } } catch (NullReferenceException) { return("Unable to calculate - DVH is not valid"); } }
public void GetPQMSummaries(ConstraintViewModel constraintPath, PlanningItemViewModel planningItem, Patient patient) { PqmSummaries = new ObservableCollection <PQMSummaryViewModel>(); StructureSet structureSet = planningItem.PlanningItemStructureSet; Structure evalStructure; ObservableCollection <PQMSummaryViewModel> pqmSummaries = new ObservableCollection <PQMSummaryViewModel>(); ObservableCollection <StructureViewModel> foundStructureList = new ObservableCollection <StructureViewModel>(); var calculator = new PQMSummaryCalculator(); Objectives = calculator.GetObjectives(constraintPath); if (planningItem.PlanningItemObject is PlanSum) { var waitWindowPQM = new WaitWindowPQM(); PlanSum plansum = (PlanSum)planningItem.PlanningItemObject; if (plansum.IsDoseValid() == true) { waitWindowPQM.Show(); foreach (PQMSummaryViewModel objective in Objectives) { evalStructure = calculator.FindStructureFromAlias(structureSet, objective.TemplateId, objective.TemplateAliases, objective.TemplateCodes); if (evalStructure != null) { var evalStructureVM = new StructureViewModel(evalStructure); var obj = calculator.GetObjectiveProperties(objective, planningItem, structureSet, evalStructureVM); PqmSummaries.Add(obj); NotifyPropertyChanged("Structure"); } } waitWindowPQM.Close(); } } if (planningItem.PlanningItemObject is PlanSetup) //is plansetup { var waitWindowPQM = new WaitWindowPQM(); PlanSetup planSetup = (PlanSetup)planningItem.PlanningItemObject; if (planSetup.IsDoseValid() == true) { waitWindowPQM.Show(); foreach (PQMSummaryViewModel objective in Objectives) { evalStructure = calculator.FindStructureFromAlias(structureSet, objective.TemplateId, objective.TemplateAliases, objective.TemplateCodes); if (evalStructure != null) { if (evalStructure.Id.Contains("PTV") == true) { foreach (Structure s in structureSet.Structures) { if (s.Id == planSetup.TargetVolumeID) { evalStructure = s; } } } var evalStructureVM = new StructureViewModel(evalStructure); var obj = calculator.GetObjectiveProperties(objective, planningItem, structureSet, evalStructureVM); PqmSummaries.Add(obj); NotifyPropertyChanged("Structure"); } } waitWindowPQM.Close(); } } }
public ObservableCollection <PlanningItemDetailsViewModel> Calculate(PlanningItemViewModel activePlanningItem, ObservableCollection <PlanningItemViewModel> planningItemComboBoxList, ObservableCollection <PQMViewModel> PqmSummaries, List <CollisionCheckViewModel> CollisionSummaries, List <ErrorViewModel> ErrorGrid) { var PlanningItemSummaries = new ObservableCollection <PlanningItemDetailsViewModel>(); var PlanSummary = new ObservableCollection <PlanningItemDetailsViewModel>(); bool planIsBold = false; bool isCCEnabled = false; foreach (PlanningItemViewModel planningItem in planningItemComboBoxList) { string pqmResult = ""; string ccResult = ""; string pcResult = ""; string rpiResult = ""; if (planningItem.PlanningItemIdWithCourse == activePlanningItem.PlanningItemIdWithCourse) { int pqmsPassing = 0; int pqmsTotal = 0; if (PqmSummaries != null) { pqmsTotal = PqmSummaries.Count; foreach (var row in PqmSummaries) { if (row.Met == "Goal" || row.Met == "Variation") { pqmsPassing += 1; } } } pqmResult = pqmsPassing.ToString() + "/" + pqmsTotal.ToString(); int beamCollisionChecksClearing = 0; int beamsTotal = 0; string beamsTotalString = " - "; if (planningItem.PlanningItemObject is PlanSetup) { PlanSetup planSetup = (PlanSetup)planningItem.PlanningItemObject; foreach (Beam b in planSetup.Beams) { if (b.IsSetupField != true) { beamsTotal += 1; } } beamsTotalString = beamsTotal.ToString(); } if (CollisionSummaries != null) { foreach (var row in CollisionSummaries) { if (row.Status == "Clear" || row.Status == " - ") { beamCollisionChecksClearing += 1; } } } ccResult = beamCollisionChecksClearing.ToString() + "/" + beamsTotal; int errorChecksPassing = 0; int errorChecksTotal = ErrorGrid.Count(); foreach (var row in ErrorGrid) { if (row.Status == "3 - OK" || row.Status == "2 - Variation") { errorChecksPassing += 1; } } pcResult = errorChecksPassing.ToString() + "/" + errorChecksTotal.ToString(); } if (planningItem.PlanningItemObject is PlanSum) { PlanSum planSum = (PlanSum)planningItem.PlanningItemObject; int sumOfFractions = 0; double sumOfPlanSetupDoses = 0; isCCEnabled = false; if (planSum == activePlanningItem.PlanningItemObject) { planIsBold = true; } else { planIsBold = false; } foreach (PlanSetup planSetup in planSum.PlanSetups.OrderBy(x => x.CreationDateTime)) { string planTarget; sumOfFractions += planSetup.NumberOfFractions.Value; sumOfPlanSetupDoses += planSetup.TotalDose.Dose; if (planSetup.TargetVolumeID != null) { planTarget = planSetup.TargetVolumeID; } else { planTarget = "No target selected"; } } var PlanSumSummary = new PlanningItemDetailsViewModel { IsBold = planIsBold, CC = isCCEnabled, PlanningItemIdWithCourse = planSum.Course + "/" + planSum.Id, ApprovalStatus = "PlanSum", PlanningItemObject = planningItem.PlanningItemObject, PlanName = planSum.Course + "/" + planSum.Id, PlanCreated = planSum.CreationDateTime.ToString(), PlanFractions = sumOfFractions.ToString(), PlanTotalDose = sumOfPlanSetupDoses.ToString(), PQMResult = pqmResult, CCResult = ccResult, PCResult = pcResult, RPIResult = rpiResult, }; PlanningItemSummaries.Add(PlanSumSummary); } else //planningitem is plansetup { PlanSetup planSetup = (PlanSetup)planningItem.PlanningItemObject; if (planSetup == activePlanningItem.PlanningItemObject) { planIsBold = true; isCCEnabled = true; } else { planIsBold = false; isCCEnabled = false; } var approvalStatus = ""; if (planSetup.PlanIntent == "VERIFICATION") { approvalStatus = "VerificationPlan"; } else { approvalStatus = planSetup.ApprovalStatus.ToString(); } string planTarget; if (planSetup.TargetVolumeID != null) { planTarget = planSetup.TargetVolumeID; } else { planTarget = "No target selected"; } var PlanningItemSummary = new PlanningItemDetailsViewModel { IsBold = planIsBold, CC = isCCEnabled, PlanningItemIdWithCourse = planSetup.Course + "/" + planSetup.Id, ApprovalStatus = approvalStatus, PlanName = planSetup.Course + "/" + planSetup.Id, PlanningItemObject = planningItem.PlanningItemObject, PlanCreated = planSetup.CreationDateTime.ToString(), PlanFxDose = planSetup.DosePerFraction.Dose.ToString(), PlanFractions = planSetup.NumberOfFractions.ToString(), PlanTotalDose = planSetup.TotalDose.Dose.ToString(), PlanTarget = planTarget, PQMResult = pqmResult, CCResult = ccResult, PCResult = pcResult, RPIResult = rpiResult, }; PlanningItemSummaries.Add(PlanningItemSummary); } } return(PlanningItemSummaries); }
public string Absmean(string strnum, double criteria, int updown, StructureSet list, PlanSum plan)//updown(1up,0down) { Structure retstructure = null; int bit = 0; double binwidth = 0.1; string doostr = ""; string judge = ""; foreach (Structure scan in list.Structures) { if (scan.Id == strnum) { retstructure = scan; if (retstructure.IsEmpty) { bit = 2; break; } bit = 1; DVHData dvhData = plan.GetDVHCumulativeData(retstructure, DoseValuePresentation.Absolute, VolumePresentation.AbsoluteCm3, binwidth); DoseValue bbb = dvhData.MeanDose; double Doo = bbb.Dose; doostr = (Doo / 100).ToString("F2"); if (updown == 1)//upper dose { if (Doo <= criteria) { judge = "o"; } else { judge = "x"; } } else { if (Doo > criteria) { judge = "o"; } else { judge = "x"; } } break; } } string doseindexreturn = ""; string judgement = ""; string retstring = ""; if (bit == 1) { retstring = retstructure.Id; doseindexreturn = doostr; judgement = judge; string ud = "0"; if (updown == 1) { ud = "<"; } else { ud = ">"; } retstring = string.Format("{0}\t\tDmean{4}{1}Gy\t{2}Gy\t{3}\n", retstructure.Id, (criteria / 100).ToString("F0"), doseindexreturn, judgement, ud); } else if (bit == 2) { retstring = strnum + "\tis Empty structure" + "\n"; } else { retstring = "No Structure named " + strnum + "\n"; } return(retstring); }
public void Execute(ScriptContext context /*, System.Windows.Window window*/) { //************************** // Please check the parameters. //************************** String path_to_OutputFolder = @"C:\Users\Administrator\Desktop"; double scaling_factor = 1.0; //************************** Patient patient = context.Patient; if (patient == null) { throw new ApplicationException("Please open a plan or a plan sum before running the script."); } PlanSetup planSetup = context.PlanSetup; PlanSum psum = context.PlanSumsInScope.FirstOrDefault(); if (planSetup == null && psum == null) { throw new ApplicationException("Please open a plan or a plan sum before running the script."); } SelectedPlanningItem = planSetup != null ? (PlanningItem)planSetup : (PlanningItem)psum; SelectedStructureSet = planSetup != null ? planSetup.StructureSet : psum.PlanSetups.First().StructureSet; // Retrieve StructureSet //StructureSet structureSet = planSetup.StructureSet; if (SelectedStructureSet == null) { throw new ApplicationException("The selected plan does not reference a StructureSet."); } // Retrieve image VMS.TPS.Common.Model.API.Image image = SelectedStructureSet.Image; //------------------------------------- // Plan //------------------------------------- var beams = planSetup.Beams; foreach (var beam in beams) { if (!beam.IsSetupField) { String fileName = path_to_OutputFolder + @"\" + patient.FirstName + patient.LastName + @"_" + patient.Id + @"_" + planSetup.Id + @".txt"; StreamWriter writer = new StreamWriter(fileName, false); String machine = beam.TreatmentUnit.Id; //MLC Plan Type int MLCPlanType = (int)beam.MLCPlanType; //MLCPlanType // 1 MLC plan type: DoseDynamic( The gantry does not rotate. ) // 2 MLC plan type: ArcDynamic // 3 MLC plan type: VMAT int Count = beam.ControlPoints.Count; // Exporting number of control points writer.WriteLine(Count); var JawPositions = beam.ControlPoints.ElementAt(0).JawPositions; if (MLCPlanType == 1 || MLCPlanType == 2 || MLCPlanType == 3) { double MUw = 0.0; double gantryAngle = 0.0; double collimatorAngle = 0.0; double patientSupportAngle = 0.0; foreach (var controlPoints in beam.ControlPoints) { // Exporting number of control points MUw = controlPoints.MetersetWeight; writer.WriteLine(MUw.ToString("0.0000000")); gantryAngle = controlPoints.GantryAngle; collimatorAngle = controlPoints.CollimatorAngle; patientSupportAngle = controlPoints.PatientSupportAngle; //MLC ----- var LeafPositions = controlPoints.LeafPositions; for (int i = 0; i < 60; i++) { double mlc_a = LeafPositions[0, i]; mlc_a = mlc_a * scaling_factor; double mlc_b = LeafPositions[1, i]; mlc_b = mlc_b * scaling_factor; String mlc_positions = mlc_a.ToString("0.00000") + @", " + mlc_b.ToString("0.00000") + @", 1"; // Exporting number of control points writer.WriteLine(mlc_positions); } //MLC ----- end } } writer.Close(); } } }
private PlanResult AddPlan(PlanSum planSum) { return(AddPlan(planSum as PlanningItem)); }
public List <ErrorViewModel> GetPlanSumRxErrors(PlanSum planSum) { var errorGrid = new List <ErrorViewModel>(); double totalRxDose = 0; string error; string errorStatus; int errorSeverity; var doseValueList = new List <string>(); var doseNameList = new List <string>(); var siteNameList = new List <string>(); foreach (PlanSetup planSetup in planSum.PlanSetups.OrderBy(x => x.CreationDateTime)) { totalRxDose += planSetup.TotalDose.Dose; if (planSetup.Id.Contains('_')) { var doseName = planSetup.Id.Split('_')[1]; doseName = Regex.Match(doseName, @"\d+").Value; doseNameList.Add(doseName); siteNameList.Add(planSetup.Id.Split('_')[0]); doseValueList.Add(totalRxDose.ToString()); } } int i = 0; foreach (string doseName in doseNameList) { if (doseName == doseValueList[i]) { error = string.Format("Plan name {0} matches Rx dose of {1} cGy.", siteNameList[i] + "_" + doseName, doseValueList[i]); errorStatus = "3 - OK"; errorSeverity = 1; AddNewRow(error, errorStatus, errorSeverity, errorGrid); } else { error = string.Format("Plan name {0} does NOT match Rx dose of {1} cGy.", siteNameList[i] + "_" + doseName, doseValueList[i]); errorStatus = "1 - Error"; errorSeverity = 1; AddNewRow(error, errorStatus, errorSeverity, errorGrid); } i++; } var numbersInString = Regex.Match(planSum.Id, @"\d+").Value; if (numbersInString != "") //contains no numbers at all { if (Int32.Parse(numbersInString).ToString() == totalRxDose.ToString()) { error = string.Format("PlanSum name {0} matches Rx dose of {1} cGy.", planSum.Id, totalRxDose); errorStatus = "3 - OK"; errorSeverity = 1; AddNewRow(error, errorStatus, errorSeverity, errorGrid); } else { error = string.Format("PlanSum name {0} does NOT match Rx dose of {1} cGy.", planSum.Id, totalRxDose); errorStatus = "1 - Error"; errorSeverity = 1; AddNewRow(error, errorStatus, errorSeverity, errorGrid); } } return(errorGrid); }