Ejemplo n.º 1
0
        public void Run(
            User user,
            Patient patient,
            Common.Model.API.Image image,
            StructureSet structureSet,
            PlanSetup planSetup,
            IEnumerable <PlanSetup> planSetupsInScope,
            IEnumerable <PlanSum> planSumsInScope,
            Window mainWindow)
        {
            // Your main code now goes here

            UserControl optimalFluenceView = new OptimalFluenceView();

            optimalFluenceView.DataContext = new OptimalFluenceViewModel(planSetup.Beams);
            mainWindow.Width   = 400;
            mainWindow.Height  = 600;
            mainWindow.Content = optimalFluenceView;
        }
Ejemplo n.º 2
0
        public void Execute(ScriptContext context, System.Windows.Window window, ScriptEnvironment environment)
        {
            // Retrieve the count of plans displayed in Scope Window
            int scopePlanCount = context.PlansInScope.Count();

            if (scopePlanCount == 0)
            {
                MessageBox.Show("Scope Window does not contain any plans.");
                return;
            }

            // Retrieve names for different types of plans
            List <string> externalPlanIds = new List <string>();
            List <string> brachyPlanIds   = new List <string>();
            List <string> protonPlanIds   = new List <string>();

            foreach (var ps in context.PlansInScope)
            {
                // KK: "is" compares the type. Equiv to ps.GetType() == typeof(BrachyPlanSetup))
                if (ps is BrachyPlanSetup)
                {
                    brachyPlanIds.Add(ps.Id);
                }
                else if (ps is IonPlanSetup)
                {
                    protonPlanIds.Add(ps.Id);
                }
                else
                {
                    externalPlanIds.Add(ps.Id);
                }
            }

            // Construct output message
            string message = string.Format("Hello {0}, the number of plans in Scope Window is {1}.",
                                           context.CurrentUser.Name,
                                           scopePlanCount);

            if (externalPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are external beam plans.", string.Join(", ", externalPlanIds));
            }
            if (brachyPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are brachytherapy plans.", string.Join(", ", brachyPlanIds));
            }
            if (protonPlanIds.Count > 0)
            {
                message += string.Format("\nPlan(s) {0} are proton plans.", string.Join(", ", protonPlanIds));
            }

            // Display additional information. Use the active plan if available.
            PlanSetup plan = context.PlanSetup != null ? context.PlanSetup : context.PlansInScope.ElementAt(0);

            message += string.Format("\n\nAdditional details for plan {0}:", plan.Id);

            // Access the structure set of the plan
            if (plan.StructureSet != null)
            {
                Common.Model.API.Image image = plan.StructureSet.Image;
                var structures = plan.StructureSet.Structures;
                message += string.Format("\n* Image ID: {0}", image.Id);
                message += string.Format("\n* Size of the Structure Set associated with the plan: {0}.", structures.Count());

                string structureNames = "";
                foreach (var s in structures)
                {
                    structureNames += String.Format("\n\t{0}: volume is {1:F2} cc.", s.Id, s.Volume);
                }
                message += structureNames;
            }


            message += string.Format("\n* Number of Fractions: {0}.", plan.NumberOfFractions);

            message += string.Format("\n \t Dose per Fraction: {0}.", plan.DosePerFraction);

            // Handle brachytherapy plans separately from external beam plans
            if (plan is BrachyPlanSetup)
            {
                BrachyPlanSetup brachyPlan      = (BrachyPlanSetup)plan;
                var             catheters       = brachyPlan.Catheters;
                var             seedCollections = brachyPlan.SeedCollections;
                message += string.Format("\n* Number of Catheters: {0}.", catheters.Count());
                message += string.Format("\n* Number of Seed Collections: {0}.", seedCollections.Count());
            }
            else
            {
                var beams = plan.Beams;
                message += string.Format("\n* Number of Beams: {0}.", beams.Count());

                string beamNames = "";
                foreach (var b in beams.OrderBy(x => x.BeamNumber))
                {
                    beamNames += String.Format("\n\t{0} has {1} MU.", b.Id, b.Meterset.Value);
                }
                message += beamNames;
            }
            if (plan is IonPlanSetup)
            {
                IonPlanSetup ionPlan = plan as IonPlanSetup;
                IonBeam      beam    = ionPlan.IonBeams.FirstOrDefault();
                if (beam != null)
                {
                    message += string.Format("\n* Number of Lateral Spreaders in first beam: {0}.", beam.LateralSpreadingDevices.Count());
                    message += string.Format("\n* Number of Range Modulators in first beam: {0}.", beam.RangeModulators.Count());
                    message += string.Format("\n* Number of Range Shifters in first beam: {0}.", beam.RangeShifters.Count());
                }
            }

            //MessageBox.Show(message);
            window.Background = Brushes.Blue;
            window.Content    = new TextBlock
            {
                Foreground = Brushes.White,
                FontFamily = new FontFamily("Ariel"),
                FontSize   = 18,
                Text       = message
            };
            //window.Content = message;
        }
