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(); } }
private void ChooseFile(DvhObjectivesViewModel dvhObjectivesViewModel) { var dialog = new OpenFileDialog { Title = "Choose file", Filter = "CSV file (*.csv)|*.csv", InitialDirectory = Path.Combine(DvhCheckerDirectoryPath, "templates") }; if (dialog.ShowDialog() == true) { ProtocolFilePath = dialog.FileName; } else { ProtocolFilePath = string.Empty; Message = "\"Choose file\" is canceled"; return; } dvhObjectivesViewModel.DvhObjectives = new ObservableCollection <DvhObjective>(DvhObjective.ReadObjectivesFromCsv(ProtocolFilePath)); var dvhObjectives = dvhObjectivesViewModel.DvhObjectives; if (!StructureNames.Contains(StructureNameNone)) { StructureNames.Insert(0, StructureNameNone); } foreach (var o in dvhObjectives) { if (StructureNames.Contains(o.StructureName)) { o.StructureNameTps = o.StructureName; o.InUse = true; } else { o.StructureNameTps = StructureNameNone; } } if (dvhObjectives.Count > 0) { dvhObjectivesViewModel.ProtocolId = dvhObjectives[0].ProtocolId; } }