public PlanChooserView(PlanChooserViewModel viewModel)
 {
     InitializeMaterialDesign();
     InitializeComponent();
     ViewModel        = viewModel;
     base.DataContext = ViewModel;
 }
Beispiel #2
0
        // Main Program
        // Reads in the CSV file and saves as a list of StructureObjective objects
        // For each plan, creates a PlanResults object
        public void InitializeViewModel()
        {
            // Read in the objectives. The same objectives are used for all plans
            CreateObjectives();

            // Add plans to check
            // Determine whether this is a standard DVHEvaluator ("singlePlan"), Plan Comparison tool ("planComparison"), or debugging ("debug") situation
            switch (Mode)
            {
            case "singlePlan":
                // Validate context and add it to plan.
                PlanResult contextPlanResult = ValidateContext();
                Results.Add(contextPlanResult);
                break;

            case "planComparison":
                // Open GUI to allow user to choose plans
                PlanChooserViewModel planChooserViewModel = new PlanChooserViewModel(this);
                if (planChooserViewModel.ChosenPlans.Any())
                {
                    planChooserViewModel.ChosenPlans.ForEach(x => Results.Add(AddPlan(x)));
                }
                // If no plan, exit. Error-handling is dealth with in the GUI.
                else
                {
                    return;
                }

                break;

            case "debug":
                // Load all plans in scope
                ContextPlanSetupsInScope.ToList().ForEach(x => Results.Add(AddPlan(x)));
                ContextPlanSumsInScope.ToList().ForEach(x => Results.Add(AddPlan(x)));
                break;

            default:
                throw new ApplicationException(string.Format("Chosen mode '{0}' does not exist.", Mode));
            }

            // Reorder results by given convention
            ReOrderResults();

            // Compute results for all plans
            Results.ForEach(x => x.ComputeResults(Objectives));

            // Find all unique warnings in the plan and assign codes to them.
            List <string> warn = (from res in Results
                                  from s in res.StructureObjectiveResults
                                  from w in s.Warnings
                                  select w).ToList().Distinct().ToList();

            foreach (int i in Enumerable.Range(1, warn.Count))
            {
                WarningDictionary.Add(warn[i - 1], i.ToString());
            }

            // Check plan ID for invalid filename characters and delete if present
            string regexSearch  = new string(System.IO.Path.GetInvalidFileNameChars()) + new string(System.IO.Path.GetInvalidPathChars());
            Regex  r            = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch)));
            string strPlanId    = r.Replace(Results.First().PlanningItem.Id.ToString(), "_");
            string strPatientId = r.Replace(Results.First().Patient.Id.ToString(), "_");
            string outputpath   = System.IO.Path.Combine(WORKBOOK_RESULT_DIR, strPatientId + "-" + strPlanId + "-" + DateTime.Now.ToString("yyyy-MM-dd-hh-mm-ss") + ".html");

            // Print to HTML and open it
            DataOut = UpdateWorkbook(CSVSheet, Results);
            DataTable table    = ConvertListToDataTable(DataOut, CSVHeader);
            string    HtmlBody = ExportToHtml(table);

            System.IO.File.WriteAllText(outputpath, HtmlBody);
            System.Diagnostics.Process.Start(outputpath);
        }