Ejemplo n.º 1
0
        private void LoadCourses()
        {
            Patient patient = _application.OpenPatientById(_viewModel.SelectedPatient.PatientId);

            foreach (Course course in patient.Courses)
            {
                MyCourse vmCourse = new MyCourse();
                vmCourse.CourseId = course.Id;
                _viewModel.SelectedPatient.Courses.Add(vmCourse);
            }
            _application.ClosePatient();
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        ////////////////////////////////////////////////////////////
        // This is where the code begins when run as a standalone //
        ////////////////////////////////////////////////////////////
        private void App_OnStartup(object sender, StartupEventArgs e)
        {
            //// Manually define plan to be opened when run as a standalone app ////
            SomeProperties.PatientId = "QA_ESAPI";  // Set patient ID property
            SomeProperties.CourseId  = "C1";        // Set course ID property
            SomeProperties.PlanId    = "UnitTest0"; // Set plan ID property

            // Load general settigns;
            UserSettings.DefineUserSettings();

            // Create the application and connect to the API
            Patient   patient = null;
            Course    course  = null;
            PlanSetup plan    = null;

            try
            {
                // Create the application
                VMS.TPS.Common.Model.API.Application app = ESAPIApplication.Instance.Context;
                // Open the plan
                patient = app.OpenPatientById(SomeProperties.PatientId);
                course  = patient.Courses.Where(c => c.Id == SomeProperties.CourseId).Single();
                plan    = course.PlanSetups.Where(p => p.Id == SomeProperties.PlanId).Single();
            }
            catch
            {
                string errorlog = DateTime.Now + ", The script was not able to connect to the Eclipse API or load the plan info for some reason.";
                MessageBox.Show(errorlog);
                return;
            }

            // Launch the main part of the code.
            MainCode.RunMainCode(patient, course, plan);
        }
Ejemplo n.º 4
0
        public Patient abrirPaciente(string ID)
        {
            VMS.TPS.Common.Model.API.Application app = VMS.TPS.Common.Model.API.Application.CreateApplication(null, null);
            Patient paciente = app.OpenPatientById(ID);

            paciente.BeginModifications();
            return(paciente);
        }
Ejemplo n.º 5
0
        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();
        }
Ejemplo n.º 6
0
 public Patient abrirPaciente(string ID)
 {
     if (paciente != null)
     {
         cerrarPaciente();
     }
     try
     {
         return(app.OpenPatientById(ID));
     }
     catch (Exception)
     {
         MessageBox.Show("El paciente no existe");
         throw;
     }
 }
Ejemplo n.º 7
0
 private void Application_Startup(object sender, StartupEventArgs e)
 {
     app = VMS.TPS.Common.Model.API.Application.CreateApplication();
     if (app != null)
     {
         if (!String.IsNullOrEmpty(e.Args.FirstOrDefault()))
         {
             _patient   = app.OpenPatientById(e.Args[0].Split(';').First().Trim('"'));
             _course    = _patient.Courses.FirstOrDefault(x => x.Id == e.Args[0].Split(';')[1]);
             _planSetup = _course.PlanSetups.FirstOrDefault(x => x.Id == e.Args[0].Split(';').Last().Trim('"'));
         }
         var bootstrapper = new Bootstrapper();
         var container    = bootstrapper.Bootstrap(app, _patient, _course, _planSetup);
         var mainview     = container.Resolve <MainView>();
         mainview.Show();
     }
 }
Ejemplo n.º 8
0
 public bool abrirPaciente(string ID)
 {
     if (paciente != null)
     {
         cerrarPaciente();
     }
     if (app.PatientSummaries.Any(p => p.Id == ID))
     {
         paciente = app.OpenPatientById(ID);
         return(true);
     }
     else
     {
         //MessageBox.Show("El paciente no existe");
         return(false);
     }
 }
Ejemplo n.º 9
0
        public static void GeneratePlan(VMS.TPS.Common.Model.API.Application app,
                                        MLCDefinitions mlcs,
                                        ExternalBeamMachineParameters beamPars,
                                        IMRTGenerator.JSON.Patient patient,
                                        IEnumerable <IMRTGenerator.JSON.Beam> beams
                                        )
        {
            var pat  = app.OpenPatientById(patient.PatientId);
            var sSet = pat.StructureSets.Single(ss => ss.Id == patient.StructureSet);

            pat.BeginModifications();

            var cr = pat.Courses.SingleOrDefault(cr_ => cr_.Id == "DTPCOURSE");

            if (null == cr)
            {
                cr    = pat.AddCourse();
                cr.Id = "DTPCOURSE";
            }
            var plan = cr.AddExternalPlanSetup(sSet);
            //
            // Cannot use target structure
            //
            var targetStructure = sSet.Structures.Single(s => s.Id == plan.TargetVolumeID);
            var isoCenter       = targetStructure.CenterPoint;

            foreach (var bm in beams)
            {
                var beam = plan.AddMLCBeam(beamPars, null, default(VRect <double>), 0.0, bm.GantryAngleInDeg, bm.PatientSupportAngleInDeg, isoCenter);
                beam.FitMLCToStructure(new FitToStructureMargins(bm.MlcMarginInmm),
                                       targetStructure,
                                       true,
                                       JawFitting.FitToRecommended,
                                       OpenLeavesMeetingPoint.OpenLeavesMeetingPoint_Middle,
                                       ClosedLeavesMeetingPoint.ClosedLeavesMeetingPoint_Center);
                adjustJaws(beam, bm.BeamletSizeXInmm, mlcs.MLCs[beam.MLC.Id].LeafWidths());
            }
            if (null == calcModel)
            {
                calcModel = plan.GetModelsForCalculationType(CalculationType.PhotonInfluenceMatrix)?.OrderByDescending(cm => cm, new ModelNameComparer()).First();
                calcModel = calcModel == null ? "" : calcModel;
            }
            plan.SetCalculationModel(CalculationType.PhotonInfluenceMatrix, calcModel);
            app.SaveModifications();
        }
