static public ObservableCollection <StructureViewModel> GetStructureList(StructureSet structureSet) { var StructureList = new ObservableCollection <StructureViewModel>(); foreach (Structure structure in structureSet.Structures) { if (!structure.IsEmpty && structure.DicomType != "SUPPORT") { var structureViewModel = new StructureViewModel(structure); StructureList.Add(structureViewModel); } } var StructureComboBoxList = new ObservableCollection <StructureViewModel>(StructureList.OrderBy(x => x.StructureName)); return(StructureComboBoxList); }
public string CalculateMetricDose(Patient patient, string courseId, string planId, string structureId, string structureCode, string dvhObjective) { var plan = Extensions.GetPlanningItem(patient, courseId, planId); var planVM = new PlanningItemViewModel(plan); Structure structure; if (structureCode == null) { structure = Extensions.GetStructureFromId(plan, structureId); } else { structure = Extensions.GetStructureFromCode(plan, structureCode); } var structureVM = new StructureViewModel(structure); string metric = dvhObjective; string result = _metricCalc.CalculateMetric(planVM.PlanningItemStructureSet, structureVM, planVM, metric); return(result); }
public string CalculateMetric(StructureSet structureSet, StructureViewModel evalStructure, PlanningItemViewModel planningItem, string DVHObjective) { //start with a general regex that pulls out the metric type and the @ (evalunit) part. string pattern = @"^(?<type>[^\[\]]+)(\[(?<evalunit>[^\[\]]+)\])$"; string minmaxmean_Pattern = @"^(M(in|ax|ean)|Volume)$"; //check for Max or Min or Mean or Volume string d_at_v_pattern = @"^D(?<evalpt>\d+\p{P}\d+|\d+)(?<unit>(%|cc))$"; // matches D95%, D2cc string dc_at_v_pattern = @"^DC(?<evalpt>\d+)(?<unit>(%|cc))$"; // matches DC95%, DC700cc string v_at_d_pattern = @"^V(?<evalpt>\d+\p{P}\d+|\d+)(?<unit>(%|Gy|cGy))$"; // matches V98%, V40Gy string cv_at_d_pattern = @"^CV(?<evalpt>\d+)(?<unit>(%|Gy|cGy))$"; // matches CV98%, CV40Gy // Max[Gy] D95%[%] V98%[%] CV98%[%] D2cc[Gy] V40Gy[%] string cn_pattern = @"^CN(?<evalpt>\d+\p{P}\d+|\d+)(?<unit>(%|Gy|cGy))$"; //matches CN50% string gi_pattern = @"^GI(?<evalpt>\d+\p{P}\d+|\d+)(?<unit>(%|Gy|cGy))$"; //matches GI50% //Structure evalStructure = ; if (evalStructure == null) { return("Structure not found"); } //start with a general regex that pulls out the metric type and the [evalunit] part. var matches = Regex.Matches(DVHObjective, pattern); if (matches.Count != 1) { return(string.Format("DVH Objective expression \"{0}\" is not a recognized expression type.", DVHObjective)); } Match m = matches[0]; Group type = m.Groups["type"]; Group evalunit = m.Groups["evalunit"]; Console.WriteLine("expression {0} => type = {1}, unit = {2}", DVHObjective, type.Value, evalunit.Value); // further decompose <type> var testMatch = Regex.Matches(type.Value, minmaxmean_Pattern); if (testMatch.Count != 1) { testMatch = Regex.Matches(type.Value, v_at_d_pattern); if (testMatch.Count != 1) { testMatch = Regex.Matches(type.Value, d_at_v_pattern); if (testMatch.Count != 1) { testMatch = Regex.Matches(type.Value, cv_at_d_pattern); if (testMatch.Count != 1) { testMatch = Regex.Matches(type.Value, dc_at_v_pattern); if (testMatch.Count != 1) { testMatch = Regex.Matches(type.Value, cn_pattern); if (testMatch.Count != 1) { testMatch = Regex.Matches(type.Value, gi_pattern); if (testMatch.Count != 1) { return(string.Format("DVH Objective expression \"{0}\" is not a recognized expression type.", DVHObjective)); } else { // we have Gradient Index pattern return(PQMGradientIndex.GetGradientIndex(structureSet, planningItem, evalStructure, testMatch, evalunit)); } } else { // we have Conformation Number pattern return(PQMConformationNumber.GetConformationNumber(structureSet, planningItem, evalStructure, testMatch, evalunit)); } } else { // we have Covered Dose at Volume pattern return(PQMCoveredDoseAtVolume.GetCoveredDoseAtVolume(structureSet, planningItem, evalStructure, testMatch, evalunit)); } } else { // we have Covered Volume at Dose pattern return(PQMCoveredVolumeAtDose.GetCoveredVolumeAtDose(structureSet, planningItem, evalStructure, testMatch, evalunit)); } } else { // we have Dose at Volume pattern return(PQMDoseAtVolume.GetDoseAtVolume(structureSet, planningItem, evalStructure, testMatch, evalunit)); } } else { // we have Volume at Dose pattern return(PQMVolumeAtDose.GetVolumeAtDose(structureSet, planningItem, evalStructure, testMatch, evalunit)); } } else { // we have Min, Max, Mean, or Volume return(PQMMinMaxMean.GetMinMaxMean(structureSet, planningItem, evalStructure, testMatch, evalunit, type)); } }
public void GetPQMSummaries(ConstraintViewModel constraintPath, PlanningItemViewModel planningItem, Patient patient) { PqmSummaries = new ObservableCollection <PQMSummaryViewModel>(); StructureSet structureSet = planningItem.PlanningItemStructureSet; Structure evalStructure; ObservableCollection <PQMSummaryViewModel> pqmSummaries = new ObservableCollection <PQMSummaryViewModel>(); ObservableCollection <StructureViewModel> foundStructureList = new ObservableCollection <StructureViewModel>(); var calculator = new PQMSummaryCalculator(); Objectives = calculator.GetObjectives(constraintPath); if (planningItem.PlanningItemObject is PlanSum) { var waitWindowPQM = new WaitWindowPQM(); PlanSum plansum = (PlanSum)planningItem.PlanningItemObject; if (plansum.IsDoseValid() == true) { waitWindowPQM.Show(); foreach (PQMSummaryViewModel objective in Objectives) { evalStructure = calculator.FindStructureFromAlias(structureSet, objective.TemplateId, objective.TemplateAliases, objective.TemplateCodes); if (evalStructure != null) { var evalStructureVM = new StructureViewModel(evalStructure); var obj = calculator.GetObjectiveProperties(objective, planningItem, structureSet, evalStructureVM); PqmSummaries.Add(obj); NotifyPropertyChanged("Structure"); } } waitWindowPQM.Close(); } } if (planningItem.PlanningItemObject is PlanSetup) //is plansetup { var waitWindowPQM = new WaitWindowPQM(); PlanSetup planSetup = (PlanSetup)planningItem.PlanningItemObject; if (planSetup.IsDoseValid() == true) { waitWindowPQM.Show(); foreach (PQMSummaryViewModel objective in Objectives) { evalStructure = calculator.FindStructureFromAlias(structureSet, objective.TemplateId, objective.TemplateAliases, objective.TemplateCodes); if (evalStructure != null) { if (evalStructure.Id.Contains("PTV") == true) { foreach (Structure s in structureSet.Structures) { if (s.Id == planSetup.TargetVolumeID) { evalStructure = s; } } } var evalStructureVM = new StructureViewModel(evalStructure); var obj = calculator.GetObjectiveProperties(objective, planningItem, structureSet, evalStructureVM); PqmSummaries.Add(obj); NotifyPropertyChanged("Structure"); } } waitWindowPQM.Close(); } } }
// public ObservableCollection<Structure> FindMatchingStructures(ConstraintViewModel constraintVM, StructureSet structureSet) // { // PQMSummaryViewModel[] m_objectives = GetObjectives(constraintVM); // var evalStructureList = new ObservableCollection<Structure>(); //int i = 0; // foreach (var objective in m_objectives) // { // Structure evalStructure = FindStructureFromAlias(structureSet, objective.TemplateId, objective.TemplateAliases, objective.TemplateCodes); //objective.Structure = evalStructure; // evalStructureList.Add(evalStructure); //i++; // } // return evalStructureList; // } public PQMSummaryViewModel GetObjectiveProperties(PQMSummaryViewModel objective, PlanningItemViewModel planningItemVM, StructureSet structureSet, StructureViewModel evalStructure) { objective.ActivePlanningItem = planningItemVM; PlanningItem planningItem = planningItemVM.PlanningItemObject; if (evalStructure == null) { objective.Achieved = "Structure not found or empty."; objective.isCalculated = false; objective.StructureList = StructureSetListViewModel.GetStructureList(structureSet); return(objective); } else { objective.isCalculated = true; objective.Structure = evalStructure; objective.StructureName = evalStructure.StructureName; objective.StructVolume = evalStructure.VolumeValue; //objective.StructureNameWithCode = evalStructure.StructureNameWithCode; NotifyPropertyChanged("Structure"); objective.StructureList = StructureSetListViewModel.GetStructureList(structureSet); return(objective); } }