Ejemplo n.º 3
0
        public void Execute(ScriptContext context /*, System.Windows.Window window, ScriptEnvironment environment*/)
        {
            StructureSet ss        = context.StructureSet;
            PlanSetup    plan      = context.PlanSetup;
            PlanSum      planSum   = null;
            Dose         dose      = null;
            double       totalDose = -1;

            if (plan == null)
            {
                if (context.PlanSumsInScope.Count() == 0)
                {
                    MessageBox.Show("Plan and PlanSum not found");
                    return;
                }
                else if (context.PlanSumsInScope.Count() > 1)
                {
                    MessageBox.Show(string.Format("{0} PlanSums are in scope. Close all but the PlunSums that are currently open.", context.PlanSumsInScope.Count()));
                    return;
                }
                else
                {
                    planSum = context.PlanSumsInScope.First();
                    ss      = planSum.StructureSet;
                    //planSum.DoseValuePresentation = DoseValuePresentation.Relative;
                    dose = planSum.Dose;
                    foreach (var ps in planSum.PlanSetups)
                    {
#if ESAPI_V15
                        DoseValue TotalDose = ps.TotalDose;
#else
                        DoseValue TotalDose = ps.TotalPrescribedDose;
#endif
                        var val = TotalDose.Dose;
                        if (TotalDose.Unit == DoseValue.DoseUnit.cGy)
                        {
                            val /= 100;
                        }
                        totalDose += val;
                    }
                }
            }
            else
            {
                plan.DoseValuePresentation = DoseValuePresentation.Relative;
                dose = plan.Dose;
#if ESAPI_V15
                DoseValue TotalDose = plan.TotalDose;
#else
                DoseValue TotalDose = plan.TotalPrescribedDose;
#endif
                totalDose = TotalDose.Dose;
                if (TotalDose.Unit == DoseValue.DoseUnit.cGy)
                {
                    totalDose /= 100;
                }
            }
            if (dose == null)
            {
                MessageBox.Show("Dose not found");
                return;
            }
            if (ss == null)
            {
                MessageBox.Show("StructureSet not found");
                return;
            }
            Common.Model.API.Image img = ss.Image;
            if (img == null)
            {
                MessageBox.Show("Image not found");
                return;
            }
            double dz = img.ZRes;
            // Grid 0:Menu 1:SurfaceView
            Grid grid = new Grid();
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions.Add(new RowDefinition());
            grid.RowDefinitions[0].Height = GridLength.Auto;
            grid.RowDefinitions[1].Height = new GridLength(1.0, GridUnitType.Star);
            // Menu
            Menu     menu        = new Menu();
            MenuItem menu_option = new MenuItem()
            {
                Header = "Option(_O)"
            };
            RadioButton radioButton1 = new RadioButton()
            {
                Content = "Outer Surface View"
            };
            RadioButton radioButton2 = new RadioButton()
            {
                Content = "Inner Surface View"
            };
            radioButton1.Checked   += RadioButton1_Checked;
            radioButton2.Checked   += RadioButton2_Checked;
            radioButton1.Foreground = Brushes.Black;
            radioButton2.Foreground = Brushes.Black;
            menu_option.Items.Add(radioButton1);
            menu_option.Items.Add(radioButton2);
            menu.Items.Add(menu_option);
            grid.Children.Add(menu);
            menu.SetValue(Grid.RowProperty, 0);
            // SurfaceView
            surfaceView = new SurfaceView(dose, ss, totalDose, dz);
            grid.Children.Add(surfaceView);
            surfaceView.SetValue(Grid.RowProperty, 1);
            surfaceView.SetViewMode(1);
            radioButton1.IsChecked = true;
            // Main Window
            window         = new Window();
            window.Content = grid;
            window.Title   = "Surface Dose on Selected ROI";
            window.ShowDialog();
        }