예제 #1
0
 // Create and evaluate plan-specific StructureObjectiveResults list
 public void ComputeResults(List <StructureObjective> objectives)
 {
     foreach (StructureObjective objective in objectives)
     {
         StructureObjectiveResult planObjective = new StructureObjectiveResult {
             Objective = objective, Plan = PlanningItem
         };
         planObjective.EvaluateObjective(StructureSetDict);
         StructureObjectiveResults.Add(planObjective);
     }
 }
예제 #2
0
        // Update Workbook and Header. Works for multiple plans.
        private List <string[]> UpdateWorkbook(List <string[]> CSVsheet, List <PlanResult> planResults)
        {
            // Update header: Remove StructureCode, Aliases, Met, Achieved. Rename Variation.
            CSVHeader = new List <string> {
                "StructureName", "DVHObjective", "Evaluator", "Variation", "Priority"
            };
            foreach (PlanResult planResult in planResults) // Add headers for each plan for Met, Achieved, Warnings
            {
                CSVHeader.Add(string.Format("Met {0}:{1}", planResult.CourseName, planResult.PlanName));
                CSVHeader.Add(string.Format("Achieved {0}:{1}", planResult.CourseName, planResult.PlanName));
                CSVHeader.Add(string.Format("Warnings {0}:{1}", planResult.CourseName, planResult.PlanName));
            }

            // Headers are now:
            // [0]StructureName [1]DVH Objective [2]Evaluator [3]Variation [4] Priority [5]Met1 [6]Achieved1 [7]Met2 [8]Achieved2 .....

            int             row        = 0;
            List <string[]> Calculated = new List <string[]>();

            foreach (StructureObjective DVHObjective in Objectives)
            {
                List <string> line = new List <string>();
                line.Add(DVHObjective.ID);
                line.Add(DVHObjective.DVHObjective == "Parsing Error" ? "" : DVHObjective.DVHObjective);
                line.Add(DVHObjective.Evaluator);
                line.Add(DVHObjective.Variation);
                line.Add(DVHObjective.Priority);

                // If everything is blank except the first column, it's probably a subheading (e.g.: "Initial" or "CD" for breast). Ignore it.
                bool allIsBlank = string.IsNullOrEmpty(DVHObjective.DVHObjective) &&
                                  string.IsNullOrEmpty(DVHObjective.Evaluator) &&
                                  string.IsNullOrEmpty(DVHObjective.Variation) &&
                                  string.IsNullOrEmpty(DVHObjective.Priority);

                // Loop through Plans for Met/Achieved/Warnings
                foreach (PlanResult planResult in planResults)
                {
                    if (allIsBlank)
                    {
                        line.Add("");
                        line.Add("");
                        line.Add("");
                        continue;
                    }
                    StructureObjectiveResult objective = planResult.StructureObjectiveResults.Where(x => x.Objective.Equals(DVHObjective)).First();
                    line.Add(objective.Met);
                    line.Add(objective.Achieved);
                    line.Add(string.Join(",", objective.Warnings.Select(x => WarningDictionary[x]).OrderBy(x => int.Parse(x)))); //Add codes for all warnings
                }
                Calculated.Add(line.ToArray());
                row++;
            }
            // Save the CSV if necessary
            if (!string.IsNullOrEmpty(CSVSaveLocation))
            {
                // Make temporary changes to the CSV (that we don't want propogating to HTML)
                List <string[]> tmp = new List <string[]>(Calculated.Select(x => x.Clone() as string[]));
                tmp.Insert(0, CSVHeader.ToArray());
                string[] anEmptyLine = new string[] { "" };
                tmp.Add(anEmptyLine);
                tmp.Add(anEmptyLine);
                tmp.Add(new string[] { "Warnings: " });
                foreach (KeyValuePair <string, string> w in WarningDictionary)
                {
                    tmp.Add(new string[] { string.Format("{0}: {1}", w.Value, w.Key) });
                }

                File.WriteAllLines(CSVSaveLocation, tmp.Select(x => string.Join(",", x.Select(y => y.Replace(",", ";")))));
                MessageBox.Show("Data successfully saved to " + CSVSaveLocation + ".");
            }

            return(Calculated);
        }