public void SelectDvhObjectivesViewModel(string planId) { var query = DvhObjectivesViewModels.Where(d => d.PlanId == planId); if (query.Count() == 1) { SelectedDvhObjectivesViewModel = query.Single(); } }
private void SetDvhObjectivesViewModels(List <Models.PlanPrescription> planPrescriptions) { foreach (var p in planPrescriptions) { var dvhObjectivesViewModel = new DvhObjectivesViewModel { NumberOfFractions = p.NumberOfFractions, PlanId = p.PlanId, PrescribedDose = p.PrescribedDose }; dvhObjectivesViewModel.ChooseFileCommand = new DelegateCommand <DvhObjectivesViewModel>(ChooseFile); dvhObjectivesViewModel.StructureNames = StructureNames; string planFolderPath = Path.Combine(PlanCheckerDirectoryPath, Path.Combine(PatientId, Path.Combine(p.PlanId, "PlanCheckData"))); string filePath = Path.Combine(planFolderPath, "DvhObjectives.json"); if (File.Exists(filePath)) { string json; using (FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (StreamReader sr = new StreamReader(fs, Encoding.GetEncoding("shift_jis"))) { json = sr.ReadToEnd(); } var jObject = JObject.Parse(json); var dvhObjectivesJarray = (JArray)jObject["DvhObjectives"]; var dvhObjectives = dvhObjectivesJarray.ToObject <ObservableCollection <DvhObjective> >(); dvhObjectivesViewModel.DvhObjectives = dvhObjectives; dvhObjectivesViewModel.PrescribedDose = jObject["PrescribedDose"].ToObject <double>(); dvhObjectivesViewModel.CourseId = jObject["CourseId"].ToObject <string>(); dvhObjectivesViewModel.ProtocolId = jObject["ProtocolId"].ToObject <string>(); //var dvhObjectives = JsonConvert.DeserializeObject<List<DvhObjective>>(json); //dvhObjectivesViewModel.DvhObjectives = new ObservableCollection<DvhObjective>(dvhObjectives); } DvhObjectivesViewModels.Add(dvhObjectivesViewModel); } if (DvhObjectivesViewModels.Count > 0) { SelectedDvhObjectivesViewModel = DvhObjectivesViewModels.First(); } }