public SaveObjectiveFunctionsViewModel(string objectiveFunctionsJson, string defaultDirectoryPath) { DefaultDirectoryPath = defaultDirectoryPath; var objectiveFunctionsJObject = JObject.Parse(objectiveFunctionsJson); var objectiveFunctionArguments = (JArray)objectiveFunctionsJObject["Arguments"]; ObjectiveFunctions.Clear(); foreach (var a in objectiveFunctionArguments) { var jObject = JObject.Parse(a.ToString()); ObjectiveFunctions.Add(new Models.ObjectiveFunction(jObject)); } var prescriptionsJArray = (JArray)objectiveFunctionsJObject["Prescriptions"]; var PrescriptionsAll = prescriptionsJArray.ToObject <List <Models.Prescription> >(); Prescriptions.Clear(); foreach (var p in PrescriptionsAll) { if (ObjectiveFunctions.Where(o => (o.PlanLabel == p.PlanLabel)).Count() > 0) { Prescriptions.Add(p); } } OkCommand = new DelegateCommand(() => { CanExecute = true; }); CancelCommand = new DelegateCommand(() => { CanExecute = false; }); SaveFileCommand = new DelegateCommand(SaveFile); }
private void SetObjectiveFunctionArguments() { foreach (var r in Rois) { if (!r.InUse || r.NameInObjectiveFunction == RoiNameNone) { continue; } var query = ObjectiveFunctions.Where(o => (o.InUse && o.RoiName == r.NameInObjectiveFunction)); if (query.Count() == 0) { continue; } foreach (var o in query) { var planLabelQuery = PlanLabels.Where(p => p.LabelInObjectiveFunction == o.PlanLabel); string newLabel = string.Empty; if (planLabelQuery.Count() > 0) { var newPlanLabel = planLabelQuery.First(); bool inUse = newPlanLabel.InUse; if (!inUse) { continue; } newLabel = newPlanLabel.Label; if (planLabelQuery.Count() >= 2) { Message = $"Multiple plans are assigned to {o.PlanLabel}. Use {newLabel}."; } o.SetPlanLabelInArguments(newLabel); } else if (!(o.PlanLabel == PlanLabelCombinedDose)) { continue; } o.UpdateWeightInArguments(); o.SetRoiNameInArguments(r.Name); if (o.PlanLabel == PlanLabelCombinedDose) { if (!DoesUseCombinedDose) { continue; } newLabel = PlanLabelCombinedDose; } var prescriptionQuery = Prescriptions.Where(p => p.PlanLabel == o.PlanLabel); double scale = 0; if (prescriptionQuery.Count() == 0) { scale = 1.0; Message = $"Prescription does not exist for new: {newLabel} and original: {o.PlanLabel}"; } else { var prescription = prescriptionQuery.First(); var originalPrescribedDose = prescription.PrescribedDoseInObjectiveFunction; var prescribedDose = prescription.PrescribedDose; if (DoesRescaleDose) { if (originalPrescribedDose == 0) { Message = $"No rescale because the original prescribed dose = 0"; scale = 1.0; } else { scale = prescribedDose / originalPrescribedDose; } } } var functionType = o.Arguments["FunctionType"].ToObject <string>(); if (functionType == "DoseFallOff") { var highDoseLevel = scale * o.Arguments["HighDoseLevel"].ToObject <double>(); var lowDoseLevel = scale * o.Arguments["LowDoseLevel"].ToObject <double>(); o.Arguments["HighDoseLevel"] = highDoseLevel; o.Arguments["LowDoseLevel"] = lowDoseLevel; } else if (functionType == "UniformDose" || functionType == "MaxDose" || functionType == "MinDose" || functionType == "MaxEud" || functionType == "MinEud" || functionType == "MaxDvh" || functionType == "MinDvh") { var doseLevel = scale * o.Arguments["DoseLevel"].ToObject <double>(); o.Arguments["DoseLevel"] = doseLevel; } r.ObjectiveFunctionArguments.Add(o.Arguments.ToString()); } } }