static void Execute(VMS.TPS.Common.Model.API.Application app) { // Open the report file string temp = System.Environment.GetEnvironmentVariable("TEMP"); string dataFilePath = temp + @"\DataMiningOutput.txt"; PrintStartupMsg(dataFilePath); using (StreamWriter reportFile = new StreamWriter(dataFilePath, false)) { // Iterate over all patients in the database. foreach (PatientSummary patsum in app.PatientSummaries) { // Check if the user has hit a key. if (StopNow()) { break; } // Open a patient, report on the treatment history for that patient, and close the patient. // If there is no treatment history, nothing is reported. Patient pat = app.OpenPatient(patsum); ReportOnePatient(pat, reportFile); app.ClosePatient(); } reportFile.Flush(); } MessageBox.Show("the results to the simple report '" + dataFilePath + "'."); // Open the folder with explore.exe. System.Diagnostics.Process.Start(temp); }
public MainWindow(VMS.TPS.Common.Model.API.Application Application) { _application = Application; _viewModel = new ViewModel(); InitializeComponent(); this.DataContext = _viewModel; //lstPatients.SelectedIndex = 1; //lstPlans.SelectedIndex=0; foreach (PatientSummary patientSummary in _application.PatientSummaries) { MyPatient myPatient = new MyPatient(); myPatient.PatientId = patientSummary.Id; myPatient.LastName = patientSummary.LastName; myPatient.FirstName = patientSummary.FirstName; Patient patient = _application.OpenPatient(patientSummary); foreach (Course course in patient.Courses) { MyCourse vmCourse = new MyCourse(); vmCourse.CourseId = course.Id; foreach (PlanSetup planSetup in course.PlanSetups) { vmCourse.PlanItems.Add(new MyPlanItem { pItemId = planSetup.Id, IsInScope = false, IsPlanSum = false }); } foreach (PlanSum planSum in course.PlanSums) { vmCourse.PlanItems.Add(new MyPlanItem { pItemId = planSum.Id, IsInScope = false, IsPlanSum = true }); } myPatient.Courses.Add(vmCourse); } _application.ClosePatient(); _viewModel.Patients.Add(myPatient); } OpenSelections(); }
private void btnStart_Click(object sender, RoutedEventArgs e) { MyPatient myPatient = _viewModel.SelectedPatient; string patientId = myPatient.PatientId; PatientSummary patientSummary = _application.PatientSummaries.FirstOrDefault(s => s.Id == patientId); if (patientSummary == null) { return; } Patient patient = _application.OpenPatient(patientSummary); List <Course> courses = new List <Course>(); foreach (var vmCourse in _viewModel.SelectedPatient.Courses.Where(s => s.IsSelected)) { Course course = patient.Courses.FirstOrDefault(s => s.Id == vmCourse.CourseId); if (course != null) { courses.Add(course); } } if (courses.Count == 0) { MessageBox.Show("Can't find selected courses in Aria"); return; } //Plan items in scope List <PlanningItem> PlansInScope = new List <PlanningItem>(); PlanningItem pItem = null; foreach (var pitem in _viewModel.CoursePlanItems.Where(s => s.IsInScope)) { //check if planSetup foreach (var course in courses) { pItem = course.PlanSetups.FirstOrDefault(s => s.Id == pitem.pItemId); if (pItem == null) { pItem = course.PlanSums.FirstOrDefault(s => s.Id == pitem.pItemId); } if (pItem != null) { PlansInScope.Add(pItem); break; } } if (pItem == null) { MessageBox.Show("No Planning Item found with Id = " + pitem.pItemId, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } } //Opened plan Item string openPlanId = string.Empty; foreach (var pitem in _viewModel.PlansInScope) { if (pitem.IsOpened) { openPlanId = pitem.pItemId; break; } } //check if planSetup foreach (var course in courses) { pItem = course.PlanSetups.FirstOrDefault(s => s.Id == openPlanId); if (pItem == null) { pItem = course.PlanSums.FirstOrDefault(s => s.Id == openPlanId); } if (pItem != null) { break; } } if (pItem == null) { MessageBox.Show("No Planning Item found with Id = " + openPlanId, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } Window window = new Window(); window.Closing += WindowClosingHandler; window.Show(); //Save selections for use in next run SaveToRecent(); try { StartPlugin(patient, courses, PlansInScope, pItem, _application.CurrentUser, window); } catch (Exception ex) { MessageBox.Show("Caught exception from Script\n" + ex.Message + "\n" + ex.StackTrace); return; } }
private void DrawDVHs() { this.plotModel.Series.Clear(); string ptid1 = patient1.Split(',')[0]; string ptid2 = patient2.Split(',')[0]; try { // search for patient in database foreach (var patientSummary in cur_app.PatientSummaries) { if (patientSummary.Id == ptid1) //this is the first patient { VMS.TPS.Common.Model.API.Patient pt1 = cur_app.OpenPatient(patientSummary); if (pt1 == null) { throw new ApplicationException("Cannot open patient No.1" + patientSummary.Id); } Console.WriteLine("Open patient No.1"); //get patient info rd1.CurPatientInfo.LastName = pt1.LastName; rd1.CurPatientInfo.FirstName = pt1.FirstName; rd1.CurPatientInfo.PatientID = pt1.Id; //loop through courses foreach (var course in pt1.Courses) { Console.WriteLine("course=" + course.Id); //print course name and send to UI rd1.CurPlanInfo.CourseID = course.Id; foreach (var planSetup in course.PlanSetups) { Console.WriteLine("planID=" + planSetup.Id); rd1.CurPlanInfo.PlaneID = planSetup.Id; rd1.CurDosePrescription.Fractionation = planSetup.UniqueFractionation.Id; rd1.CurDosePrescription.TotalPrescribedDose = planSetup.TotalPrescribedDose.ToString(); rd1.CurDosePrescription.PlanNormalization = planSetup.PlanNormalizationValue.ToString(); rd1.CurDosePrescription.PrescribedDoseFractination = planSetup.UniqueFractionation.PrescribedDosePerFraction.ToString(); rd1.CurDosePrescription.NumberOfFraction = planSetup.UniqueFractionation.NumberOfFractions.ToString(); foreach (var beam in planSetup.Beams) { FieldInfo fieldInfo1 = new FieldInfo(); fieldInfo1.BeamID = beam.Id; fieldInfo1.Collimator = beam.ControlPoints[0].CollimatorAngle.ToString(); fieldInfo1.Gantry = beam.ControlPoints[0].GantryAngle.ToString(); fieldInfo1.Couch = beam.ControlPoints[0].PatientSupportAngle.ToString(); fieldInfo1.DoseRate = beam.DoseRate.ToString(); fieldInfo1.Energy = beam.EnergyModeDisplayName; fieldInfo1.Machine = beam.TreatmentUnit.Id; fieldInfo1.MU = beam.Meterset.ToString(); fieldInfo1.X1 = beam.ControlPoints[0].JawPositions.X1.ToString(); fieldInfo1.Y1 = beam.ControlPoints[0].JawPositions.Y1.ToString(); fieldInfo1.X2 = beam.ControlPoints[0].JawPositions.X2.ToString(); fieldInfo1.Y2 = beam.ControlPoints[0].JawPositions.Y2.ToString(); rd1.CurFieldInfoList.Add(fieldInfo1); } // get structure Set StructureSet structureSet = planSetup.StructureSet; foreach (var structure in structureSet.Structures) { //StructureData structureData1 = new StructureData(); if (colors.ContainsKey(structure.Id.ToLower()) || colors.ContainsKey(structure.DicomType.ToLower())) { DVHData dvhData = planSetup.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, VolumePresentation.Relative, 0.2); if (dvhData == null) { continue; throw new ApplicationException("DVH data does not exist. Script execution cancelled."); } //To print and anlyze the DVH // if (colors.ContainsKey(structure.Id.ToLower())) { OxyPlot.OxyColor color = colors[structure.Id.ToLower()]; Console.WriteLine("maximum dose of" + structure.Id + " is:" + dvhData.MaxDose.ToString()); AddData(dvhData, structure.Id, color, OxyPlot.MarkerType.Circle); } else if (colors.ContainsKey(structure.DicomType.ToLower())) { OxyPlot.OxyColor color = colors[structure.DicomType.ToLower()]; Console.WriteLine("maximum dose of" + structure.DicomType + " is:" + dvhData.MaxDose.ToString()); AddData(dvhData, structure.Id, color, OxyPlot.MarkerType.Circle); } } } } } cur_app.ClosePatient(); //close the first patient } //Read second patient if (patientSummary.Id == ptid2) //this is the second patient { VMS.TPS.Common.Model.API.Patient pt2 = cur_app.OpenPatient(patientSummary); if (pt2 == null) { throw new ApplicationException("Cannot open patient No.2" + patientSummary.Id); } Console.WriteLine("==========================="); Console.WriteLine("Open patient No.2"); //loop through courses foreach (var course in pt2.Courses) { Console.WriteLine("course=" + course.Id); //print course name and send to UI foreach (var planSetup in course.PlanSetups) { Console.WriteLine("planID=" + planSetup.Id); // get structure Set StructureSet structureSet = planSetup.StructureSet; foreach (var structure in structureSet.Structures) { if (colors.ContainsKey(structure.Id.ToLower()) || colors.ContainsKey(structure.DicomType.ToLower())) { DVHData dvhData2 = planSetup.GetDVHCumulativeData(structure, DoseValuePresentation.Absolute, VolumePresentation.Relative, 1); if (dvhData2 == null) { continue; throw new ApplicationException("DVH data does not exist. Script execution cancelled."); } //To print and anlyze the DVH // if (colors.ContainsKey(structure.Id.ToLower())) { OxyPlot.OxyColor color = colors[structure.Id.ToLower()]; Console.WriteLine("maximum dose of" + structure.Id + " is:" + dvhData2.MaxDose.ToString()); AddData(dvhData2, structure.Id, color, OxyPlot.MarkerType.Cross); } else if (colors.ContainsKey(structure.DicomType.ToLower())) { OxyPlot.OxyColor color = colors[structure.DicomType.ToLower()]; Console.WriteLine("maximum dose of" + structure.Id + " is:" + dvhData2.MaxDose.ToString()); AddData(dvhData2, structure.Id, color, OxyPlot.MarkerType.Cross); } } } } } cur_app.ClosePatient(); //close the second patient } } } catch (Exception ex) { Console.WriteLine(ex.ToString()); cur_app.ClosePatient(); } plotModel.InvalidatePlot(true); }
static void Execute(Application app, string inputfile, string outputfile) { CreatePlan cPln = new CreatePlan(); StreamReader readStream; StreamWriter writeStream; string[] inputVals; List <PlnInfoSim> arcPlnLs = new List <PlnInfoSim>(); string pt_Ref; string crs_Ref; string pln_Ref; string ds_Ref; PlanParameters plnParam_Ref; string pt_Tgt; string crs_Tgt; string pln_Tgt; string struct_Tgt; PatientSummary ptSumm; Patient pt; bool cpSucc; bool psSucc; ////First, create list of patient plans already in the archive//// readStream = new StreamReader(outputfile); //Skip title row// readStream.ReadLine(); while (!readStream.EndOfStream) { PlnInfoSim plnInfo = new PlnInfoSim(); inputVals = readStream.ReadLine().Split(','); plnInfo.ptId = inputVals[0]; plnInfo.crsId = inputVals[1]; plnInfo.plnId = inputVals[2]; arcPlnLs.Add(plnInfo); } readStream.Close(); ////Copy plans from the database file, and paste to the archived patients//// readStream = new StreamReader(inputfile); //Skip title row// readStream.ReadLine(); writeStream = new StreamWriter(outputfile, append: true); while (!readStream.EndOfStream) { ////Read input plan from csv file//// inputVals = readStream.ReadLine().Split(','); pt_Ref = inputVals[0]; crs_Ref = inputVals[1]; pln_Ref = inputVals[2]; ds_Ref = inputVals[3]; msg = "-Reference:\n Patient: " + pt_Ref + ", course: " + crs_Ref + ", plan: " + pln_Ref; Console.WriteLine(msg); //Compare input plan with archived list// if (arcPlnLs.Exists(p => p.ptId == pt_Ref && p.crsId == crs_Ref && p.plnId == pln_Ref)) { Console.WriteLine("--Plan already exists in archive, skipping...\n"); } else { ////Copy reference plan parameters//// plnParam_Ref = new PlanParameters(); cpSucc = plnParam_Ref.extractParametersFromPlan(app, pt_Ref, crs_Ref, pln_Ref); if (cpSucc) { pt_Tgt = "AOA0002"; //Check which course to put plan into// ptSumm = app.PatientSummaries.FirstOrDefault(ps => ps.Id == pt_Tgt); pt = app.OpenPatient(ptSumm); crs_Tgt = null; foreach (Course crs in pt.Courses) { //Add at most 10 plans to a course// if (crs.PlanSetups.Count() < 2) { crs_Tgt = crs.Id; break; } } if (crs_Tgt == null) { crs_Tgt = "C" + pt.Courses.Count().ToString(); } app.ClosePatient(); //Create plan name// pln_Tgt = pt_Ref + crs_Ref.Substring(0, Math.Min(3, crs_Ref.Length)) + pln_Ref.Substring(0, Math.Min(3, pln_Ref.Length)); struct_Tgt = "AC_27cm"; msg = "-Copy plan to:\n Patient: " + pt_Tgt + ", course: " + crs_Tgt + ", plan: " + pln_Tgt; Console.WriteLine(msg); ////Copy and create new plan to archived patient//// psSucc = cPln.CopyAndCreate(app, pt_Tgt, crs_Tgt, pln_Tgt, struct_Tgt, plnParam_Ref); if (psSucc) { msg = pt_Ref + "," + crs_Ref + "," + pln_Ref + "," + pt_Tgt + "," + crs_Tgt + "," + pln_Tgt + "," + ds_Ref; writeStream.WriteLine(msg); } } } } //Close the file stream// readStream.Close(); writeStream.Close(); }
private void btnStart_Click(object sender, RoutedEventArgs e) { MyPatient myPatient = _viewModel.SelectedPatient; string patientId = myPatient.PatientId; PatientSummary patientSummary = _application.PatientSummaries.FirstOrDefault(s => s.Id == patientId); if (patientSummary == null) { return; } Patient patient = _application.OpenPatient(patientSummary); Course course = patient.Courses.FirstOrDefault(s => s.Id == _viewModel.SelectedCourse.CourseId); if (course == null) { MessageBox.Show("Can't find selected course in Aria"); return; } //planId items in scope List <PlanSetup> PlansInScope = new List <PlanSetup>(); foreach (var pitem in _viewModel.PlansInScope) { //check if planSetup PlanSetup plan = (PlanSetup)course.PlanSetups.FirstOrDefault(s => s.Id == pitem.pItemId); if (plan != null) { PlansInScope.Add(plan); } } //Opened plan Item string openPlanId = string.Empty; foreach (var pitem in _viewModel.PlansInScope) { if (pitem.IsOpened) { openPlanId = pitem.pItemId; break; } } //check if planSetup PlanSetup openedPlan = course.PlanSetups.FirstOrDefault(s => s.Id == openPlanId); if (openedPlan == null) { MessageBox.Show("No PlanSetup found with Id = " + openPlanId, "Error", MessageBoxButton.OK, MessageBoxImage.Error); return; } Window window = new Window(); window.Closing += WindowClosingHandler; window.Show(); //Save selections for use in next run SaveSelections(); try { VMS.TPS.Script.Start(patient, course, PlansInScope, openedPlan, _application.CurrentUser, window); } catch (Exception ex) { MessageBox.Show("Caught exception from Script\n" + ex.Message + "\n" + ex.StackTrace); return; } }