private IEnumerable <double> GetLeafWidthsFromAria( Patient patient, PlanSetup plan, Beam beam) { var course = plan.Course; using (var ac = new AriaContext()) { // Use ESAPI IDs to get to the ARIA Radiation row var dbPatient = ac.Patients.First(p => p.PatientId == patient.Id); var dbCourse = dbPatient.Courses.First(c => c.CourseId == course.Id); var dbPlan = dbCourse.PlanSetups.First(ps => ps.PlanSetupId == plan.Id); var dbRad = dbPlan.Radiations.First(r => r.RadiationId == beam.Id); // Use the RadiationSer to get to the MLC add-on var dbFieldAddOns = ac.FieldAddOns.Where(f => f.RadiationSer == dbRad.RadiationSer); var dbMlcAddOn = dbFieldAddOns.First(f => f.AddOn.AddOnType == "MLC"); // Use the MLC row to get to the leaves (and their width) // Note: We only need to use one of the MLC banks because // the leaf widths are the same between leaf pairs var dbMlc = dbMlcAddOn.AddOn.MLC; var dbMlcLeaves = dbMlc.MLCBanks.First().MLCLeaves; return(dbMlcLeaves.Select(lf => lf.Width)); } }
public double[] GetLeafWidths(Patient patient, PlanSetup plan, Beam beam) { try { return(GetLeafWidthsFromAria(patient, plan, beam).ToArray()); } catch (Exception e) { throw new LeafWidthsNotFoundException ("Unable to obtain leaf widths for beam " + beam.Id, e); } }
public IEnumerable <Aperture> Create(Patient patient, PlanSetup plan, Beam beam) { List <Aperture> apertures = new List <Aperture>(); double[] leafWidths = GetLeafWidths(patient, plan, beam); foreach (ControlPoint controlPoint in beam.ControlPoints) { double[,] leafPositions = GetLeafPositions(controlPoint); double[] jaw = CreateJaw(controlPoint); apertures.Add(new Aperture(leafPositions, leafWidths, jaw)); } return(apertures); }
private TPReportData GetReportData(string patientstring) { CurCursor = Cursors.Wait; TPReportData returnvalue = new TPReportData(); VMS.TPS.Common.Model.API.Patient curpat = null; VMS.TPS.Common.Model.API.PlanSetup curps = null; if (patientstring.Split(',').Count() == 3) { string patient_id = patientstring.Split(',')[0]; string course_id = patientstring.Split(',')[1]; string plansetup_id = patientstring.Split(',')[2]; curpat = cur_app.OpenPatientById(patient_id); if (curpat != null) { curps = curpat.Courses.Where(x => x.Id == course_id).Single().PlanSetups.Where(x => x.Id == plansetup_id).Single(); } if (curps != null) { returnvalue.CurPatientInfo.FirstName = curpat.FirstName; returnvalue.CurPatientInfo.LastName = curpat.LastName; returnvalue.CurPatientInfo.PatientID = curpat.Id; returnvalue.CurPlanInfo.CourseID = curps.Course.Id; returnvalue.CurPlanInfo.PlaneID = curps.Id; returnvalue.CurDosePrescription.NumberOfFraction = curps.UniqueFractionation.NumberOfFractions.Value.ToString(); returnvalue.CurDosePrescription.PrescribedDoseFractination = Math.Round(curps.UniqueFractionation.PrescribedDosePerFraction.Dose, 1).ToString(); returnvalue.CurDosePrescription.PlanNormalization = Math.Round(curps.PlanNormalizationValue, 1).ToString(); returnvalue.CurDosePrescription.TotalPrescribedDose = Math.Round(curps.TotalPrescribedDose.Dose, 1).ToString(); FieldInfo curfi = new FieldInfo(); foreach (Beam b in curps.Beams) { curfi = new FieldInfo(); curfi.BeamID = b.Id; curfi.Collimator = Math.Round(b.ControlPoints[0].CollimatorAngle, 1).ToString(); curfi.Gantry = Math.Round(b.ControlPoints[0].GantryAngle, 1).ToString(); curfi.Couch = Math.Round(b.ControlPoints[0].PatientSupportAngle, 1).ToString(); curfi.Energy = b.EnergyModeDisplayName; curfi.Machine = b.TreatmentUnit.Id; curfi.MU = Math.Round(b.Meterset.Value, 1).ToString(); curfi.X1 = Math.Round(b.ControlPoints[0].JawPositions.X1 / 10.0f, 1).ToString(); curfi.X2 = Math.Round(b.ControlPoints[0].JawPositions.X2 / 10.0f, 1).ToString(); curfi.Y1 = Math.Round(b.ControlPoints[0].JawPositions.Y1 / 10.0f, 1).ToString(); curfi.Y2 = Math.Round(b.ControlPoints[0].JawPositions.Y2 / 10.0f, 1).ToString(); returnvalue.CurFieldInfoList.Add(curfi); } StructureData cursd = new StructureData(); DVHData dvhd = null; foreach (Structure s in curps.StructureSet.Structures) { if (colors.ContainsKey(s.Id.ToLower()) || colors.ContainsKey(s.DicomType.ToLower())) { if (!s.IsEmpty && s.Volume > 0.0f) { cursd = new StructureData(); cursd.StructureID = s.Id; cursd.Type = s.DicomType; cursd.Volume = Math.Round(s.Volume, 1).ToString(); dvhd = curps.GetDVHCumulativeData(s, DoseValuePresentation.Absolute, VolumePresentation.Relative, 1.0f); if (dvhd != null) { cursd.MaxDose = Math.Round(dvhd.MaxDose.Dose, 1).ToString(); cursd.MinDose = Math.Round(dvhd.MinDose.Dose, 1).ToString(); } returnvalue.CurStructureDataList.Add(cursd); } } } } } cur_app.ClosePatient(); CurCursor = Cursors.Arrow; return(returnvalue); }
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 Globals() { Globals.patientCtx = null; Globals.eclipseAPI = VMS.TPS.Common.Model.API.Application.CreateApplication("allrights", "allrights"); }