Ejemplo n.º 10
0
 public bool abrirPaciente(string ID)
 {
     if (paciente != null)
     {
         cerrarPaciente();
     }
     if (app.PatientSummaries.Any(p => p.Id == ID))
     {
         //paciente = AriaEntityContext.Patients.Where(p => p.PatientId == ID).FirstOrDefault();
         paciente = app.OpenPatientById(ID);
         return(true);
     }
     else
     {
         MessageBox.Show("El paciente no existe");
         return(false);
     }
 }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
 private void buttonOpen_Click(object sender, EventArgs e)
 {
     try
     {
         Patient pat = app.OpenPatientById(textBoxPatId.Text);
         listBoxCourse.Items.Clear();
         if (pat != null)
         {
             textBoxPat.Tag  = pat;
             textBoxPat.Text = pat.ToString();
             foreach (Course course in pat.Courses)
             {
                 listBoxCourse.Items.Add(course);
             }
         }
     }
     catch (Exception exc)
     {
         MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Ejemplo n.º 13
0
 public bool abrirPaciente(string ID)
 {
     if (paciente != null)
     {
         cerrarPaciente();
     }
     if (app.PatientSummaries.Any(p => p.Id == ID))
     {
         paciente = app.OpenPatientById(ID);
         L_NombrePaciente.Text    = paciente.LastName + ", " + paciente.FirstName;
         L_NombrePaciente.Visible = true;
         this.Text += " - " + paciente.LastName + ", " + paciente.FirstName;
         return(true);
     }
     else
     {
         MessageBox.Show("El paciente no existe");
         L_NombrePaciente.Visible = false;
         return(false);
     }
 }
Ejemplo n.º 14
0
        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!"); }
        }
Ejemplo n.º 15
0
        //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);
        }
Ejemplo n.º 16
0
 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;
     }
 }
Ejemplo n.º 17
0
        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.ShutdownMode = ShutdownMode.OnMainWindowClose;
            try
            {
                _esapiApp = VMS.TPS.Common.Model.API.Application.CreateApplication();
                _patient  = _esapiApp.OpenPatientById(e.Args.First().Split(';').First().Trim('\"'));
                _course   = _patient.Courses.FirstOrDefault(x => x.Id == e.Args.First().Split(';').ElementAt(1));
                if (e.Args.FirstOrDefault().Split(';').Count() > 2)
                {
                    _plan = _course.PlanSetups.FirstOrDefault(x => x.Id == e.Args.First().Split(';').Last());
                }
            }
            catch
            {
                _course = null;
                _plan   = null;
            }
            var bootStrapper = new Bootstrapper();
            var container    = bootStrapper.Bootstrap(_patient, _course, _plan);

            mv = container.Resolve <MainView>();
            mv.ShowDialog();
        }
Ejemplo n.º 18
0
 public Patient abrirPaciente(string ID)
 {
     return(app.OpenPatientById(ID));
 }
Ejemplo n.º 19
0
        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;
            }
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 21
0
        //static string[] HCaux = File.ReadAllLines("lista.txt");
        //string[] datosAExportar = new string[HCaux.Count()];


        public Form1()
        {
            InitializeComponent();

            Patient paciente = app.OpenPatientById("1-89080-0");
            //Patient paciente = app.OpenPatientById("1-83694-0");
            string texto = "";
            Course curso = paciente.Courses.Where(C => C.Id.Contains("C0")).First();

            //Course curso = paciente.Courses.Where(C => C.Id.Contains("C2")).First();
            foreach (PlanSetup plan in curso.PlanSetups)
            {
                //PlanSetup plan = curso.PlanSetups.Where(p => p.Id.Contains("falla")).First();
                texto += "\n" + plan.Id;
                foreach (Beam campo in plan.Beams)
                {
                    bool hayDiferencia = false;
                    if (campo.ControlPoints.Count > 2)
                    {
                        float[]  valores    = new float[campo.ControlPoints.Count()];
                        double[] valoresDif = new double[campo.ControlPoints.Count() - 1];

                        for (int i = 0; i < 60; i++)
                        {
                            for (int j = 0; j < 2; j++)
                            {
                                for (int cp = 0; cp < campo.ControlPoints.Count(); cp++)
                                {
                                    valores[cp] = Math.Abs(campo.ControlPoints[cp].LeafPositions[j, i]);
                                    if (cp != 0)
                                    {
                                        valoresDif[cp - 1] = Math.Abs(Math.Round(valores[cp] - valores[cp - 1], 2));
                                    }
                                }
                                var max = valores.Max();
                                var min = valores.Min();
                                if (valores.Max() > 0)
                                {
                                    //if (valoresDif.Max() > 1)
                                    if (Math.Round(max - min, 5) >= 1)
                                    {
                                        hayDiferencia = true;
                                        texto        += "\n" + campo.Id + "hay movimiento de más de 1mm en lámina (" + j.ToString() + "," + i.ToString() + ") " + Math.Round(max - min, 5).ToString();
                                        break;
                                    }
                                }
                                if (Math.Round(max - min, 1) > 1)
                                {
                                }
                            }
                            if (hayDiferencia)
                            {
                                break;
                            }
                        }
                        if (!hayDiferencia)

                        {
                            texto += "\n" + campo.Id + " no hay movimiento de láminas";
                        }
                    }
                    else
                    {
                        texto += "\n" + campo.Id + "tiene menos de dos controlPoints";
                    }
                }
            }
            MessageBox.Show(texto);
        }