public PlanOrPlanSum[] GetPlansAndPlanSumsFor(string patientId) { if (patientId == null) { return(null); } var patient = _esapiApp.OpenPatientById(patientId); // Must call ToArray() before closing the patient var plansAndPlanSums = patient?.GetPlanningItems().Select(CreatePlanOrPlanSum).ToArray(); _esapiApp.ClosePatient(); return(plansAndPlanSums); }
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 OpenPatient_Click(object sender, RoutedEventArgs e) { //open the patient with the user-entered MRN number string pat_mrn = MRN.Text; clearEverything(); try { app.ClosePatient(); pi = app.OpenPatientById(pat_mrn); //grab instances of the course and VMAT tbi plans that were created using the binary plug in script. This is explicitly here to let the user know if there is a problem with the course OR plan Course c = pi.Courses.FirstOrDefault(x => x.Id.ToLower() == "vmat tbi"); if (c == null) { MessageBox.Show("No course named VMAT TBI!"); return; } ExternalPlanSetup plan = c.ExternalPlanSetups.FirstOrDefault(x => x.Id.ToLower() == "_vmat tbi"); if (plan == null) { MessageBox.Show("No plan named _VMAT TBI!"); return; } //populate the optimization stackpanel with the optimization parameters that were stored in the VMAT TBI plan populateOptimizationTab(plan); //populate the prescription text boxes with the prescription stored in the VMAT TBI plan populateRx(plan); //set the default parameters for the optimization loop runCoverageCk.IsChecked = false; numOptLoops.Text = defautlNumOpt; runAdditionalOpt.IsChecked = true; copyAndSave.IsChecked = false; targetNormTB.Text = defaultPlanNorm; } catch { MessageBox.Show("No such patient exists!"); } }
public static void Execute(VMS.TPS.Common.Model.API.Application app) { string[] args = { "", "", "", "", "", "", "", "" }; args[0] = "$P-901"; Patient this_patient = app.OpenPatientById(args[0]); System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); System.Windows.Forms.Application.Run(new Form1(this_patient, args)); app.ClosePatient(); app.Dispose(); }
private void buttonClose_Click(object sender, EventArgs e) { try { application.ClosePatient(); textBoxPatient.Text = string.Empty; listBoxCourses.Items.Clear(); listBoxPlans.Items.Clear(); } catch (Exception exception) { MessageBox.Show(exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Application_Startup(object sender, StartupEventArgs e) { try { using (_app = VMS.TPS.Common.Model.API.Application.CreateApplication()) { IEventAggregator eventAggregator = new EventAggregator(); mv = new MainView(); mv.DataContext = new MainViewModel( new NavigationViewModel(_app, eventAggregator), new ScanCompareViewModel(eventAggregator)); mv.ShowDialog(); } } catch (ApplicationException ex) { // give the exception to the user somehow (log file, messagebox, etc) _app.ClosePatient(); //this is like closing the patient in Eclipse _app.Dispose(); //This is like closing Eclipse } }
public static void Execute(VMS.TPS.Common.Model.API.Application app) { Form1 ventana = new Form1(); System.Windows.Forms.Application.EnableVisualStyles(); System.Windows.Forms.Application.SetCompatibleTextRenderingDefault(false); System.Windows.Forms.Application.Run(ventana); string HC = ventana.traerHC(); Patient paciente = app.OpenPatientById(HC); Course curso = paciente.Courses.Where(c => c.Id == "C1").FirstOrDefault(); ventana.escribirNombreCurso(curso.Id); foreach (PlanSetup p in curso.PlanSetups) { ventana.agregarALista(p.Id); } app.ClosePatient(); }
//ESAPI Calls /// <summary> /// Contacts Eclipse directly for each structure's info instead of getting the patient info /// </summary> /// <param name="id"></param> /// <returns></returns> private List <MeshInfo> GetMeshFromPatient(string id) { List <MeshInfo> meshes = new List <MeshInfo>(); try { app.ClosePatient(); } catch { } try { Patient patient = app.OpenPatientById(id); patient_name = patient.LastName + ", " + patient.FirstName; patient_id = patient.Id.ToString(); foreach (StructureSet s in patient.StructureSets) { foreach (Structure ss in s.Structures) { if (!ss.HasSegment || ss.Volume == 0) { continue; } var mesh = new MeshInfo(); mesh.id = ss.Id; mesh.structureset = s.Id; mesh.last_edit = ss.HistoryDateTime.ToLongDateString(); mesh.volume = ss.Volume; mesh.mesh = ss.MeshGeometry; meshes.Add(mesh); } } } catch { } return(meshes); }
public void abrirPaciente(string ID) { try { VMS.TPS.Common.Model.API.Application app = VMS.TPS.Common.Model.API.Application.CreateApplication("pa", "123qwe"); Patient paciente = app.OpenPatientById(ID); XmlWriterSettings settings = new XmlWriterSettings(); settings.Indent = true; settings.IndentChars = ("\t"); XmlWriter writer = XmlWriter.Create(paciente.Id + ".xml", settings); writer.WriteStartDocument(); writer.WriteStartElement("Patient"); paciente.WriteXml(writer); writer.WriteEndElement(); writer.WriteEndDocument(); MessageBox.Show("terminó"); app.ClosePatient(); } catch (Exception e) { File.WriteAllText("log.txt", e.ToString()); throw; } }
public void cerrarPaciente() { app.ClosePatient(); L_NombrePaciente.Visible = false; }
static void Execute(Application app) { // Read patient list stored in a JSON file OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.RestoreDirectory = true; openFileDialog.ShowDialog(); if (openFileDialog.FileName != "" && File.Exists(openFileDialog.FileName)) { // Parse JSON string text = File.ReadAllText(openFileDialog.FileName); PatientList patientList = JsonConvert.DeserializeObject <PatientList>(text); // 创建输出文件夹 if (!Directory.Exists("OutputModels")) { Directory.CreateDirectory("OutputModels"); } if (null != patientList?.IdList && patientList.IdList.Count != 0) { foreach (string patientId in patientList.IdList) { try { var patientA = app.OpenPatientById(patientId); if (null == patientA) { Console.WriteLine($"Could not open patient {patientId}"); continue; } string patientIndex = patientA.Id + "_" + patientA.LastName + patientA.FirstName; Console.Write($"Working with {patientIndex}"); // 创建患者名称文件夹 string patStrName = Path.Combine("OutputModels", patientIndex); if (!Directory.Exists(patStrName)) { Directory.CreateDirectory(patStrName); } // 输出 var strTmps = patientA?.StructureSets?.ToArray(); if (strTmps == null || strTmps.Length == 0) { Console.WriteLine($"Could not find structure"); } else { Regex regex = new Regex(@"[^1-9^a-z^A-Z]+"); foreach (StructureSet structureSet in strTmps) { if (structureSet != null && structureSet.Structures != null && structureSet.Structures.Count() != 0) { string validSetId = regex.Replace(structureSet.Id, "_"); // 按照结构集创建文件夹 string strSetName = Path.Combine(patStrName, validSetId); if (!Directory.Exists(strSetName)) { Directory.CreateDirectory(strSetName); } // 按照不同的结构集进行输出到不同文件夹 foreach (var structure in structureSet.Structures) { if (!structure.IsEmpty && structure.HasSegment) { MeshOps.ObjWriter obj = new MeshOps.ObjWriter(structure.MeshGeometry, null); obj.OutPut(Path.Combine(strSetName, structure.Id + ".obj"), "structure" + structure.Id); } } } } } Console.WriteLine($", Finished"); app.ClosePatient(); } catch (Exception e) { app.ClosePatient(); Console.WriteLine(e); Console.WriteLine($"Error, deal with patient {patientId}"); } } } else { Console.WriteLine("Empty patient list"); } } else { Console.WriteLine("Please specified the patient list JSON file"); return; } }
public void WindowClosingHandler(object sender, System.ComponentModel.CancelEventArgs e) { _application.ClosePatient(); Window.GetWindow(this).Close(); }
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) { _app.ClosePatient(); _app.Dispose(); }
public string cerrarPaciente() { app.ClosePatient(); return("Se ha cerrado el paciente"); }
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(); }
public void cerrarPaciente() { app.ClosePatient(); }
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); }